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 |
|
|
% create an empty MITprof netcdf file |
9 |
|
|
% 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 |
roquet |
1.7 |
list_vars={'prof_T','prof_Tweight','prof_Testim','prof_Terr','prof_Tflag',... |
37 |
gforget |
1.10 |
'prof_S','prof_Sweight','prof_Sestim','prof_Serr','prof_Sflag','prof_D','prof_Destim'}; |
38 |
roquet |
1.7 |
if nargin>3; list_vars=varargin{1}; end |
39 |
gforget |
1.1 |
|
40 |
roquet |
1.7 |
list_vars_plus=[{'prof_depth','prof_descr','prof_date','prof_YYYYMMDD','prof_HHMMSS',... |
41 |
gforget |
1.9 |
'prof_lon','prof_lat','prof_basin','prof_point','prof_flag'}... |
42 |
gforget |
1.5 |
list_vars]; |
43 |
gforget |
1.1 |
|
44 |
roquet |
1.7 |
% eliminate doublons |
45 |
|
|
[list,m]=unique(list_vars_plus); |
46 |
|
|
list_vars_plus=list_vars_plus(sort(m)); |
47 |
|
|
|
48 |
gforget |
1.1 |
%==========masters table of variables, units, names and dimensions=============% |
49 |
|
|
|
50 |
|
|
mt_v={'prof_depth'}; mt_u={'me'}; mt_n={'depth'}; mt_d={'iDEPTH'}; |
51 |
|
|
%mt_v=[mt_v '']; mt_u=[mt_u ' ']; mt_n=[mt_n '']; mt_d=[mt_d '']; |
52 |
|
|
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']; |
53 |
|
|
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']; |
54 |
|
|
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']; |
55 |
|
|
mt_v=[mt_v 'prof_lon']; mt_u=[mt_u ' ']; mt_n=[mt_n 'Longitude (degree East)']; mt_d=[mt_d 'iPROF']; |
56 |
|
|
mt_v=[mt_v 'prof_lat']; mt_u=[mt_u ' ']; mt_n=[mt_n 'Latitude (degree North)']; mt_d=[mt_d 'iPROF']; |
57 |
|
|
mt_v=[mt_v 'prof_basin']; mt_u=[mt_u ' ']; mt_n=[mt_n 'ocean basin index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
58 |
|
|
mt_v=[mt_v 'prof_point']; mt_u=[mt_u ' ']; mt_n=[mt_n 'grid point index (ecco 4g)']; mt_d=[mt_d 'iPROF']; |
59 |
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']; |
60 |
gforget |
1.1 |
% |
61 |
|
|
mt_v=[mt_v 'prof_T']; mt_u=[mt_u 'degree C']; mt_n=[mt_n 'potential temperature']; mt_d=[mt_d 'iPROF,iDEPTH']; |
62 |
|
|
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']; |
63 |
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']; |
64 |
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']; |
65 |
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']; |
66 |
gforget |
1.1 |
% |
67 |
|
|
mt_v=[mt_v 'prof_S']; mt_u=[mt_u 'psu']; mt_n=[mt_n 'salinity']; mt_d=[mt_d 'iPROF,iDEPTH']; |
68 |
|
|
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']; |
69 |
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']; |
70 |
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']; |
71 |
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']; |
72 |
gforget |
1.1 |
% |
73 |
|
|
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']; |
74 |
|
|
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']; |
75 |
|
|
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']; |
76 |
|
|
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']; |
77 |
|
|
mt_v=[mt_v 'prof_ptr']; mt_u=[mt_u 'X']; mt_n=[mt_n 'passive tracer']; mt_d=[mt_d 'iPROF,iDEPTH']; |
78 |
|
|
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']; |
79 |
|
|
% |
80 |
gforget |
1.10 |
mt_v=[mt_v 'prof_D']; mt_u=[mt_u 'me']; mt_n=[mt_n 'variable depth']; mt_d=[mt_d 'iPROF,iDEPTH']; |
81 |
|
|
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']; |
82 |
|
|
% |
83 |
gforget |
1.1 |
mt_v=[mt_v 'prof_bp']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'bottom pressure']; mt_d=[mt_d 'iPROF']; |
84 |
|
|
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']; |
85 |
|
|
mt_v=[mt_v 'prof_ssh']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'sea surface height']; mt_d=[mt_d 'iPROF']; |
86 |
|
|
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']; |
87 |
|
|
|
88 |
|
|
%=============================create the file=================================% |
89 |
|
|
|
90 |
roquet |
1.6 |
% write the netcdf structure |
91 |
roquet |
1.7 |
ncid=nccreate(fileOut,'clobber'); |
92 |
roquet |
1.6 |
|
93 |
roquet |
1.7 |
aa=sprintf(['Format: MITprof netcdf. This file was created using \n' ... |
94 |
roquet |
1.6 |
'the matlab toolbox which can be obtained (see README) from \n'... |
95 |
|
|
'http://mitgcm.org/viewvc/MITgcm/MITgcm_contrib/gael/profilesMatlabProcessing/']); |
96 |
|
|
ncputAtt(ncid,'','description',aa); |
97 |
|
|
ncputAtt(ncid,'','date',date); |
98 |
|
|
|
99 |
|
|
ncdefDim(ncid,'iPROF',iPROF); |
100 |
|
|
ncdefDim(ncid,'iDEPTH',iDEPTH); |
101 |
|
|
ncdefDim(ncid,'lTXT',lTXT); |
102 |
|
|
|
103 |
|
|
for ii=1:length(list_vars_plus); |
104 |
|
|
jj=find(strcmp(mt_v,list_vars_plus{ii})); |
105 |
|
|
if ~isempty(jj); |
106 |
|
|
if strcmp(mt_d{jj},'iPROF,iDEPTH'); |
107 |
|
|
ncdefVar(ncid,mt_v{jj},'double',{'iDEPTH','iPROF'});%note the direction flip |
108 |
gforget |
1.5 |
else; |
109 |
roquet |
1.6 |
ncdefVar(ncid,mt_v{jj},'double',{mt_d{jj}}); |
110 |
gforget |
1.5 |
end; |
111 |
roquet |
1.6 |
ncputAtt(ncid,mt_v{jj},'long_name',mt_n{jj}); |
112 |
|
|
ncputAtt(ncid,mt_v{jj},'units',mt_u{jj}); |
113 |
|
|
ncputAtt(ncid,mt_v{jj},'missing_value',fillval); |
114 |
|
|
ncputAtt(ncid,mt_v{jj},'_FillValue',fillval); |
115 |
|
|
else; |
116 |
roquet |
1.8 |
if strcmp(list_vars_plus{ii},'prof_descr') |
117 |
|
|
ncdefVar(ncid,'prof_descr','char',{'lTXT','iPROF'}); |
118 |
|
|
ncputAtt(ncid,'prof_descr','long_name','profile description'); |
119 |
|
|
else |
120 |
|
|
warning([list_vars_plus{ii} ' not included -- it is not a MITprof variable']); |
121 |
|
|
end |
122 |
gforget |
1.1 |
end; |
123 |
|
|
end; |
124 |
|
|
|
125 |
roquet |
1.6 |
ncclose(ncid); |
126 |
|
|
|
127 |
roquet |
1.7 |
%=============================set prof_depth=================================% |
128 |
|
|
|
129 |
|
|
ncid=ncopen(fileOut,'write'); |
130 |
|
|
ncputvar(ncid,'prof_depth',prof_depth); |
131 |
|
|
ncclose(ncid); |
132 |
gforget |
1.5 |
|
133 |
gforget |
1.1 |
|