1 |
gforget |
1.1 |
%function: MITprof_create |
2 |
|
|
%object: read netcdf data files in the "MIT format" |
3 |
|
|
%author: Gael Forget (gforget@mit.edu) |
4 |
|
|
%date: june 21th, 2006 |
5 |
|
|
% |
6 |
gforget |
1.5 |
%usage: [MITprof]=MITprof_create(fileOut,nProf,nLev); |
7 |
gforget |
1.1 |
% ---> create an empty MITprof netcdf file that contains all T/S fields |
8 |
gforget |
1.5 |
% [MITprof]=MITprof_create(fileOut,nProf,nLev,list_vars); |
9 |
gforget |
1.1 |
% ---> same but specifying the list of variables in list_vars cell |
10 |
|
|
% array (e.g. list_vars={'prof_T','prof_Tweight'}). |
11 |
|
|
% |
12 |
gforget |
1.4 |
%inputs: fileOut data file name |
13 |
|
|
% nProf number of profiles |
14 |
|
|
% nLev number of levels |
15 |
|
|
% list_vars variable list (optional) |
16 |
gforget |
1.1 |
% |
17 |
gforget |
1.4 |
%outputs: (none) |
18 |
gforget |
1.1 |
|
19 |
gforget |
1.4 |
function []=MITprof_create(fileOut,nProf,nLev,varargin); |
20 |
gforget |
1.1 |
|
21 |
|
|
%=============list of variables that will actually be in the file==============% |
22 |
gforget |
1.5 |
if nargin>3; list_vars=varargin{1}; |
23 |
gforget |
1.2 |
else; list_vars={'prof_T','prof_Tweight','prof_Testim','prof_Terr','prof_Tflag',... |
24 |
gforget |
1.5 |
'prof_S','prof_Sweight','prof_Sestim','prof_Serr','prof_Sflag'}; |
25 |
gforget |
1.1 |
end; |
26 |
|
|
|
27 |
|
|
list_vars_plus=[{'prof_depth','prof_date','prof_YYYYMMDD','prof_HHMMSS',... |
28 |
gforget |
1.5 |
'prof_lon','prof_lat','prof_basin','prof_point'}... |
29 |
|
|
list_vars]; |
30 |
gforget |
1.1 |
|
31 |
|
|
%==========masters table of variables, units, names and dimensions=============% |
32 |
|
|
|
33 |
|
|
mt_v={'prof_depth'}; mt_u={'me'}; mt_n={'depth'}; mt_d={'iDEPTH'}; |
34 |
|
|
%mt_v=[mt_v '']; mt_u=[mt_u ' ']; mt_n=[mt_n '']; mt_d=[mt_d '']; |
35 |
|
|
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']; |
36 |
|
|
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']; |
37 |
|
|
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']; |
38 |
|
|
mt_v=[mt_v 'prof_lon']; mt_u=[mt_u ' ']; mt_n=[mt_n 'Longitude (degree East)']; mt_d=[mt_d 'iPROF']; |
39 |
|
|
mt_v=[mt_v 'prof_lat']; mt_u=[mt_u ' ']; mt_n=[mt_n 'Latitude (degree North)']; mt_d=[mt_d 'iPROF']; |
40 |
|
|
mt_v=[mt_v 'prof_basin']; mt_u=[mt_u ' ']; mt_n=[mt_n 'ocean basin index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
41 |
|
|
mt_v=[mt_v 'prof_point']; mt_u=[mt_u ' ']; mt_n=[mt_n 'grid point index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
42 |
|
|
% |
43 |
|
|
mt_v=[mt_v 'prof_T']; mt_u=[mt_u 'degree C']; mt_n=[mt_n 'potential temperature']; mt_d=[mt_d 'iPROF,iDEPTH']; |
44 |
|
|
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']; |
45 |
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']; |
46 |
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']; |
47 |
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']; |
48 |
gforget |
1.1 |
% |
49 |
|
|
mt_v=[mt_v 'prof_S']; mt_u=[mt_u 'psu']; mt_n=[mt_n 'salinity']; mt_d=[mt_d 'iPROF,iDEPTH']; |
50 |
|
|
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']; |
51 |
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']; |
52 |
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']; |
53 |
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']; |
54 |
gforget |
1.1 |
% |
55 |
|
|
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']; |
56 |
|
|
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']; |
57 |
|
|
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']; |
58 |
|
|
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']; |
59 |
|
|
mt_v=[mt_v 'prof_ptr']; mt_u=[mt_u 'X']; mt_n=[mt_n 'passive tracer']; mt_d=[mt_d 'iPROF,iDEPTH']; |
60 |
|
|
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']; |
61 |
|
|
% |
62 |
|
|
mt_v=[mt_v 'prof_bp']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'bottom pressure']; mt_d=[mt_d 'iPROF']; |
63 |
|
|
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']; |
64 |
|
|
mt_v=[mt_v 'prof_ssh']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'sea surface height']; mt_d=[mt_d 'iPROF']; |
65 |
|
|
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']; |
66 |
|
|
|
67 |
|
|
%=============================create the file=================================% |
68 |
|
|
|
69 |
|
|
if ~strcmp(fileOut(end-2:end),'.nc'); suff='.nc'; else; suff=''; end; |
70 |
gforget |
1.3 |
|
71 |
gforget |
1.1 |
%define netcdf dimensions : |
72 |
gforget |
1.4 |
iPROF=nProf; iDEPTH=nLev; |
73 |
|
|
lTXT=30; fillval=-9999; |
74 |
gforget |
1.1 |
|
75 |
gforget |
1.5 |
|
76 |
|
|
global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
77 |
|
|
|
78 |
|
|
if (useNativeMatlabNetcdf); |
79 |
|
|
|
80 |
|
|
ncid=netcdf.create([fileOut suff],'clobber'); |
81 |
|
|
|
82 |
|
|
%put a couple global attributes |
83 |
|
|
aa=sprintf(['Format: MITprof. This file was created using \n' ... |
84 |
|
|
'the matlab toolbox which can be obtained (see README) from \n'... |
85 |
|
|
'http://mitgcm.org/viewvc/MITgcm/MITgcm_contrib/gael/profilesMatlabProcessing/']); |
86 |
|
|
netcdf.putAtt(ncid,-1,'description',aa); |
87 |
|
|
netcdf.putAtt(ncid,-1,'date',date); |
88 |
|
|
|
89 |
|
|
iPROFid = netcdf.defDim(ncid,'iPROF',iPROF); |
90 |
|
|
iDEPTHid = netcdf.defDim(ncid,'iDEPTH',iDEPTH); |
91 |
|
|
lTXTid = netcdf.defDim(ncid,'lTXT',lTXT); |
92 |
|
|
|
93 |
|
|
%mt_v=[mt_v 'prof_descr']; mt_u=[mt_u ' ']; mt_n=[mt_n 'profile description']; mt_d=[mt_d 'iPROF,lTXT']; |
94 |
|
|
varid = netcdf.defVar(ncid,'prof_descr','char',[lTXTid iPROFid]); |
95 |
|
|
netcdf.putAtt(ncid,varid,'long_name','profile description'); |
96 |
|
|
|
97 |
|
|
for ii=1:length(list_vars_plus); |
98 |
|
|
jj=find(strcmp(mt_v,list_vars_plus{ii})); |
99 |
|
|
if ~isempty(jj); |
100 |
|
|
if strcmp(mt_d{jj},'iPROF,iDEPTH'); |
101 |
|
|
varid = netcdf.defVar(ncid,mt_v{jj},'double',[iDEPTHid iPROFid]);%note the direction flip |
102 |
|
|
else; |
103 |
|
|
dimid = netcdf.inqDimID(ncid,mt_d{jj}); |
104 |
|
|
varid = netcdf.defVar(ncid,mt_v{jj},'double',dimid); |
105 |
|
|
end; |
106 |
|
|
netcdf.putAtt(ncid,varid,'long_name',mt_n{jj}); |
107 |
|
|
netcdf.putAtt(ncid,varid,'units',mt_u{jj}); |
108 |
|
|
netcdf.putAtt(ncid,varid,'missing_value',fillval); |
109 |
|
|
else; |
110 |
|
|
warning([list_vars_plus{ii} ' not included -- it is not a MITprof variable']); |
111 |
|
|
end; |
112 |
gforget |
1.1 |
end; |
113 |
gforget |
1.5 |
|
114 |
|
|
netcdf.close(ncid); |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
else;%try to use old mex stuff |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
nc=netcdf([fileOut suff],'clobber'); |
123 |
|
|
|
124 |
|
|
%put a couple global attributes |
125 |
|
|
aa=sprintf(['Format: MITprof. This file was created using \n' ... |
126 |
|
|
'the matlab toolbox which can be obtained (see README) from \n'... |
127 |
|
|
'http://mitgcm.org/viewvc/MITgcm/MITgcm_contrib/gael/profilesMatlabProcessing/']); |
128 |
|
|
nc.description=aa; |
129 |
|
|
nc.date = date; |
130 |
|
|
|
131 |
|
|
nc('iPROF') = iPROF; |
132 |
|
|
nc('iDEPTH') = iDEPTH; |
133 |
|
|
nc('lTXT') = lTXT; |
134 |
|
|
|
135 |
|
|
%mt_v=[mt_v 'prof_descr']; mt_u=[mt_u ' ']; mt_n=[mt_n 'profile description']; mt_d=[mt_d 'iPROF,lTXT']; |
136 |
|
|
nc{'prof_descr'} = ncchar('iPROF','lTXT'); |
137 |
|
|
nc{'prof_descr'}.long_name='profile description'; |
138 |
|
|
|
139 |
|
|
for ii=1:length(list_vars_plus); |
140 |
|
|
jj=find(strcmp(mt_v,list_vars_plus{ii})); |
141 |
|
|
if ~isempty(jj); |
142 |
|
|
if strcmp(mt_d{jj},'iPROF,iDEPTH'); |
143 |
|
|
nc{mt_v{jj}} = ncdouble('iPROF','iDEPTH'); |
144 |
|
|
else; |
145 |
|
|
nc{mt_v{jj}} = mt_d{jj}; |
146 |
|
|
end; |
147 |
|
|
nc{mt_v{jj}}.long_name = mt_n{jj}; |
148 |
|
|
nc{mt_v{jj}}.units = mt_u{jj}; |
149 |
|
|
nc{mt_v{jj}}.missing_value=fillval; |
150 |
|
|
else; |
151 |
|
|
warning([list_vars_plus{ii} ' not included -- it is not a MITprof varaiable']); |
152 |
|
|
end; |
153 |
|
|
end; |
154 |
|
|
|
155 |
|
|
close(nc); |
156 |
|
|
|
157 |
gforget |
1.1 |
end; |
158 |
|
|
|
159 |
gforget |
1.5 |
|
160 |
gforget |
1.1 |
|