source: trunk/src/tropflux_swr_blnd.pro @ 175

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

an other bunch of new functions

  • Property svn:keywords set to URL
File size: 10.0 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:`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; :ref:`Tropflux_NRT_ncdf.pro`
69;
70; EXAMPLES
71; ========
72;
73; ::
74;
75;  IDL> yyyymmddb = 20000101L
76;  IDL> yyyymmdde = 20001231L
77;  IDL> result = tropflux_swr_blnd(yyyymmddb, yyyymmdde)
78;  IDL> 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_overwite 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 understanted SAXO strange behaviour
126;
127;     this resolve crash on cratos idl7::
128;
129;       % Attempt to subscript SWR_DT with JT is out of range.
130;
131;     line::
132;
133;        for jt=0,jpt-1 do swr_merged(*,*,jt)=swr_dt(*,*,jt)*a(jt)+(1-a(jt))*swr_nrt(*,*,jt)
134;
135;     problably because  6938+731=7669 and not 7670 when
136;     :samp:`dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr)`
137;     was used ::
138;
139;        DT              FLOAT     = Array[350, 60, 6938]
140;        NRT             FLOAT     = Array[350, 60, 731]
141;        SWR_DT          FLOAT     = Array[350, 60, 7669]
142;        SWR_NRT         FLOAT     = Array[350, 60, 7670]
143;
144;     nb jours 19890101-20071231::
145;
146;        IDL>  print, julday(12,31,2007) - julday(01, 01, 1989) +1
147;        6939
148;
149;     et ncdump -h $PROJECT_OD/TropFlux_swr_19890101_20071231_DT.nc time = UNLIMITED ; // (6939 currently)
150;
151;     nb jours 19890101-20091231::
152;
153;        IDL>  print, julday(12,31,2009) - julday(01, 01, 1989) +1
154;        7670
155;
156;     strange behaviour of read_ncdf ... see::
157;
158;        IDL> fullfilename_dt='TropFlux_swr_19890101_20071231_DT.nc'
159;        IDL> dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr)
160;        IDL> print, 'first time step (should crash with invalid date)', jul2date(time[0])
161;        first time step (should be 19890101)       19890101.
162;        IDL> dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr)
163;        IDL> print, 'first time step (should be 19890101)', jul2date(time[0])
164;        first time step (should be 19890101)       19890102.
165;
166;   * correction for reading gustiness file
167;
168; - fplod 20110809T115747Z aedon.locean-ipsl.upmc.fr (Darwin)
169;
170;   * usage of ${PROJECT_OD}
171;   * remove v* from filenames (in and out)
172;   * add test on IO files
173;
174; - fplod 20101215T085754Z aedon.locean-ipsl.upmc.fr (Darwin)
175;
176;   * add graph in header
177;
178; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
179;
180;   * minimal header
181;
182; - pbk 2008
183;
184;   * creation
185;
186;-
187function tropflux_swr_blnd $
188         , yyyymmddb $
189         , yyyymmdde
190;
191compile_opt idl2, strictarrsubs, logical_predicate
192;
193@cm_4cal
194@cm_4data
195@cm_4mesh
196@cm_4data
197@cm_project
198;
199; Return to caller if errors
200ON_ERROR, 2
201;
202result = -1
203;
204usage = 'result = tropflux_swr_blnd(yyyymmddb, yyyymmdde)'
205nparam = N_PARAMS()
206IF (nparam NE 2) THEN BEGIN
207   ras = report(['Incorrect number of arguments.' $
208         + '!C' $
209         + 'Usage : ' + usage])
210   return, result
211ENDIF
212;
213; test if ${PROJECT_OD} defined
214CASE project_od_env OF
215  '' : BEGIN
216         msg = 'eee : ${PROJECT_OD} is not defined'
217         ras = report(msg)
218       return, result
219       END
220  ELSE: BEGIN
221          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
222          ras = report(msg)
223        END
224 ENDCASE
225;
226; check if output data will be possible
227iodirout = isadirectory(project_od_env)
228;
229; existence and protection for reading
230IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
231   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
232   ras = report(msg)
233   return, result
234ENDIF
235;
236; existence and protection for writing
237IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
238    msg = 'eee : the directory' + iodirout  + ' was not found.'
239    ras = report(msg)
240    return, result
241ENDIF
242;
243; build dt data filename
244filename_dt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
245;
246; check if this file exists
247msg='iii : looking for ' + filename_dt
248ras = report(msg)
249fullfilename_dt = isafile(iodirout + filename_dt, NEW=0, /MUST_EXIST)
250IF fullfilename_dt[0] EQ '' THEN BEGIN
251   msg = 'eee : the file ' + fullfilename_dt + ' was not found.'
252   ras = report(msg)
253   return, result
254ENDIF
255;
256; build nrt data filename
257filename_nrt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc'
258;
259; check if this file exists
260msg='iii : looking for ' + filename_nrt
261ras = report(msg)
262fullfilename_nrt = isafile(iodirout + filename_nrt, NEW=0, /MUST_EXIST)
263IF fullfilename_nrt[0] EQ '' THEN BEGIN
264   msg = 'eee : the file ' + fullfilename_nrt + ' was not found.'
265   ras = report(msg)
266   return, result
267ENDIF
268;
269; build wg data filename
270filename_wg='TropFlux_gustiness_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
271;
272; check if this file exists
273msg='iii : looking for ' + filename_wg
274ras = report(msg)
275fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
276IF fullfilename_wg[0] EQ '' THEN BEGIN
277   msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
278   ras = report(msg)
279   return, result
280ENDIF
281;
282; build output filename
283filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc'
284fullfilename_out = iodirout + filename_out
285; in order to avoid unexpected overwritten
286IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
287   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
288   ras = report(msg)
289   return, result
290ENDIF
291;
292initncdf, fullfilename_dt
293dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr)
294print, 'www : should crash with invalide date 19890100'
295help, dt
296print, 'first time step (should be 19890101)', jul2date(time[0])
297print, 'last time step (should be 20071231)', jul2date(time[jpt-1])
298;
299initncdf, fullfilename_nrt
300nrt=read_ncdf('sw', 20080100, 20100112, file=fullfilename_nrt,/nostr)
301help, nrt
302;
303swr_nrt=read_ncdf('sw', 19880101, 20100112, file=fullfilename_nrt,/nostr)
304;
305swr_dt=[[[dt]],[[nrt]]]
306help, nrt, swr_dt, swr_nrt
307;
308swr_merged=swr_dt*0.
309;
310time=timegen(7670, start=julday(1,1,1989,0), units='days')
311jpt=n_elements(time)
312;
313a=interpol([1.,0.],[julday(10,01,2007),julday(12,31,2007)],time)
314a=((a > 0.) < 1.)
315for jt=0,jpt-1 do begin
316    swr_merged[*,*,jt]=swr_dt[*,*,jt]*a[jt]+(1-a[jt])*swr_nrt[*,*,jt]
317endfor
318;
319initncdf, fullfilename_wg
320time=timegen(7670, units='days', start=julday(1,1,1989,0))
321jpt=n_elements(time)
322lat=reform(gphit[0,0:jpj-1])
323lon=reform(glamt[0:jpi-1,0])
324cda0=string(jul2date(time[0]),format='(i8.8)')
325cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
326;
327time=time-julday(1,1,1950,00,00)
328ncfile='!' + fullfilename_out
329lon_attr={units:'degrees_east',long_name:'Longitude'}
330lat_attr={units:'degrees_north',long_name:'Latitude'}
331time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
332globattr={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'}
333sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
334;
335ncfields = 'swr[longitude,latitude,time]=swr_merged:sw_attr; ' $
336                      + 'longitude[]=lon:lon_attr; ' $
337                      + 'latitude[]=lat:lat_attr; ' $
338                      + 'time[*time]=time:time_attr ' $
339                      + ' @ globattr'
340;
341@ncdf_quickwrite
342;
343end
Note: See TracBrowser for help on using the repository browser.