/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_gcm2nc.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_gcm2nc.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (hide annotations) (download)
Fri Dec 30 21:10:03 2016 UTC (8 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66o, HEAD
Changes since 1.8: +31 -23 lines
- 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 gforget 1.3 function []=MITprof_gcm2nc(varargin);
2 gforget 1.9 %MITPROF_GCM2NC(dir_model,list_model);
3 gforget 1.3 %
4 gforget 1.9 %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'};
21 gforget 1.1 % MITprof_gcm2nc(dir_model,list_model);
22    
23     warning off MATLAB:mir_warning_variable_used_as_function;
24    
25 gforget 1.4 if nargin==2; dir_model=varargin{1}; list_model=varargin{2};
26 gforget 1.3 else;
27     dir_model='./';
28 gforget 1.9 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'};
30 gforget 1.3 end;
31    
32 gforget 1.8 if iscell(dir_model);
33     %the following assumes that
34     %dir_model{1} is the run directory where *.nc MITgcm input files and profiles/*bin MITgcm output files are
35     %dir_model{2} typically is dirMat/profiles/output/ and is where the new *.nc files will be created
36     dir_out=dir_model{2};
37     dir_data=dir_model{1};
38     dir_model=[dir_model{1} 'profiles/'];
39     else;
40     %the following assumes that
41 gforget 1.9 %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/'];
46 gforget 1.8 end;
47 gforget 1.1
48     %loop over files:
49     for ff=1:length(list_model)
50 gforget 1.9
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;
54 roquet 1.2
55     %initialize the process:
56     clear prof_*;
57 gforget 1.9 file_data=dir([dir_data fil_root '*.nc']);
58 roquet 1.2 file_data2=file_data.name;
59    
60     %load the data:
61     MITprof=MITprof_load([dir_data file_data2]);
62    
63     %prepare relevant output:
64 gforget 1.5 varList={'T','S','U','V','ptr','ssh','OXY'};
65     varMax=length(varList);
66 gforget 1.6 varNum=zeros(varMax,1); varCount=0;
67 gforget 1.5 for v=1:varMax; vv=varList{v};
68 roquet 1.2 if isfield(MITprof,['prof_' vv]);
69     varCount=varCount+1; varNum(v)=varCount;
70     eval(['prof_' vv '=-9999*ones(size(MITprof.prof_' vv ')); prof_' vv 'mask=prof_' vv ';']);
71     end;
72     end;
73     varList={varList{find(varNum)}};
74     nr=length(MITprof.prof_depth);
75    
76     %list tile/processor model files:
77 gforget 1.9 eval(['model_list_model=dir(''' dir_model fil_root '*.data'');']);
78 roquet 1.2
79     %if no model files then stop
80     if size(model_list_model,1)==0; fprintf(['file: ' file_data2 ' \n, no model files found\n']);
81     else;
82    
83     %loop over model files:
84     for ffM=1:length(model_list_model)
85     file_model2=model_list_model(ffM).name;
86     np=model_list_model(ffM).bytes/8/2/(nr+1)/varCount;
87     tmp_prof=read2memory([dir_model file_model2],[nr+1 2 varCount np],64);
88    
89     for v=1:varCount; vv=varList{v};
90     tmp1=squeeze(tmp_prof(1:nr,1,v,:))'; tmp2=squeeze(tmp_prof(1:nr,2,v,:))'; tmp3=squeeze(tmp_prof(nr+1,1,v,:));
91     tmp4=find(tmp3>0); tmp1=tmp1(tmp4,:); tmp2=tmp2(tmp4,:); tmp3=tmp3(tmp4,:);
92     eval(['prof_' vv '(tmp3,:)=tmp1; prof_' vv 'mask(tmp3,:)=tmp2;']);
93     end;
94     end; %for ffM
95    
96     %include in structure:
97     for v=1:varCount; vv=varList{v}; eval(['prof_' vv '(prof_' vv 'mask==0)=-9999; MITprof.prof_' vv 'estim=prof_' vv ';']); end;
98    
99     %prepare fields list:
100     list_out=fieldnames(MITprof)';
101     ii=find(strncmp(list_out,'prof_U',6)+strncmp(list_out,'prof_S',6)+strncmp(list_out,'prof_T',6)+...
102 gforget 1.5 strncmp(list_out,'prof_V',6)+strncmp(list_out,'prof_ssh',8)+strncmp(list_out,'prof_ptr',8)+...
103     strncmp(list_out,'prof_OXY',8));
104 roquet 1.2 list_out={list_out{ii}};
105     %prepare other fields:
106     file_out=[file_data2(1:end-3) '_model.nc'];
107     nr=length(MITprof.prof_depth);
108     np=length(MITprof.prof_lon);
109     %write to file:
110 gforget 1.7 fprintf(['writing file: ' file_data2 ' \n']);
111 roquet 1.2 MITprof_write([dir_out file_out],MITprof);
112    
113     fprintf(['file: ' file_data2 ' \n has been processed \n']);
114     end %if size(model_list_model,1)~=0;
115 gforget 1.1 end%for ff=1:length(list_model)
116    
117    

  ViewVC Help
Powered by ViewVC 1.1.22