source: trunk/src/d2m_to_q2m_erai.pro @ 72

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

start to work on correction tools

File size: 6.5 KB
Line 
1;+
2;
3; .. _d2m_to_q2m_erai.pro:
4;
5; ===================
6; d2m_to_q2m_erai.pro
7; ===================
8;
9; Converstion 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 ++.
19;
20; q2m on OAFLUX grid is written in
21; :file:`${PROJECT_OD}/q2m_erai_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}/q2m_erai_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; :ref:`project_profile.sh`
51;
52; :ref:`mooring_corrections`
53;
54; :ref:`interp_erai_dewt_1989_2009.pro`
55; :ref:`interp_erai_t2m_1989_2009.pro`
56;
57; :ref:`d2m_to_q2m_erai.pro`
58;
59; :func:`rh_to_spechum`
60; :func:`initncdf <saxo:initncdf>`
61; :func:`read_ncdf <saxo:read_ncdf>`
62; :func:`julday <saxo:julday>`
63; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
64;
65; EXAMPLES
66; ========
67;
68; ::
69;
70;  IDL> d2m_to_q2m_erai
71;
72; TODO
73; ====
74;
75; I (fp) do not know how
76; ${PROJECT_OD}/erai_msl_19890101_20091231_oafluxgrid.nc is produced.
77;
78; es0 undefined
79;
80; coding rules
81;
82; EVOLUTIONS
83; ==========
84;
85; - fplod 20110808T120234Z cratos (Linux)
86;
87;   * usage of ${PROJECT_OD}
88;   * complete description
89;   * remove return statement
90;
91; - fplod 20101215T162933Z aedon.locean-ipsl.upmc.fr (Darwin)
92;
93;   * graph correction
94;
95; - fplod 20101215T093141Z aedon.locean-ipsl.upmc.fr (Darwin)
96;
97;   * add graph in header
98;
99; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
100;
101;   * minimal header
102;
103; - pbk 2008
104;
105;   * creation
106;
107;-
108pro d2m_to_q2m_erai
109;
110@cm_4cal
111@cm_4data
112@cm_4mesh
113@cm_4data
114@cm_project
115;
116; test if ${PROJECT_OD} defined
117CASE project_od_env OF
118  '' : BEGIN
119         msg = 'eee : ${PROJECT_OD} is not defined'
120         ras = report(msg)
121       STOP
122       END
123  ELSE: BEGIN
124          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
125          ras = report(msg)
126        END
127 ENDCASE
128;
129; check if output data will be possible
130iodirout = isadirectory(project_od_env)
131;
132; existence and protection for reading
133IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
134   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
135   ras = report(msg)
136   STOP
137ENDIF
138;
139; existence and protection for writing
140IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
141    msg = 'eee : the directory' + iodirout  + ' was not found.'
142    ras = report(msg)
143    STOP
144ENDIF
145;
146d1=19881001 & d2=20101231
147;
148; build d2m filename
149filename_d2m='erai_d2m_19890101_20091231_oafluxgrid.nc'
150;
151; check if this file exists
152fullfilename_d2m = isafile(iodirout + filename_d2m, NEW=0, /MUST_EXIST)
153IF fullfilename_d2m[0] EQ '' THEN BEGIN
154   msg = 'eee : the file ' + fullfilename_d2m + ' was not found.'
155   ras = report(msg)
156   STOP
157ENDIF
158;
159; build t2m filename
160filename_t2m='erai_t2m_19890101_20091231_oafluxgrid.nc'
161;
162; check if this file exists
163fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
164IF fullfilename_t2m[0] EQ '' THEN BEGIN
165   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
166   ras = report(msg)
167   STOP
168ENDIF
169;
170; build msl filename
171filename_msl='erai_msl_19890101_20091231_oafluxgrid.nc'
172;
173; check if this file exists
174fullfilename_msl = isafile(iodirout + filename_msl, NEW=0, /MUST_EXIST)
175IF fullfilename_msl[0] EQ '' THEN BEGIN
176   msg = 'eee : the file ' + fullfilename_msl + ' was not found.'
177   ras = report(msg)
178   STOP
179ENDIF
180;
181; build output filename
182filename_out = 'q2m_erai_19890101_20091231_oafluxgrid.nc'
183fullfilename_out = iodirout + filename_out
184; in order to avoid unexpected overwritten
185IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
186   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
187   ras = report(msg)
188   STOP
189ENDIF
190;
191; reading erai dew point temperature
192initncdf, fullfilename_d2m
193td=read_ncdf("d2m", d1,d2, file=fullfilename_d2m,/nostr)
194
195; reading erai air temperature
196initncdf, fullfilename_t2m
197t=read_ncdf("t2m", d1,d2, file=fullfilename_t2m,/nostr)
198tt=time &jpt=n_elements(time)
199help, t, td
200
201;;since the t2m and d2m are already in K, no need for conversion
202
203e=es0*exp((25.e5/461.5)*((1/273.15)-(1/td)))
204es=es0*exp((25.e5/461.5)*((1/273.15)-(1/t)))
205
206rh=(e/es)*100
207
208;; conversion of relative humidity to sp. humidity
209;; Ref.1 -  Gill, Appendix 4,
210;; Ref.2 - http://efdl.cims.nyu.edu/project_aomip/forcing_data/atmosphere/humidity.html
211
212t=t-273.15
213
214initncdf, fullfilename_msl
215P=read_ncdf("msl", d1, d2, file=fullfilename_msl,/nostr)
216help, P
217q2m=rh_to_spechum(rh,t,P)
218
219;writing field
220ncfile='!' + fullfilename_out
221time=timegen(7670, units='days', start=julday(1,1,1989)) & jpt=n_elements(time)
222cda0=string(jul2date(time(0)),format='(i8.8)')
223cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
224
225
226tt=time-julday(1,1,1950,00,00,00)
227xlon=reform(glamt(*,0) ) & ylat=reform(gphit(0,*))
228valmask=1.e20
229
230lon_attr={units:'degrees_east',long_name:'Longitude'}
231lat_attr={units:'degrees_north',long_name:'Latitude'}
232q2m_attr={units:'kg/kg',missing_value:valmask,long_name:'Surface specific humidity at 2m ',short_name:'q2m',axis:'TYX'}
233time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'}
234globattr={source:'Surface specific humidity at 2m calculated from dew point temperature',timerange:cda0+' - '+cda1}
235
236ncfields = 'q2m[longitude,latitude,time]=q2m:q2m_attr; ' $
237                      + 'longitude[]=xlon:lon_attr; ' $
238                      + 'latitude[]=ylat:lat_attr; ' $
239                      + 'tt[*time]=tt:time_attr ' $
240                      + ' @ globattr'
241
242@ncdf_quickwrite
243end
Note: See TracBrowser for help on using the repository browser.