1 |
gforget |
1.13 |
function []=MITprof_create(fileOut,MITprofCur,varargin); |
2 |
|
|
% MITPROF_CREATE(fileOut,MITprofCur,list_vars) |
3 |
|
|
% Creates a file in the MITprof format. The list of variables |
4 |
|
|
% can further be specified via list_vars (optional). |
5 |
roquet |
1.7 |
|
6 |
|
|
% check that file exists and add prefix and suffix if necessary |
7 |
|
|
[pathstr, name, ext] = fileparts(fileOut); |
8 |
|
|
if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end |
9 |
|
|
if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end |
10 |
|
|
fileOut=[pathstr '/' name ext]; |
11 |
|
|
|
12 |
|
|
%define netcdf dimensions : |
13 |
gforget |
1.13 |
prof_depth=MITprofCur.prof_depth; |
14 |
roquet |
1.7 |
prof_depth=reshape(prof_depth,length(prof_depth),1); |
15 |
gforget |
1.13 |
iPROF=MITprofCur.np; iDEPTH=MITprofCur.nr; |
16 |
|
|
if isfield(MITprofCur,'prof_interp_weights'); |
17 |
|
|
iINTERP=size(MITprofCur.prof_interp_weights,2); |
18 |
gforget |
1.14 |
addGrid=1; |
19 |
gforget |
1.13 |
else; |
20 |
|
|
iINTERP=1; |
21 |
gforget |
1.14 |
addGrid=0; |
22 |
gforget |
1.13 |
end; |
23 |
roquet |
1.7 |
lTXT=30; fillval=double(-9999); |
24 |
gforget |
1.1 |
|
25 |
|
|
%=============list of variables that will actually be in the file==============% |
26 |
gforget |
1.13 |
if nargin>2; |
27 |
gforget |
1.11 |
list_vars=varargin{1}; |
28 |
|
|
else; |
29 |
|
|
list_vars={'prof_depth','prof_descr','prof_date','prof_YYYYMMDD','prof_HHMMSS',... |
30 |
|
|
'prof_lon','prof_lat','prof_basin','prof_point','prof_flag','prof_T','prof_Tweight','prof_Testim','prof_Terr','prof_Tflag',... |
31 |
|
|
'prof_S','prof_Sweight','prof_Sestim','prof_Serr','prof_Sflag','prof_D','prof_Destim'}; |
32 |
gforget |
1.14 |
if addGrid; |
33 |
|
|
list_vars={list_vars{:},'prof_interp_XC11','prof_interp_YC11','prof_interp_XCNINJ','prof_interp_YCNINJ'}; |
34 |
|
|
list_vars={list_vars{:},'prof_interp_i','prof_interp_j','prof_interp_lon','prof_interp_lat','prof_interp_weights'}; |
35 |
|
|
end; |
36 |
gforget |
1.11 |
end; |
37 |
|
|
|
38 |
gforget |
1.14 |
% eliminate duplicates |
39 |
gforget |
1.11 |
[list,m]=unique(list_vars); |
40 |
|
|
list_vars=list_vars(sort(m)); |
41 |
|
|
|
42 |
|
|
list_vars_plus={}; |
43 |
|
|
for ii=1:length(list_vars); |
44 |
|
|
if ~isempty(strfind(list_vars{ii},'estim'))&... |
45 |
|
|
~strcmp(list_vars{ii},'prof_Testim')&... |
46 |
|
|
~strcmp(list_vars{ii},'prof_Sestim'); |
47 |
|
|
list_vars_plus={list_vars_plus{:},list_vars{ii}(1:end-5)}; |
48 |
|
|
end; |
49 |
|
|
end; |
50 |
roquet |
1.7 |
|
51 |
gforget |
1.1 |
%==========masters table of variables, units, names and dimensions=============% |
52 |
|
|
|
53 |
|
|
mt_v={'prof_depth'}; mt_u={'me'}; mt_n={'depth'}; mt_d={'iDEPTH'}; |
54 |
|
|
%mt_v=[mt_v '']; mt_u=[mt_u ' ']; mt_n=[mt_n '']; mt_d=[mt_d '']; |
55 |
|
|
mt_v=[mt_v 'prof_date']; mt_u=[mt_u ' ']; mt_n=[mt_n 'Julian day since Jan-1-0000']; mt_d=[mt_d 'iPROF']; |
56 |
|
|
mt_v=[mt_v 'prof_YYYYMMDD']; mt_u=[mt_u ' ']; mt_n=[mt_n 'year (4 digits), month (2 digits), day (2 digits)']; mt_d=[mt_d 'iPROF']; |
57 |
|
|
mt_v=[mt_v 'prof_HHMMSS']; mt_u=[mt_u ' ']; mt_n=[mt_n 'hour (2 digits), minute (2 digits), second (2 digits)']; mt_d=[mt_d 'iPROF']; |
58 |
gforget |
1.15 |
mt_v=[mt_v 'prof_lon']; mt_u=[mt_u 'degrees_east']; mt_n=[mt_n 'Longitude (degree East)']; mt_d=[mt_d 'iPROF']; |
59 |
|
|
mt_v=[mt_v 'prof_lat']; mt_u=[mt_u 'degrees_north']; mt_n=[mt_n 'Latitude (degree North)']; mt_d=[mt_d 'iPROF']; |
60 |
gforget |
1.1 |
mt_v=[mt_v 'prof_basin']; mt_u=[mt_u ' ']; mt_n=[mt_n 'ocean basin index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
61 |
|
|
mt_v=[mt_v 'prof_point']; mt_u=[mt_u ' ']; mt_n=[mt_n 'grid point index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
62 |
gforget |
1.9 |
mt_v=[mt_v 'prof_flag']; mt_u=[mt_u ' ']; mt_n=[mt_n 'flag = i > 0 for suspicious profile ']; mt_d=[mt_d 'iPROF']; |
63 |
gforget |
1.1 |
% |
64 |
|
|
mt_v=[mt_v 'prof_T']; mt_u=[mt_u 'degree C']; mt_n=[mt_n 'potential temperature']; mt_d=[mt_d 'iPROF,iDEPTH']; |
65 |
|
|
mt_v=[mt_v 'prof_Tweight']; mt_u=[mt_u '(degree C)^-2']; mt_n=[mt_n 'pot. temp. least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
66 |
gforget |
1.2 |
mt_v=[mt_v 'prof_Testim']; mt_u=[mt_u 'degree C']; mt_n=[mt_n 'pot. temp. estimate (e.g. from atlas)']; mt_d=[mt_d 'iPROF,iDEPTH']; |
67 |
gforget |
1.1 |
mt_v=[mt_v 'prof_Terr']; mt_u=[mt_u 'degree C']; mt_n=[mt_n 'pot. temp. instrumental error']; mt_d=[mt_d 'iPROF,iDEPTH']; |
68 |
gforget |
1.2 |
mt_v=[mt_v 'prof_Tflag']; mt_u=[mt_u ' ']; mt_n=[mt_n 'flag = i > 0 means test i rejected data.']; mt_d=[mt_d 'iPROF,iDEPTH']; |
69 |
gforget |
1.1 |
% |
70 |
|
|
mt_v=[mt_v 'prof_S']; mt_u=[mt_u 'psu']; mt_n=[mt_n 'salinity']; mt_d=[mt_d 'iPROF,iDEPTH']; |
71 |
|
|
mt_v=[mt_v 'prof_Sweight']; mt_u=[mt_u '(psu)^-2']; mt_n=[mt_n 'salinity least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
72 |
gforget |
1.2 |
mt_v=[mt_v 'prof_Sestim']; mt_u=[mt_u 'psu']; mt_n=[mt_n 'salinity estimate (e.g. from atlas)']; mt_d=[mt_d 'iPROF,iDEPTH']; |
73 |
gforget |
1.1 |
mt_v=[mt_v 'prof_Serr']; mt_u=[mt_u 'psu']; mt_n=[mt_n 'salinity instrumental error']; mt_d=[mt_d 'iPROF,iDEPTH']; |
74 |
gforget |
1.2 |
mt_v=[mt_v 'prof_Sflag']; mt_u=[mt_u ' ']; mt_n=[mt_n 'flag = i > 0 means test i rejected data.']; mt_d=[mt_d 'iPROF,iDEPTH']; |
75 |
gforget |
1.1 |
% |
76 |
gforget |
1.11 |
for ii=1:length(list_vars_plus); |
77 |
|
|
mt_v=[mt_v list_vars_plus{ii}]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'unknown']; mt_d=[mt_d 'iPROF,iDEPTH']; |
78 |
|
|
mt_v=[mt_v [list_vars_plus{ii} 'weight']]; mt_u=[mt_u '(unknown)^-2']; mt_n=[mt_n 'unknown least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
79 |
|
|
mt_v=[mt_v [list_vars_plus{ii} 'estim']]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'unknown estimate (e.g. from atlas)']; mt_d=[mt_d 'iPROF,iDEPTH']; |
80 |
|
|
mt_v=[mt_v [list_vars_plus{ii} 'err']]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'unknown instrumental error']; mt_d=[mt_d 'iPROF,iDEPTH']; |
81 |
|
|
mt_v=[mt_v [list_vars_plus{ii} 'flag']]; mt_u=[mt_u ' ']; mt_n=[mt_n 'flag = i > 0 means test i rejected data.']; mt_d=[mt_d 'iPROF,iDEPTH']; |
82 |
|
|
end; |
83 |
gforget |
1.12 |
% |
84 |
|
|
list_interpr={'prof_interp_XC11','prof_interp_YC11','prof_interp_XCNINJ','prof_interp_YCNINJ'}; |
85 |
|
|
for ii=1:length(list_interpr); |
86 |
|
|
mt_v=[mt_v list_interpr{ii}]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'interpolation variable']; mt_d=[mt_d 'iPROF']; |
87 |
|
|
end; |
88 |
|
|
list_interpr={'prof_interp_i','prof_interp_j','prof_interp_lon','prof_interp_lat','prof_interp_weights'}; |
89 |
|
|
for ii=1:length(list_interpr); |
90 |
|
|
mt_v=[mt_v list_interpr{ii}]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'interpolation variable']; mt_d=[mt_d 'iPROF,iINTERP']; |
91 |
|
|
end; |
92 |
|
|
% |
93 |
gforget |
1.11 |
if 0; |
94 |
|
|
mt_v=[mt_v 'prof_U']; mt_u=[mt_u 'm/s']; mt_n=[mt_n 'eastward velocity comp.']; mt_d=[mt_d 'iPROF,iDEPTH']; |
95 |
|
|
mt_v=[mt_v 'prof_Uweight']; mt_u=[mt_u '(m/s)^-2']; mt_n=[mt_n 'east. v. least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
96 |
|
|
mt_v=[mt_v 'prof_V']; mt_u=[mt_u 'm/s']; mt_n=[mt_n 'northward velocity comp.']; mt_d=[mt_d 'iPROF,iDEPTH']; |
97 |
|
|
mt_v=[mt_v 'prof_Vweight']; mt_u=[mt_u '(m/s)^-2']; mt_n=[mt_n 'north. v. least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
98 |
|
|
mt_v=[mt_v 'prof_ptr']; mt_u=[mt_u 'X']; mt_n=[mt_n 'passive tracer']; mt_d=[mt_d 'iPROF,iDEPTH']; |
99 |
|
|
mt_v=[mt_v 'prof_ptrweight']; mt_u=[mt_u '(X)^-2']; mt_n=[mt_n 'pass. tracer least-square weight']; mt_d=[mt_d 'iPROF,iDEPTH']; |
100 |
|
|
% |
101 |
|
|
mt_v=[mt_v 'prof_D']; mt_u=[mt_u 'me']; mt_n=[mt_n 'variable depth']; mt_d=[mt_d 'iPROF,iDEPTH']; |
102 |
|
|
mt_v=[mt_v 'prof_Destim']; mt_u=[mt_u 'me']; mt_n=[mt_n 'variable depth estimate (e.g. from atlas)']; mt_d=[mt_d 'iPROF,iDEPTH']; |
103 |
|
|
% |
104 |
|
|
mt_v=[mt_v 'prof_bp']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'bottom pressure']; mt_d=[mt_d 'iPROF']; |
105 |
|
|
mt_v=[mt_v 'prof_bpweight']; mt_u=[mt_u '(cm)^-2']; mt_n=[mt_n 'bot. pres. least-square weight']; mt_d=[mt_d 'iPROF']; |
106 |
|
|
mt_v=[mt_v 'prof_ssh']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'sea surface height']; mt_d=[mt_d 'iPROF']; |
107 |
|
|
mt_v=[mt_v 'prof_sshweight']; mt_u=[mt_u '(cm)^-2']; mt_n=[mt_n 'ssh least-square weight']; mt_d=[mt_d 'iPROF']; |
108 |
|
|
end; |
109 |
gforget |
1.1 |
|
110 |
|
|
%=============================create the file=================================% |
111 |
|
|
|
112 |
roquet |
1.6 |
% write the netcdf structure |
113 |
gforget |
1.16 |
ncid=nccreateFile(fileOut,'clobber'); |
114 |
roquet |
1.6 |
|
115 |
gforget |
1.15 |
aa=sprintf(['The contents of this MITprof file were processed \n' ... |
116 |
|
|
'using the MITprof matlab toolbox which can be obtained from \n'... |
117 |
|
|
'http://mitgcm.org/viewvc/MITgcm/MITgcm_contrib/gael/profilesMatlabProcessing/']); |
118 |
|
|
ncputAtt(ncid,'','Format',aa); |
119 |
roquet |
1.6 |
ncputAtt(ncid,'','date',date); |
120 |
|
|
|
121 |
|
|
ncdefDim(ncid,'iPROF',iPROF); |
122 |
|
|
ncdefDim(ncid,'iDEPTH',iDEPTH); |
123 |
gforget |
1.14 |
if addGrid; ncdefDim(ncid,'iINTERP',iINTERP); end; |
124 |
roquet |
1.6 |
ncdefDim(ncid,'lTXT',lTXT); |
125 |
|
|
|
126 |
gforget |
1.11 |
for ii=1:length(list_vars); |
127 |
|
|
jj=find(strcmp(mt_v,list_vars{ii})); |
128 |
roquet |
1.6 |
if ~isempty(jj); |
129 |
|
|
if strcmp(mt_d{jj},'iPROF,iDEPTH'); |
130 |
|
|
ncdefVar(ncid,mt_v{jj},'double',{'iDEPTH','iPROF'});%note the direction flip |
131 |
gforget |
1.12 |
elseif strcmp(mt_d{jj},'iPROF,iINTERP'); |
132 |
|
|
ncdefVar(ncid,mt_v{jj},'double',{'iINTERP','iPROF'});%note the direction flip |
133 |
gforget |
1.5 |
else; |
134 |
roquet |
1.6 |
ncdefVar(ncid,mt_v{jj},'double',{mt_d{jj}}); |
135 |
gforget |
1.5 |
end; |
136 |
roquet |
1.6 |
ncputAtt(ncid,mt_v{jj},'long_name',mt_n{jj}); |
137 |
|
|
ncputAtt(ncid,mt_v{jj},'units',mt_u{jj}); |
138 |
|
|
ncputAtt(ncid,mt_v{jj},'missing_value',fillval); |
139 |
|
|
ncputAtt(ncid,mt_v{jj},'_FillValue',fillval); |
140 |
|
|
else; |
141 |
gforget |
1.11 |
if strcmp(list_vars{ii},'prof_descr') |
142 |
roquet |
1.8 |
ncdefVar(ncid,'prof_descr','char',{'lTXT','iPROF'}); |
143 |
|
|
ncputAtt(ncid,'prof_descr','long_name','profile description'); |
144 |
|
|
else |
145 |
gforget |
1.11 |
warning([list_vars{ii} ' not included -- it is not a MITprof variable']); |
146 |
roquet |
1.8 |
end |
147 |
gforget |
1.1 |
end; |
148 |
|
|
end; |
149 |
|
|
|
150 |
roquet |
1.6 |
ncclose(ncid); |
151 |
|
|
|
152 |
roquet |
1.7 |
%=============================set prof_depth=================================% |
153 |
|
|
|
154 |
|
|
ncid=ncopen(fileOut,'write'); |
155 |
|
|
ncputvar(ncid,'prof_depth',prof_depth); |
156 |
|
|
ncclose(ncid); |
157 |
gforget |
1.5 |
|
158 |
gforget |
1.1 |
|