Skip to content

Commit

Permalink
update directory and file handling
Browse files Browse the repository at this point in the history
- By default: dir_model is where MITgcm directory where *.nc MITgcm
input files and profiles/*bin MITgcm output files are.
- Remove '*' or '.nc' from file names if included.
- Update list_model default and help section accordingly.
  • Loading branch information
gaelforget committed Dec 30, 2016
1 parent 41442dc commit db67478
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions MITprof_IO/MITprof_gcm2nc.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
function []=MITprof_gcm2nc(varargin);
%[]=MITprof_gcm2nc;
%[]=MITprof_gcm2nc;
%object: takes binary output from MITgcm/pkg/profiles (in dir_model)
% and recomposes a MITprof netcdf file (in dir_model/input)
%optional inputs:
% dir_model is the directory where the binary files are ('./' by default)
% list_model is the list of the corresponding MITprof files, which
% need to be copied or linked to dir_model/input
% ({'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'} by default)
%MITPROF_GCM2NC(dir_model,list_model);
%
%e.g. dir_model='./';
% list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
%object: reformat MITprof binary files from MITgcm into MITprof netcdf files
%
%inputs:
% dir_model is the directory where the binary files are ('./' by default). If dir_model is a cell containing
% two directory names then the first will be used for inputs whereas the second will be used for output.
% By assumption the input directory contains the nc files listed in list_model and a subdirectory called
% 'profiles/' that contains the corresponding binary files generated by MITgcm
% list_model is the list of the corresponding MITprof files; by default:
% {'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
% 'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'}
%
%example:
% MITprof_gcm2nc;
%or:
% dir_model='./';
% list_model={'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
% 'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'};
% MITprof_gcm2nc(dir_model,list_model);
%note:
% by assumption, dir_model contains the binaries,
% dir_model/input contains the matching MITprof file
% that was provided as input to MITgcm/pkg/profiles, and
% the recomposed MITprof file will be put in dir_model/output

warning off MATLAB:mir_warning_variable_used_as_function;

if nargin==2; dir_model=varargin{1}; list_model=varargin{2};
else;
dir_model='./';
list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
list_model={'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'};
end;

if iscell(dir_model);
Expand All @@ -35,18 +38,23 @@
dir_model=[dir_model{1} 'profiles/'];
else;
%the following assumes that
%dir_model is where MITgcm input and output files have been linked to dir_model (*.bin)
%and dir_model/input/ (*.nc) -- the new *.nc files will then be created in dir_model/output/
dir_out=[dir_model 'output/'];
dir_data=[dir_model 'input/'];
%dir_model is where MITgcm directory where *.nc MITgcm input files and profiles/*bin MITgcm output files are
%and where the new *model.nc files will then be created
dir_out=dir_model;
dir_data=dir_model;
dir_model=[dir_model 'profiles/'];
end;

%loop over files:
for ff=1:length(list_model)

fil_root=list_model{ff};
if strcmp(fil_root(end-2:end),'.nc'); fil_root=fil_root(1:end-3); end;
if strcmp(fil_root(end),'*'); fil_root=fil_root(1:end-1); end;

%initialize the process:
clear prof_*;
file_data=dir([dir_data list_model{ff} '*.nc']);
file_data=dir([dir_data fil_root '*.nc']);
file_data2=file_data.name;

%load the data:
Expand All @@ -66,7 +74,7 @@
nr=length(MITprof.prof_depth);

%list tile/processor model files:
eval(['model_list_model=dir(''' dir_model list_model{ff} '*.data'');']);
eval(['model_list_model=dir(''' dir_model fil_root '*.data'');']);

%if no model files then stop
if size(model_list_model,1)==0; fprintf(['file: ' file_data2 ' \n, no model files found\n']);
Expand Down

0 comments on commit db67478

Please sign in to comment.