source: trunk/src/ws_tropflux_1d_to_1m_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 Id URL
File size: 5.0 KB
Line 
1;+
2;
3; .. _ws_tropflux_1d_to_1m_ncdf.pro:
4;
5; =============================
6; ws_tropflux_1d_to_1m_ncdf.pro
7; =============================
8;
9; DESCRIPTION
10; ===========
11;
12; convert wind daily file to monthly file
13;
14; :file:`${PROJECT_OD}/ws_tropflux_1d_1989_2010.nc`
15; containing daily ++
16; has been produced by ++
17;
18; Monthly ++
19; is written in
20; :file:`${PROJECT_OD}/ws_tropflux_1m_1989_2010.nc`
21; if this file not already exists.
22;
23;     .. graphviz::
24;
25;        digraph ws_tropflux_1d_to_1m_ncdf {
26;
27;           file_1d [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/ws_tropflux_1d_1989_2010.nc"];
28;           file_1m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/ws_tropflux_1m_1989_2010.nc"];
29;
30;           ws_tropflux_1d_to_1m_ncdf [shape=box,
31;           fontname=Courier,
32;           color=blue,
33;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/ws_tropflux_1d_to_1m_ncdf.pro",
34;           label="${PROJECT}/src/ws_tropflux_1d_to_1m_ncdf.pro"];
35;
36;           {file_1d} -> {ws_tropflux_1d_to_1m_ncdf} -> {file_1m}
37;
38;        }
39;
40; SEE ALSO
41; ========
42;
43; :ref:`project_profile.sh`
44;
45; EXAMPLES
46; ========
47;
48; .. code-block:: idl
49;
50;    ws_tropflux_1d_to_1m_ncdf
51;
52; KNOWN ISSUES
53; ============
54;
55; test of existence of fullfilename_in not very efficient because
56; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
57;
58; TODO
59; ====
60;
61; coding rules
62;
63; get rid of hard coded yyyymmdd and nb month
64;
65; include in the whole process
66;
67; any NCO or CDO equivalent ?
68;
69; EVOLUTIONS
70; ==========
71;
72; $Id$
73;
74; $URL$
75;
76; - fplod 20110826T151225Z aedon.locean-ipsl.upmc.fr (Darwin)
77;
78;   * remove hard coded creation date
79;
80; - fplod 20110817T084001Z aedon.locean-ipsl.upmc.fr (Darwin)
81;
82;   * usage of ${PROJECT_OD}
83;   * header
84;
85; - pk 20110815
86;
87;   * provided to fp
88;
89;-
90pro ws_tropflux_1d_to_1m_ncdf
91;
92@cm_4cal
93@cm_4data
94@cm_4mesh
95@cm_4data
96@cm_project
97;
98; test if ${PROJECT_OD} defined
99CASE project_od_env OF
100    '' : BEGIN
101        msg = 'eee : ${PROJECT_OD} is not defined'
102        ras = report(msg)
103        STOP
104    END
105    ELSE : BEGIN
106        msg = 'iii : ${PROJECT_OD} is ' + project_od_env
107        ras = report(msg)
108    END
109ENDCASE
110;
111; check if output data will be possible
112iodirout = isadirectory(project_od_env)
113;
114; existence and protection for reading
115IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
116    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
117    ras = report(msg)
118    STOP
119ENDIF
120;
121; existence and protection for writing
122IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
123    msg = 'eee : the directory' + iodirout  + ' was not found.'
124    ras = report(msg)
125    STOP
126ENDIF
127;
128; build 1d filename
129filename="ws_tropflux_1d_1989_2010.nc"
130;
131; check if this file exists
132msg='iii : looking for ' + filename
133ras = report(msg)
134fullfilename = isafile(iodirout + filename, NEW=0, /MUST_EXIST)
135IF fullfilename[0] EQ '' THEN BEGIN
136   msg = 'eee : the file ' + fullfilename + ' was not found.'
137   ras = report(msg)
138   STOP
139ENDIF
140;
141; build output filename
142filename_out = 'ws_tropflux_1m_1989_2010.nc'
143fullfilename_out = iodirout + filename_out
144; in order to avoid unexpected overwritten
145IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
146   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
147   ras = report(msg)
148   STOP
149ENDIF
150;
151initncdf, fullfilename
152st=19890101
153en=20101231
154ws=read_ncdf("ws", st, en, file=fullfilename,/nostr)
155;
156help, ws
157;
158; Monthly data
159;
160jpt=22*12.
161time=timegen(jpt, start=julday(1,15,1989,0), units='Months')
162caldat, time, m, d, y
163caldat, time, mon, day, yea
164;
165wsm=fltarr(nxt,nyt,jpt)
166;
167for jt=0,jpt-1 do begin
168;
169    ind=where((m eq mon(jt)) and (y eq yea(jt)))
170    wsm(*,*,jt)=total(ws(*,*,ind),3)/n_elements(ind)
171;
172endfor
173;
174;-----------------------------------------------------------------------------
175cda0=string(jul2date(time(0)),format='(i8.8)')
176cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
177time=time-julday(1,1,1950,00,00,00)
178xlon=reform(glamt(firstxt:lastxt,0))
179ylat=reform(gphit(0,firstyt:lastyt))
180;
181ncfile='!' + fullfilename_out
182;
183lon_attr={units:'degrees_east',long_name:'Longitude'}
184lat_attr={units:'degrees_north',long_name:'Latitude'}
185;
186time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
187ws_attr={units:'m/s',missing_value:1.e20,long_name:'Mean wind speed at 10m height',short_name:'ws',axis:'TYX'}
188;
189creation_date=string(jul2date(SYSTIME( /JULIAN , /UTC )), format='(I8)')
190;
191globattr={Source:'TropFlux - Air-Sea Fluxes for the Global Tropics' $
192    , Methodology:'Praveen Kumar et al., Clim. Dyn 2011' $
193    , Producer_Agency:'Joint research collaboration between IPSL, Paris and NIO, India' $
194    , Time_range:cda0+' - '+cda1 $
195    , Creation_date:creation_date $
196    , Website:'http://www.locean-ipsl.upmc.fr/tropflux/'}
197;
198ncfields = 'ws[longitude,latitude,time]=wsm:ws_attr; ' $
199                      + 'longitude[]=xlon:lon_attr; ' $
200                      + 'latitude[]=ylat:lat_attr; ' $
201                      + 'time[*time]=time:time_attr ' $
202                      + ' @ globattr'
203;
204@ncdf_quickwrite
205;
206end
Note: See TracBrowser for help on using the repository browser.