1 | ;+ |
---|
2 | ; |
---|
3 | ; ======================= |
---|
4 | ; q2m_correction_ncdf.pro |
---|
5 | ; ======================= |
---|
6 | ; |
---|
7 | ; .. function:: q2m_correction_ncdf(yyyymmddb,yyyymmdde) |
---|
8 | ; |
---|
9 | ; DESCRIPTION |
---|
10 | ; =========== |
---|
11 | ; |
---|
12 | ; Correction of q2m on OAFLUX grid |
---|
13 | ; |
---|
14 | ; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc` |
---|
15 | ; containing |
---|
16 | ; ++ |
---|
17 | ; has been produced by |
---|
18 | ; :func:`d2m_to_q2m_erai`. |
---|
19 | ; |
---|
20 | ; Corrected q2m on OAFLUX grid |
---|
21 | ; is written in |
---|
22 | ; :file:`${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc` |
---|
23 | ; if this file not already exists. |
---|
24 | ; |
---|
25 | ; This file will be used by |
---|
26 | ; :func:`tropflux`. |
---|
27 | ; |
---|
28 | ; .. only:: man |
---|
29 | ; |
---|
30 | ; Figure is visible on PDF and HTML documents only. |
---|
31 | ; |
---|
32 | ; .. only:: html or latex |
---|
33 | ; |
---|
34 | ; .. graphviz:: |
---|
35 | ; |
---|
36 | ; digraph q2m_correction_ncdf { |
---|
37 | ; |
---|
38 | ; file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"]; |
---|
39 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc"]; |
---|
40 | ; |
---|
41 | ; q2m_correction_ncdf [shape=box, |
---|
42 | ; fontname=Courier, |
---|
43 | ; color=blue, |
---|
44 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/q2m_correction_ncdf.pro", |
---|
45 | ; label="${PROJECT}/src/q2m_correction_ncdf.pro"]; |
---|
46 | ; |
---|
47 | ; {file_in} -> {q2m_correction_ncdf} -> {file_out} |
---|
48 | ; |
---|
49 | ; } |
---|
50 | ; |
---|
51 | ; SEE ALSO |
---|
52 | ; ======== |
---|
53 | ; |
---|
54 | ; :ref:`mooring_corrections` |
---|
55 | ; |
---|
56 | ; Used by :ref:`tropflux.sh` |
---|
57 | ; |
---|
58 | ; :ref:`project_profile.sh` |
---|
59 | ; |
---|
60 | ; :func:`d2m_to_q2m_erai` |
---|
61 | ; |
---|
62 | ; :func:`initncdf <saxo:initncdf>` |
---|
63 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
64 | ; :func:`grossemoyenne <saxo:grossemoyenne>` |
---|
65 | ; :func:`julday <saxo:julday>` |
---|
66 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
67 | ; |
---|
68 | ; EXAMPLES |
---|
69 | ; ======== |
---|
70 | ; |
---|
71 | ; .. code-block:: idl |
---|
72 | ; |
---|
73 | ; yyyymmddb = 20000101L |
---|
74 | ; yyyymmdde = 20001231L |
---|
75 | ; result = q2m_correction_ncdf(yyyymmddb, yyyymmdde) |
---|
76 | ; print, result |
---|
77 | ; |
---|
78 | ; TODO |
---|
79 | ; ==== |
---|
80 | ; |
---|
81 | ; make it work : |
---|
82 | ; |
---|
83 | ; .. parsed-literal: |
---|
84 | ; |
---|
85 | ; Writing fields: |
---|
86 | ; q2m[longitude,latitude,time*]=q2m_new:q2m_attr; longitude[]=lon:lon_attr; latitude[]=lat:lat_attr; time[]=timein:time_attr @ globattr |
---|
87 | ; % NCDF_DIMDEF: Unable to create dimension. (NC_ERROR=-59) |
---|
88 | ; % NCDF_VARDEF: Unable to define variable, bad dimension id . |
---|
89 | ; % NCDF_VARPUT: Variable Inquiry failed, -1 is not a valid variable id. |
---|
90 | ; % Stop encountered: Q2M_CORRECTION_NCDF 1 |
---|
91 | ; /.autofs/lodyc/incas/fplod/tropflux/tropflux_ws/src/q2m_correction_ncdf.pro |
---|
92 | ; |
---|
93 | ; No way ... NaNf also in this output !! |
---|
94 | ; |
---|
95 | ; coding rules |
---|
96 | ; |
---|
97 | ; EVOLUTIONS |
---|
98 | ; ========== |
---|
99 | ; |
---|
100 | ; $Id: q2m_correction_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $ |
---|
101 | ; |
---|
102 | ; $URL$ |
---|
103 | ; |
---|
104 | ; - fplod 20120322 |
---|
105 | ; |
---|
106 | ; * taking project_overwrite into account |
---|
107 | ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite |
---|
108 | ; * pro -> function |
---|
109 | ; * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters |
---|
110 | ; * get rid of timegen |
---|
111 | ; |
---|
112 | ; - fplod 20110808T143129Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
113 | ; |
---|
114 | ; * usage of ${PROJECT_OD} |
---|
115 | ; * remove v20 in output filename |
---|
116 | ; |
---|
117 | ; - fplod 20101215T113945Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
118 | ; |
---|
119 | ; * add graph in header |
---|
120 | ; |
---|
121 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
122 | ; |
---|
123 | ; * minimal header |
---|
124 | ; |
---|
125 | ; - pbk 2008 |
---|
126 | ; |
---|
127 | ; * creation |
---|
128 | ; |
---|
129 | ;- |
---|
130 | function q2m_correction_ncdf $ |
---|
131 | , yyyymmddb $ |
---|
132 | , yyyymmdde |
---|
133 | ; |
---|
134 | ;++compile_opt idl2, strictarrsubs, logical_predicate |
---|
135 | ; |
---|
136 | @cm_4cal |
---|
137 | @cm_4data |
---|
138 | @cm_4mesh |
---|
139 | @cm_4data |
---|
140 | @cm_project |
---|
141 | ; |
---|
142 | ; Return to caller if errors |
---|
143 | ON_ERROR, 2 |
---|
144 | ; |
---|
145 | result = -1 |
---|
146 | ; |
---|
147 | usage = 'result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)' |
---|
148 | nparam = N_PARAMS() |
---|
149 | IF (nparam NE 2) THEN BEGIN |
---|
150 | ras = report(['Incorrect number of arguments.' $ |
---|
151 | + '!C' $ |
---|
152 | + 'Usage : ' + usage]) |
---|
153 | return, result |
---|
154 | ENDIF |
---|
155 | |
---|
156 | ; test if ${PROJECT_OD} defined |
---|
157 | CASE project_od_env OF |
---|
158 | '' : BEGIN |
---|
159 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
160 | ras = report(msg) |
---|
161 | return, result |
---|
162 | END |
---|
163 | ELSE : BEGIN |
---|
164 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
165 | ras = report(msg) |
---|
166 | END |
---|
167 | ENDCASE |
---|
168 | ; |
---|
169 | ; check if output data will be possible |
---|
170 | iodirout = isadirectory(project_od_env) |
---|
171 | ; |
---|
172 | ; existence and protection for reading |
---|
173 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
174 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
175 | ras = report(msg) |
---|
176 | return, result |
---|
177 | ENDIF |
---|
178 | ; |
---|
179 | ; existence and protection for writing |
---|
180 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
181 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
182 | ras = report(msg) |
---|
183 | return, result |
---|
184 | ENDIF |
---|
185 | ; |
---|
186 | ; build data filename |
---|
187 | filename='erai_q2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc' |
---|
188 | ; |
---|
189 | ; check if this file exists |
---|
190 | msg='iii : looking for ' + filename |
---|
191 | ras = report(msg) |
---|
192 | fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST) |
---|
193 | IF fullfilename[0] EQ '' THEN BEGIN |
---|
194 | msg = 'eee : the file ' + fullfilename + ' was not found.' |
---|
195 | ras = report(msg) |
---|
196 | return, result |
---|
197 | ENDIF |
---|
198 | ; |
---|
199 | ; build output filename |
---|
200 | filename_out = 'TropFlux_q2m_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' |
---|
201 | fullfilename_out = iodirout + filename_out |
---|
202 | ; in order to avoid unexpected overwritten |
---|
203 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
204 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
205 | ras = report(msg) |
---|
206 | return, result |
---|
207 | ENDIF |
---|
208 | ; |
---|
209 | initncdf, fullfilename |
---|
210 | q2m=read_ncdf('q2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr) |
---|
211 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
212 | jpt=n_elements(timein) |
---|
213 | da=jul2date(time[0]) |
---|
214 | cda0=string(da,format='(i8.8)') |
---|
215 | da=jul2date(time[jpt-1]) |
---|
216 | cda1=string(da,format='(i8.8)') |
---|
217 | print, 'q2m in q2m_correction_ncdf first date ', cda0 |
---|
218 | print, 'q2m in q2m_correction_ncdf last date ' , cda1 |
---|
219 | ; |
---|
220 | help, q2m |
---|
221 | ; |
---|
222 | q2m_mean=grossemoyenne(q2m,'t',/nan) |
---|
223 | help, q2m_mean |
---|
224 | ; |
---|
225 | jpt=n_elements(time) |
---|
226 | caldat, time,mon,day,yea |
---|
227 | q2m_m=q2m*0. |
---|
228 | ; |
---|
229 | for jt=0,jpt-1 do begin |
---|
230 | jtt=(time[jt]-julday(1,1,yea[jt])) < 364 |
---|
231 | q=reform(q2m_mean[*,*]) |
---|
232 | q2m_m[*,*,jt]=q |
---|
233 | endfor |
---|
234 | help, q2m_m |
---|
235 | ; |
---|
236 | q2m_ano=q2m-q2m_m |
---|
237 | ; |
---|
238 | ; correction for mean based on scatter |
---|
239 | ;q2m_m=q2m_m+0.815445 ; (2000-2008) |
---|
240 | q2m_m=q2m_m+0.792717 ; (2000-2009) |
---|
241 | help, q2m_ano |
---|
242 | ; |
---|
243 | ; applying the correction for variability based on the scatter |
---|
244 | ;q2m_ano=q2m_ano*(1/0.919333) ; (2000-2008) |
---|
245 | q2m_ano=q2m_ano*(1/0.924674) ; (2000-2009) |
---|
246 | ; |
---|
247 | q2m_new=q2m_m+q2m_ano |
---|
248 | help, q2m_new |
---|
249 | ; |
---|
250 | ;writing field |
---|
251 | lat=reform(gphit[0,0:jpj-1]) |
---|
252 | lon=reform(glamt[0:jpi-1,0]) |
---|
253 | ; |
---|
254 | ncfile='!' + fullfilename_out |
---|
255 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
256 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
257 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
258 | globattr={source:'Basic data obtained from ERAI. Mean correction for bias and correction for variability are applied',timerange:cda0+' - '+cda1} |
---|
259 | q2m_attr={units:'g/kg',missing_value:1.e20,long_name:'Specific humidity at 2m height',short_name:'q2m',axis:'TYX'} |
---|
260 | ; |
---|
261 | ncfields = 'q2m[longitude,latitude,time*]=q2m_new:q2m_attr; ' $ |
---|
262 | + 'longitude[]=lon:lon_attr; ' $ |
---|
263 | + 'latitude[]=lat:lat_attr; ' $ |
---|
264 | + 'time[]=timein:time_attr ' $ |
---|
265 | + ' @ globattr' |
---|
266 | ; |
---|
267 | @ncdf_quickwrite |
---|
268 | ; |
---|
269 | result = 0 |
---|
270 | return, result |
---|
271 | ; |
---|
272 | end |
---|