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