source: trunk/src/d2m_to_q2m_erai.pro @ 96

Last change on this file since 96 was 94, checked in by pinsard, 13 years ago

get rid of multistatement lines

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