1 | ;+ |
---|
2 | ; |
---|
3 | ; ==================== |
---|
4 | ; tropflux_swr_nrt.pro |
---|
5 | ; ==================== |
---|
6 | ; |
---|
7 | ; .. function:: tropflux_swr_nrt(yyyymmddb,yyyymmdde) |
---|
8 | ; |
---|
9 | ; DESCRITION |
---|
10 | ; ========== |
---|
11 | ; |
---|
12 | ; Correction of swr near real time on OAFLUX grid |
---|
13 | ; |
---|
14 | ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc` |
---|
15 | ; containing |
---|
16 | ; Corrected swr delay on OAFLUX grid |
---|
17 | ; has been produced by |
---|
18 | ; :func:`tropflux_swr_dt`. |
---|
19 | ; |
---|
20 | ; :file:`${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc` |
---|
21 | ; have been produced |
---|
22 | ; :func:`interp_olr_30n30s`. |
---|
23 | ; |
---|
24 | ; Corrected swr near real time on OAFLUX grid |
---|
25 | ; ; is written in |
---|
26 | ; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc` |
---|
27 | ; if this file not already exists. |
---|
28 | ; |
---|
29 | ; .. graphviz:: |
---|
30 | ; |
---|
31 | ; digraph tropflux_swr_nrt { |
---|
32 | ; |
---|
33 | ; file_swr_dt [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc"]; |
---|
34 | ; file_olr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/olr_oafluxgrid_30n30s_{yyyymmdd}_{yyyymmdd}.nc"]; |
---|
35 | ; file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc"]; |
---|
36 | ; |
---|
37 | ; tropflux_swr_nrt [shape=box, |
---|
38 | ; fontname=Courier, |
---|
39 | ; color=blue, |
---|
40 | ; URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_nrt.pro", |
---|
41 | ; label="${PROJECT}/src/tropflux_swr_nrt.pro"]; |
---|
42 | ; |
---|
43 | ; {file_swr_dt file_olr}-> {tropflux_swr_nrt} -> {file_out} |
---|
44 | ; } |
---|
45 | ; |
---|
46 | ; SEE ALSO |
---|
47 | ; ======== |
---|
48 | ; |
---|
49 | ; :ref:`mooring_corrections` |
---|
50 | ; |
---|
51 | ; :ref:`data_in_swr` |
---|
52 | ; :ref:`data_in_olr` |
---|
53 | ; |
---|
54 | ; Used by :ref:`tropflux.sh` |
---|
55 | ; |
---|
56 | ; :ref:`project_profile.sh` |
---|
57 | ; |
---|
58 | ; :func:`initncdf <saxo:initncdf>` |
---|
59 | ; :func:`read_ncdf <saxo:read_ncdf>` |
---|
60 | ; :func:`julday <saxo:julday>` |
---|
61 | ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>` |
---|
62 | ; |
---|
63 | ; EXAMPLES |
---|
64 | ; ======== |
---|
65 | ; |
---|
66 | ; :: |
---|
67 | ; |
---|
68 | ; yyyymmddb = 20000101L |
---|
69 | ; yyyymmdde = 20001231L |
---|
70 | ; result = tropflux_swr_nrt(yyyymmddb, yyyymmdde) |
---|
71 | ; print, result |
---|
72 | ; |
---|
73 | ; TODO |
---|
74 | ; ==== |
---|
75 | ; |
---|
76 | ; handlind yyyymmdde > 20071231 |
---|
77 | ; |
---|
78 | ; remove NaNf values in ouptut file (may be not because of this module) |
---|
79 | ; |
---|
80 | ; why two sequence initcdf et read_ndcf on olr file ? |
---|
81 | ; |
---|
82 | ; coding rules |
---|
83 | ; |
---|
84 | ; KNOWN ISSUES |
---|
85 | ; ============ |
---|
86 | ; |
---|
87 | ; test of existence of fullfilename not very efficient because |
---|
88 | ; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented |
---|
89 | ; |
---|
90 | ; EVOLUTIONS |
---|
91 | ; ========== |
---|
92 | ; |
---|
93 | ; $Id: tropflux_swr_nrt.pro 88 2011-08-19 15:40:14Z pinsard $ |
---|
94 | ; |
---|
95 | ; $URL$ |
---|
96 | ; |
---|
97 | ; - fplod 20120321 |
---|
98 | ; |
---|
99 | ; * pro -> func |
---|
100 | ; * rename with lower case TropFlux_swr_NRT_19890101_20091231.pro become |
---|
101 | ; tropflux_swr_nrt.pro |
---|
102 | ; * taking project_overwite into account |
---|
103 | ; * try to add compile_opt seems to be incompatible with ncdf_quickwrite |
---|
104 | ; |
---|
105 | ; - fplod 20110830T135938Z cratos (Linux) |
---|
106 | ; |
---|
107 | ; * replace tt by time |
---|
108 | ; * fill empty time_origin |
---|
109 | ; |
---|
110 | ; - fplod 20110812T075406Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
111 | ; |
---|
112 | ; * usage of ${PROJECT_OD} |
---|
113 | ; * complete description |
---|
114 | ; * remove v50 in filenames |
---|
115 | ; |
---|
116 | ; - fplod 20101215T092145Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
117 | ; |
---|
118 | ; * add graph in header |
---|
119 | ; |
---|
120 | ; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
121 | ; |
---|
122 | ; * minimal header |
---|
123 | ; |
---|
124 | ; - pbk 2008 |
---|
125 | ; |
---|
126 | ; * creation |
---|
127 | ; |
---|
128 | ;- |
---|
129 | function tropflux_swr_nrt $ |
---|
130 | , yyyymmddb $ |
---|
131 | , yyyymmdde |
---|
132 | ; |
---|
133 | compile_opt idl2, strictarrsubs, logical_predicate |
---|
134 | ; |
---|
135 | @cm_4cal |
---|
136 | @cm_4data |
---|
137 | @cm_4mesh |
---|
138 | @cm_4data |
---|
139 | @cm_project |
---|
140 | ; |
---|
141 | ; Return to caller if errors |
---|
142 | ON_ERROR, 2 |
---|
143 | ; |
---|
144 | result = -1 |
---|
145 | ; |
---|
146 | usage = 'result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)' |
---|
147 | nparam = N_PARAMS() |
---|
148 | IF (nparam NE 2) THEN BEGIN |
---|
149 | ras = report(['Incorrect number of arguments.' $ |
---|
150 | + '!C' $ |
---|
151 | + 'Usage : ' + usage]) |
---|
152 | return, result |
---|
153 | ENDIF |
---|
154 | ; |
---|
155 | ; test if ${PROJECT_OD} defined |
---|
156 | CASE project_od_env OF |
---|
157 | '' : BEGIN |
---|
158 | msg = 'eee : ${PROJECT_OD} is not defined' |
---|
159 | ras = report(msg) |
---|
160 | return, result |
---|
161 | END |
---|
162 | ELSE: BEGIN |
---|
163 | msg = 'iii : ${PROJECT_OD} is ' + project_od_env |
---|
164 | ras = report(msg) |
---|
165 | END |
---|
166 | ENDCASE |
---|
167 | ; check if output data will be possible |
---|
168 | iodirout = isadirectory(project_od_env) |
---|
169 | ; |
---|
170 | ; existence and protection for reading |
---|
171 | IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN |
---|
172 | msg = 'eee : the directory' + iodirout + ' is not accessible.' |
---|
173 | ras = report(msg) |
---|
174 | return, result |
---|
175 | ENDIF |
---|
176 | ; |
---|
177 | ; existence and protection for writing |
---|
178 | IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN |
---|
179 | msg = 'eee : the directory' + iodirout + ' was not found.' |
---|
180 | ras = report(msg) |
---|
181 | return, result |
---|
182 | ENDIF |
---|
183 | ; |
---|
184 | ; build swr dt data filename |
---|
185 | filename_swr_dt='TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc' |
---|
186 | ; |
---|
187 | ; check if this file exists |
---|
188 | msg='iii : looking for ' + filename_swr_dt |
---|
189 | ras = report(msg) |
---|
190 | fullfilename_swr_dt = isafile(iodirout + filename_swr_dt, NEW=0, /MUST_EXIST) |
---|
191 | IF fullfilename_swr_dt[0] EQ '' THEN BEGIN |
---|
192 | msg = 'eee : the file ' + fullfilename_swr_dt + ' was not found.' |
---|
193 | ras = report(msg) |
---|
194 | return, result |
---|
195 | ENDIF |
---|
196 | ; |
---|
197 | ; build olr data filename |
---|
198 | filename_olr='olr_oafluxgrid_30n30s_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc' |
---|
199 | ; |
---|
200 | ; check if this file exists |
---|
201 | msg='iii : looking for ' + filename_olr |
---|
202 | ras = report(msg) |
---|
203 | fullfilename_olr = isafile(iodirout + filename_olr, NEW=0, /MUST_EXIST) |
---|
204 | IF fullfilename_olr[0] EQ '' THEN BEGIN |
---|
205 | msg = 'eee : the file ' + fullfilename_olr + ' was not found.' |
---|
206 | ras = report(msg) |
---|
207 | return, result |
---|
208 | ENDIF |
---|
209 | ; |
---|
210 | ; build output filename |
---|
211 | filename_out = 'TropFlux_swr_' + string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc' |
---|
212 | fullfilename_out = iodirout + filename_out |
---|
213 | ; in order to avoid unexpected overwritten |
---|
214 | IF ((FILE_TEST(fullfilename_out) EQ 1) AND (project_overwrite EQ 0)) THEN BEGIN |
---|
215 | msg = 'eee : the file ' + fullfilename_out + ' already exists.' |
---|
216 | ras = report(msg) |
---|
217 | return, result |
---|
218 | ENDIF |
---|
219 | ; |
---|
220 | initncdf, fullfilename_swr_dt |
---|
221 | sw=read_ncdf("swr", yyyymmddb-.5d, yyyymmdde, file=fullfilename_swr_dt,/nostr) |
---|
222 | swi=sw |
---|
223 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
224 | jptin=n_elements(timein) |
---|
225 | da=jul2date(timein[0]) |
---|
226 | cda0=string(da,format='(i8.8)') |
---|
227 | da=jul2date(timein[jptin-1]) |
---|
228 | cda1=string(da,format='(i8.8)') |
---|
229 | print, 'swr_dt first date ', cda0 |
---|
230 | print, 'swr_dt last date ' , cda1 |
---|
231 | ; |
---|
232 | initncdf, fullfilename_olr |
---|
233 | olr=read_ncdf('olr', yyyymmddb-.5d, yyyymmdde, file=fullfilename_olr,/nost) |
---|
234 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
235 | jptin=n_elements(timein) |
---|
236 | da=jul2date(timein[0]) |
---|
237 | cda0=string(da,format='(i8.8)') |
---|
238 | da=jul2date(timein[jptin-1]) |
---|
239 | cda1=string(da,format='(i8.8)') |
---|
240 | print, 'olr first date ', cda0 |
---|
241 | print, 'olr last date ' , cda1 |
---|
242 | ; |
---|
243 | help, sw, olr |
---|
244 | ; |
---|
245 | ;creating climatology |
---|
246 | ; |
---|
247 | ny=(2007-1989)+1 ;+++ |
---|
248 | nt=365*ny |
---|
249 | olri=total(reform(olr[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny |
---|
250 | swi=total(reform(swi[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny |
---|
251 | ; |
---|
252 | help, olri, swi |
---|
253 | ; |
---|
254 | ; applying smoothing |
---|
255 | nsmooth=45 |
---|
256 | ; |
---|
257 | swi=[[[swi]],[[swi]],[[swi]]] |
---|
258 | olri=[[[olri]],[[olri]],[[olri]]] |
---|
259 | si=size(sw) |
---|
260 | n1=si[1] |
---|
261 | n2=si[2] |
---|
262 | ; |
---|
263 | for j=0,n2-1 do begin |
---|
264 | for i=0,n1-1 do begin |
---|
265 | x=reform(swi[i,j,*]) |
---|
266 | y=reform(olri[i,j,*]) |
---|
267 | swi[i,j,*]=smooth(x,nsmooth) |
---|
268 | olri[i,j,*]=smooth(y,nsmooth) |
---|
269 | endfor |
---|
270 | endfor |
---|
271 | ; |
---|
272 | swi=swi[*,*,365:365+364] |
---|
273 | olri=olri[*,*,365:365+364] |
---|
274 | help, swi |
---|
275 | ; |
---|
276 | initncdf, fullfilename_olr |
---|
277 | olr=read_ncdf('olr', yyyymmddb-.5d,yyyymmdde, box=box, file=fullfilename_olr,/nostr) |
---|
278 | timein=24.d*(time-julday(1,1,1957,0,0,0)) |
---|
279 | jptin=n_elements(timein) |
---|
280 | da=jul2date(timein[0]) |
---|
281 | cda0=string(da,format='(i8.8)') |
---|
282 | da=jul2date(timein[jptin-1]) |
---|
283 | cda1=string(da,format='(i8.8)') |
---|
284 | print, 'olr 2 first date ', cda0 |
---|
285 | print, 'olr 2 last date ' , cda1 |
---|
286 | |
---|
287 | jpt=n_elements(time) |
---|
288 | caldat, time,mon,day,yea |
---|
289 | swm=olr*0. |
---|
290 | olrm=olr*0. |
---|
291 | for jt=0,jpt-1 do begin |
---|
292 | jtt=(time[jt]-julday(1,1,yea[jt])) < 364 |
---|
293 | swm[*,*,jt]=swi[*,*,jtt] |
---|
294 | olrm[*,*,jt]=olri[*,*,jtt] |
---|
295 | endfor |
---|
296 | ; |
---|
297 | help, swm, olrm |
---|
298 | ; |
---|
299 | olra=olr-olrm ; olr anomaly |
---|
300 | rec=swm+(olra/0.760364) ; reconstructed sw |
---|
301 | ; |
---|
302 | ; writing field |
---|
303 | time=timegen(7670, start=julday(1,1,1989,0), units='days') ;+++ |
---|
304 | cda0=string(jul2date(time[0]),format='(i8.8)') |
---|
305 | cda1=string(jul2date(time[jpt-1]),format='(i8.8)') |
---|
306 | ; |
---|
307 | lat=reform(gphit[0,0:jpj-1]) |
---|
308 | lon=reform(glamt[0:jpi-1,0]) |
---|
309 | time=time-julday(1,1,1950) |
---|
310 | jpt=n_elements(time) |
---|
311 | ; |
---|
312 | ncfile='!' + fullfilename_out |
---|
313 | lon_attr={units:'degrees_east',long_name:'Longitude'} |
---|
314 | lat_attr={units:'degrees_north',long_name:'Latitude'} |
---|
315 | time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'} |
---|
316 | globattr={source:'Reconstructed from corrected OLR anomalies and TropFlux mean SWR climatology',timerange:cda0+' - '+cda1} |
---|
317 | sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'} |
---|
318 | ; |
---|
319 | ncfields = 'sw[longitude,latitude,time]=rec:sw_attr; ' $ |
---|
320 | + 'longitude[]=lon:lon_attr; ' $ |
---|
321 | + 'latitude[]=lat:lat_attr; ' $ |
---|
322 | + 'time[*time]=time:time_attr ' $ |
---|
323 | + ' @ globattr' |
---|
324 | ; |
---|
325 | @ncdf_quickwrite |
---|
326 | ; |
---|
327 | result = 0 |
---|
328 | return, result |
---|
329 | ; |
---|
330 | end |
---|