source: trunk/src/TropFlux_19890101_20091231.pro @ 85

Last change on this file since 85 was 85, checked in by pinsard, 13 years ago

restart consolidation of paper01 software

  • Property svn:executable set to *
File size: 14.7 KB
Line 
1;+
2;
3; .. _TropFlux_19890101_20091231.pro:
4;
5; ==============================
6; TropFlux_19890101_20091231.pro
7; ==============================
8;
9; This program computes net heat flux components on the 1° oaflux grid.
10;
11; all input variables are corrected for mean bias and variability.
12;
13; gustiness correction is applied for wind speed based on cronin's climatological
14; gustiness values.
15;
16; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
17; containing
18; OAFLUX grid
19; has been produced by
20; :ref:`oaflux_mask_30N30S.pro`.
21;
22; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
23; containing
24; sst corrected on OAFLUX grid
25; has been produced by
26; :ref:`sst_correction_ncdf.pro`.
27;
28; :file:`${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc`
29; containing
30; ws corrected on OAFLUX grid
31; has been produced by
32; :ref:`ws_correction_ncdf.pro`.
33;
34; :file:`${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc`
35; containing
36; ++
37; has been produced by
38; :ref:`cronin_gustiness_ncdf.pro`.
39;
40; :file:`${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc`
41; containing
42; ws corrected on OAFLUX grid
43; has been produced by
44; :ref:`TropFlux_swr_BLND_19890101_20091231.pro`.
45;
46; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc`
47; containing
48; lwr corrected on OAFLUX grid
49; has been produced by
50; :ref:`lwr_correction_ncdf.pro`.
51;
52; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc`
53; containing
54; t2m corrected on OAFLUX grid
55; has been produced by
56; :ref:`t2m_correction_ncdf.pro`.
57;
58; :file:`${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc`
59; containing
60; q2m corrected on OAFLUX grid
61; has been produced by
62; :ref:`d2m_to_q2m_erai.pro`.
63;
64; net heat flux components are written
65; in :file:`${PROJECT_OD}/TropFlux_19890101_20091231.nc`
66; if this file not already exists.
67;
68;     .. graphviz::
69;
70;        digraph tropflux_19890101_20091231 {
71;           graph [
72;           rankdir="LR",
73;           ]
74;
75;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
76;           file_sst [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
77;           file_ws [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc"];
78;           file_wg [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc"];
79;           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc"];
80;           file_lwr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"];
81;           file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"];
82;           file_q2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc"];
83;
84;           file_out[shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_19890101_20091231.nc"];
85;
86;           tropflux_19890101_20091231 [shape=box,
87;           fontname=Courier,
88;           color=blue,
89;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/TropFlux_19890101_20091231.pro",
90;           label="${PROJECT}/src/TropFlux_19890101_20091231.pro"];
91;
92;           {mask file_sst file_ws file_wg file_swr file_lwr file_t2m file_q2m} -> {tropflux_19890101_20091231} -> {file_out}
93;
94;          }
95;
96; SEE ALSO
97; ========
98;
99; :ref:`project_profile.sh`
100;
101; :func:`report <saxo:report>`
102; :func:`isadirectory <saxo:isadirectory>`
103; :func:`isafile <saxo:isafile>`
104; :func:`initncdf <saxo:initncdf>`
105; :func:`ncdf_lec <saxo:ncdf_lec>`
106; :func:`read_ncdf <saxo:read_ncdf>`
107; :func:`caldat <saxo:caldat>`
108; :func:`julday <saxo:julday>`
109; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
110;
111; :func:`cor30a`
112;
113; EXAMPLES
114; ========
115;
116; ::
117;
118;  IDL> .compile TropFlux_19890101_20091231
119;  IDL> tropflux_19890101_20091231
120;
121; TODO
122; ====
123;
124; no ${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc yet because of pb in
125; TropFlux_swr_BLND_19890101_20091231.pro
126;
127; avoid mix lower/uppercase in pro name to avoid compile
128;
129; coding rules
130;
131; KNOWN ISSUES
132; ============
133;
134; test of existence of fullfilename_msk not very efficient because
135; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
136;
137; EVOLUTIONS
138; ==========
139;
140; $Id
141;
142; $URL$
143;
144; - fplod 20110809T110911Z aedon.locean-ipsl.upmc.fr (Darwin)
145;
146;   * complete descritption
147;   * remove v* from filenames (in and out)
148;   * usage of ${PROJECT_OD}
149;   * remove return statement
150;   * add test on IO files
151;
152; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
153;
154;   * remove hard coded directory for mask_oaflux_30N30S.nc
155;
156; - fplod 20101214T112131Z aedon.locean-ipsl.upmc.fr (Darwin)
157;
158;   * add graph
159;
160; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
161;
162;   * minimal header
163;
164; - pbk 2008
165;
166;   * creation
167;
168;-
169;
170pro TropFlux_19890101_20091231
171;
172@cm_4cal
173@cm_4data
174@cm_4mesh
175@cm_4data
176@cm_project
177;
178; check for input directory
179;
180; test if ${PROJECT_ID} defined
181CASE project_id_env OF
182    ''  :  BEGIN
183     msg = 'eee : ${PROJECT_ID} is not defined'
184     ras = report(msg)
185     STOP
186           END
187 ELSE: BEGIN
188     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
189     ras = report(msg)
190       END
191ENDCASE
192;
193iodirin = isadirectory(project_id_env)
194;
195; existence and protection of ${PROJECT_ID}
196IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
197   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
198   ras = report(msg)
199   STOP
200ENDIF
201;
202; build mask filename
203filename_msk='mask_oaflux_30N30S.nc'
204;
205; check if this file exists
206msg='iii : looking for ' + filename_msk
207ras = report(msg)
208fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
209IF fullfilename_msk[0] EQ '' THEN BEGIN
210   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
211   ras = report(msg)
212   STOP
213ENDIF
214;
215; test if ${PROJECT_OD} defined
216CASE project_od_env OF
217  '' : BEGIN
218         msg = 'eee : ${PROJECT_OD} is not defined'
219         ras = report(msg)
220       STOP
221       END
222  ELSE: BEGIN
223          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
224          ras = report(msg)
225        END
226 ENDCASE
227;
228; check if output data will be possible
229iodirout = isadirectory(project_od_env)
230;
231; existence and protection for reading
232IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
233   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
234   ras = report(msg)
235   STOP
236ENDIF
237;
238; existence and protection for writing
239IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
240    msg = 'eee : the directory' + iodirout  + ' was not found.'
241    ras = report(msg)
242    STOP
243ENDIF
244;
245; build sst data filename
246filename_sst='TropFlux_sst_19890101_20091231.nc'
247;
248; check if this file exists
249msg='iii : looking for ' + filename_sst
250ras = report(msg)
251fullfilename_sst = isafile(iodirout + filename_sst, NEW=0, /MUST_EXIST)
252IF fullfilename_sst[0] EQ '' THEN BEGIN
253   msg = 'eee : the file ' + fullfilename_sst + ' was not found.'
254   ras = report(msg)
255   STOP
256ENDIF
257;
258; build ws data filename
259filename_ws='TropFlux_ws_19890101_20091231.nc'
260;
261; check if this file exists
262msg='iii : looking for ' + filename_ws
263ras = report(msg)
264fullfilename_ws = isafile(iodirout + filename_ws, NEW=0, /MUST_EXIST)
265IF fullfilename_ws[0] EQ '' THEN BEGIN
266   msg = 'eee : the file ' + fullfilename_ws + ' was not found.'
267   ras = report(msg)
268   STOP
269ENDIF
270;
271; build swr data filename
272filename_swr='TropFlux_swr_19890101_20091231_BLND.nc'
273;
274; check if this file exists
275msg='iii : looking for ' + filename_swr
276ras = report(msg)
277fullfilename_swr = isafile(iodirout + filename_swr, NEW=0, /MUST_EXIST)
278IF fullfilename_swr[0] EQ '' THEN BEGIN
279   msg = 'eee : the file ' + fullfilename_swr + ' was not found.'
280   ras = report(msg)
281   STOP
282ENDIF
283;
284; build lwr data filename
285filename_lwr='TropFlux_lwr_19890101_20091231.nc'
286;
287; check if this file exists
288msg='iii : looking for ' + filename_lwr
289ras = report(msg)
290fullfilename_lwr = isafile(iodirout + filename_lwr, NEW=0, /MUST_EXIST)
291IF fullfilename_lwr[0] EQ '' THEN BEGIN
292   msg = 'eee : the file ' + fullfilename_lwr + ' was not found.'
293   ras = report(msg)
294   STOP
295ENDIF
296;
297; build t2m data filename
298filename_t2m='TropFlux_t2m_19890101_20091231.nc'
299;
300; check if this file exists
301msg='iii : looking for ' + filename_t2m
302ras = report(msg)
303fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
304IF fullfilename_t2m[0] EQ '' THEN BEGIN
305   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
306   ras = report(msg)
307   STOP
308ENDIF
309;
310; build q2m data filename
311filename_q2m='TropFlux_q2m_19890101_20091231.nc'
312;
313; check if this file exists
314msg='iii : looking for ' + filename_q2m
315ras = report(msg)
316fullfilename_q2m = isafile(iodirout + filename_q2m, NEW=0, /MUST_EXIST)
317IF fullfilename_q2m[0] EQ '' THEN BEGIN
318   msg = 'eee : the file ' + fullfilename_q2m + ' was not found.'
319   ras = report(msg)
320   STOP
321ENDIF
322;
323; build wg data filename
324filename_wg='TropFlux_gustiness_19890101_20091231.nc'
325;
326; check if this file exists
327msg='iii : looking for ' + filename_wg
328ras = report(msg)
329fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
330IF fullfilename_wg[0] EQ '' THEN BEGIN
331   msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
332   ras = report(msg)
333   STOP
334ENDIF
335;
336da1=19880101 & da2=20101231
337;
338initncdf, fullfilename_msk
339msk=ncdf_lec(fullfilename_msk,var='msk')
340
341initncdf, fullfilename_sst
342
343ws=read_ncdf('ws',da1,da2,file=fullfilename_ws,/nostr)
344wg=read_ncdf('wg',da1-1,da2,file=fullfilename_wg,/nostr)
345tt=time & jpt=n_elements(time)
346sst=read_ncdf('sst',da1,da2,file=fullfilename_sst,/nostr)
347sst=reform(sst-273.15)
348swd=read_ncdf('swr',da1,da2,file=fullfilename_swr,/nostr)
349lw=read_ncdf('lwr',da1,da2,file=fullfilename_lwr,/nostr)
350swd=swd/0.94  ;; converting from net swr to downward swr
351
352t2m=read_ncdf('t2m',da1,da2,file=fullfilename_t2m,/nostr)-273.15   ; in C
353q2m=read_ncdf('q2m',da1,da2,file=fullfilename_q2m,/nostr)    ; in g/kg
354
355w=sqrt(ws*ws+wg*wg)  ;; wind corrected for gustiness
356w=ws
357tmask=msk
358help, ws,w,wg,u,sst,swd,t2m,q2m
359ocean=where(msk eq 1,compl=land)
360valmask=1.e20
361time=tt & jpt=n_elements(time)
362
363;
364;; Constants for flux computation
365;
366zu=10.                          ; height of wind speed measurement (m)
367us=0.                           ; surf current (m/s)
368zt=2.                           ; Height of air T measurement (m)
369zq=2.                           ; height of humidity measurement (m)
370P=1008.                         ; Pressure
371zi=600.                         ; Inversion height (m)
372jcool=0                         ; Compute cool-skin
373jwave=0                         ; No waves
374twave=5.
375hwave=1.
376
377caldat, time,mon,day,yea
378swr=fltarr(jpi,jpj,jpt)+1.e20
379lwr=fltarr(jpi,jpj,jpt)+1.e20
380lat=fltarr(jpi,jpj,jpt)+1.e20
381sen=fltarr(jpi,jpj,jpt)+1.e20
382lwnet_clrk=fltarr(jpi,jpj,jpt)+1.e20
383;Ch=fltarr(jpi,jpj,jpt)+1.e20
384;Ce=fltarr(jpi,jpj,jpt)+1.e20
385junk=fltarr(jpi,jpj,jpt)+1.e20
386
387for jt=0,jpt-1 do begin
388  jday=time(jt)-julday(1,1,yea(jt))
389  print, 'Computing Fluxes ',jt,' / ',jpt-1
390;
391;  P=msl(*,*,jt) & P=P(ocean)
392  wn=w(*,*,jt) & wn=wn(ocean)          ; wind speed (m/s)
393  ts=sst(*,*,jt) & ts=ts(ocean)        ; Bulk sst (°C)
394  t=t2m(*,*,jt) & t=t(ocean)           ; 2m Air T (°C)
395  qs=qsee(ts,P)                        ; Sea surface sat. spec. humidity (g/kg)
396  q=q2m(*,*,jt) & q=q(ocean)           ; 2m AIr specific humidity  (g/kg)
397  Rs=swd(*,*,jt) & Rs=Rs(ocean)        ; Downward solar flux (W/m2)
398  ylat=gphit(ocean)
399;  cld=calc_cloud(jday,Rs,ylat)
400  cld=calc_cloud_vlat(jday,Rs,ylat)
401;  Rl=lwdown_clark(ts,q,cld,t,P)        ; Downward IR flux (W/m2)
402  Rl=lw(*,*,jt) & Rl=Rl(ocean)
403  rain=0.
404  lw_clrk=-lwnet_clark(ts,q,cld,t,P)
405;  junk(*,*,jt)=lw_clrk
406;
407;stop
408  y=cor30a(wn,us,ts,t,Qs,Q,Rs,Rl,rain,zi,P,zu,zt,zq,ylat,jcool,jwave,twave,hwave)
409;
410
411; A few punctual missing values (coare does not converge): filled by spatial extrapolation
412  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,0)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & swr(*,*,jt)=tab*msk+valmask*(1-msk)
413  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,1)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lwr(*,*,jt)=tab*msk+valmask*(1-msk)
414  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,2)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lat(*,*,jt)=tab*msk+valmask*(1-msk)
415  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,3)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & sen(*,*,jt)=tab*msk+valmask*(1-msk)
416;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(lw_clrk) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & lwnet_clrk(*,*,jt)=tab*msk+valmask*(1-msk)
417;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,6)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & Ch(*,*,jt)=tab*msk+valmask*(1-msk)
418;  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,7)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & Ce(*,*,jt)=tab*msk+valmask*(1-msk)
419endfor
420tt=time
421time=timegen(7670, start=julday(1,1,1989,0), units='days') & jpt=n_elements(time)
422;
423cda0=string(jul2date(time(0)),format='(i8.8)')
424cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
425tt=time-julday(1,1,1950,00,00,00)
426xlon=reform(glamt(*,0) ) & ylat=reform(gphit(0,*))
427
428ncfile='!${PROJECT_OD}/TropFlux_19890101_20091231.nc'
429lon_attr={units:'degrees_east',long_name:'Longitude'}
430lat_attr={units:'degrees_north',long_name:'Latitude'}
431swr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net shortwave radiation',short_name:'swr',axis:'TYX'}
432lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation',short_name:'lwr',axis:'TYX'}
433lwr_clrk_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation from clark',short_name:'lwr',axis:'TYX'}
434lhf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface latent flux',short_name:'lhf',axis:'TYX'}
435shf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface sensible flux',short_name:'shf',axis:'TYX'}
436time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:' 1950-JAN-01 00:00:00'}
437Ch_attr={units:'',missing_value:valmask,long_name:'heat transfer coefficient at zt',short_name:'Ch',axis:'TYX'}
438Ce_attr={units:'',missing_value:valmask,long_name:'moisture transfer coefficient at zq',short_name:'Ce',axis:'TYX'}
439
440globattr={source:'Fluxes for the Global Tropical Ocean - TropFlux',timerange:cda0+' - '+cda1}
441
442help, swr,lwr,lat,sen,tt,xlon,ylat
443
444ncfields = 'swr[longitude,latitude,time]=swr:swr_attr; ' $
445;          +'lwr_coare[longitude,latitude,time]=lwr:lwr_attr; ' $
446          +'lwr[longitude,latitude,time]=lwnet_clrk:lwr_clrk_attr; ' $
447          +'lhf[longitude,latitude,time]=lat:lhf_attr; ' $
448          +'shf[longitude,latitude,time]=sen:shf_attr; ' $
449;          +'Ch[longitude,latitude,time]=Ch:Ch_attr; ' $
450;          +'Ce[longitude,latitude,time]=Ce:Ce_attr; ' $
451                      + 'longitude[]=xlon:lon_attr; ' $
452                      + 'latitude[]=ylat:lat_attr; ' $
453                      + 'tt[*time]=tt:time_attr ' $
454                      + ' @ globattr'
455
456@ncdf_quickwrite
457
458end
Note: See TracBrowser for help on using the repository browser.