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
RevLine 
[6]1;+
2;
[174]3; =====================
4; tropflux_swr_blnd.pro
5; =====================
[6]6;
[174]7; .. function:: tropflux_swr_blnd(yyyymmddb,yyyymmdde)
[6]8;
[81]9; DESCRIPTION
10; ===========
11;
[174]12; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc`
[74]13; containing ++
[85]14; has been produced by
[174]15; :func:`tropflux_swr_dt`.
[74]16;
[174]17; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_NRT.nc`
[74]18; containing ++
[85]19; has been produced by
[174]20; :func:`tropflux_swr_nrt`.
[74]21;
[174]22; :file:`${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc` containing ++
[85]23; has been produced by
[174]24; :func:`cronin_gustiness_ncdf`.
[74]25;
26; ++ are written
[174]27; in :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc`
[74]28; if this file not already exists.
29;
[100]30; This file will be used by
31; :ref:`TropFlux_NRT_ncdf.pro`.
[74]32;
[8]33;     .. graphviz::
34;
[174]35;        digraph tropflux_swr_blnd {
[8]36;
[174]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"];
[8]41;
[174]42;           tropflux_swr_blnd [shape=box,
[8]43;           fontname=Courier,
44;           color=blue,
[174]45;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_blnd.pro",
46;           label="${PROJECT}/src/tropflux_swr_blnd.pro"];
[8]47;
[174]48;           {file_dt file_nrt file_gustiness} -> {tropflux_swr_blnd} -> {file_out}
[74]49;
[8]50;       }
51;
[6]52; SEE ALSO
53; ========
54;
[175]55; :ref:`mooring_corrections`
56;
57; Used by :ref:`tropflux.sh`
58;
[81]59; :ref:`project_profile.sh`
60;
61; :ref:`data_in_swr`
62;
[20]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;
[88]68; :ref:`Tropflux_NRT_ncdf.pro`
[81]69;
[6]70; EXAMPLES
71; ========
72;
73; ::
74;
[174]75;  IDL> yyyymmddb = 20000101L
76;  IDL> yyyymmdde = 20001231L
77;  IDL> result = tropflux_swr_blnd(yyyymmddb, yyyymmdde)
78;  IDL> print, result
[6]79;
80; TODO
81; ====
82;
[174]83; handling date > 20071231
84;
85; read_ncdf usage of yyyymmddb yyyymmdde
86;
87; get rid of timegen
88;
[88]89; submit read_ncdf with 19890101 pb to saxo-dev
[81]90;
[6]91; coding rules
92;
[74]93; complete description
94;
[88]95; why 20080100, 20100112 as  date1 and date2 when readind nrt
[74]96;
[97]97; why two read_ncdf for nrt
[74]98;
[97]99; according to pk 20110811 we can include this process in
[174]100; tropflux_swr_nrt.pro ... later
[78]101;
[74]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;
[6]108; EVOLUTIONS
109; ==========
110;
[174]111; $Id: tropflux_swr_blnd.pro 88 2011-08-19 15:40:14Z pinsard $
[85]112;
[81]113; $URL$
114;
[174]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;
[88]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
[174]136;     :samp:`dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr)`
[88]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'
[174]159;        IDL> dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr)
[97]160;        IDL> print, 'first time step (should crash with invalid date)', jul2date(time[0])
[88]161;        first time step (should be 19890101)       19890101.
[174]162;        IDL> dt=read_ncdf('swr', 19890101, 20071231, file=fullfilename_dt,/nostr)
[97]163;        IDL> print, 'first time step (should be 19890101)', jul2date(time[0])
[88]164;        first time step (should be 19890101)       19890102.
165;
166;   * correction for reading gustiness file
[97]167;
[74]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;
[8]174; - fplod 20101215T085754Z aedon.locean-ipsl.upmc.fr (Darwin)
175;
176;   * add graph in header
177;
[6]178; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
179;
180;   * minimal header
181;
182; - pbk 2008
183;
184;   * creation
185;
186;-
[174]187function tropflux_swr_blnd $
188         , yyyymmddb $
189         , yyyymmdde
[74]190;
[174]191compile_opt idl2, strictarrsubs, logical_predicate
192;
[74]193@cm_4cal
194@cm_4data
195@cm_4mesh
196@cm_4data
197@cm_project
198;
[174]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;
[74]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)
[174]218       return, result
[74]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)
[174]233   return, result
[74]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)
[174]240    return, result
[74]241ENDIF
242;
243; build dt data filename
[174]244filename_dt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
[74]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)
[174]253   return, result
[74]254ENDIF
[97]255;
[74]256; build nrt data filename
[174]257filename_nrt='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_NRT.nc'
[74]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)
[174]266   return, result
[74]267ENDIF
268;
269; build wg data filename
[174]270filename_wg='TropFlux_gustiness_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
[74]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)
[174]279   return, result
[74]280ENDIF
281;
282; build output filename
[174]283filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc'
[74]284fullfilename_out = iodirout + filename_out
285; in order to avoid unexpected overwritten
[174]286IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
[74]287   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
288   ras = report(msg)
[174]289   return, result
[74]290ENDIF
291;
292initncdf, fullfilename_dt
[174]293dt=read_ncdf('swr', 19890100, 20071231, file=fullfilename_dt,/nostr)
[88]294print, 'www : should crash with invalide date 19890100'
[5]295help, dt
[88]296print, 'first time step (should be 19890101)', jul2date(time[0])
297print, 'last time step (should be 20071231)', jul2date(time[jpt-1])
[97]298;
[74]299initncdf, fullfilename_nrt
[174]300nrt=read_ncdf('sw', 20080100, 20100112, file=fullfilename_nrt,/nostr)
[5]301help, nrt
[97]302;
[174]303swr_nrt=read_ncdf('sw', 19880101, 20100112, file=fullfilename_nrt,/nostr)
[97]304;
[5]305swr_dt=[[[dt]],[[nrt]]]
[88]306help, nrt, swr_dt, swr_nrt
[97]307;
[5]308swr_merged=swr_dt*0.
[97]309;
[100]310time=timegen(7670, start=julday(1,1,1989,0), units='days')
[94]311jpt=n_elements(time)
[97]312;
[5]313a=interpol([1.,0.],[julday(10,01,2007),julday(12,31,2007)],time)
314a=((a > 0.) < 1.)
[88]315for jt=0,jpt-1 do begin
[174]316    swr_merged[*,*,jt]=swr_dt[*,*,jt]*a[jt]+(1-a[jt])*swr_nrt[*,*,jt]
[88]317endfor
[97]318;
[88]319initncdf, fullfilename_wg
[97]320time=timegen(7670, units='days', start=julday(1,1,1989,0))
[94]321jpt=n_elements(time)
[174]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)')
[97]326;
[5]327time=time-julday(1,1,1950,00,00)
[74]328ncfile='!' + fullfilename_out
[5]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'}
[100]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'}
[5]333sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
[97]334;
[5]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'
[97]340;
[5]341@ncdf_quickwrite
[97]342;
[5]343end
Note: See TracBrowser for help on using the repository browser.