% Read in the subset of SSTs, and write them in ASCII to a file
fname = 'EPIC_oi_2001_big_binary.dat'

missingv = -99;
% read from netcdf, data has cubic interp-filled coastlines
nc = netcdf('sst_fill_2001_big.nc');
time = nc{'time'}(:);
lon = nc{'lon'}(:);
lat = nc{'lat'}(:);
% reading all SST at once hogs too much memory
%sst = nc{'sst'}(:);
%sst(sst==nc{'sst'}.missing_value(:)) = missingv;
am = nc{'available_mask'}(1,:,:); % the same every day

fid = fopen(fname,'w','ieee-be');
% write the sst in the order (lon,lat,day)
for i = 1:length(time);
  sst = nc{'sst'}(i,:,:);
  sst(sst==nc{'sst'}.missing_value(:)) = missingv;
  fwrite(fid,sst,'single');
end
fid = fclose(fid);

nc = close(nc);

if 0 %%% a sample read: read 1st day
fid = fopen(fid,'r','ieee-be');
sst = reshape(fread(fid,644*248,'single'),644,248);
end