Skip to content

Commit db67478

Browse files
committed
update directory and file handling
- 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.
1 parent 41442dc commit db67478

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

MITprof_IO/MITprof_gcm2nc.m

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
function []=MITprof_gcm2nc(varargin);
2-
%[]=MITprof_gcm2nc;
3-
%[]=MITprof_gcm2nc;
4-
%object: takes binary output from MITgcm/pkg/profiles (in dir_model)
5-
% and recomposes a MITprof netcdf file (in dir_model/input)
6-
%optional inputs:
7-
% dir_model is the directory where the binary files are ('./' by default)
8-
% list_model is the list of the corresponding MITprof files, which
9-
% need to be copied or linked to dir_model/input
10-
% ({'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'} by default)
2+
%MITPROF_GCM2NC(dir_model,list_model);
113
%
12-
%e.g. dir_model='./';
13-
% list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
4+
%object: reformat MITprof binary files from MITgcm into MITprof netcdf files
5+
%
6+
%inputs:
7+
% dir_model is the directory where the binary files are ('./' by default). If dir_model is a cell containing
8+
% two directory names then the first will be used for inputs whereas the second will be used for output.
9+
% By assumption the input directory contains the nc files listed in list_model and a subdirectory called
10+
% 'profiles/' that contains the corresponding binary files generated by MITgcm
11+
% list_model is the list of the corresponding MITprof files; by default:
12+
% {'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
13+
% 'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'}
14+
%
15+
%example:
16+
% MITprof_gcm2nc;
17+
%or:
18+
% dir_model='./';
19+
% list_model={'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
20+
% 'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'};
1421
% MITprof_gcm2nc(dir_model,list_model);
15-
%note:
16-
% by assumption, dir_model contains the binaries,
17-
% dir_model/input contains the matching MITprof file
18-
% that was provided as input to MITgcm/pkg/profiles, and
19-
% the recomposed MITprof file will be put in dir_model/output
2022

2123
warning off MATLAB:mir_warning_variable_used_as_function;
2224

2325
if nargin==2; dir_model=varargin{1}; list_model=varargin{2};
2426
else;
2527
dir_model='./';
26-
list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
28+
list_model={'argo_feb2016_set1.nc','argo_feb2016_set2.nc','argo_feb2016_set3.nc','argo_feb2016_set4.nc','argo_feb2016_set5.nc',...
29+
'argo_feb2016_set6.nc','climode_jan2016.nc','ctd_jan2016.nc','itp_jan2016.nc','seals_jan2016.nc','xbt_jan2016.nc'};
2730
end;
2831

2932
if iscell(dir_model);
@@ -35,18 +38,23 @@
3538
dir_model=[dir_model{1} 'profiles/'];
3639
else;
3740
%the following assumes that
38-
%dir_model is where MITgcm input and output files have been linked to dir_model (*.bin)
39-
%and dir_model/input/ (*.nc) -- the new *.nc files will then be created in dir_model/output/
40-
dir_out=[dir_model 'output/'];
41-
dir_data=[dir_model 'input/'];
41+
%dir_model is where MITgcm directory where *.nc MITgcm input files and profiles/*bin MITgcm output files are
42+
%and where the new *model.nc files will then be created
43+
dir_out=dir_model;
44+
dir_data=dir_model;
45+
dir_model=[dir_model 'profiles/'];
4246
end;
4347

4448
%loop over files:
4549
for ff=1:length(list_model)
50+
51+
fil_root=list_model{ff};
52+
if strcmp(fil_root(end-2:end),'.nc'); fil_root=fil_root(1:end-3); end;
53+
if strcmp(fil_root(end),'*'); fil_root=fil_root(1:end-1); end;
4654

4755
%initialize the process:
4856
clear prof_*;
49-
file_data=dir([dir_data list_model{ff} '*.nc']);
57+
file_data=dir([dir_data fil_root '*.nc']);
5058
file_data2=file_data.name;
5159

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

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

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

0 commit comments

Comments
 (0)