source: trunk/src/tropflux_swr_dt.pro @ 191

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

no more IDL prompt in examples

  • Property svn:keywords set to URL
File size: 6.8 KB
RevLine 
[6]1;+
2;
[174]3; ===================
4; tropflux_swr_dt.pro
5; ===================
[6]6;
[174]7; .. function:: tropflux_swr_dt(yyyymmddb,yyyymmdde)
[6]8;
[81]9; DESCRIPTION
10; ===========
[6]11;
[81]12; Correction of swr delay time on OAFLUX grid
13;
14; :file:`${PROJECT_OD}/swr_oafluxgrid_1985_2007.nc`
15; have been produced ++by pk
16;
[97]17; Corrected swr delay on OAFLUX grid
[81]18; is written in
[174]19; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc`
[81]20; if this file not already exists.
21;
[8]22;     .. graphviz::
23;
[174]24;        digraph tropflux_swr_dt {
[8]25;
[81]26;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/swr_oafluxgrid_1985_2007.nc"];
[174]27;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc"];
[8]28;
[174]29;           tropflux_swr_dt [shape=box,
[8]30;           fontname=Courier,
31;           color=blue,
[174]32;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_dt.pro",
33;           label="${PROJECT}/src/tropflux_swr_dt.pro"];
[8]34;
[174]35;           {file_in}-> {tropflux_swr_dt} -> {file_out}
[8]36;
37;        }
38;
[6]39; SEE ALSO
40; ========
41;
[174]42; :ref:`mooring_corrections`
43;
44; Used by :ref:`tropflux.sh`
45;
[81]46; :ref:`project_profile.sh`
47;
48; :ref:`data_in_swr`
49;
[20]50; :func:`initncdf <saxo:initncdf>`
51; :func:`read_ncdf <saxo:read_ncdf>`
52; :func:`grossemoyenne <saxo:grossemoyenne>`
53; :func:`julday <saxo:julday>`
54; :func:`caldat <saxo:caldat>`
55; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
56;
[6]57; EXAMPLES
58; ========
59;
60; ::
61;
[180]62;  yyyymmddb = 20000101L
63;  yyyymmdde = 20001231L
64;  result = tropflux_swr_dt(yyyymmddb, yyyymmdde)
65;  print, result
[6]66;
67; TODO
68; ====
69;
[174]70; handlind yyyymmdde > 20071231
71;
72; first date 19991231 vs yyyymmddb = 20000101L
73;
[81]74; NaNf values in ouptut file while 1.e20 in input file !!
[6]75;
76; coding rules
77;
[81]78; use the output of concat_swr.sh to be written.
79; now use swr_oafluxgrid_1985_2007.nc provided by pk 20110811
[174]80; stored in :file:`cratos:/usr/lodyc/incas/fplod/tropflux_d/from_pk/stage_0/swr_oafluxgrid_1985_2007.nc`
[81]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;
[6]88; EVOLUTIONS
89; ==========
90;
[174]91; $Id: tropflux_swr_dt.pro 88 2011-08-19 15:40:14Z pinsard $
[81]92;
93; $URL$
94;
[174]95; - fplod 20120321
96;
97;   * pro -> func
98;   * rename with lower case TropFlux_swr_DT_19890101_20071231.pro become
99;     tropflux_swr_dt.pro
100;   * taking project_overwite into account
101;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
102;   * start to homogenize time handling and netcdf writing
103;
[98]104; - fplod 20110830T135743Z cratos (Linux)
105;
106;   * replace tt by time
107;
[81]108; - fplod 20110812T073138Z aedon.locean-ipsl.upmc.fr (Darwin)
109;
110;   * usage of ${PROJECT_OD}
111;   * complete description
112;   * remove v50 in output filename
113;
[8]114; - fplod 20101215T091726Z aedon.locean-ipsl.upmc.fr (Darwin)
115;
116;   * add graph in header
117;
[6]118; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
119;
120;   * minimal header
121;
122; - pbk 2008
123;
124;   * creation
125;
126;-
[174]127function tropflux_swr_dt $
128         , yyyymmddb $
129         , yyyymmdde
[81]130;
[174]131;++compile_opt idl2, strictarrsubs, logical_predicate
132;
[81]133@cm_4cal
134@cm_4data
135@cm_4mesh
136@cm_4data
137@cm_project
138;
[174]139; Return to caller if errors
140ON_ERROR, 2
141;
142result = -1
143;
144usage = 'result = tropflux_swr_dt(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
[81]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)
[174]158       return, result
[81]159       END
160  ELSE: BEGIN
161          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
162          ras = report(msg)
163        END
164 ENDCASE
165;
166; check if output data will be possible
167iodirout = isadirectory(project_od_env)
168;
169; existence and protection for reading
170IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
171   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
172   ras = report(msg)
[174]173   return, result
[81]174ENDIF
175;
176; existence and protection for writing
177IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
178    msg = 'eee : the directory' + iodirout  + ' was not found.'
179    ras = report(msg)
[174]180    return, result
[81]181ENDIF
182;
183; build data filename
184filename='swr_oafluxgrid_1985_2007.nc'
185;
186; check if this file exists
187msg='iii : looking for ' + filename
188ras = report(msg)
189fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
190IF fullfilename[0] EQ '' THEN BEGIN
191   msg = 'eee : the file ' + fullfilename + ' was not found.'
192   ras = report(msg)
[174]193   return, result
[81]194ENDIF
195;
196; build output filename
[174]197filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
[81]198fullfilename_out = iodirout + filename_out
199; in order to avoid unexpected overwritten
[174]200IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
[81]201   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
202   ras = report(msg)
[174]203   return, result
[81]204ENDIF
205;
206initncdf, filename
[97]207;
[174]208sw=read_ncdf("swr", yyyymmddb-.5d,yyyymmdde, file=filename,/nostr)
209timein=24.d*(time-julday(1,1,1957,0,0,0))
210jptin=n_elements(timein)
211da=jul2date(time[0])
212cda0=string(da,format='(i8.8)')
213da=jul2date(time[jptin-1])
214cda1=string(da,format='(i8.8)')
215print, 'first date ', cda0
216print, 'last date ' , cda1
[5]217help, sw
[97]218;
[5]219sw_mean=grossemoyenne(sw, 't',/nan)
220help, sw_mean
[97]221;
[94]222jpt=n_elements(time)
[5]223caldat, time,mon,day,yea
[97]224sw_m=sw*0.
[94]225sw_bias=sw*0.
[97]226;
[5]227for jt=0,jpt-1 do begin
[174]228  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
229  swr=reform(sw_mean[*,*])
230  sw_m[*,*,jt]=swr
231  sw_bias[*,*,jt]=(((swr-295.4)*18.36/(200.-295.4)) > 0.) < 18.37
[5]232endfor
[97]233;
[5]234help, sw_m, sw_bias
235swa=sw-sw_m
[97]236swa=swa/(0.901273)       ; variability correction (seasonal_cycle_swr_isccp.pro)
237;
238swr=sw_m+swa-sw_bias       ; new swr, corrected for bias and variability
[100]239;
240; writing field
[174]241cda0=string(jul2date(time[0]),format='(i8.8)')
242cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
[97]243;
[174]244lat=reform(gphit[0,0:jpj-1])
245lon=reform(glamt[0:jpi-1,0])
[97]246time=time-julday(1,1,1950)
[94]247jpt=n_elements(time)
[97]248;
[81]249ncfile='!' + fullfilename_out
[5]250lon_attr={units:'degrees_east',long_name:'Longitude'}
251lat_attr={units:'degrees_north',long_name:'Latitude'}
252time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
[100]253globattr={source:'Obtained from ISCCP.  Corrections has been done on mean bias and variability',timerange:cda0+' - '+cda1}
[5]254sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
[97]255;
[174]256ncfields = 'swr[longitude,latitude,*time]=swr:sw_attr; ' $
[5]257                      + 'longitude[]=lon:lon_attr; ' $
258                      + 'latitude[]=lat:lat_attr; ' $
[174]259                      + 'time[]=timein:time_attr ' $
[5]260                      + ' @ globattr'
[97]261;
[5]262@ncdf_quickwrite
[97]263;
[174]264result = 0
265return, result
266;
[5]267end
Note: See TracBrowser for help on using the repository browser.