/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/netcdf_ecco_create.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/netcdf_ecco_create.m

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


Revision 1.2 - (hide annotations) (download)
Thu May 13 19:56:35 2010 UTC (15 years, 2 months ago) by gforget
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
moving to profiles_process_main_v1

1 gforget 1.1 %function: netcdf_ecco_create
2     %object: create netcdf data files in the "MIT format"
3     %author: Gael Forget (gforget@mit.edu)
4     %date: Apr 17th, 2006
5     %
6     %main inputs: (structure arrays)
7     % mystruct1D=struct('prof_YYYYMMDD',prof_YYYYMMDD,'prof_HHMMSS',...
8     % prof_HHMMSS, 'prof_lon',prof_lon,'prof_lat',prof_lat);
9     % mystruct=struct('prof_T',prof_T,'prof_Tweight',prof_Tweight, etc );
10     % OR mystruct=struct('prof_T',prof_T,'prof_Tmask',prof_Tmask, etc );
11     %
12     %other inputs: file_name, file_characteristics, depth (1D vector), prof_descr (texte)
13     % file_characteristics(1)=total number of profiles
14     % file_characteristics(2)=last profile written
15     % if file_characteristics(2)==0 we create the file
16     % file_characteristics(3)=length of the character description
17     % file_characteristics(4)=missing_value
18     %
19     %asumptions about the inputs:
20     % T is potential temperature, we do not use the missing value
21     % but 0 for weight/mask (facilitate "cost" computation),
22     % units are the standard ones (see the netcdf attributes)
23     %
24     %usage: see netcdf_postprocess_argoctd.m, netcdf_ecco_recompose.m
25     %
26     %Gael, June 7th 1007: I add the option to write interpolation information
27     % assumption: varargin is mystructInterp (i,j,weights), while
28     % XC11 etc. have been added to mystruct1D
29     %Left for later: genericity (read/compute dim4mygrid), additional info about interp stuff
30    
31     function []=netcdf_ecco_create(file_name, file_characteristics, depth, prof_descr, mystruct, mystruct1D,varargin);
32    
33     %a couple of checks:
34     tmp1=length(mystruct1D.prof_lon);
35     if (file_characteristics(2)+tmp1>file_characteristics(1));
36     fprintf('problem: total number of profiles exceeded \n');
37     fprintf('writing aborted'); return; end;
38     if (file_characteristics(3)<size(prof_descr,2));
39     fprintf('problem: profiles description is too long \n');
40     fprintf('writing aborted'); return; end;
41    
42     %incl interp coeffs for genericgrid option
43     if ~isempty(varargin)
44     incl4mygrid=1; dim4mygridInterp=size(varargin{1}.prof_interp_i,2); %dim4mygridInterp=2;
45     else
46     incl4mygrid=0;
47     end
48    
49     %creation of the file:
50     if file_characteristics(2)==0
51    
52     fcdf=netcdf(deblank(file_name), 'clobber');
53    
54     %define netcdf dimensions :
55     nb_lev=length(depth);
56     fcdf('iPROF') = file_characteristics(1);
57     fcdf('iDEPTH') = nb_lev;
58     fcdf('lTXT') = file_characteristics(3);
59     if incl4mygrid; fcdf('iINTERP') = dim4mygridInterp; end;
60     missing_value=file_characteristics(4);
61    
62     %define netcdf variables :
63     fcdf{'depth'} = ncdouble('iDEPTH');
64     fcdf{'depth'}.units='meters';
65     fcdf{'prof_YYYYMMDD'} = ncdouble('iPROF');
66     fcdf{'prof_YYYYMMDD'}.missing_value=missing_value;
67     fcdf{'prof_YYYYMMDD'}.long_name='year (4 digits), month (2 digits), day (2 digits)';
68     fcdf{'prof_HHMMSS'} = ncdouble('iPROF');
69     fcdf{'prof_HHMMSS'}.missing_value=missing_value;
70     fcdf{'prof_HHMMSS'}.long_name='hour (2 digits), minute (2 digits), seconde (2 digits)';
71     fcdf{'prof_lon'} = ncdouble('iPROF');
72     fcdf{'prof_lon'}.units='(degree E)';
73     fcdf{'prof_lon'}.missing_value=missing_value;
74     fcdf{'prof_lat'} = ncdouble('iPROF');
75     fcdf{'prof_lat'}.units='(degree N)';
76     fcdf{'prof_lat'}.missing_value=missing_value;
77     fcdf{'prof_descr'} = ncchar('iPROF','lTXT');
78     fcdf{'prof_descr'}.long_name='profile description';
79     fcdf{'depth'}(1:nb_lev)=depth;
80     if incl4mygrid;
81     fcdf{'prof_interp_XC11'} = ncdouble('iPROF'); fcdf{'prof_interp_YC11'} = ncdouble('iPROF');
82     fcdf{'prof_interp_XCNINJ'} = ncdouble('iPROF'); fcdf{'prof_interp_YCNINJ'} = ncdouble('iPROF');
83     fcdf{'prof_interp_i'} = ncdouble('iPROF','iINTERP');
84     fcdf{'prof_interp_j'} = ncdouble('iPROF','iINTERP');
85     fcdf{'prof_interp_lon'} = ncdouble('iPROF','iINTERP');
86     fcdf{'prof_interp_lat'} = ncdouble('iPROF','iINTERP');
87     fcdf{'prof_interp_weights'} = ncdouble('iPROF','iINTERP');
88     end
89    
90     if isfield(mystruct,'prof_T')
91     fcdf{'prof_T'} = ncdouble('iPROF','iDEPTH');
92     fcdf{'prof_T'}.long_name='potential temperature';
93     fcdf{'prof_T'}.units='degree Celsius';
94     fcdf{'prof_T'}.missing_value=missing_value;
95     end
96     if isfield(mystruct,'prof_Tweight')
97     fcdf{'prof_Tweight'} = ncdouble('iPROF','iDEPTH');
98     fcdf{'prof_Tweight'}.long_name='weights';
99     fcdf{'prof_Tweight'}.units='(degree Celsius)^-2';
100     fcdf{'prof_Tweight'}.missing_value=missing_value;
101     end
102     if isfield(mystruct,'prof_Tmask')
103     fcdf{'prof_Tmask'} = ncdouble('iPROF','iDEPTH');
104     fcdf{'prof_Tmask'}.long_name='model mask';
105     fcdf{'prof_Tmask'}.units='no units';
106     fcdf{'prof_Tmask'}.missing_value=missing_value;
107     end
108     if isfield(mystruct,'prof_S')
109     fcdf{'prof_S'} = ncdouble('iPROF','iDEPTH');
110     fcdf{'prof_S'}.long_name='salinity';
111     fcdf{'prof_S'}.units='(no units)';
112     fcdf{'prof_S'}.missing_value=missing_value;
113     end
114     if isfield(mystruct,'prof_Sweight')
115     fcdf{'prof_Sweight'} = ncdouble('iPROF','iDEPTH');
116     fcdf{'prof_Sweight'}.long_name='weights';
117     fcdf{'prof_Sweight'}.units='(no units)^-2';
118     fcdf{'prof_Sweight'}.missing_value=missing_value;
119     end
120     if isfield(mystruct,'prof_Smask')
121     fcdf{'prof_Smask'} = ncdouble('iPROF','iDEPTH');
122     fcdf{'prof_Smask'}.long_name='model mask';
123     fcdf{'prof_Smask'}.units='no units';
124     fcdf{'prof_Smask'}.missing_value=missing_value;
125     end
126     if isfield(mystruct,'prof_U')
127     fcdf{'prof_U'} = ncdouble('iPROF','iDEPTH');
128     fcdf{'prof_U'}.long_name='zonal velocity';
129     fcdf{'prof_U'}.units='m/s';
130     fcdf{'prof_U'}.missing_value=missing_value;
131     fcdf{'prof_V'} = ncdouble('iPROF','iDEPTH');
132     fcdf{'prof_V'}.long_name='meridional velocity';
133     fcdf{'prof_V'}.units='m/s';
134     fcdf{'prof_V'}.missing_value=missing_value;
135     end
136     if isfield(mystruct,'prof_Uweight')
137     fcdf{'prof_Uweight'} = ncdouble('iPROF','iDEPTH');
138     fcdf{'prof_Uweight'}.long_name='weights';
139     fcdf{'prof_Uweight'}.units='(m/s)^-2';
140     fcdf{'prof_Uweight'}.missing_value=missing_value;
141     fcdf{'prof_Vweight'} = ncdouble('iPROF','iDEPTH');
142     fcdf{'prof_Vweight'}.long_name='weights';
143     fcdf{'prof_Vweight'}.units='(m/s)^-2';
144     fcdf{'prof_Vweight'}.missing_value=missing_value;
145     end
146     if isfield(mystruct,'prof_Umask')
147     fcdf{'prof_Umask'} = ncdouble('iPROF','iDEPTH');
148     fcdf{'prof_Umask'}.long_name='model mask';
149     fcdf{'prof_Umask'}.units='no units';
150     fcdf{'prof_Umask'}.missing_value=missing_value;
151     fcdf{'prof_Vmask'} = ncdouble('iPROF','iDEPTH');
152     fcdf{'prof_Vmask'}.long_name='model mask';
153     fcdf{'prof_Vmask'}.units='no units';
154     fcdf{'prof_Vmask'}.missing_value=missing_value;
155     end
156     if isfield(mystruct,'prof_ptr')
157     fcdf{'prof_ptr'} = ncdouble('iPROF','iDEPTH');
158     fcdf{'prof_ptr'}.long_name='passive tracer';
159     fcdf{'prof_ptr'}.units='XX';
160     fcdf{'prof_ptr'}.missing_value=missing_value;
161     end
162     if isfield(mystruct,'prof_ptrweight')
163     fcdf{'prof_ptrweight'} = ncdouble('iPROF','iDEPTH');
164     fcdf{'prof_ptrweight'}.long_name='weights';
165     fcdf{'prof_ptrweight'}.units='(XX)^-2';
166     fcdf{'prof_ptrweight'}.missing_value=missing_value;
167     end
168     if isfield(mystruct,'prof_ptrmask')
169     fcdf{'prof_ptrmask'} = ncdouble('iPROF','iDEPTH');
170     fcdf{'prof_ptrmask'}.long_name='model mask';
171     fcdf{'prof_ptrmask'}.units='no units';
172     fcdf{'prof_ptrmask'}.missing_value=missing_value;
173     end
174     if isfield(mystruct,'prof_ssh')
175     fcdf{'prof_ssh'} = ncdouble('iPROF','iDEPTH');
176     fcdf{'prof_ssh'}.long_name='sea surface height';
177     fcdf{'prof_ssh'}.units='m';
178     fcdf{'prof_ssh'}.missing_value=missing_value;
179     end
180     if isfield(mystruct,'prof_sshweight')
181     fcdf{'prof_sshweight'} = ncdouble('iPROF','iDEPTH');
182     fcdf{'prof_sshweight'}.long_name='weights';
183     fcdf{'prof_sshweight'}.units='(m)^-2';
184     fcdf{'prof_sshweight'}.missing_value=missing_value;
185     end
186     if isfield(mystruct,'prof_sshmask')
187     fcdf{'prof_sshmask'} = ncdouble('iPROF','iDEPTH');
188     fcdf{'prof_sshmask'}.long_name='model mask';
189     fcdf{'prof_sshmask'}.units='no units';
190     fcdf{'prof_sshmask'}.missing_value=missing_value;
191     end
192    
193     fcdf=close(fcdf);
194    
195     end; %if file_characteristics(2)==0
196    
197    
198     fcdf=netcdf(deblank(file_name), 'write');
199    
200     tmp1=length(mystruct1D.prof_lon);
201     tmp1=[1:tmp1]+file_characteristics(2);
202    
203     %fill the date and position vectors :
204     fcdf{'prof_YYYYMMDD'}(tmp1')=mystruct1D.prof_YYYYMMDD;
205     fcdf{'prof_HHMMSS'}(tmp1')=mystruct1D.prof_HHMMSS;
206     fcdf{'prof_lon'}(tmp1')=mystruct1D.prof_lon;
207     fcdf{'prof_lat'}(tmp1')=mystruct1D.prof_lat;
208     tmp0=double(prof_descr); prof_descr(find(tmp0==0))=' ';
209     tmp2=file_characteristics(3)-size(prof_descr,2);
210     if (tmp2>0); prof_descr=[prof_descr char(double(' ')*ones(length(tmp1'),tmp2)) ]; end;
211     fcdf{'prof_descr'}(tmp1',:)=prof_descr(:,:);
212    
213     if incl4mygrid;
214     fcdf{'prof_interp_XC11'}(tmp1')=mystruct1D.prof_interp_XC11; fcdf{'prof_interp_YC11'}(tmp1')=mystruct1D.prof_interp_YC11;
215     fcdf{'prof_interp_XCNINJ'}(tmp1')=mystruct1D.prof_interp_XCNINJ; fcdf{'prof_interp_YCNINJ'}(tmp1')=mystruct1D.prof_interp_YCNINJ;
216     fcdf{'prof_interp_i'}(tmp1',:)=varargin{1}.prof_interp_i;
217     fcdf{'prof_interp_j'}(tmp1',:)=varargin{1}.prof_interp_j;
218     fcdf{'prof_interp_lon'}(tmp1',:)=varargin{1}.prof_interp_lon;
219     fcdf{'prof_interp_lat'}(tmp1',:)=varargin{1}.prof_interp_lat;
220     fcdf{'prof_interp_weights'}(tmp1',:)=varargin{1}.prof_interp_weights;
221     end
222    
223     %fill the data matrices :
224    
225     if isfield(mystruct,'prof_T'); fcdf{'prof_T'}(tmp1',:)=mystruct.prof_T; end;
226     if isfield(mystruct,'prof_Tweight');
227     fcdf{'prof_Tweight'}(tmp1',:)=mystruct.prof_Tweight; end;
228     if isfield(mystruct,'prof_Tmask');
229     fcdf{'prof_Tmask'}(tmp1',:)=mystruct.prof_Tmask; end;
230    
231     if isfield(mystruct,'prof_S'); fcdf{'prof_S'}(tmp1',:)=mystruct.prof_S; end;
232     if isfield(mystruct,'prof_Sweight');
233     fcdf{'prof_Sweight'}(tmp1',:)=mystruct.prof_Sweight; end;
234     if isfield(mystruct,'prof_Smask');
235     fcdf{'prof_Smask'}(tmp1',:)=mystruct.prof_Smask; end;
236    
237     if isfield(mystruct,'prof_U'); fcdf{'prof_U'}(tmp1',:)=mystruct.prof_U; end;
238     if isfield(mystruct,'prof_Uweight');
239     fcdf{'prof_Uweight'}(tmp1',:)=mystruct.prof_Uweight; end;
240     if isfield(mystruct,'prof_Umask');
241     fcdf{'prof_Umask'}(tmp1',:)=mystruct.prof_Umask; end;
242    
243     if isfield(mystruct,'prof_V'); fcdf{'prof_V'}(tmp1',:)=mystruct.prof_V; end;
244     if isfield(mystruct,'prof_Vweight');
245     fcdf{'prof_Vweight'}(tmp1',:)=mystruct.prof_Vweight; end;
246     if isfield(mystruct,'prof_Vmask');
247     fcdf{'prof_Vmask'}(tmp1',:)=mystruct.prof_Vmask; end;
248    
249     if isfield(mystruct,'prof_ptr');
250     fcdf{'prof_ptr'}(tmp1',:)=mystruct.prof_ptr; end;
251     if isfield(mystruct,'prof_ptrweight');
252     fcdf{'prof_ptrweight'}(tmp1',:)=mystruct.prof_ptrweight; end;
253     if isfield(mystruct,'prof_ptrmask');
254     fcdf{'prof_ptrmask'}(tmp1',:)=mystruct.prof_ptrmask; end;
255    
256     if isfield(mystruct,'prof_ssh');
257     fcdf{'prof_ssh'}(tmp1',:)=mystruct.prof_ssh; end;
258     if isfield(mystruct,'prof_sshweight');
259     fcdf{'prof_sshweight'}(tmp1',:)=mystruct.prof_sshweight; end;
260     if isfield(mystruct,'prof_sshmask');
261     fcdf{'prof_sshmask'}(tmp1',:)=mystruct.prof_sshmask; end;
262    
263     %close the file
264     fcdf=close(fcdf);
265    
266    

  ViewVC Help
Powered by ViewVC 1.1.22