source: trunk/src/d2m_to_q2m_erai.pro

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • 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; .. code-block:: idl
97;
98;    yyyymmddb = 20000101L
99;    yyyymmdde = 20001231L
100;    result = d2m_to_q2m_erai(yyyymmddb, yyyymmdde)
101;    print, result
102;
103; TODO
104; ====
105;
106; fix time pb:
107;
108; .. parsed-literal::
109;
110;    % the time axis has no date before date 2: 20000302
111;    d2m first date 29811221
112;    d2m last date 29851224
113;
114; compare time between d2m and t2m and msl after reading
115;
116; pb on cratos idl7 even if output file is written:
117;
118; .. parsed-literal::
119;
120;    % Program caused arithmetic error: Floating overflow
121;    % Program caused arithmetic error: Floating illegal operand
122;
123; related to occurrence of NaNf in ncdump output ? do no yet
124;
125; pk also see these error messages ...
126;
127; check for NaN value in P return by reading netCDF msl file
128; solution is may be to apply *mskout to q2m like in interp* tools
129; not yet done to keep close as possible to pk processing
130;
131; coding rules
132;
133; EVOLUTIONS
134; ==========
135;
136; $Id$
137;
138; $URL$
139;
140; - fplod 20120320
141;
142;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
143;   * pro -> function with yyyymmddb and yyyymmdde parameters
144;   * hard coded d1 and d2 replaced by yyyymmddb and yyyymmdde parameters
145;   * start to homogenize time handling regarding :func:`interp_erai_t2m`
146;
147; - fplod 20110811T114932Z aedon.locean-ipsl.upmc.fr (Darwin)
148;
149;   * add es0 value
150;   * add reference
151;   * replace q2m_erai by erai_q2m in output filename
152;
153; - fplod 20110809T154249Z aedon.locean-ipsl.upmc.fr (Darwin)
154;
155;   * typo
156;
157; - fplod 20110808T120234Z cratos (Linux)
158;
159;   * usage of ${PROJECT_OD}
160;   * complete description
161;   * remove return statement
162;
163; - fplod 20101215T162933Z aedon.locean-ipsl.upmc.fr (Darwin)
164;
165;   * graph correction
166;
167; - fplod 20101215T093141Z aedon.locean-ipsl.upmc.fr (Darwin)
168;
169;   * add graph in header
170;
171; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
172;
173;   * minimal header
174;
175; - pbk 2008
176;
177;   * creation
178;
179;-
180function d2m_to_q2m_erai $
181, yyyymmddb $
182, yyyymmdde
183;
184compile_opt idl2, strictarrsubs, logical_predicate
185;
186@cm_4cal
187@cm_4data
188@cm_4mesh
189@cm_4data
190@cm_project
191;
192; Return to caller if errors
193;+++ ON_ERROR, 2
194;
195result = -1
196;
197usage = 'result = d2m_to_q2m_erai(yyyymmddb, yyyymmdde)'
198nparam = N_PARAMS()
199IF (nparam NE 2) THEN BEGIN
200    ras = report(['Incorrect number of arguments.' $
201    + '!C' $
202    + 'Usage : ' + usage])
203    return, result
204ENDIF
205;
206; test if ${PROJECT_OD} defined
207CASE project_od_env OF
208    '' : BEGIN
209        msg = 'eee : ${PROJECT_OD} is not defined'
210        ras = report(msg)
211        return, result
212    END
213    ELSE : BEGIN
214        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
215        ras = report(msg)
216    END
217ENDCASE
218;
219; check if output data will be possible
220iodirout = isadirectory(project_od_env)
221;
222; existence and protection for reading
223IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
224    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
225    ras = report(msg)
226    return, result
227ENDIF
228;
229; existence and protection for writing
230IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
231    msg = 'eee : the directory' + iodirout  + ' was not found.'
232    ras = report(msg)
233    return, result
234ENDIF
235;
236; build d2m filename
237filename_d2m='erai_d2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
238;
239; check if this file exists
240msg='iii : looking for ' + filename_d2m
241ras = report(msg)
242fullfilename_d2m = isafile(iodirout + filename_d2m, NEW=0, /MUST_EXIST)
243IF fullfilename_d2m[0] EQ '' THEN BEGIN
244    msg = 'eee : the file ' + fullfilename_d2m + ' was not found.'
245    ras = report(msg)
246    return, result
247ENDIF
248;
249; build t2m filename
250filename_t2m='erai_t2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
251;
252; check if this file exists
253msg='iii : looking for ' + filename_t2m
254ras = report(msg)
255fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
256IF fullfilename_t2m[0] EQ '' THEN BEGIN
257    msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
258    ras = report(msg)
259    return, result
260ENDIF
261;
262; build msl filename
263filename_msl='erai_msl_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
264;
265; check if this file exists
266msg='iii : looking for ' + filename_msl
267ras = report(msg)
268fullfilename_msl = isafile(iodirout + filename_msl, NEW=0, /MUST_EXIST)
269IF fullfilename_msl[0] EQ '' THEN BEGIN
270    msg = 'eee : the file ' + fullfilename_msl + ' was not found.'
271    ras = report(msg)
272    return, result
273ENDIF
274;
275; build output filename
276filename_out = 'erai_q2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
277fullfilename_out = iodirout + filename_out
278; in order to avoid unexpected overwritten
279IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
280    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
281    ras = report(msg)
282    return, result
283ENDIF
284;
285; reading erai dew point temperature
286initncdf, fullfilename_d2m
287td=read_ncdf("d2m", yyyymmddb, yyyymmdde, file=fullfilename_d2m,/nostr)
288timein=24.d*(time-julday(1,1,1957,0,0,0))
289jpt=n_elements(timein)
290da=jul2date(time[0])
291cda0=string(da,format='(i8.8)')
292da=jul2date(time[jpt-1])
293cda1=string(da,format='(i8.8)')
294print, 'd2m first date ', cda0
295print, 'd2m last date ' , cda1
296;
297; reading erai air temperature
298initncdf, fullfilename_t2m
299t=read_ncdf("t2m", yyyymmddb, yyymmdde, file=fullfilename_t2m,/nostr)
300timein=24.d*(time-julday(1,1,1957,0,0,0))
301jpt=n_elements(timein)
302da=jul2date(time[0])
303cda0=string(da,format='(i8.8)')
304da=jul2date(time[jpt-1])
305cda1=string(da,format='(i8.8)')
306print, 't2m in d2m_to_q2m_erai first date ', cda0
307print, 't2m in d2m_to_q2m_erai last date ' , cda1
308
309help, t, td
310;
311;since the t2m and d2m are already in K, no need for conversion
312es0=6.11
313e=es0*exp((25.e5/461.5)*((1/273.15)-(1/td)))
314es=es0*exp((25.e5/461.5)*((1/273.15)-(1/t)))
315;
316rh=(e/es)*100
317;
318; conversion of relative humidity to sp. humidity
319; Ref.1 -  Gill, Appendix 4,
320; Ref.2 - http://efdl.cims.nyu.edu/project_aomip/forcing_data/atmosphere/humidity.html
321;
322t=t-273.15
323;
324initncdf, fullfilename_msl
325P=read_ncdf("msl", yyyymmddb, yyyymmdde, file=fullfilename_msl,/nostr)
326timein=24.d*(time-julday(1,1,1957,0,0,0))
327jpt=n_elements(timein)
328da=jul2date(time[0])
329cda0=string(da,format='(i8.8)')
330da=jul2date(time[jpt-1])
331cda1=string(da,format='(i8.8)')
332print, 'msl in d2m_to_q2m_erai first date ', cda0
333print, 'msl in d2m_to_q2m_erai last date ' , cda1
334help, P
335; ++ for debug ftp error
336; ++print,P[0:1,0,0]
337; ++stop
338q2m=rh_to_spechum(rh,t,P)
339;
340;writing field
341ncfile='!' + fullfilename_out
342xlon=reform(glamt[*,0])
343ylat=reform(gphit[0,*])
344valmask=1.e20
345;
346lon_attr={units:'degrees_east',long_name:'Longitude'}
347lat_attr={units:'degrees_north',long_name:'Latitude'}
348q2m_attr={units:'kg/kg',missing_value:valmask,long_name:'Surface specific humidity at 2m ',short_name:'q2m',axis:'TYX'}
349time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
350globattr={source:'Surface specific humidity at 2m calculated from dew point temperature',timerange:cda0+' - '+cda1}
351;
352ncfields = 'q2m[longitude,latitude,*time]=q2m:q2m_attr; ' $
353+ 'longitude[]=xlon:lon_attr; ' $
354+ 'latitude[]=ylat:lat_attr; ' $
355+ 'time[]=timein:time_attr ' $
356+ ' @ globattr'
357;
358@ncdf_quickwrite
359;
360result = 0
361return, result
362;
363end
Note: See TracBrowser for help on using the repository browser.