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.1 |
dir_out=[dir_model 'output/']; dir_data=[dir_model 'input/']; |
30 |
|
|
|
31 |
|
|
%loop over files: |
32 |
|
|
for ff=1:length(list_model) |
33 |
roquet |
1.2 |
|
34 |
|
|
%initialize the process: |
35 |
|
|
clear prof_*; |
36 |
|
|
file_data=dir([dir_data list_model{ff} '*.nc']); |
37 |
|
|
file_data2=file_data.name; |
38 |
|
|
|
39 |
|
|
%load the data: |
40 |
|
|
MITprof=MITprof_load([dir_data file_data2]); |
41 |
|
|
|
42 |
|
|
%prepare relevant output: |
43 |
gforget |
1.5 |
varList={'T','S','U','V','ptr','ssh','OXY'}; |
44 |
|
|
varMax=length(varList); |
45 |
gforget |
1.6 |
varNum=zeros(varMax,1); varCount=0; |
46 |
gforget |
1.5 |
for v=1:varMax; vv=varList{v}; |
47 |
roquet |
1.2 |
if isfield(MITprof,['prof_' vv]); |
48 |
|
|
varCount=varCount+1; varNum(v)=varCount; |
49 |
|
|
eval(['prof_' vv '=-9999*ones(size(MITprof.prof_' vv ')); prof_' vv 'mask=prof_' vv ';']); |
50 |
|
|
end; |
51 |
|
|
end; |
52 |
|
|
varList={varList{find(varNum)}}; |
53 |
|
|
nr=length(MITprof.prof_depth); |
54 |
|
|
|
55 |
|
|
%list tile/processor model files: |
56 |
|
|
eval(['model_list_model=dir(''' dir_model list_model{ff} '*.data'');']); |
57 |
|
|
|
58 |
|
|
%if no model files then stop |
59 |
|
|
if size(model_list_model,1)==0; fprintf(['file: ' file_data2 ' \n, no model files found\n']); |
60 |
|
|
else; |
61 |
|
|
|
62 |
|
|
%loop over model files: |
63 |
|
|
for ffM=1:length(model_list_model) |
64 |
|
|
file_model2=model_list_model(ffM).name; |
65 |
|
|
np=model_list_model(ffM).bytes/8/2/(nr+1)/varCount; |
66 |
|
|
tmp_prof=read2memory([dir_model file_model2],[nr+1 2 varCount np],64); |
67 |
|
|
|
68 |
|
|
for v=1:varCount; vv=varList{v}; |
69 |
|
|
tmp1=squeeze(tmp_prof(1:nr,1,v,:))'; tmp2=squeeze(tmp_prof(1:nr,2,v,:))'; tmp3=squeeze(tmp_prof(nr+1,1,v,:)); |
70 |
|
|
tmp4=find(tmp3>0); tmp1=tmp1(tmp4,:); tmp2=tmp2(tmp4,:); tmp3=tmp3(tmp4,:); |
71 |
|
|
eval(['prof_' vv '(tmp3,:)=tmp1; prof_' vv 'mask(tmp3,:)=tmp2;']); |
72 |
|
|
end; |
73 |
|
|
end; %for ffM |
74 |
|
|
|
75 |
|
|
%include in structure: |
76 |
|
|
for v=1:varCount; vv=varList{v}; eval(['prof_' vv '(prof_' vv 'mask==0)=-9999; MITprof.prof_' vv 'estim=prof_' vv ';']); end; |
77 |
|
|
|
78 |
|
|
%prepare fields list: |
79 |
|
|
list_out=fieldnames(MITprof)'; |
80 |
|
|
ii=find(strncmp(list_out,'prof_U',6)+strncmp(list_out,'prof_S',6)+strncmp(list_out,'prof_T',6)+... |
81 |
gforget |
1.5 |
strncmp(list_out,'prof_V',6)+strncmp(list_out,'prof_ssh',8)+strncmp(list_out,'prof_ptr',8)+... |
82 |
|
|
strncmp(list_out,'prof_OXY',8)); |
83 |
roquet |
1.2 |
list_out={list_out{ii}}; |
84 |
|
|
%prepare other fields: |
85 |
|
|
file_out=[file_data2(1:end-3) '_model.nc']; |
86 |
|
|
nr=length(MITprof.prof_depth); |
87 |
|
|
np=length(MITprof.prof_lon); |
88 |
|
|
%write to file: |
89 |
|
|
MITprof_write([dir_out file_out],MITprof); |
90 |
|
|
|
91 |
|
|
fprintf(['file: ' file_data2 ' \n has been processed \n']); |
92 |
|
|
end %if size(model_list_model,1)~=0; |
93 |
gforget |
1.1 |
end%for ff=1:length(list_model) |
94 |
|
|
|
95 |
|
|
|