source: trunk/src/d2m_to_q2m_erai.pro @ 81

Last change on this file since 81 was 80, checked in by pinsard, 13 years ago

progress on humidity processing

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