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

Annotation 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.12 - (hide annotations) (download)
Mon Apr 13 20:06:07 2015 UTC (10 years, 3 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.11: +14 -1 lines
- allow prof_interp_* etc through MITprof_create.m, MITprof_write.m

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 gforget 1.12 iPROF=nProf; iDEPTH=nLev; iINTERP=1;
33 roquet 1.7 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 gforget 1.12 %
91     list_interpr={'prof_interp_XC11','prof_interp_YC11','prof_interp_XCNINJ','prof_interp_YCNINJ'};
92     for ii=1:length(list_interpr);
93     mt_v=[mt_v list_interpr{ii}]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'interpolation variable']; mt_d=[mt_d 'iPROF'];
94     end;
95     list_interpr={'prof_interp_i','prof_interp_j','prof_interp_lon','prof_interp_lat','prof_interp_weights'};
96     for ii=1:length(list_interpr);
97     mt_v=[mt_v list_interpr{ii}]; mt_u=[mt_u 'unknown']; mt_n=[mt_n 'interpolation variable']; mt_d=[mt_d 'iPROF,iINTERP'];
98     end;
99     %
100 gforget 1.11 if 0;
101     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'];
102     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'];
103     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'];
104     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'];
105     mt_v=[mt_v 'prof_ptr']; mt_u=[mt_u 'X']; mt_n=[mt_n 'passive tracer']; mt_d=[mt_d 'iPROF,iDEPTH'];
106     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'];
107     %
108     mt_v=[mt_v 'prof_D']; mt_u=[mt_u 'me']; mt_n=[mt_n 'variable depth']; mt_d=[mt_d 'iPROF,iDEPTH'];
109     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'];
110     %
111     mt_v=[mt_v 'prof_bp']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'bottom pressure']; mt_d=[mt_d 'iPROF'];
112     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'];
113     mt_v=[mt_v 'prof_ssh']; mt_u=[mt_u 'cm']; mt_n=[mt_n 'sea surface height']; mt_d=[mt_d 'iPROF'];
114     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'];
115     end;
116 gforget 1.1
117     %=============================create the file=================================%
118    
119 roquet 1.6 % write the netcdf structure
120 roquet 1.7 ncid=nccreate(fileOut,'clobber');
121 roquet 1.6
122 roquet 1.7 aa=sprintf(['Format: MITprof netcdf. This file was created using \n' ...
123 roquet 1.6 'the matlab toolbox which can be obtained (see README) from \n'...
124     'http://mitgcm.org/viewvc/MITgcm/MITgcm_contrib/gael/profilesMatlabProcessing/']);
125     ncputAtt(ncid,'','description',aa);
126     ncputAtt(ncid,'','date',date);
127    
128     ncdefDim(ncid,'iPROF',iPROF);
129     ncdefDim(ncid,'iDEPTH',iDEPTH);
130 gforget 1.12 ncdefDim(ncid,'iINTERP',iINTERP);
131 roquet 1.6 ncdefDim(ncid,'lTXT',lTXT);
132    
133 gforget 1.11 for ii=1:length(list_vars);
134     jj=find(strcmp(mt_v,list_vars{ii}));
135 roquet 1.6 if ~isempty(jj);
136     if strcmp(mt_d{jj},'iPROF,iDEPTH');
137     ncdefVar(ncid,mt_v{jj},'double',{'iDEPTH','iPROF'});%note the direction flip
138 gforget 1.12 elseif strcmp(mt_d{jj},'iPROF,iINTERP');
139     ncdefVar(ncid,mt_v{jj},'double',{'iINTERP','iPROF'});%note the direction flip
140 gforget 1.5 else;
141 roquet 1.6 ncdefVar(ncid,mt_v{jj},'double',{mt_d{jj}});
142 gforget 1.5 end;
143 roquet 1.6 ncputAtt(ncid,mt_v{jj},'long_name',mt_n{jj});
144     ncputAtt(ncid,mt_v{jj},'units',mt_u{jj});
145     ncputAtt(ncid,mt_v{jj},'missing_value',fillval);
146     ncputAtt(ncid,mt_v{jj},'_FillValue',fillval);
147     else;
148 gforget 1.11 if strcmp(list_vars{ii},'prof_descr')
149 roquet 1.8 ncdefVar(ncid,'prof_descr','char',{'lTXT','iPROF'});
150     ncputAtt(ncid,'prof_descr','long_name','profile description');
151     else
152 gforget 1.11 warning([list_vars{ii} ' not included -- it is not a MITprof variable']);
153 roquet 1.8 end
154 gforget 1.1 end;
155     end;
156    
157 roquet 1.6 ncclose(ncid);
158    
159 roquet 1.7 %=============================set prof_depth=================================%
160    
161     ncid=ncopen(fileOut,'write');
162     ncputvar(ncid,'prof_depth',prof_depth);
163     ncclose(ncid);
164 gforget 1.5
165 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22