source: trunk/src/tropflux_swr_dt.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: 6.7 KB
Line 
1;+
2;
3; ===================
4; tropflux_swr_dt.pro
5; ===================
6;
7; .. function:: tropflux_swr_dt(yyyymmddb,yyyymmdde)
8;
9; DESCRIPTION
10; ===========
11;
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;
17; Corrected swr delay on OAFLUX grid
18; is written in
19; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc`
20; if this file not already exists.
21;
22;     .. graphviz::
23;
24;        digraph tropflux_swr_dt {
25;
26;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/swr_oafluxgrid_1985_2007.nc"];
27;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_DT.nc"];
28;
29;           tropflux_swr_dt [shape=box,
30;           fontname=Courier,
31;           color=blue,
32;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_swr_dt.pro",
33;           label="${PROJECT}/src/tropflux_swr_dt.pro"];
34;
35;           {file_in}-> {tropflux_swr_dt} -> {file_out}
36;
37;        }
38;
39; SEE ALSO
40; ========
41;
42; :ref:`mooring_corrections`
43;
44; Used by :ref:`tropflux.sh`
45;
46; :ref:`project_profile.sh`
47;
48; :ref:`data_in_swr`
49;
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;
57; EXAMPLES
58; ========
59;
60; .. code-block:: idl
61;
62;    yyyymmddb = 20000101L
63;    yyyymmdde = 20001231L
64;    result = tropflux_swr_dt(yyyymmddb, yyyymmdde)
65;    print, result
66;
67; TODO
68; ====
69;
70; handle yyyymmdde > 20071231
71;
72; first date 19991231 vs yyyymmddb = 20000101L
73;
74; NaNf values in output file while 1.e20 in input file !!
75;
76; coding rules
77;
78; use the output of concat_swr.sh to be written.
79; now use swr_oafluxgrid_1985_2007.nc provided by pk 20110811
80; stored in :file:`cratos:/usr/lodyc/incas/fplod/tropflux_d/from_pk/stage_0/swr_oafluxgrid_1985_2007.nc`
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;
88; EVOLUTIONS
89; ==========
90;
91; $Id: tropflux_swr_dt.pro 88 2011-08-19 15:40:14Z pinsard $
92;
93; $URL$
94;
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_overwrite 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;
104; - fplod 20110830T135743Z cratos (Linux)
105;
106;   * replace tt by time
107;
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;
114; - fplod 20101215T091726Z aedon.locean-ipsl.upmc.fr (Darwin)
115;
116;   * add graph in header
117;
118; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
119;
120;   * minimal header
121;
122; - pbk 2008
123;
124;   * creation
125;
126;-
127function tropflux_swr_dt $
128, yyyymmddb $
129, yyyymmdde
130;
131;++compile_opt idl2, strictarrsubs, logical_predicate
132;
133@cm_4cal
134@cm_4data
135@cm_4mesh
136@cm_4data
137@cm_project
138;
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
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)
158        return, result
159    END
160    ELSE : BEGIN
161        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
162        ras = report(msg)
163    END
164ENDCASE
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)
173   return, result
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)
180    return, result
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)
193   return, result
194ENDIF
195;
196; build output filename
197filename_out = 'TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_DT.nc'
198fullfilename_out = iodirout + filename_out
199; in order to avoid unexpected overwritten
200IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
201   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
202   ras = report(msg)
203   return, result
204ENDIF
205;
206initncdf, filename
207;
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
217help, sw
218;
219sw_mean=grossemoyenne(sw, 't',/nan)
220help, sw_mean
221;
222jpt=n_elements(time)
223caldat, time,mon,day,yea
224sw_m=sw*0.
225sw_bias=sw*0.
226;
227for jt=0,jpt-1 do begin
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
232endfor
233;
234help, sw_m, sw_bias
235swa=sw-sw_m
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
239;
240; writing field
241cda0=string(jul2date(time[0]),format='(i8.8)')
242cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
243;
244lat=reform(gphit[0,0:jpj-1])
245lon=reform(glamt[0:jpi-1,0])
246time=time-julday(1,1,1950)
247jpt=n_elements(time)
248;
249ncfile='!' + fullfilename_out
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'}
253globattr={source:'Obtained from ISCCP.  Corrections has been done on mean bias and variability',timerange:cda0+' - '+cda1}
254sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
255;
256ncfields = 'swr[longitude,latitude,*time]=swr:sw_attr; ' $
257+ 'longitude[]=lon:lon_attr; ' $
258+ 'latitude[]=lat:lat_attr; ' $
259+ 'time[]=timein:time_attr ' $
260+ ' @ globattr'
261;
262@ncdf_quickwrite
263;
264result = 0
265return, result
266;
267end
Note: See TracBrowser for help on using the repository browser.