source: trunk/src/tropflux_nrt_ncdf.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: 8.8 KB
Line 
1;+
2;
3; =====================
4; tropflux_nrt_ncdf.pro
5; =====================
6;
7; .. function:: tropflux_nrt_ncdf(yyyymmddb, yyyymmdde)
8;
9; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc`
10; containing
11; ws corrected on OAFLUX grid
12; has been produced by
13; :func:`tropflux_swr_blnd`.
14;
15; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
16; containing
17; lwr corrected on OAFLUX grid
18; has been produced by
19; :func:`lwr_correction_ncdf`.
20;
21; :file:`${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}_coare3.nc`
22; containing
23; ++
24; has been produced by
25; :func:`tropflux`.
26;
27; ++ are written
28; in :file:`${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}.nc`
29; if this file not already exists.
30;
31;     .. graphviz::
32;
33;        digraph tropflux_nrt_ncdf {
34;
35;           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc"];
36;           file_lwr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc"];
37;           file_coare [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}_coarev3.nc"];
38;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}.nc"];
39;
40;           tropflux_nrt_ncdf [shape=box,
41;           fontname=Courier,
42;           color=blue,
43;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux_nrt_ncdf.pro",
44;           label="${PROJECT}/src/tropflux_nrt_ncdf.pro" ];
45;
46;           {file_swr file_lwr file_coare} -> {tropflux_nrt_ncdf} -> {file_out}
47;
48;        }
49;
50; SEE ALSO
51; ========
52;
53; Used by :ref:`tropflux.sh`
54;
55; :ref:`project_profile.sh`
56;
57; :func:`initncdf <saxo:initncdf>`
58; :func:`read_ncdf <saxo:read_ncdf>`
59; :func:`julday <saxo:julday>`
60; :func:`jul2date <saxo:jul2date>`
61; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
62;
63; EXAMPLES
64; ========
65;
66; .. code-block:: idl
67;
68;    yyyymmddb = 20000101L
69;    yyyymmdde = 20001231L
70;    result = tropflux_nrt_ncdf(yyyymmddb, yyyymmdde)
71;    print, result
72;
73; TODO
74; ====
75;
76; handle yyyymmdde > 20071231 see attributes also
77;
78; coding rules
79;
80; create 4 files instead of one now
81;
82; EVOLUTIONS
83; ==========
84;
85; $Id: tropflux_nrt_ncdf.pro 88 2011-08-19 15:40:14Z pinsard $
86;
87; $URL$
88;
89; - fplod 20120326
90;
91;   * pro -> func
92;   * rename with lower case TropFlux_NRT_ncdf.pro become tropflux_nrt_ncdf.pro
93;   * taking project_overwrite into account
94;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
95;   * hard coded st and en replaced by yyyymmddb and yyyymmdde parameters
96;   * get rid of timegen
97;
98; - fplod 20110809T133815Z cratos (Linux)
99;
100;   * remove v50 from pro name and in the graph
101;   * add coarev3 to the file coming from TropFlux_19890101_20091231.pro
102;   * use $PROJECT_OD
103;
104; - fplod 20101214T112526Z aedon.locean-ipsl.upmc.fr (Darwin)
105;
106;   * add graph
107;
108; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
109;
110;   * minimal header
111;
112; - pbk 2008
113;
114;   * creation
115;
116;-
117function tropflux_nrt_ncdf $
118, yyyymmddb $
119, yyyymmdde
120;
121compile_opt idl2, strictarrsubs, logical_predicate
122;
123@cm_4cal
124@cm_4data
125@cm_4mesh
126@cm_4data
127@cm_project
128;
129; Return to caller if errors
130ON_ERROR, 2
131;
132result = -1
133;
134usage = 'result = tropflux_swr_dt(yyyymmddb, yyyymmdde)'
135nparam = N_PARAMS()
136IF (nparam NE 2) THEN BEGIN
137    ras = report(['Incorrect number of arguments.' $
138              + '!C' $
139              + 'Usage : ' + usage])
140    return, result
141ENDIF
142;
143; test if ${PROJECT_OD} defined
144CASE project_od_env OF
145    '' : BEGIN
146        msg = 'eee : ${PROJECT_OD} is not defined'
147        ras = report(msg)
148        return, result
149    END
150    ELSE : BEGIN
151        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
152        ras = report(msg)
153    END
154ENDCASE
155;
156; check if output data will be possible
157iodirout = isadirectory(project_od_env)
158;
159; existence and protection for reading
160IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
161    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
162    ras = report(msg)
163    return, result
164ENDIF
165;
166; existence and protection for writing
167IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
168    msg = 'eee : the directory' + iodirout  + ' was not found.'
169    ras = report(msg)
170    return, result
171ENDIF
172;
173; build SWR blnd data filename
174filename_swr_blnd="TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc"
175;
176; check if this file exists
177msg='iii : looking for ' + filename_swr_blnd
178ras = report(msg)
179fullfilename_swr_blnd = isafile(iodirout + filename_swr_blnd, NEW=0, /MUST_EXIST)
180IF fullfilename_swr_blnd[0] EQ '' THEN BEGIN
181    msg = 'eee : the file ' + fullfilename_swr_blnd + ' was not found.'
182    ras = report(msg)
183    return, result
184ENDIF
185;
186; build LWR data filename
187filename_lwr="TropFlux_lwr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc"
188;
189; check if this file exists
190msg='iii : looking for ' + filename_lwr
191ras = report(msg)
192fullfilename_lwr = isafile(iodirout + filename_lwr, NEW=0, /MUST_EXIST)
193IF fullfilename_lwr[0] EQ '' THEN BEGIN
194    msg = 'eee : the file ' + fullfilename_lwr + ' was not found.'
195    ras = report(msg)
196    return, result
197ENDIF
198;
199;  build COARE data filename
200filename_coare="TropFlux_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_coarev3.nc"
201;
202; check if this file exists
203msg='iii : looking for ' + filename_lwr
204ras = report(msg)
205fullfilename_coare = isafile(iodirout + filename_coare, NEW=0, /MUST_EXIST)
206IF fullfilename_coare[0] EQ '' THEN BEGIN
207    msg = 'eee : the file ' + fullfilename_coare + ' was not found.'
208    ras = report(msg)
209    return, result
210ENDIF
211;
212filename_out='TropFlux_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
213fullfilename_out = iodirout + filename_out
214; in order to avoid unexpected overwritten
215IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
216    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
217    ras = report(msg)
218    return, result
219ENDIF
220;
221initncdf, fullfilename_swr_blnd
222;
223swr=read_ncdf("swr", yyyymmddb - .5d, yyyymmdde, file=fullfilename_swr_blnd,/nostr)
224timein=24.d*(time-julday(1,1,1957,0,0,0))
225jpt=n_elements(timein)
226da=jul2date(time[0])
227cda0=string(da,format='(i8.8)')
228da=jul2date(time[jpt-1])
229cda1=string(da,format='(i8.8)')
230print, 'swr in tropflux_nrt_ncdf first date ', cda0
231print, 'swr in tropflux_nrt_ncdf last date ' , cda1
232;
233initncdf, fullfilename_lwr
234lwr=read_ncdf("lwr", yyyymmddb - .5d, yyyymmdde, file=fullfilename_lwr,/nostr)
235timein=24.d*(time-julday(1,1,1957,0,0,0))
236jpt=n_elements(timein)
237da=jul2date(time[0])
238cda0=string(da,format='(i8.8)')
239da=jul2date(time[jpt-1])
240cda1=string(da,format='(i8.8)')
241print, 'lwr in tropflux_nrt_ncdf first date ', cda0
242print, 'lwr in tropflux_nrt_ncdf last date ' , cda1
243;
244initncdf, fullfilename_coare
245lhf=read_ncdf("lhf", yyyymmddb - .5d, yyyymmdde, file=fullfilename_coare,/nostr)
246timein=24.d*(time-julday(1,1,1957,0,0,0))
247jpt=n_elements(timein)
248da=jul2date(time[0])
249cda0=string(da,format='(i8.8)')
250da=jul2date(time[jpt-1])
251cda1=string(da,format='(i8.8)')
252print, 'lhf in tropflux_nrt_ncdf first date ', cda0
253print, 'lhf in tropflux_nrt_ncdf last date ' , cda1
254;
255shf=read_ncdf("shf", yyyymmddb - .5d, yyyymmdde, file=fullfilename_coare,/nostr)
256timein=24.d*(time-julday(1,1,1957,0,0,0))
257jpt=n_elements(timein)
258da=jul2date(time[0])
259cda0=string(da,format='(i8.8)')
260da=jul2date(time[jpt-1])
261cda1=string(da,format='(i8.8)')
262print, 'shf in tropflux_nrt_ncdf first date ', cda0
263print, 'shf in tropflux_nrt_ncdf last date ' , cda1
264;
265help, swr, lwr, lhf, shf
266;
267lat=reform(gphit[0,0:jpj-1])
268lon=reform(glamt[0:jpi-1,0])
269;
270ncfile='!' + fullfilename_out
271lon_attr={units:'degrees_east',long_name:'Longitude'}
272lat_attr={units:'degrees_north',long_name:'Latitude'}
273time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
274globattr={Source:'TropFlux - Air-Sea Fluxes for the Global Tropics', Resolution:'1 x 1 degree and daily', IDL_program_name:'TropFlux_ncdf.pro',Timerange:cda0+' - '+cda1, More_Info:'ISCCP based SWR until 2007 and OLR based SWR after that with a 90 day linear transition between the two'}
275sw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Shortwave Radiation',short_name:'swr',axis:'TYX'}
276lw_attr={units:'w/m^2',missing_value:1.e20,long_name:'Net Longwave Radiation',short_name:'lwr',axis:'TYX'}
277sh_attr={units:'w/m^2',missing_value:1.e20,long_name:'Sensible Heat Flux',short_name:'shf',axis:'TYX'}
278lh_attr={units:'w/m^2',missing_value:1.e20,long_name:'Latent Heat Flux',short_name:'lhf',axis:'TYX'}
279;
280ncfields = 'swr[longitude,latitude,*time]=swr:sw_attr; ' $
281+'lwr[longitude,latitude,*time]=lwr:lw_attr; ' $
282+'lhf[longitude,latitude,*time]=lhf:lh_attr; ' $
283+'shf[longitude,latitude,*time]=shf:sh_attr; ' $
284+ 'longitude[]=lon:lon_attr; ' $
285+ 'latitude[]=lat:lat_attr; ' $
286+ 'time[]=timein:time_attr ' $
287+ ' @ globattr'
288;
289@ncdf_quickwrite
290;
291result = 0
292return, result
293;
294end
Note: See TracBrowser for help on using the repository browser.