/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_create.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_create.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download)
Thu Feb 23 18:27:22 2017 UTC (8 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66o, HEAD
Changes since 1.15: +1 -1 lines
- replace call to nccreate with nccreateFile following gcmfaces_IO update where
  nccreate was renamed as nccreateFile to avoid overriding native nccreate matlab function

1 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
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 prof_depth=MITprofCur.prof_depth;
14 prof_depth=reshape(prof_depth,length(prof_depth),1);
15 iPROF=MITprofCur.np; iDEPTH=MITprofCur.nr;
16 if isfield(MITprofCur,'prof_interp_weights');
17 iINTERP=size(MITprofCur.prof_interp_weights,2);
18 addGrid=1;
19 else;
20 iINTERP=1;
21 addGrid=0;
22 end;
23 lTXT=30; fillval=double(-9999);
24
25 %=============list of variables that will actually be in the file==============%
26 if nargin>2;
27 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 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 end;
37
38 % eliminate duplicates
39 [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
51 %==========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 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 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 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 %
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 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 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 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 %
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 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 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 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 %
76 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 %
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 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
110 %=============================create the file=================================%
111
112 % write the netcdf structure
113 ncid=nccreateFile(fileOut,'clobber');
114
115 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 ncputAtt(ncid,'','date',date);
120
121 ncdefDim(ncid,'iPROF',iPROF);
122 ncdefDim(ncid,'iDEPTH',iDEPTH);
123 if addGrid; ncdefDim(ncid,'iINTERP',iINTERP); end;
124 ncdefDim(ncid,'lTXT',lTXT);
125
126 for ii=1:length(list_vars);
127 jj=find(strcmp(mt_v,list_vars{ii}));
128 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 elseif strcmp(mt_d{jj},'iPROF,iINTERP');
132 ncdefVar(ncid,mt_v{jj},'double',{'iINTERP','iPROF'});%note the direction flip
133 else;
134 ncdefVar(ncid,mt_v{jj},'double',{mt_d{jj}});
135 end;
136 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 if strcmp(list_vars{ii},'prof_descr')
142 ncdefVar(ncid,'prof_descr','char',{'lTXT','iPROF'});
143 ncputAtt(ncid,'prof_descr','long_name','profile description');
144 else
145 warning([list_vars{ii} ' not included -- it is not a MITprof variable']);
146 end
147 end;
148 end;
149
150 ncclose(ncid);
151
152 %=============================set prof_depth=================================%
153
154 ncid=ncopen(fileOut,'write');
155 ncputvar(ncid,'prof_depth',prof_depth);
156 ncclose(ncid);
157
158

  ViewVC Help
Powered by ViewVC 1.1.22