source: trunk/src/d2m_to_q2m_erai.pro @ 175

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

an other bunch of new functions

  • Property svn:keywords set to Id URL
File size: 9.5 KB
Line 
1;+
2;
3; ===================
4; d2m_to_q2m_erai.pro
5; ===================
6;
7; .. function:: d2m_to_q2m_erai(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
12; Conversion of d2m to q2m on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
15; containing
16; ++
17; has been produced by
18; :func:`interp_erai_dewt`.
19;
20; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
21; containing
22; ++
23; has been produced by
24; :func:`interp_erai_t2m`.
25;
26; :file:`${PROJECT_OD}/erai_msl_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
27; containing
28; ++
29; has been
30; produced by
31; :func:`interp_erai_msl`.
32;
33; q2m on OAFLUX grid
34; is written in
35; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
36; if this file not already exists.
37;
38; This file
39; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
40; will be used by
41; :func:`q2m_correction_ncdf`.
42;
43; .. only:: man
44;
45;    Figure is visible on PDF and HTML documents only.
46;
47; .. only:: html or latex
48;
49;     .. graphviz::
50;
51;        digraph d2m_to_q2m_erai {
52;
53;           file_d2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_d2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
54;           file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
55;           file_msl [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_msl_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
56;           file_q2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
57;
58;           d2m_to_q2m_erai [shape=box,
59;           fontname=Courier,
60;           color=blue,
61;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/d2m_to_q2m_erai.pro",
62;           label="${PROJECT}/src/d2m_to_q2m_erai.pro"];
63;
64;           {file_d2m file_t2m file_msl} -> {d2m_to_q2m_erai} -> {file_q2m}
65;
66;        }
67;
68; SEE ALSO
69; ========
70;
71; :ref:`mooring_corrections`
72;
73; [Gill:AP:1982]_
74;
75; [AOMIP]_
76;
77; Used by :ref:`tropflux.sh`
78;
79; :ref:`project_profile.sh`
80;
81; :func:`interp_erai_dewt`
82; :func:`interp_erai_msl`
83; :func:`interp_erai_t2m`
84;
85; :func:`q2m_correction_ncdf`
86;
87; :func:`rh_to_spechum`
88; :func:`initncdf <saxo:initncdf>`
89; :func:`read_ncdf <saxo:read_ncdf>`
90; :func:`julday <saxo:julday>`
91; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
92;
93; EXAMPLES
94; ========
95;
96; ::
97;
98;  IDL> yyyymmddb = 20000101L
99;  IDL> yyyymmdde = 20001231L
100;  IDL> result = d2m_to_q2m_erai(yyyymmddb, yyyymmdde)
101;  IDL> print, result
102;
103; TODO
104; ====
105;
106; fix time pb::
107;
108;   % the time axis has no date before date 2: 20000302
109;   d2m first date 29811221
110;   d2m last date 29851224
111;
112; compare time between d2m and t2m and msl after reading
113;
114; pb on cratos idl7 even if output file is written::
115;
116;   % Program caused arithmetic error: Floating overflow
117;   % Program caused arithmetic error: Floating illegal operand
118;
119; related to occurence of NaNf in ncdump output ? do no yet
120;
121; pk also see these error messages ...
122;
123; check for NaN value in P return by reading Netcdf msl file
124; solution is may be to apply *mskout to q2m like  in interp* tools
125; not yet done to keep close as possible to pk processing
126;
127; coding rules
128;
129; EVOLUTIONS
130; ==========
131;
132; $Id$
133;
134; $URL$
135;
136; - fplod 20120320
137;
138;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
139;   * pro -> function with yyyymmddb and yyyymmdde parameters
140;   * hard coded d1 and d2 replaced by yyyymmddb and yyyymmdde parameters
141;   * start to homogenize time handling regarding :func:`interp_erai_t2m`
142;
143; - fplod 20110811T114932Z aedon.locean-ipsl.upmc.fr (Darwin)
144;
145;   * add es0 value
146;   * add reference
147;   * replace q2m_erai by erai_q2m in output filename
148;
149; - fplod 20110809T154249Z aedon.locean-ipsl.upmc.fr (Darwin)
150;
151;   * typo
152;
153; - fplod 20110808T120234Z cratos (Linux)
154;
155;   * usage of ${PROJECT_OD}
156;   * complete description
157;   * remove return statement
158;
159; - fplod 20101215T162933Z aedon.locean-ipsl.upmc.fr (Darwin)
160;
161;   * graph correction
162;
163; - fplod 20101215T093141Z aedon.locean-ipsl.upmc.fr (Darwin)
164;
165;   * add graph in header
166;
167; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
168;
169;   * minimal header
170;
171; - pbk 2008
172;
173;   * creation
174;
175;-
176function d2m_to_q2m_erai $
177         , yyyymmddb $
178         , yyyymmdde
179;
180compile_opt idl2, strictarrsubs, logical_predicate
181;
182@cm_4cal
183@cm_4data
184@cm_4mesh
185@cm_4data
186@cm_project
187;
188; Return to caller if errors
189;+++ ON_ERROR, 2
190;
191result = -1
192;
193usage = 'result = d2m_to_q2m_erai(yyyymmddb, yyyymmdde)'
194nparam = N_PARAMS()
195IF (nparam NE 2) THEN BEGIN
196ras = report(['Incorrect number of arguments.' $
197      + '!C' $
198      + 'Usage : ' + usage])
199      return, result
200ENDIF
201;
202; test if ${PROJECT_OD} defined
203CASE project_od_env OF
204  '' : BEGIN
205         msg = 'eee : ${PROJECT_OD} is not defined'
206         ras = report(msg)
207       return, result
208       END
209  ELSE: BEGIN
210          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
211          ras = report(msg)
212        END
213 ENDCASE
214;
215; check if output data will be possible
216iodirout = isadirectory(project_od_env)
217;
218; existence and protection for reading
219IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
220   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
221   ras = report(msg)
222   return, result
223ENDIF
224;
225; existence and protection for writing
226IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
227    msg = 'eee : the directory' + iodirout  + ' was not found.'
228    ras = report(msg)
229    return, result
230ENDIF
231;
232; build d2m filename
233filename_d2m='erai_d2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
234;
235; check if this file exists
236msg='iii : looking for ' + filename_d2m
237ras = report(msg)
238fullfilename_d2m = isafile(iodirout + filename_d2m, NEW=0, /MUST_EXIST)
239IF fullfilename_d2m[0] EQ '' THEN BEGIN
240   msg = 'eee : the file ' + fullfilename_d2m + ' was not found.'
241   ras = report(msg)
242   return, result
243ENDIF
244;
245; build t2m filename
246filename_t2m='erai_t2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
247;
248; check if this file exists
249msg='iii : looking for ' + filename_t2m
250ras = report(msg)
251fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
252IF fullfilename_t2m[0] EQ '' THEN BEGIN
253   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
254   ras = report(msg)
255   return, result
256ENDIF
257;
258; build msl filename
259filename_msl='erai_msl_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
260;
261; check if this file exists
262msg='iii : looking for ' + filename_msl
263ras = report(msg)
264fullfilename_msl = isafile(iodirout + filename_msl, NEW=0, /MUST_EXIST)
265IF fullfilename_msl[0] EQ '' THEN BEGIN
266   msg = 'eee : the file ' + fullfilename_msl + ' was not found.'
267   ras = report(msg)
268   return, result
269ENDIF
270;
271; build output filename
272filename_out = 'erai_q2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
273fullfilename_out = iodirout + filename_out
274; in order to avoid unexpected overwritten
275IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
276   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
277   ras = report(msg)
278   return, result
279ENDIF
280;
281; reading erai dew point temperature
282initncdf, fullfilename_d2m
283td=read_ncdf("d2m", yyyymmddb, yyyymmdde, file=fullfilename_d2m,/nostr)
284timein=24.d*(time-julday(1,1,1957,0,0,0))
285jpt=n_elements(timein)
286da=jul2date(time[0])
287cda0=string(da,format='(i8.8)')
288da=jul2date(time[jpt-1])
289cda1=string(da,format='(i8.8)')
290print, 'd2m first date ', cda0
291print, 'd2m last date ' , cda1
292;
293; reading erai air temperature
294initncdf, fullfilename_t2m
295t=read_ncdf("t2m", yyyymmddb, yyymmdde, file=fullfilename_t2m,/nostr)
296timein=24.d*(time-julday(1,1,1957,0,0,0))
297jpt=n_elements(timein)
298da=jul2date(time[0])
299cda0=string(da,format='(i8.8)')
300da=jul2date(time[jpt-1])
301cda1=string(da,format='(i8.8)')
302print, 't2m in d2m_to_q2m_erai first date ', cda0
303print, 't2m in d2m_to_q2m_erai last date ' , cda1
304
305help, t, td
306;
307;since the t2m and d2m are already in K, no need for conversion
308es0=6.11
309e=es0*exp((25.e5/461.5)*((1/273.15)-(1/td)))
310es=es0*exp((25.e5/461.5)*((1/273.15)-(1/t)))
311;
312rh=(e/es)*100
313;
314; conversion of relative humidity to sp. humidity
315; Ref.1 -  Gill, Appendix 4,
316; Ref.2 - http://efdl.cims.nyu.edu/project_aomip/forcing_data/atmosphere/humidity.html
317;
318t=t-273.15
319;
320initncdf, fullfilename_msl
321P=read_ncdf("msl", yyyymmddb, yyyymmdde, file=fullfilename_msl,/nostr)
322timein=24.d*(time-julday(1,1,1957,0,0,0))
323jpt=n_elements(timein)
324da=jul2date(time[0])
325cda0=string(da,format='(i8.8)')
326da=jul2date(time[jpt-1])
327cda1=string(da,format='(i8.8)')
328print, 'msl in d2m_to_q2m_erai first date ', cda0
329print, 'msl in d2m_to_q2m_erai last date ' , cda1
330help, P
331; ++ for debug ftp error
332; ++print,P[0:1,0,0]
333; ++stop
334q2m=rh_to_spechum(rh,t,P)
335;
336;writing field
337ncfile='!' + fullfilename_out
338xlon=reform(glamt[*,0])
339ylat=reform(gphit[0,*])
340valmask=1.e20
341;
342lon_attr={units:'degrees_east',long_name:'Longitude'}
343lat_attr={units:'degrees_north',long_name:'Latitude'}
344q2m_attr={units:'kg/kg',missing_value:valmask,long_name:'Surface specific humidity at 2m ',short_name:'q2m',axis:'TYX'}
345time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
346globattr={source:'Surface specific humidity at 2m calculated from dew point temperature',timerange:cda0+' - '+cda1}
347;
348ncfields = 'q2m[longitude,latitude,*time]=q2m:q2m_attr; ' $
349                      + 'longitude[]=xlon:lon_attr; ' $
350                      + 'latitude[]=ylat:lat_attr; ' $
351                      + 'time[]=timein:time_attr ' $
352                      + ' @ globattr'
353;
354@ncdf_quickwrite
355;
356result = 0
357return, result
358;
359end
Note: See TracBrowser for help on using the repository browser.