1 |
gforget |
1.3 |
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) |
11 |
|
|
% |
12 |
|
|
%e.g. dir_model='./'; |
13 |
|
|
% list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'}; |
14 |
gforget |
1.1 |
% 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 |
roquet |
1.2 |
% that was provided as input to MITgcm/pkg/profiles, and |
19 |
gforget |
1.1 |
% the recomposed MITprof file will be put in dir_model/output |
20 |
|
|
|
21 |
|
|
warning off MATLAB:mir_warning_variable_used_as_function; |
22 |
|
|
|
23 |
gforget |
1.4 |
if nargin==2; dir_model=varargin{1}; list_model=varargin{2}; |
24 |
gforget |
1.3 |
else; |
25 |
|
|
dir_model='./'; |
26 |
|
|
list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'}; |
27 |
|
|
end; |
28 |
|
|
|
29 |
gforget |
1.8 |
if iscell(dir_model); |
30 |
|
|
%the following assumes that |
31 |
|
|
%dir_model{1} is the run directory where *.nc MITgcm input files and profiles/*bin MITgcm output files are |
32 |
|
|
%dir_model{2} typically is dirMat/profiles/output/ and is where the new *.nc files will be created |
33 |
|
|
dir_out=dir_model{2}; |
34 |
|
|
dir_data=dir_model{1}; |
35 |
|
|
dir_model=[dir_model{1} 'profiles/']; |
36 |
|
|
else; |
37 |
|
|
%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/']; |
42 |
|
|
end; |
43 |
gforget |
1.1 |
|
44 |
|
|
%loop over files: |
45 |
|
|
for ff=1:length(list_model) |
46 |
roquet |
1.2 |
|
47 |
|
|
%initialize the process: |
48 |
|
|
clear prof_*; |
49 |
|
|
file_data=dir([dir_data list_model{ff} '*.nc']); |
50 |
|
|
file_data2=file_data.name; |
51 |
|
|
|
52 |
|
|
%load the data: |
53 |
|
|
MITprof=MITprof_load([dir_data file_data2]); |
54 |
|
|
|
55 |
|
|
%prepare relevant output: |
56 |
gforget |
1.5 |
varList={'T','S','U','V','ptr','ssh','OXY'}; |
57 |
|
|
varMax=length(varList); |
58 |
gforget |
1.6 |
varNum=zeros(varMax,1); varCount=0; |
59 |
gforget |
1.5 |
for v=1:varMax; vv=varList{v}; |
60 |
roquet |
1.2 |
if isfield(MITprof,['prof_' vv]); |
61 |
|
|
varCount=varCount+1; varNum(v)=varCount; |
62 |
|
|
eval(['prof_' vv '=-9999*ones(size(MITprof.prof_' vv ')); prof_' vv 'mask=prof_' vv ';']); |
63 |
|
|
end; |
64 |
|
|
end; |
65 |
|
|
varList={varList{find(varNum)}}; |
66 |
|
|
nr=length(MITprof.prof_depth); |
67 |
|
|
|
68 |
|
|
%list tile/processor model files: |
69 |
|
|
eval(['model_list_model=dir(''' dir_model list_model{ff} '*.data'');']); |
70 |
|
|
|
71 |
|
|
%if no model files then stop |
72 |
|
|
if size(model_list_model,1)==0; fprintf(['file: ' file_data2 ' \n, no model files found\n']); |
73 |
|
|
else; |
74 |
|
|
|
75 |
|
|
%loop over model files: |
76 |
|
|
for ffM=1:length(model_list_model) |
77 |
|
|
file_model2=model_list_model(ffM).name; |
78 |
|
|
np=model_list_model(ffM).bytes/8/2/(nr+1)/varCount; |
79 |
|
|
tmp_prof=read2memory([dir_model file_model2],[nr+1 2 varCount np],64); |
80 |
|
|
|
81 |
|
|
for v=1:varCount; vv=varList{v}; |
82 |
|
|
tmp1=squeeze(tmp_prof(1:nr,1,v,:))'; tmp2=squeeze(tmp_prof(1:nr,2,v,:))'; tmp3=squeeze(tmp_prof(nr+1,1,v,:)); |
83 |
|
|
tmp4=find(tmp3>0); tmp1=tmp1(tmp4,:); tmp2=tmp2(tmp4,:); tmp3=tmp3(tmp4,:); |
84 |
|
|
eval(['prof_' vv '(tmp3,:)=tmp1; prof_' vv 'mask(tmp3,:)=tmp2;']); |
85 |
|
|
end; |
86 |
|
|
end; %for ffM |
87 |
|
|
|
88 |
|
|
%include in structure: |
89 |
|
|
for v=1:varCount; vv=varList{v}; eval(['prof_' vv '(prof_' vv 'mask==0)=-9999; MITprof.prof_' vv 'estim=prof_' vv ';']); end; |
90 |
|
|
|
91 |
|
|
%prepare fields list: |
92 |
|
|
list_out=fieldnames(MITprof)'; |
93 |
|
|
ii=find(strncmp(list_out,'prof_U',6)+strncmp(list_out,'prof_S',6)+strncmp(list_out,'prof_T',6)+... |
94 |
gforget |
1.5 |
strncmp(list_out,'prof_V',6)+strncmp(list_out,'prof_ssh',8)+strncmp(list_out,'prof_ptr',8)+... |
95 |
|
|
strncmp(list_out,'prof_OXY',8)); |
96 |
roquet |
1.2 |
list_out={list_out{ii}}; |
97 |
|
|
%prepare other fields: |
98 |
|
|
file_out=[file_data2(1:end-3) '_model.nc']; |
99 |
|
|
nr=length(MITprof.prof_depth); |
100 |
|
|
np=length(MITprof.prof_lon); |
101 |
|
|
%write to file: |
102 |
gforget |
1.7 |
fprintf(['writing file: ' file_data2 ' \n']); |
103 |
roquet |
1.2 |
MITprof_write([dir_out file_out],MITprof); |
104 |
|
|
|
105 |
|
|
fprintf(['file: ' file_data2 ' \n has been processed \n']); |
106 |
|
|
end %if size(model_list_model,1)~=0; |
107 |
gforget |
1.1 |
end%for ff=1:length(list_model) |
108 |
|
|
|
109 |
|
|
|