1 | ;+ |
---|
2 | ; |
---|
3 | ; ===================== |
---|
4 | ; tropflux_swr_blnd.pro |
---|
5 | ; ===================== |
---|
6 | ; |
---|
7 | ; .. function:: tropflux_swr_blnd(yyyymmddb,yyyymmdde) |
---|
8 | ; |
---|
9 | ; DESCRIPTION |
---|
10 | ; =========== |
---|
11 | ; |
---|
12 | ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc` |
---|
13 | ; containing ++ |
---|
14 | ; has been produced by |
---|
15 | ; :func:`tropflux_swr_dt`. |
---|
16 | ; |
---|
17 | ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc` |
---|
18 | ; containing ++ |
---|
19 | ; has been produced by |
---|
20 | ; :func:`tropflux_swr_nrt`. |
---|
21 | ; |
---|
22 | ; :file:`${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc` containing ++ |
---|
23 | ; has been produced by |
---|
24 | ; :func:`cronin_gustiness_ncdf`. |
---|
25 | ; |
---|
26 | ; ++ are written |
---|
27 | ; in :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc` |
---|
28 | ; if this file not already exists. |
---|
29 | ; |
---|
30 | ; This file will be used by |
---|
31 | ; :func:`tropflux_nrt_ncdf`. |
---|
32 | ; |
---|
33 | ; .. graphviz:: |
---|
34 | ; |
---|
35 | ; digraph tropflux_swr_blnd { |
---|
36 | ; |
---|
37 | ; file_dt [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc"]; |
---|
38 | ; file_nrt [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc"]; |
---|
39 | ; file_gustiness [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc"]; |
---|
40 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_blnd.nc"]; |
---|
41 | ; |
---|
42 | ; tropflux_swr_blnd [shape=box, |
---|
43 | ; fontname=Courier, |
---|
44 | ; color=blue, |
---|
45 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_blnd.pro", |
---|
46 | ; label="${PROJECT}/src/tropflux_swr_blnd.pro"]; |
---|
47 | ; |
---|
48 | ; {file_dt file_nrt file_gustiness} -> {tropflux_swr_blnd} -> {file_out} |
---|
49 | ; |
---|
50 | ; } |
---|
51 | ; |
---|
52 | ; SEE ALSO |
---|
53 | ; ======== |
---|
54 | ; |
---|
55 | ; :ref:`mooring_corrections` |
---|
56 | ; |
---|
57 | ; Used by :ref:`tropflux.sh` |
---|
58 | ; |
---|
59 | ; :ref:`project_profile.sh` |
---|
60 | ; |
---|
61 | ; :ref:`data_in_swr` |
---|
62 | ; |
---|
63 | ; :func:`initncdf <saxo:initncdf>` |
---|
64 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
65 | ; :func:`julday <saxo:julday>` |
---|
66 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
67 | ; |
---|
68 | ; :func:`tropflux_nrt_ncdf` |
---|
69 | ; |
---|
70 | ; EXAMPLES |
---|
71 | ; ======== |
---|
72 | ; |
---|
73 | ; .. code-block:: idl |
---|
74 | ; |
---|
75 | ; yyyymmddb = 20000101L |
---|
76 | ; yyyymmdde = 20001231L |
---|
77 | ; result = tropflux_swr_blnd(yyyymmddb, yyyymmdde) |
---|
78 | ; print, result |
---|
79 | ; |
---|
80 | ; TODO |
---|
81 | ; ==== |
---|
82 | ; |
---|
83 | ; handling date > 20071231 |
---|
84 | ; |
---|
85 | ; read_ncdf usage of yyyymmddb yyyymmdde |
---|
86 | ; |
---|
87 | ; get rid of timegen |
---|
88 | ; |
---|
89 | ; submit read_ncdf with 19890101 pb to saxo-dev |
---|
90 | ; |
---|
91 | ; coding rules |
---|
92 | ; |
---|
93 | ; complete description |
---|
94 | ; |
---|
95 | ; why 20080100, 20100112 as date1 and date2 when readind nrt |
---|
96 | ; |
---|
97 | ; why two read_ncdf for nrt |
---|
98 | ; |
---|
99 | ; according to pk 20110811 we can include this process in |
---|
100 | ; tropflux_swr_nrt.pro ... later |
---|
101 | ; |
---|
102 | ; KNOWN ISSUES |
---|
103 | ; ============ |
---|
104 | ; |
---|
105 | ; test of existence of fullfilename_in not very efficient because |
---|
106 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
107 | ; |
---|
108 | ; EVOLUTIONS |
---|
109 | ; ========== |
---|
110 | ; |
---|
111 | ; $Id: tropflux_swr_blnd.pro 88 2011-08-19 15:40:14Z pinsard $ |
---|
112 | ; |
---|
113 | ; $URL$ |
---|
114 | ; |
---|
115 | ; - fplod 20120321 |
---|
116 | ; |
---|
117 | ; * pro -> func |
---|
118 | ; * rename with lower case TropFlux_swr_BLND_19890101_20091231.pro become |
---|
119 | ; tropflux_swr_blnd.pro |
---|
120 | ; * taking project_overwrite into account |
---|
121 | ; |
---|
122 | ; - fplod 20110819T120412Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
123 | ; |
---|
124 | ; * change 19890101 to 19890100 to read 6939 timesteps in DT file |
---|
125 | ; even if uggly and not understood SAXO strange behaviour |
---|
126 | ; |
---|
127 | ; this resolve crash on cratos idl7: |
---|
128 | ; |
---|
129 | ; .. parsed-literal:: |
---|
130 | ; |
---|
131 | ; % Attempt to subscript SWR_DT with JT is out of range. |
---|
132 | ; |
---|
133 | ; line: |
---|
134 | ; |
---|
135 | ; .. code-block:: idl |
---|
136 | ; |
---|
137 | ; for jt=0,jpt-1 do swr_merged(*,*,jt)=swr_dt(*,*,jt)*a(jt)+(1-a(jt))*swr_nrt(*,*,jt) |
---|
138 | ; |
---|
139 | ; probably because 6938+731=7669 and not 7670 when |
---|
140 | ; :samp:`dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr)` |
---|
141 | ; was used : |
---|
142 | ; .. parsed-literal:: |
---|
143 | ; |
---|
144 | ; |
---|
145 | ; DT FLOAT = Array[350, 60, 6938] |
---|
146 | ; NRT FLOAT = Array[350, 60, 731] |
---|
147 | ; SWR_DT FLOAT = Array[350, 60, 7669] |
---|
148 | ; SWR_NRT FLOAT = Array[350, 60, 7670] |
---|
149 | ; |
---|
150 | ; nb jours 19890101-20071231: |
---|
151 | ; |
---|
152 | ; .. code-block:: idl |
---|
153 | ; |
---|
154 | ; print, julday(12,31,2007) - julday(01, 01, 1989) +1 |
---|
155 | ; 6939 |
---|
156 | ; |
---|
157 | ; et ncdump -h $PROJECT_OD/TropFlux_swr_19890101_20071231_DT.nc time = UNLIMITED ; // (6939 currently) |
---|
158 | ; |
---|
159 | ; nb jours 19890101-20091231: |
---|
160 | ; |
---|
161 | ; .. code-block:: idl |
---|
162 | ; |
---|
163 | ; print, julday(12,31,2009) - julday(01, 01, 1989) +1 |
---|
164 | ; 7670 |
---|
165 | ; |
---|
166 | ; strange behaviour of read_ncdf ... see: |
---|
167 | ; |
---|
168 | ; .. code-block:: idl |
---|
169 | ; |
---|
170 | ; fullfilename_dt='TropFlux_swr_19890101_20071231_DT.nc' |
---|
171 | ; dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr) |
---|
172 | ; print, 'first time step (should crash with invalid date)', jul2date(time[0]) |
---|
173 | ; first time step (should be 19890101) 19890101. |
---|
174 | ; dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr) |
---|
175 | ; print, 'first time step (should be 19890101)', jul2date(time[0]) |
---|
176 | ; first time step (should be 19890101) 19890102. |
---|
177 | ; |
---|
178 | ; * correction for reading gustiness file |
---|
179 | ; |
---|
180 | ; - fplod 20110809T115747Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
181 | ; |
---|
182 | ; * usage of ${PROJECT_OD} |
---|
183 | ; * remove v* from filenames (in and out) |
---|
184 | ; * add test on IO files |
---|
185 | ; |
---|
186 | ; - fplod 20101215T085754Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
187 | ; |
---|
188 | ; * add graph in header |
---|
189 | ; |
---|
190 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
191 | ; |
---|
192 | ; * minimal header |
---|
193 | ; |
---|
194 | ; - pbk 2008 |
---|
195 | ; |
---|
196 | ; * creation |
---|
197 | ; |
---|
198 | ;- |
---|
199 | function tropflux_swr_blnd $ |
---|
200 | , yyyymmddb $ |
---|
201 | , yyyymmdde |
---|
202 | ; |
---|
203 | compile_opt idl2, strictarrsubs, logical_predicate |
---|
204 | ; |
---|
205 | @cm_4cal |
---|
206 | @cm_4data |
---|
207 | @cm_4mesh |
---|
208 | @cm_4data |
---|
209 | @cm_project |
---|
210 | ; |
---|
211 | ; Return to caller if errors |
---|
212 | ON_ERROR, 2 |
---|
213 | ; |
---|
214 | result = -1 |
---|
215 | ; |
---|
216 | usage = 'result = tropflux_swr_blnd(yyyymmddb, yyyymmdde)' |
---|
217 | nparam = N_PARAMS() |
---|
218 | IF (nparam NE 2) THEN BEGIN |
---|
219 | ras = report(['Incorrect number of arguments.' $ |
---|
220 | + '!C' $ |
---|
221 | + 'Usage : ' + usage]) |
---|
222 | return, result |
---|
223 | ENDIF |
---|
224 | ; |
---|
225 | ; test if ${PROJECT_OD} defined |
---|
226 | CASE project_od_env OF |
---|
227 | '' : BEGIN |
---|
228 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
229 | ras = report(msg) |
---|
230 | return, result |
---|
231 | END |
---|
232 | ELSE : BEGIN |
---|
233 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
234 | ras = report(msg) |
---|
235 | END |
---|
236 | ENDCASE |
---|
237 | ; |
---|
238 | ; check if output data will be possible |
---|
239 | iodirout = isadirectory(project_od_env) |
---|
240 | ; |
---|
241 | ; existence and protection for reading |
---|
242 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
243 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
244 | ras = report(msg) |
---|
245 | return, result |
---|
246 | ENDIF |
---|
247 | ; |
---|
248 | ; existence and protection for writing |
---|
249 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
250 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
251 | ras = report(msg) |
---|
252 | return, result |
---|
253 | ENDIF |
---|
254 | ; |
---|
255 | ; build dt data filename |
---|
256 | filename_dt='TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc' |
---|
257 | ; |
---|
258 | ; check if this file exists |
---|
259 | msg='iii : looking for ' + filename_dt |
---|
260 | ras = report(msg) |
---|
261 | fullfilename_dt = isafile(iodirout + filename_dt, NEW=0, /MUST_EXIST) |
---|
262 | IF fullfilename_dt[0] EQ '' THEN BEGIN |
---|
263 | msg = 'eee : the file ' + fullfilename_dt + ' was not found.' |
---|
264 | ras = report(msg) |
---|
265 | return, result |
---|
266 | ENDIF |
---|
267 | ; |
---|
268 | ; build nrt data filename |
---|
269 | filename_nrt='TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc' |
---|
270 | ; |
---|
271 | ; check if this file exists |
---|
272 | msg='iii : looking for ' + filename_nrt |
---|
273 | ras = report(msg) |
---|
274 | fullfilename_nrt = isafile(iodirout + filename_nrt, NEW=0, /MUST_EXIST) |
---|
275 | IF fullfilename_nrt[0] EQ '' THEN BEGIN |
---|
276 | msg = 'eee : the file ' + fullfilename_nrt + ' was not found.' |
---|
277 | ras = report(msg) |
---|
278 | return, result |
---|
279 | ENDIF |
---|
280 | ; |
---|
281 | ; build wg data filename |
---|
282 | filename_wg='TropFlux_gustiness_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' |
---|
283 | ; |
---|
284 | ; check if this file exists |
---|
285 | msg='iii : looking for ' + filename_wg |
---|
286 | ras = report(msg) |
---|
287 | fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST) |
---|
288 | IF fullfilename_wg[0] EQ '' THEN BEGIN |
---|
289 | msg = 'eee : the file ' + fullfilename_wg + ' was not found.' |
---|
290 | ras = report(msg) |
---|
291 | return, result |
---|
292 | ENDIF |
---|
293 | ; |
---|
294 | ; build output filename |
---|
295 | filename_out = 'TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc' |
---|
296 | fullfilename_out = iodirout + filename_out |
---|
297 | ; in order to avoid unexpected overwritten |
---|
298 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
299 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
300 | ras = report(msg) |
---|
301 | return, result |
---|
302 | ENDIF |
---|
303 | ; |
---|
304 | initncdf, fullfilename_dt |
---|
305 | dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr) |
---|
306 | print, 'www : should crash with invalide date 19890100' |
---|
307 | help, dt |
---|
308 | print, 'first time step (should be 19890101)', jul2date(time[0]) |
---|
309 | print, 'last time step (should be 20071231)', jul2date(time[jpt-1]) |
---|
310 | ; |
---|
311 | initncdf, fullfilename_nrt |
---|
312 | nrt=read_ncdf('sw', 20080100, 20100112, file=fullfilename_nrt,/nostr) |
---|
313 | help, nrt |
---|
314 | ; |
---|
315 | swr_nrt=read_ncdf('sw', 19880101, 20100112, file=fullfilename_nrt,/nostr) |
---|
316 | ; |
---|
317 | swr_dt=[[[dt]],[[nrt]]] |
---|
318 | help, nrt, swr_dt, swr_nrt |
---|
319 | ; |
---|
320 | swr_merged=swr_dt*0. |
---|
321 | ; |
---|
322 | time=timegen(7670, start=julday(1,1,1989,0), units='days') |
---|
323 | jpt=n_elements(time) |
---|
324 | ; |
---|
325 | a=interpol([1.,0.],[julday(10,01,2007),julday(12,31,2007)],time) |
---|
326 | a=((a > 0.) < 1.) |
---|
327 | for jt=0,jpt-1 do begin |
---|
328 | swr_merged[*,*,jt]=swr_dt[*,*,jt]*a[jt]+(1-a[jt])*swr_nrt[*,*,jt] |
---|
329 | endfor |
---|
330 | ; |
---|
331 | initncdf, fullfilename_wg |
---|
332 | time=timegen(7670, units='days', start=julday(1,1,1989,0)) |
---|
333 | jpt=n_elements(time) |
---|
334 | lat=reform(gphit[0,0:jpj-1]) |
---|
335 | lon=reform(glamt[0:jpi-1,0]) |
---|
336 | cda0=string(jul2date(time[0]),format='(i8.8)') |
---|
337 | cda1=string(jul2date(time[jpt-1]),format='(i8.8)') |
---|
338 | ; |
---|
339 | time=time-julday(1,1,1950,00,00) |
---|
340 | ncfile='!' + fullfilename_out |
---|
341 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
342 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
343 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
344 | globattr={source:'ISCCP based SWR until 2007, after 2007 timeseries is completed with OLR based SWR. A linear transition is applied from ISCCP based SWR to OLR based SWR'} |
---|
345 | sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'} |
---|
346 | ; |
---|
347 | ncfields = 'swr[longitude,latitude,time]=swr_merged:sw_attr; ' $ |
---|
348 | + 'longitude[]=lon:lon_attr; ' $ |
---|
349 | + 'latitude[]=lat:lat_attr; ' $ |
---|
350 | + 'time[*time]=time:time_attr ' $ |
---|
351 | + ' @ globattr' |
---|
352 | ; |
---|
353 | @ncdf_quickwrite |
---|
354 | ; |
---|
355 | end |
---|