%
% prepare shf forcing file, merging in new SST's
%

% SST from /HECHT/POLES/PHC2_TEMP_gx3v4.nc
sst_in      = '/ptmp/klindsay/PHC2/PHC2_TEMP_gx3v4.nc';
forcing_in  = '/fs/cgd/csm/inputdata/ocn/pop/gx3v4/forcing/shf_20011030.ieeer8';
forcing_out = 'shf_20021217.ieeer8';

sst_fid         = netcdf(sst_in, 'nowrite');
forcing_in_fid  = fopen(forcing_in, 'r');
forcing_out_fid = fopen(forcing_out, 'w');

%
% read SST's from NetCDF & write to forcing_out file
%
for l=1:12,
   slab = transpose(sst_fid{'TEMP'}(l,1,:,:));
   fwrite(forcing_out_fid, slab, 'double');
end;

%
% copy other fields from forcing_in file to forcing_out file
% first skipping SST's in original forcing file
%
fseek(forcing_in_fid, 100*116*8*12, -1);
for field_ind=2:6,
   for l=1:12,
      slab = fread(forcing_in_fid, [100 116], 'double');
      fwrite(forcing_out_fid, slab, 'double');
   end;
end;

%
% close files
%
close(sst_fid);
fclose(forcing_in_fid);
fclose(forcing_out_fid);

%
% prepare sfwf forcing file, merging in new SSS's
%

% SSS from /HECHT/POLES/PHC2_salx_gx3v4.nc
sss_in      = '/ptmp/klindsay/PHC2/PHC2_salx_gx3v4.nc';
forcing_in  = '/fs/cgd/csm/inputdata/ocn/pop/gx3v4/forcing/sfwf_20011030.ieeer8';
forcing_out = 'sfwf_20021217.ieeer8';

sss_fid         = netcdf(sss_in, 'nowrite');
forcing_in_fid  = fopen(forcing_in, 'r');
forcing_out_fid = fopen(forcing_out, 'w');

%
% read SSS's from NetCDF & write to forcing_out file
%
for l=1:12,
   slab = transpose(sss_fid{'SALT'}(l,:,:));
   fwrite(forcing_out_fid, slab, 'double');
end;

%
% copy other fields from forcing_in file to forcing_out file
% first skipping SSS's in original forcing file
%
fseek(forcing_in_fid, 100*116*8*12, -1);
for field_ind=2:2,
   for l=1:12,
      slab = fread(forcing_in_fid, [100 116], 'double');
      fwrite(forcing_out_fid, slab, 'double');
   end;
end;

%
% close files
%
close(sss_fid);
fclose(forcing_in_fid);
fclose(forcing_out_fid);

