source: trunk/src/tropflux_swr_blnd.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: 10.1 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; :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;-
199function tropflux_swr_blnd $
200, yyyymmddb $
201, yyyymmdde
202;
203compile_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
212ON_ERROR, 2
213;
214result = -1
215;
216usage = 'result = tropflux_swr_blnd(yyyymmddb, yyyymmdde)'
217nparam = N_PARAMS()
218IF (nparam NE 2) THEN BEGIN
219    ras = report(['Incorrect number of arguments.' $
220         + '!C' $
221         + 'Usage : ' + usage])
222    return, result
223ENDIF
224;
225; test if ${PROJECT_OD} defined
226CASE 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
236ENDCASE
237;
238; check if output data will be possible
239iodirout = isadirectory(project_od_env)
240;
241; existence and protection for reading
242IF (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
246ENDIF
247;
248; existence and protection for writing
249IF (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
253ENDIF
254;
255; build dt data filename
256filename_dt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
257;
258; check if this file exists
259msg='iii : looking for ' + filename_dt
260ras = report(msg)
261fullfilename_dt = isafile(iodirout + filename_dt, NEW=0, /MUST_EXIST)
262IF fullfilename_dt[0] EQ '' THEN BEGIN
263    msg = 'eee : the file ' + fullfilename_dt + ' was not found.'
264    ras = report(msg)
265    return, result
266ENDIF
267;
268; build nrt data filename
269filename_nrt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc'
270;
271; check if this file exists
272msg='iii : looking for ' + filename_nrt
273ras = report(msg)
274fullfilename_nrt = isafile(iodirout + filename_nrt, NEW=0, /MUST_EXIST)
275IF fullfilename_nrt[0] EQ '' THEN BEGIN
276    msg = 'eee : the file ' + fullfilename_nrt + ' was not found.'
277    ras = report(msg)
278    return, result
279ENDIF
280;
281; build wg data filename
282filename_wg='TropFlux_gustiness_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
283;
284; check if this file exists
285msg='iii : looking for ' + filename_wg
286ras = report(msg)
287fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
288IF fullfilename_wg[0] EQ '' THEN BEGIN
289    msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
290    ras = report(msg)
291    return, result
292ENDIF
293;
294; build output filename
295filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc'
296fullfilename_out = iodirout + filename_out
297; in order to avoid unexpected overwritten
298IF ((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
302ENDIF
303;
304initncdf, fullfilename_dt
305dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr)
306print, 'www : should crash with invalide date 19890100'
307help, dt
308print, 'first time step (should be 19890101)', jul2date(time[0])
309print, 'last time step (should be 20071231)', jul2date(time[jpt-1])
310;
311initncdf, fullfilename_nrt
312nrt=read_ncdf('sw', 20080100, 20100112, file=fullfilename_nrt,/nostr)
313help, nrt
314;
315swr_nrt=read_ncdf('sw', 19880101, 20100112, file=fullfilename_nrt,/nostr)
316;
317swr_dt=[[[dt]],[[nrt]]]
318help, nrt, swr_dt, swr_nrt
319;
320swr_merged=swr_dt*0.
321;
322time=timegen(7670, start=julday(1,1,1989,0), units='days')
323jpt=n_elements(time)
324;
325a=interpol([1.,0.],[julday(10,01,2007),julday(12,31,2007)],time)
326a=((a > 0.) < 1.)
327for jt=0,jpt-1 do begin
328    swr_merged[*,*,jt]=swr_dt[*,*,jt]*a[jt]+(1-a[jt])*swr_nrt[*,*,jt]
329endfor
330;
331initncdf, fullfilename_wg
332time=timegen(7670, units='days', start=julday(1,1,1989,0))
333jpt=n_elements(time)
334lat=reform(gphit[0,0:jpj-1])
335lon=reform(glamt[0:jpi-1,0])
336cda0=string(jul2date(time[0]),format='(i8.8)')
337cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
338;
339time=time-julday(1,1,1950,00,00)
340ncfile='!' + fullfilename_out
341lon_attr={units:'degrees_east',long_name:'Longitude'}
342lat_attr={units:'degrees_north',long_name:'Latitude'}
343time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
344globattr={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'}
345sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
346;
347ncfields = '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;
355end
Note: See TracBrowser for help on using the repository browser.