source: trunk/src/q2m_correction_ncdf.pro @ 190

Last change on this file since 190 was 180, checked in by pinsard, 12 years ago

no more IDL prompt in examples

  • Property svn:keywords set to URL
File size: 7.0 KB
Line 
1;+
2;
3; =======================
4; q2m_correction_ncdf.pro
5; =======================
6;
7; .. function:: q2m_correction_ncdf(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Correction of q2m on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
15; containing
16; ++
17; has been produced by
18; :func:`d2m_to_q2m_erai`.
19;
20; Corrected q2m on OAFLUX grid
21; is written in
22; :file:`${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc`
23; if this file not already exists.
24;
25; This file will be used by
26; :func:`tropflux`.
27;
28; .. only:: man
29;
30;    Figure is visible on PDF and HTML documents only.
31;
32; .. only:: html or latex
33;
34;     .. graphviz::
35;
36;        digraph q2m_correction_ncdf {
37;
38;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
39;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc"];
40;
41;           q2m_correction_ncdf [shape=box,
42;           fontname=Courier,
43;           color=blue,
44;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/q2m_correction_ncdf.pro",
45;           label="${PROJECT}/src/q2m_correction_ncdf.pro"];
46;
47;           {file_in} -> {q2m_correction_ncdf} -> {file_out}
48;
49;        }
50;
51; SEE ALSO
52; ========
53;
54; :ref:`mooring_corrections`
55;
56; Used by :ref:`tropflux.sh`
57;
58; :ref:`project_profile.sh`
59;
60; :func:`d2m_to_q2m_erai`
61;
62; :func:`initncdf <saxo:initncdf>`
63; :func:`read_ncdf <saxo:read_ncdf>`
64; :func:`grossemoyenne <saxo:grossemoyenne>`
65; :func:`julday <saxo:julday>`
66; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
67;
68; EXAMPLES
69; ========
70;
71; ::
72;
73;  yyyymmddb = 20000101L
74;  yyyymmdde = 20001231L
75;  result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)
76;  print, result
77;
78; TODO
79; ====
80;
81; make it work ::
82;
83;   Writing fields:
84;   q2m[longitude,latitude,time*]=q2m_new:q2m_attr; longitude[]=lon:lon_attr; latitude[]=lat:lat_attr; time[]=timein:time_attr  @ globattr
85;   % NCDF_DIMDEF: Unable to create dimension. (NC_ERROR=-59)
86;   % NCDF_VARDEF: Unable to define variable, bad dimension id .
87;   % NCDF_VARPUT: Variable Inquiry failed, -1 is not a valid variable id.
88;   % Stop encountered: Q2M_CORRECTION_NCDF    1
89;         /.autofs/lodyc/incas/fplod/tropflux/tropflux_ws/src/q2m_correction_ncdf.pro
90;
91; No way ... NaNf also in this output !!
92;
93; coding rules
94;
95; EVOLUTIONS
96; ==========
97;
98; $Id: q2m_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $
99;
100; $URL$
101;
102; - fplod 20120322
103;
104;   * taking project_overwite into account
105;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
106;   * pro -> function
107;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
108;   * get rid of timegen
109;
110; - fplod 20110808T143129Z aedon.locean-ipsl.upmc.fr (Darwin)
111;
112;   * usage of ${PROJECT_OD}
113;   * remove v20 in output filename
114;
115; - fplod 20101215T113945Z aedon.locean-ipsl.upmc.fr (Darwin)
116;
117;   * add graph in header
118;
119; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
120;
121;   * minimal header
122;
123; - pbk 2008
124;
125;   * creation
126;
127;-
128function q2m_correction_ncdf $
129         , yyyymmddb $
130         , yyyymmdde
131;
132;++compile_opt idl2, strictarrsubs, logical_predicate
133;
134@cm_4cal
135@cm_4data
136@cm_4mesh
137@cm_4data
138@cm_project
139;
140; Return to caller if errors
141ON_ERROR, 2
142;
143result = -1
144;
145usage = 'result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)'
146nparam = N_PARAMS()
147IF (nparam NE 2) THEN BEGIN
148    ras = report(['Incorrect number of arguments.' $
149          + '!C' $
150          + 'Usage : ' + usage])
151    return, result
152ENDIF
153
154; test if ${PROJECT_OD} defined
155CASE project_od_env OF
156  '' : BEGIN
157         msg = 'eee : ${PROJECT_OD} is not defined'
158         ras = report(msg)
159       return, result
160       END
161  ELSE: BEGIN
162          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
163          ras = report(msg)
164        END
165 ENDCASE
166;
167; check if output data will be possible
168iodirout = isadirectory(project_od_env)
169;
170; existence and protection for reading
171IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
172   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
173   ras = report(msg)
174   return, result
175ENDIF
176;
177; existence and protection for writing
178IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
179    msg = 'eee : the directory' + iodirout  + ' was not found.'
180    ras = report(msg)
181    return, result
182ENDIF
183;
184; build data filename
185filename='erai_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
186;
187; check if this file exists
188msg='iii : looking for ' + filename
189ras = report(msg)
190fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
191IF fullfilename[0] EQ '' THEN BEGIN
192   msg = 'eee : the file ' + fullfilename + ' was not found.'
193   ras = report(msg)
194   return, result
195ENDIF
196;
197; build output filename
198filename_out = 'TropFlux_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
199fullfilename_out = iodirout + filename_out
200; in order to avoid unexpected overwritten
201IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
202   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
203   ras = report(msg)
204   return, result
205ENDIF
206;
207initncdf, fullfilename
208q2m=read_ncdf('q2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
209timein=24.d*(time-julday(1,1,1957,0,0,0))
210jpt=n_elements(timein)
211da=jul2date(time[0])
212cda0=string(da,format='(i8.8)')
213da=jul2date(time[jpt-1])
214cda1=string(da,format='(i8.8)')
215print, 'q2m in q2m_correction_ncdf first date ', cda0
216print, 'q2m in q2m_correction_ncdf last date ' , cda1
217;
218help, q2m
219;
220q2m_mean=grossemoyenne(q2m,'t',/nan)
221help, q2m_mean
222;
223jpt=n_elements(time)
224caldat, time,mon,day,yea
225q2m_m=q2m*0.
226;
227for jt=0,jpt-1 do begin
228  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
229  q=reform(q2m_mean[*,*])
230  q2m_m[*,*,jt]=q
231endfor
232help, q2m_m
233;
234q2m_ano=q2m-q2m_m
235;
236; correction for mean based on scatter
237;q2m_m=q2m_m+0.815445  ;  (2000-2008)
238q2m_m=q2m_m+0.792717   ;  (2000-2009)
239help, q2m_ano
240;
241; applying the correction for variability based on the scatter
242;q2m_ano=q2m_ano*(1/0.919333)  ;  (2000-2008)
243q2m_ano=q2m_ano*(1/0.924674)   ;  (2000-2009)
244;
245q2m_new=q2m_m+q2m_ano
246help, q2m_new
247;
248;writing field
249lat=reform(gphit[0,0:jpj-1])
250lon=reform(glamt[0:jpi-1,0])
251;
252ncfile='!' + fullfilename_out
253lon_attr={units:'degrees_east',long_name:'Longitude'}
254lat_attr={units:'degrees_north',long_name:'Latitude'}
255time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
256globattr={source:'Basic data obtained from ERAI.  Mean correction for bias and correction for variability are applied',timerange:cda0+' - '+cda1}
257q2m_attr={units:'g/kg',missing_value:1.e20,long_name:'Specific humidity at 2m height',short_name:'q2m',axis:'TYX'}
258;
259ncfields = 'q2m[longitude,latitude,time*]=q2m_new:q2m_attr; ' $
260                      + 'longitude[]=lon:lon_attr; ' $
261                      + 'latitude[]=lat:lat_attr; ' $
262                      + 'time[]=timein:time_attr ' $
263                      + ' @ globattr'
264;
265@ncdf_quickwrite
266;
267result = 0
268return, result
269;
270end
Note: See TracBrowser for help on using the repository browser.