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