source: trunk/src/d2m_to_q2m_erai.pro @ 169

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

interp_erai_lwr is now a function

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