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