% make salt and potential temperature climatologies
% for initialization and relaxation of global model

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% temperature climatology

% load and plot thetaLevCli file
% file created by Alistair for integrating a 4-degree global configuration
clear all, clf reset, cd /if7/dimitri/mitgcm/matlab
figure(1), plot_3D('/if7/dimitri/mitgcm/UV/exe/thetaLevCli',90,40,20,1)

% load levitus 97 climatology and save in mitgcm format
% that is remove fortran record indicators between each depth
load cgrid
nlon=length(lon); nlat=length(lat); ndpt=length(mdpt);
fin=fopen('/if7/medea/tlee/levitus97/T.c','r','b');
fout=fopen('thetaLevCli','w','b');
tmp=fwrite(fout,nlon*nlat*ndpt*4,'integer*8'); % fortran record length
for i=1:length(mdpt), disp(i)        % for each depth
  tmp=fread(fin,1,'integer*8');      % fortran record length in bytes
  if tmp ~= nlon*nlat*4, error('bad fortran record'), end
  fwrite(fout,fread(fin,[nlon nlat],'real*4'),'real*4');
  tmp=fread(fin,1,'integer*8');      % fortran record length in bytes
  if tmp ~= nlon*nlat*4, error('bad fortran record'), end
end
tmp=fwrite(fout,nlon*nlat*ndpt*4,'integer*8'); % fortran record length

tmp=fclose('all');
figure(2), plot_3D('thetaLevCli',lon,lat,mdpt,1)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% salt climatology

% load and plot saltLevCli file
% file created by Alistair for integrating a 4-degree global configuration
clear all, clf reset, cd /if7/dimitri/mitgcm/matlab
figure(1), plot_3D('/if7/dimitri/mitgcm/UV/exe/saltLevCli',90,40,20,1)

% load levitus 97 climatology and save in mitgcm format
% that is remove fortran record indicators between each depth
load cgrid
nlon=length(lon); nlat=length(lat); ndpt=length(mdpt);
fin=fopen('/if7/medea/tlee/levitus97/S.c','r','b');
fout=fopen('saltLevCli','w','b');
tmp=fwrite(fout,nlon*nlat*ndpt*4,'integer*8'); % fortran record length
for i=1:length(mdpt), disp(i)        % for each depth
  tmp=fread(fin,1,'integer*8');      % fortran record length in bytes
  if tmp ~= nlon*nlat*4, error('bad fortran record'), end
  fwrite(fout,fread(fin,[nlon nlat],'real*4'),'real*4');
  tmp=fread(fin,1,'integer*8');      % fortran record length in bytes
  if tmp ~= nlon*nlat*4, error('bad fortran record'), end
end
tmp=fwrite(fout,nlon*nlat*ndpt*4,'integer*8'); % fortran record length

tmp=fclose('all');
figure(2), plot_3D('saltLevCli',lon,lat,mdpt,1)
