source: trunk/src/tropflux_swr_nrt.pro

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:keywords set to URL
File size: 8.6 KB
Line 
1;+
2;
3; ====================
4; tropflux_swr_nrt.pro
5; ====================
6;
7; .. function:: tropflux_swr_nrt(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
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; .. code-block:: idl
67;
68;    yyyymmddb = 20000101L
69;    yyyymmdde = 20001231L
70;    result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)
71;    print, result
72;
73; TODO
74; ====
75;
76; handle yyyymmdde > 20071231
77;
78; remove NaNf values in output file (may be not because of this module)
79;
80; why two sequence initncdf 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_overwrite 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;-
129function tropflux_swr_nrt $
130, yyyymmddb $
131, yyyymmdde
132;
133compile_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
142ON_ERROR, 2
143;
144result = -1
145;
146usage = 'result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)'
147nparam = N_PARAMS()
148IF (nparam NE 2) THEN BEGIN
149   ras = report(['Incorrect number of arguments.' $
150   + '!C' $
151   + 'Usage : ' + usage])
152   return, result
153ENDIF
154;
155; test if ${PROJECT_OD} defined
156CASE 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
166ENDCASE
167; check if output data will be possible
168iodirout = isadirectory(project_od_env)
169;
170; existence and protection for reading
171IF (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
175ENDIF
176;
177; existence and protection for writing
178IF (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
182ENDIF
183;
184; build swr dt data filename
185filename_swr_dt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
186;
187; check if this file exists
188msg='iii : looking for ' + filename_swr_dt
189ras = report(msg)
190fullfilename_swr_dt = isafile(iodirout + filename_swr_dt, NEW=0, /MUST_EXIST)
191IF 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
195ENDIF
196;
197; build olr data filename
198filename_olr='olr_oafluxgrid_30n30s_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
199;
200; check if this file exists
201msg='iii : looking for ' + filename_olr
202ras = report(msg)
203fullfilename_olr = isafile(iodirout + filename_olr, NEW=0, /MUST_EXIST)
204IF fullfilename_olr[0] EQ '' THEN BEGIN
205    msg = 'eee : the file ' + fullfilename_olr + ' was not found.'
206    ras = report(msg)
207    return, result
208ENDIF
209;
210; build output filename
211filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc'
212fullfilename_out = iodirout + filename_out
213; in order to avoid unexpected overwritten
214IF ((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
218ENDIF
219;
220initncdf, fullfilename_swr_dt
221sw=read_ncdf("swr", yyyymmddb-.5d, yyyymmdde, file=fullfilename_swr_dt,/nostr)
222swi=sw
223timein=24.d*(time-julday(1,1,1957,0,0,0))
224jptin=n_elements(timein)
225da=jul2date(timein[0])
226cda0=string(da,format='(i8.8)')
227da=jul2date(timein[jptin-1])
228cda1=string(da,format='(i8.8)')
229print, 'swr_dt first date ', cda0
230print, 'swr_dt last date ' , cda1
231;
232initncdf, fullfilename_olr
233olr=read_ncdf('olr', yyyymmddb-.5d, yyyymmdde, file=fullfilename_olr,/nost)
234timein=24.d*(time-julday(1,1,1957,0,0,0))
235jptin=n_elements(timein)
236da=jul2date(timein[0])
237cda0=string(da,format='(i8.8)')
238da=jul2date(timein[jptin-1])
239cda1=string(da,format='(i8.8)')
240print, 'olr first date ', cda0
241print, 'olr last date ' , cda1
242;
243help, sw, olr
244;
245;creating climatology
246;
247ny=(2007-1989)+1 ;+++
248nt=365*ny
249olri=total(reform(olr[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny
250swi=total(reform(swi[*,*,0:nt-1],nxt,nyt,365,ny),4)/ny
251;
252help, olri, swi
253;
254; applying smoothing
255nsmooth=45
256;
257swi=[[[swi]],[[swi]],[[swi]]]
258olri=[[[olri]],[[olri]],[[olri]]]
259si=size(sw)
260n1=si[1]
261n2=si[2]
262;
263for 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
270endfor
271;
272swi=swi[*,*,365:365+364]
273olri=olri[*,*,365:365+364]
274help, swi
275;
276initncdf, fullfilename_olr
277olr=read_ncdf('olr', yyyymmddb-.5d,yyyymmdde, box=box, file=fullfilename_olr,/nostr)
278timein=24.d*(time-julday(1,1,1957,0,0,0))
279jptin=n_elements(timein)
280da=jul2date(timein[0])
281cda0=string(da,format='(i8.8)')
282da=jul2date(timein[jptin-1])
283cda1=string(da,format='(i8.8)')
284print, 'olr 2 first date ', cda0
285print, 'olr 2 last date ' , cda1
286
287jpt=n_elements(time)
288caldat, time,mon,day,yea
289swm=olr*0.
290olrm=olr*0.
291for 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]
295endfor
296;
297help, swm, olrm
298;
299olra=olr-olrm                       ; olr anomaly
300rec=swm+(olra/0.760364)             ; reconstructed sw
301;
302; writing field
303time=timegen(7670, start=julday(1,1,1989,0), units='days') ;+++
304cda0=string(jul2date(time[0]),format='(i8.8)')
305cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
306;
307lat=reform(gphit[0,0:jpj-1])
308lon=reform(glamt[0:jpi-1,0])
309time=time-julday(1,1,1950)
310jpt=n_elements(time)
311;
312ncfile='!' + fullfilename_out
313lon_attr={units:'degrees_east',long_name:'Longitude'}
314lat_attr={units:'degrees_north',long_name:'Latitude'}
315time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
316globattr={source:'Reconstructed from corrected OLR anomalies and TropFlux mean SWR climatology',timerange:cda0+' - '+cda1}
317sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
318;
319ncfields = '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;
327result = 0
328return, result
329;
330end
Note: See TracBrowser for help on using the repository browser.