source: trunk/src/tropflux_swr_nrt.pro @ 174

Last change on this file since 174 was 174, checked in by pinsard, 12 years ago

bunch of new functions

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