function MITprof=prep_prof(T,Terr,S,Serr,z,yr0,nrec,freq)

%untar unzip profilepackage_4Arash.tgz
%addpath('~/MITprof_toolbox');

% a few notes:
% where there's no data, use fillvalue = -9999 for prof_[T,S] and 0 (zero) for prof_[T,S]weight

dXspacing=5000.;
dYspacing=5000.;
deltaT=3600.0;

%Z=[0,cumsum(delZ)];	This is the same as RF.data

%read in the location of the single grid:
% dirGrid=[dirRoot 'run_ad_run02/'];
XC = 2500;%readbin([dirGrid 'XC.data'],[1 1]);	%2500;
YC = 2500;%readbin([dirGrid 'YC.data'],[1 1]);	%2500
XG = 0;   %readbin([dirGrid 'XG.data'],[1 1]);	%0;
YG = 0;   %readbin([dirGrid 'YG.data'],[1 1]);	%0

RC = z;%  abs(readbin([dirGrid 'RC.data'],[1 23]));

a=[];

a.prof_depth=z;%[   5   15   25   35   45   55   65   75   85   95  105 ...
               %115  125  135  145  155  165  175  185  200  220  240 ...
               %260  280  300  320  340  360  380  400  420  440  460 ...
               %480  500  550  600  650  700  750  800  850  900  950 ...
              %1000 1100 1200 1300 1400 1500 1600 1700 1800 1900 2000 ...
              %2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 3100 ...
              %3200 3300 3400 3500 3600 3700 3800 3900 4000 4100 4200 ...
              %4300 4400 4500 4600 4700 4800 4900 5000]';		%[85 x 1]
L=length(a.prof_depth);

nprof=nrec;%2;

for i=1:nprof;
  a.prof_T(i,:)=T;%interp1(RC,tRef,a.prof_depth,'linear');	%"data"
  a.prof_S(i,:)=S;%interp1(RC,sRef,a.prof_depth,'linear');	%"data"

  a.prof_Tweight(i,:) = 1./(Terr.^2);%ones(1,L);	%data uncertainty 1/(sigmaT^2)
  a.prof_Sweight(i,:) = 1./(Serr.^2);%ones(1,L);	%data uncertainty 1/(sigmaS^2)

  a.prof_Terr(i,:)    = zeros(1,L);	%no additional errors 
  a.prof_Serr(i,:)    = zeros(1,L);	%no additional errors 

  a.prof_Testim(i,:)  = a.prof_T(i,:);	%climatology, only for cosmetic, not use by model
  a.prof_Sestim(i,:)  = a.prof_S(i,:);	%climatology, only for cosmetic, not use by model

  a.prof_Sflag(i,:) = 0;		% 0 is good, 1 is bad
  a.prof_Tflag(i,:) = 0;		% 0 is good, 1 is bad

  a.prof_lon(i,1)= XC;			% lon of data
  a.prof_lat(i,1)= YC;			% lat of data

  a.prof_point(i,1)=1;			% index of data pt in Model grid space

  a.prof_interp_lon(i,1) = XC; %% CHANGING THESE
  a.prof_interp_lat(i,1) = YC;
  a.prof_interp_XC11(i,1) = XC;		%lower-left corner of tiles, we only have 1 grid pt
  a.prof_interp_YC11(i,1) = YC;
  a.prof_interp_XCNINJ(i,1) = XG+dXspacing/2;%upper-right corner of tiles, we only have 1 grid pt
  a.prof_interp_YCNINJ(i,1) = YG+dYspacing/2;	
  
  a.prof_interp_i(i,1) = 1;		%only 1 grid pt
  a.prof_interp_j(i,1) = 1;		%only 1 grid pt

  a.prof_interp_weights(i,1) = 1;		%not sure what this is...
  a.prof_basin(i,1) = 0;			%cosmetic

%time: important: need to match with data.cal, at the moment, it's 19790101
  if(freq==24*3600);
    tmp=datenum(yr0,1,i);
    a.prof_date(i,1)=tmp;
    tmp=datevec(tmp);
    a.prof_YYYYMMDD(i,1)=tmp(1).*1e4+tmp(2).*1e2+tmp(3);
  else;					%assumes monthly for now
    tmp=datenum(yr0,i,15);
    a.prof_date(i,1)=tmp;
    tmp=datevec(tmp);
    a.prof_YYYYMMDD(i,1)=tmp(1).*1e4+tmp(2).*1e2+tmp(3);
  end;

  a.prof_HHMMSS(i,1) = 120000;

%description: should be of size [nprof,30], I forget how to define character array..
  a.prof_descr(i,:)=['prof no ' sprintf('%10.10i',i)];
end;

MITprof=a;

%
%a = 
%             prof_depth: [85x1 double]
%                 prof_T: [2x85 double]
%                 prof_S: [2x85 double]
%           prof_Tweight: [2x85 double]
%           prof_Sweight: [2x85 double]
%              prof_Terr: [2x85 double]
%              prof_Serr: [2x85 double]
%            prof_Testim: [2x85 double]
%            prof_Sestim: [2x85 double]
%             prof_Sflag: [2x1 double]
%             prof_Tflag: [2x1 double]
%               prof_lon: [2x1 double]
%               prof_lat: [2x1 double]
%             prof_point: [2x1 double]
%        prof_interp_lon: [2x1 double]
%        prof_interp_lat: [2x1 double]
%       prof_interp_XC11: [2x1 double]
%       prof_interp_YC11: [2x1 double]
%     prof_interp_XCNINJ: [2x1 double]
%     prof_interp_YCNINJ: [2x1 double]
%          prof_interp_i: [2x1 double]
%          prof_interp_j: [2x1 double]
%    prof_interp_weights: [2x1 double]
%             prof_basin: [2x1 double]
%          prof_YYYYMMDD: [2x1 double]
%            prof_HHMMSS: [2x1 double]
%              prof_date: [2x1 double]
%             prof_descr: [2x14 char]
