% initialize things, define parameters (some from namlst)
ibyy=2001;
ibmm=5;
ibdd=8;
ibhh=0;
daysec=86400.0;
nht=2280;
dt = 450.0; % s

mdat = [31,28,31,30,31,30,31,31,30,31,30,31];

nday_sst=7; % weekly

nhr_sst=nday_sst*24;

dti=1.0/dt;
inhr=floor(3600.0/dt+0.5);
nttb=inhr;


% the matlab serial day of the data
DATA = datenum('3-jan-1990 12:00'):7:datenum('20-jan-2005');

%--------------------------------------------------------
%    to find the julian day to start this model simulation
%--------------------------------------------------------
kday=0;
ibmm0=1;

% first centered timestamp of the Reynolds SST
ibyy0sst=1990;
ibmm0sst=1;
ibdd0sst=3;
%ibhh0sst=12;

if(ibmm>ibmm0)
  for i=ibmm0:ibmm-1
    kday=kday+mdat(i);
  end
end
kday=kday+ibdd-1;

mtime=0;

  nt=mtime*3600/floor(dt+0.1);
  nhr=mtime;
  nt0=nt;
  nhr0=nhr;
  
  %%%   This is the timing in question
  % int() changed to floor() for matlab, real() eliminated
  nyear90=ibyy-ibyy0sst;
  kday_year=nyear90*365;
  kday_month=0;
  if(ibmm>ibmm0sst)
    for i=ibmm0sst:ibmm-1
      kday_month=kday_month+mdat(i);
    end
  end
  aday_model=3.75+(ibhh+mtime)/24.0; % HERE!
  kday_model=floor(aday_model);
  kdayt=kday_year+kday_month+kday_model+ibdd+nyear90/4;
  akss=kdayt/nday_sst;
  ksst=floor(akss);
  aday0=(akss-ksst)*nday_sst+(aday_model-kday_model);
  nday0=floor(aday0);
  dt_sst=aday0/nday_sst;
  % write(6,*) 'KSST, nday0,aday0,dt_sst ',ksst,nday0,aday0,dt_sst
  
  to = DATA(ksst);
  tn = DATA(ksst+1);
  
  % interpolate
  t=to+(tn-to)*dt_sst;

  datestr(t)