Index: /trunk/docs/docs_dev/source/guides/data_content.rst
===================================================================
--- /trunk/docs/docs_dev/source/guides/data_content.rst	(revision 174)
+++ /trunk/docs/docs_dev/source/guides/data_content.rst	(revision 175)
@@ -133,5 +133,5 @@
  - :func:`oaflux_mask_30n30s`
 
- - :ref:`TropFlux_19890101_20091231.pro`
+ - :func:`tropflux`
 
  - :func:`interp_erai_dewt`
Index: /trunk/docs/docs_dev/source/guides/generate_tropflux.rst
===================================================================
--- /trunk/docs/docs_dev/source/guides/generate_tropflux.rst	(revision 174)
+++ /trunk/docs/docs_dev/source/guides/generate_tropflux.rst	(revision 175)
@@ -131,9 +131,9 @@
 tools :
  - :func:`tropflux_swr_dt`, :func:`tropflux_swr_nrt`, :func:`tropflux_swr_blnd`
- - :ref:`lwr_correction_ncdf.pro`
- - :ref:`q2m_correction_ncdf.pro`
- - :ref:`sst_correction_ncdf.pro`
- - :ref:`t2m_correction_ncdf.pro`
- - :ref:`ws_correction_ncdf.pro`
+ - :func:`lwr_correction_ncdf`
+ - :func:`q2m_correction_ncdf`
+ - :func:`sst_correction_ncdf`
+ - :func:`t2m_correction_ncdf`
+ - :func:`ws_correction_ncdf`
 
 Result after that, 7 netcdf files for: NOAA OLR, ERA-I :math:`T_a`, ERA-I :math:`q_a`, ERA-I wind speed, ERA-I SST, ISCCP net SW, ERA-I net LW.
@@ -148,5 +148,5 @@
 tools :
  - :func:`cronin_gustiness_ncdf`
- - :ref:`TropFlux_19890101_20091231.pro` (:func:`cor30a`), :ref:`TropFlux_NRT_ncdf.pro` 
+ - :func:`tropflux` (:func:`cor30a`), :ref:`TropFlux_NRT_ncdf.pro` 
 
 After that step, there are 5 files: Tropflux :math:`T_{2m}`, :math:`q_{2m}`, SST, wind, and one file with the 4 components of the net flux (sensible, latent, SWR, LWR)
Index: unk/src/TropFlux_19890101_20091231.pro
===================================================================
--- /trunk/src/TropFlux_19890101_20091231.pro	(revision 174)
+++ 	(revision )
@@ -1,592 +1,0 @@
-;+
-;
-; .. _TropFlux_19890101_20091231.pro:
-;
-; ==============================
-; TropFlux_19890101_20091231.pro
-; ==============================
-;
-; This program computes net heat flux components on the 1° oaflux grid.
-;
-; all input variables are corrected for mean bias and variability.
-;
-; gustiness correction is applied for wind speed based on cronin's climatological
-; gustiness values.
-;
-; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
-; containing
-; OAFLUX grid
-; has been produced by
-; :func:`oaflux_mask_30n30s`.
-;
-; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
-; containing
-; sst corrected on OAFLUX grid
-; has been produced by
-; :ref:`sst_correction_ncdf.pro`.
-;
-; :file:`${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc`
-; containing
-; ws corrected on OAFLUX grid
-; has been produced by
-; :ref:`ws_correction_ncdf.pro`.
-;
-; :file:`${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc`
-; containing
-; ++
-; has been produced by
-; :func:`cronin_gustiness_ncdf`.
-;
-; :file:`${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc`
-; containing
-; ws corrected on OAFLUX grid
-; has been produced by
-; :func:`tropflux_swr_blnd`.
-;
-; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc`
-; containing
-; lwr corrected on OAFLUX grid
-; has been produced by
-; :ref:`lwr_correction_ncdf.pro`.
-;
-; containing
-; t2m corrected on OAFLUX grid
-; has been produced by
-; :ref:`t2m_correction_ncdf.pro`.
-;
-; :file:`${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc`
-; containing
-; q2m corrected on OAFLUX grid
-; has been produced by
-; :func:`d2m_to_q2m_erai`.
-;
-; net heat flux components are written
-; in :file:`${PROJECT_OD}/TropFlux_19890101_20091231_coarev3.nc`
-; if this file not already exists.
-;
-; This output file
-; :file:`${PROJECT_OD}/TropFlux_19890101_20091231_coarev3.nc`
-; will be used by
-; :ref:`TropFlux_NRT_ncdf.pro`.
-;
-;     .. graphviz::
-;
-;        digraph tropflux_19890101_20091231 {
-;
-;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
-;           file_sst [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
-;           file_ws [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc"];
-;           file_wg [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_19890101_20091231.nc"];
-;           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_19890101_20091231_BLND.nc"];
-;           file_lwr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"];
-;           file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"];
-;           file_q2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc"];
-;
-;           file_out[shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_19890101_20091231_coarev3.nc"];
-;
-;           tropflux_19890101_20091231 [shape=box,
-;           fontname=Courier,
-;           color=blue,
-;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/TropFlux_19890101_20091231.pro",
-;           label="${PROJECT}/src/TropFlux_19890101_20091231.pro"];
-;
-;           {mask file_sst file_ws file_wg file_swr file_lwr file_t2m file_q2m} -> {tropflux_19890101_20091231} -> {file_out}
-;
-;        }
-;
-; SEE ALSO
-; ========
-;
-; :ref:`project_profile.sh`
-;
-; :func:`report <saxo:report>`
-; :func:`isadirectory <saxo:isadirectory>`
-; :func:`isafile <saxo:isafile>`
-; :func:`initncdf <saxo:initncdf>`
-; :func:`ncdf_lec <saxo:ncdf_lec>`
-; :func:`read_ncdf <saxo:read_ncdf>`
-; :func:`caldat <saxo:caldat>`
-; :func:`julday <saxo:julday>`
-; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
-;
-; :func:`qsee`
-; :func:`lwnet_clark`
-; :func:`calc_claud_vlat`
-; :func:`cor30a`
-;
-; .. note::
-;
-;    :func:`lwdown_clark` is not used here but available.
-;
-; EXAMPLES
-; ========
-;
-; ::
-;
-;  IDL> .compile TropFlux_19890101_20091231
-;  IDL> tropflux_19890101_20091231
-;
-; TODO
-; ====
-;
-; describe usage of tau
-;
-; make it work ::
-;
-;     % Compiled module: EXTRAPOLATE.
-;     % Attempt to subscript LAND with OK is out of range.
-;     % Execution halted at: EXTRAPOLATE       176
-;       /usr/home/fplod/SAXO_DIR/SRC/Interpolation/extrapolate.pro
-;     %                      TROPFLUX_19890101_20091231  450
-;       /usr/home/fplod/incas/tropflux/tropflux_ws/src/TropFlux_19890101_20091231.p
-;       ro
-;     %                      $MAIN$
-;     % Program caused arithmetic error: Floating overflow
-;     % Program caused arithmetic error: Floating illegal operand
-;
-; the incriminated line is ::
-;
-;     tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,1)) & tab(ocean)=x & m=fi    nite(tab) & tab=extrapolate(tab,m) & lwr(*,*,jt)=tab*msk+valmask*(1-msk)
-;
-; to make progress I DO NOT extrapolate anymore lwr, sen and lat
-; !!!!! must be reactivated
-;
-; when I DO NOT extrapolate lwr, sen and lat , program end with ::
-;
-;     Written to
-;     !/usr/work/incas/fplod/tropflux_d/TropFlux_19890101_20091231_coarev3.nc
-;     -------------------------
-;     % Program caused arithmetic error: Floating divide by 0
-;     % Program caused arithmetic error: Floating underflow
-;     % Program caused arithmetic error: Floating overflow
-;     % Program caused arithmetic error: Floating illegal operand
-;
-; explain why :func:`lwdown_clark` is not used
-;
-; check if K or °C in input
-;
-; get rid of::
-;
-;   % date 1: 19880101 is not found in the time axis.
-;
-; why ::
-;
-;   da1=19880101
-;
-; 1st date 19890101 no ?
-;
-; why da1-1 (with da1=19880101) when reading gustiness file ::
-;
-;   wg=read_ncdf('wg',da1-1,da2,file=fullfilename_wg,/nostr)
-;
-; avoid mix lower/uppercase in pro name to avoid compile
-;
-; coding rules
-;
-; KNOWN ISSUES
-; ============
-;
-; test of existence of fullfilename_msk not very efficient because
-; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
-;
-; EVOLUTIONS
-; ==========
-;
-; $Id
-;
-; $URL$
-;
-; - fplod 20110830T135832Z cratos (Linux)
-;
-;   * replace tt by time
-;
-; - fplod 20110830T084129Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * add tau in ouptut file
-;
-; - fplod 20110822T090838Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;    * split some multiple lines statement to investigate
-;      pb of extropalation for lwr
-;
-; - fplod 20110819T144332Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * add _coarev3 to filename output
-;   * check if filename output exists
-;
-; - fplod 20110809T110911Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * complete descritption
-;   * remove v* from filenames (in and out)
-;   * usage of ${PROJECT_OD}
-;   * remove return statement
-;   * add test on IO files
-;
-; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * remove hard coded directory for mask_oaflux_30N30S.nc
-;
-; - fplod 20101214T112131Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * add graph
-;
-; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
-;
-;   * minimal header
-;
-; - pbk 2008
-;
-;   * creation
-;
-;-
-;
-pro TropFlux_19890101_20091231
-;
-@cm_4cal
-@cm_4data
-@cm_4mesh
-@cm_4data
-@cm_project
-;
-; check for input directory
-;
-; test if ${PROJECT_ID} defined
-CASE project_id_env OF
-    ''  :  BEGIN
-     msg = 'eee : ${PROJECT_ID} is not defined'
-     ras = report(msg)
-     STOP
-           END
- ELSE: BEGIN
-     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
-     ras = report(msg)
-       END
-ENDCASE
-;
-iodirin = isadirectory(project_id_env)
-;
-; existence and protection of ${PROJECT_ID}
-IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
-   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build mask filename
-filename_msk='mask_oaflux_30N30S.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_msk
-ras = report(msg)
-fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
-IF fullfilename_msk[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; test if ${PROJECT_OD} defined
-CASE project_od_env OF
-  '' : BEGIN
-         msg = 'eee : ${PROJECT_OD} is not defined'
-         ras = report(msg)
-       STOP
-       END
-  ELSE: BEGIN
-          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
-          ras = report(msg)
-        END
- ENDCASE
-;
-; check if output data will be possible
-iodirout = isadirectory(project_od_env)
-;
-; existence and protection for reading
-IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
-   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; existence and protection for writing
-IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
-    msg = 'eee : the directory' + iodirout  + ' was not found.'
-    ras = report(msg)
-    STOP
-ENDIF
-;
-; build sst data filename
-filename_sst='TropFlux_sst_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_sst
-ras = report(msg)
-fullfilename_sst = isafile(iodirout + filename_sst, NEW=0, /MUST_EXIST)
-IF fullfilename_sst[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_sst + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build ws data filename
-filename_ws='TropFlux_ws_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_ws
-ras = report(msg)
-fullfilename_ws = isafile(iodirout + filename_ws, NEW=0, /MUST_EXIST)
-IF fullfilename_ws[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_ws + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build swr data filename
-filename_swr='TropFlux_swr_19890101_20091231_BLND.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_swr
-ras = report(msg)
-fullfilename_swr = isafile(iodirout + filename_swr, NEW=0, /MUST_EXIST)
-IF fullfilename_swr[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_swr + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build lwr data filename
-filename_lwr='TropFlux_lwr_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_lwr
-ras = report(msg)
-fullfilename_lwr = isafile(iodirout + filename_lwr, NEW=0, /MUST_EXIST)
-IF fullfilename_lwr[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_lwr + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build t2m data filename
-filename_t2m='TropFlux_t2m_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_t2m
-ras = report(msg)
-fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
-IF fullfilename_t2m[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build q2m data filename
-filename_q2m='TropFlux_q2m_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_q2m
-ras = report(msg)
-fullfilename_q2m = isafile(iodirout + filename_q2m, NEW=0, /MUST_EXIST)
-IF fullfilename_q2m[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_q2m + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build wg data filename
-filename_wg='TropFlux_gustiness_19890101_20091231.nc'
-;
-; check if this file exists
-msg='iii : looking for ' + filename_wg
-ras = report(msg)
-fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
-IF fullfilename_wg[0] EQ '' THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-; build output filename
-filename_out = 'TropFlux_19890101_20091231_coarev3.nc'
-fullfilename_out = iodirout + filename_out
-; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
-   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
-   ras = report(msg)
-   STOP
-ENDIF
-;
-da1=19880101
-da2=20101231
-;
-initncdf, fullfilename_msk
-msk=ncdf_lec(fullfilename_msk,var='msk')
-;
-initncdf, fullfilename_sst
-;
-ws=read_ncdf('ws',da1,da2,file=fullfilename_ws,/nostr)
-wg=read_ncdf('wg',da1-1,da2,file=fullfilename_wg,/nostr)
-tt=time
-jpt=n_elements(time)
-sst=read_ncdf('sst',da1,da2,file=fullfilename_sst,/nostr)
-sst=reform(sst-273.15)
-swd=read_ncdf('swr',da1,da2,file=fullfilename_swr,/nostr)
-lw=read_ncdf('lwr',da1,da2,file=fullfilename_lwr,/nostr)
-swd=swd/0.94  ; converting from net swr to downward swr
-;
-t2m=read_ncdf('t2m',da1,da2,file=fullfilename_t2m,/nostr)-273.15   ; in C
-q2m=read_ncdf('q2m',da1,da2,file=fullfilename_q2m,/nostr)    ; in g/kg
-;
-w=sqrt(ws*ws+wg*wg)  ; wind corrected for gustiness
-w=ws
-tmask=msk
-help, ws,w,wg,u,sst,swd,t2m,q2m
-ocean=where(msk eq 1,compl=land)
-valmask=1.e20
-time=tt
-jpt=n_elements(time)
-;
-; Constants for flux computation
-;
-zu=10.                          ; height of wind speed measurement (m)
-us=0.                           ; surf current (m/s)
-zt=2.                           ; Height of air T measurement (m)
-zq=2.                           ; height of humidity measurement (m)
-P=1008.                         ; Pressure
-zi=600.                         ; Inversion height (m)
-jcool=0                         ; Compute cool-skin
-jwave=0                         ; No waves
-twave=5.
-hwave=1.
-;
-caldat, time,mon,day,yea
-swr=fltarr(jpi,jpj,jpt)+1.e20
-lwr=fltarr(jpi,jpj,jpt)+1.e20
-lat=fltarr(jpi,jpj,jpt)+1.e20
-sen=fltarr(jpi,jpj,jpt)+1.e20
-lwnet_clrk=fltarr(jpi,jpj,jpt)+1.e20
-;Ch=fltarr(jpi,jpj,jpt)+1.e20
-;Ce=fltarr(jpi,jpj,jpt)+1.e20
-junk=fltarr(jpi,jpj,jpt)+1.e20
-;
-for jt=0,jpt-1 do begin
-  jday=time(jt)-julday(1,1,yea(jt))
-  print, 'Computing Fluxes ',jt,' / ',jpt-1
-;
-;  P=msl(*,*,jt)
-;  P=P(ocean)
-;
-  ; wind speed (m/s)
-  wn=w(*,*,jt)
-  wn=wn(ocean)
-  ; Bulk sst (°C)
-  ts=sst(*,*,jt)
-  ts=ts(ocean)
-  ; 2m Air T (°C)
-  t=t2m(*,*,jt)
-  t=t(ocean)
-  ; Sea surface sat. spec. humidity (g/kg)
-  qs=qsee(ts,P)
-  ; 2m AIr specific humidity  (g/kg)
-  q=q2m(*,*,jt)
-  q=q(ocean)
-  ; Downward solar flux (W/m2)
-  Rs=swd(*,*,jt)
-  Rs=Rs(ocean)
-  ylat=gphit(ocean)
-  ;  cld=calc_cloud(jday,Rs,ylat)
-  cld=calc_cloud_vlat(jday,Rs,ylat)
-  ; Downward IR flux (W/m2)
-  ;  Rl=lwdown_clark(ts,q,cld,t,P)
-  Rl=lw(*,*,jt)
-  Rl=Rl(ocean)
-  rain=0.
-  lw_clrk=-lwnet_clark(ts,q,cld,t,P)
-;  junk(*,*,jt)=lw_clrk
-;
-;stop
-  y=cor30a(wn,us,ts,t,Qs,Q,Rs,Rl,rain,zi,P,zu,zt,zq,ylat,jcool,jwave,twave,hwave)
-; A few punctual missing values (coare does not converge): filled by spatial extrapolation
-  tab=fltarr(jpi,jpj)+!values.f_nan
-  x=reform(y(*,0))
-  tab(ocean)=x
-  m=finite(tab)
-  help, tab, m, swr
-  tab=extrapolate(tab,m)
-  swr(*,*,jt)=tab*msk+valmask*(1-msk)
-;
-  tab=fltarr(jpi,jpj)+!values.f_nan
-  x=reform(y(*,1))
-  tab(ocean)=x
-  m=finite(tab)
-  help, tab, m, lwr
-  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
-  print, 'www : extrapolation for lwr is not done'
-  tab=tab
-  lwr(*,*,jt)=tab*msk+valmask*(1-msk)
-;
-  tab=fltarr(jpi,jpj)+!values.f_nan
-  x=reform(y(*,2))
-  tab(ocean)=x
-  m=finite(tab)
-  help, tab, m, lat
-  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
-  print, 'www : extrapolation for lat is not done'
-  tab=tab
-  lat(*,*,jt)=tab*msk+valmask*(1-msk)
-  tab=fltarr(jpi,jpj)+!values.f_nan
-  x=reform(y(*,3))
-  tab(ocean)=x
-  m=finite(tab)
-  help, tab, m, sen
-  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
-  print, 'www : extrapolation for sen is not done'
-  tab=tab
-  sen(*,*,jt)=tab*msk+valmask*(1-msk)
-  ;  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)
-  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,5)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & tau(*,*,jt)=tab*msk+valmask*(1-msk)
-  ;  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)
-  ;  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)
-  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,8)) & tab(ocean)=x & m=finite(tab) & tab=extrapolate(tab,m) & wg(*,*,jt)=tab*msk+valmask*(1-msk)
-endfor
-time=timegen(7670, start=julday(1,1,1989,0), units='days')
-jpt=n_elements(time)
-;
-cda0=string(jul2date(time(0)),format='(i8.8)')
-cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
-time=time-julday(1,1,1950,00,00,00)
-xlon=reform(glamt(*,0) )
-ylat=reform(gphit(0,*))
-;
-ncfile='!' + fullfilename_out
-lon_attr={units:'degrees_east',long_name:'Longitude'}
-lat_attr={units:'degrees_north',long_name:'Latitude'}
-time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
-globattr={source:'Fluxes for the Global Tropical Ocean - TropFlux',timerange:cda0+' - '+cda1}
-swr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net shortwave radiation',short_name:'swr',axis:'TYX'}
-lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation',short_name:'lwr',axis:'TYX'}
-lwr_clrk_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation from clark',short_name:'lwr',axis:'TYX'}
-lhf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface latent flux',short_name:'lhf',axis:'TYX'}
-shf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface sensible flux',short_name:'shf',axis:'TYX'}
-wg_attr={units:'m/s',missing_value:valmask,long_name:'COARE convective gustiness',short_name:'wg',axis:'TYX'}
-tau_attr={units:'N/m2',missing_value:valmask,long_name:'Wind stress magnitude',short_name:'tau',axis:'TYX'}
-;
-help, swr,lwr,lat,sen,time,xlon,ylat
-;
-ncfields = 'tau[longitude,latitude,time]=tau:tau_attr; ' $
-         + 'wg[longitude,latitude,time]=wg:wg_attr; ' $
-         + 'swr[longitude,latitude,time]=swr:swr_attr; ' $
-;         +'lwr_coare[longitude,latitude,time]=lwr:lwr_attr; ' $
-         +'lwr[longitude,latitude,time]=lwnet_clrk:lwr_clrk_attr; ' $
-         +'lhf[longitude,latitude,time]=lat:lhf_attr; ' $
-         +'shf[longitude,latitude,time]=sen:shf_attr; ' $
-;         +'Ch[longitude,latitude,time]=Ch:Ch_attr; ' $
-;         +'Ce[longitude,latitude,time]=Ce:Ce_attr; ' $
-         + 'longitude[]=xlon:lon_attr; ' $
-         + 'latitude[]=ylat:lat_attr; ' $
-         + 'time[*time]=time:time_attr ' $
-         + ' @ globattr'
-;
-@ncdf_quickwrite
-;
-end
Index: /trunk/src/TropFlux_NRT_ncdf.pro
===================================================================
--- /trunk/src/TropFlux_NRT_ncdf.pro	(revision 174)
+++ /trunk/src/TropFlux_NRT_ncdf.pro	(revision 175)
@@ -17,5 +17,5 @@
 ; lwr corrected on OAFLUX grid
 ; has been produced by
-; :ref:`lwr_correction_ncdf.pro`.
+; :func:`lwr_correction_ncdf`.
 ;
 ; :file:`${PROJECT_OD}/TropFlux_19890101_20091231_coare3.nc`
@@ -23,5 +23,5 @@
 ; ++
 ; has been produced by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; ++ are written
Index: /trunk/src/cor30a.pro
===================================================================
--- /trunk/src/cor30a.pro	(revision 174)
+++ /trunk/src/cor30a.pro	(revision 175)
@@ -69,5 +69,5 @@
 ; ========
 ;
-; used by :ref:`TropFlux_19890101_20091231.pro`
+; used by :func:`tropflux`
 ;
 ; call :func:`psiu`, :func:`psit`.
Index: /trunk/src/cronin_gustiness_ncdf.pro
===================================================================
--- /trunk/src/cronin_gustiness_ncdf.pro	(revision 174)
+++ /trunk/src/cronin_gustiness_ncdf.pro	(revision 175)
@@ -13,5 +13,5 @@
 ;
 ; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc` have been produced by
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; Cronin gustiness corrected ++ on corrected sst on OAFLUX grid
@@ -23,5 +23,5 @@
 ; :func:`tropflux_swr_blnd`
 ; and
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ;     .. graphviz::
@@ -58,5 +58,5 @@
 ; :ref:`mooring_corrections`
 ;
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; :func:`initncdf <saxo:initncdf>`
Index: /trunk/src/d2m_to_q2m_erai.pro
===================================================================
--- /trunk/src/d2m_to_q2m_erai.pro	(revision 174)
+++ /trunk/src/d2m_to_q2m_erai.pro	(revision 175)
@@ -39,5 +39,5 @@
 ; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; will be used by
-; :ref:`q2m_correction_ncdf.pro`.
+; :func:`q2m_correction_ncdf`.
 ;
 ; .. only:: man
@@ -83,5 +83,5 @@
 ; :func:`interp_erai_t2m`
 ;
-; :ref:`q2m_correction_ncdf.pro`
+; :func:`q2m_correction_ncdf`
 ;
 ; :func:`rh_to_spechum`
Index: /trunk/src/interp_erai_lwr.pro
===================================================================
--- /trunk/src/interp_erai_lwr.pro	(revision 174)
+++ /trunk/src/interp_erai_lwr.pro	(revision 175)
@@ -91,5 +91,5 @@
 ;
 ; lwr first date 19991231 vs yyyymmddb = 20000101L
-; 
+;
 ; make it work : pb on loholt1 idl8:
 ;
@@ -154,5 +154,5 @@
 ; - fplod 20110819T084310Z aedon.locean-ipsl.upmc.fr (Darwin)
 ;
-;   * replace next step :ref:`lwr_correction_ncdf.pro` by :ref:`add_19890101.sh`
+;   * replace next step lwr_correction_ncdf.pro by :ref:`add_19890101.sh`
 ;   * fix output file name to erai_lwr_19890102_20091231_oafluxgrid.nc
 ;
Index: /trunk/src/interp_erai_sst.pro
===================================================================
--- /trunk/src/interp_erai_sst.pro	(revision 174)
+++ /trunk/src/interp_erai_sst.pro	(revision 175)
@@ -32,5 +32,5 @@
 ; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; must be processed after by
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; .. only:: man
@@ -76,5 +76,5 @@
 ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
 ;
-; :ref:`sst_correction_ncdf.pro`
+; :func:`sst_correction_ncdf`
 ;
 ; EXAMPLES
Index: /trunk/src/interp_erai_t2m.pro
===================================================================
--- /trunk/src/interp_erai_t2m.pro	(revision 174)
+++ /trunk/src/interp_erai_t2m.pro	(revision 175)
@@ -31,5 +31,5 @@
 ; :file:`${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; must be processed after by
-; :ref:`t2m_correction_ncdf.pro`.
+; :func:`t2m_correction_ncdf`.
 ;
 ; .. only:: man
@@ -81,5 +81,5 @@
 ; :func:`ncdf_getatt <saxo:ncdf_getatt>`
 ;
-; :ref:`t2m_correction_ncdf.pro`
+; :func:`t2m_correction_ncdf`
 ;
 ; EXAMPLES
@@ -380,9 +380,9 @@
 t2min=read_ncdf('t2',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2,/nost)
 ;; time:units = "hours since 1957-01-01 00:00:0.0" ;
-timein=24.d*(time-julday(1,1,1957,0,0,0)) 
+timein=24.d*(time-julday(1,1,1957,0,0,0))
 jptin=n_elements(timein)
 da=jul2date(time[0])
 cda0=string(da,format='(i8.8)')
-da=jul2date(time[jpt-1]) 
+da=jul2date(time[jpt-1])
 cda1=string(da,format='(i8.8)')
 print, 't2m first date ', cda0
Index: /trunk/src/interp_erai_ws.pro
===================================================================
--- /trunk/src/interp_erai_ws.pro	(revision 174)
+++ /trunk/src/interp_erai_ws.pro	(revision 175)
@@ -37,5 +37,5 @@
 ; :file:`${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc`
 ; must be processed after by
-; :ref:`ws_correction_ncdf.pro`.
+; :func:`ws_correction_ncdf`.
 ;
 ; .. only:: man
@@ -82,5 +82,5 @@
 ; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
 ;
-; :ref:`ws_correction_ncdf.pro`
+; :func:`ws_correction_ncdf`
 ;
 ; EXAMPLES
@@ -306,9 +306,9 @@
 u10in=read_ncdf("u10", yyyymmddb - .5d, yyyymmdde, file=fullfilename,/nostr)
 ;
-timein=24.d*(time-julday(1,1,1957,0,0,0)) 
+timein=24.d*(time-julday(1,1,1957,0,0,0))
 jpt=n_elements(timein)
 da=jul2date(time[0])
 cda0=string(da,format='(i8.8)')
-da=jul2date(time[jpt-1]) 
+da=jul2date(time[jpt-1])
 cda1=string(da,format='(i8.8)')
 print, 'u10 first date ', cda0
Index: /trunk/src/lwr_correction_ncdf.pro
===================================================================
--- /trunk/src/lwr_correction_ncdf.pro	(revision 174)
+++ /trunk/src/lwr_correction_ncdf.pro	(revision 175)
@@ -1,5 +1,3 @@
 ;+
-;
-; .. _lwr_correction_ncdf.pro:
 ;
 ; =======================
@@ -7,7 +5,12 @@
 ; =======================
 ;
+; .. function:: lwr_correction_ncdf(yyyymmddb,yyyymmdde)
+;
+; DESCRIPTION
+; ===========
+;
 ; Correction of lwr on OAFLUX grid
 ;
-; :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc`
+; :file:`${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; containing
 ; ++
@@ -17,11 +20,11 @@
 ; Corrected lwr on OAFLUX grid
 ; is written in
-; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
 ; if this file not already exists.
 ;
 ; This output file
-; :file:`${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
 ; will be used by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; .. only:: man
@@ -35,6 +38,6 @@
 ;        digraph lwr_correction_ncdf {
 ;
-;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc"];
-;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_19890101_20091231.nc"];
+;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_lwr_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
+;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc"];
 ;
 ;           lwr_correction_ncdf [shape=box,
@@ -51,7 +54,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :func:`interp_erai_lwr` and :ref:`add_19890101.sh`
@@ -69,5 +74,8 @@
 ; ::
 ;
-;  IDL> lwr_correction_ncdf
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = lwr_correction_ncdf(yyyymmddb, yyyymmdde)
+;  IDL> print, result
 ;
 ; TODO
@@ -94,4 +102,12 @@
 ;
 ; $URL$
+;
+; - fplod 20120322
+;
+;   * taking project_overwite into account
+;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
+;   * pro -> function
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * get rid of timegen
 ;
 ; - fplod 20110819T105050Z aedon.locean-ipsl.upmc.fr (Darwin)
@@ -121,5 +137,9 @@
 ;
 ;-
-pro lwr_correction_ncdf
+function lwr_correction_ncdf $
+         , yyyymmddb $
+	 , yyyymmdde
+;
+;++compile_opt idl2, strictarrsubs, logical_predicate
 ;
 @cm_4cal
@@ -129,4 +149,18 @@
 @cm_project
 ;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = lwr_correction_ncdf(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+;
 ; test if ${PROJECT_OD} defined
 CASE project_od_env OF
@@ -134,5 +168,5 @@
          msg = 'eee : ${PROJECT_OD} is not defined'
          ras = report(msg)
-       STOP
+       return, result
        END
   ELSE: BEGIN
@@ -149,5 +183,5 @@
    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -156,12 +190,9 @@
     msg = 'eee : the directory' + iodirout  + ' was not found.'
     ras = report(msg)
-    STOP
-ENDIF
-;
-da1=19880101
-da2=20091231
+    return, result
+ENDIF
 ;
 ; build data filename
-filename='erai_lwr_19890101_20091231_oafluxgrid.nc'
+filename='erai_lwr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
 ;
 ; check if this file exists
@@ -172,19 +203,28 @@
    msg = 'eee : the file ' + fullfilename + ' was not found.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 ; build output filename
-filename_out = 'TropFlux_lwr_19890101_20091231.nc'
+filename_out = 'TropFlux_lwr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
 fullfilename_out = iodirout + filename_out
 ; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 initncdf, fullfilename
-lwr=read_ncdf('lwr',da1,da2,file=fullfilename,/nostr)
+lwr=read_ncdf('lwr',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'lwr in lwr_correction_ncdf first date ', cda0
+print, 'lwr in lwr_correction_ncdf last date ' , cda1
+;
 help, lwr
 ;
@@ -197,7 +237,7 @@
 ;
 for jt=0,jpt-1 do begin
-  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
-  t=reform(lwr_mean(*,*))
-  lwr_m(*,*,jt)=t
+  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
+  t=reform(lwr_mean[*,*])
+  lwr_m[*,*,jt]=t
 endfor
 help, lwr_m
@@ -219,14 +259,6 @@
 ;
 ;writing field
-lat=reform(gphit(0,0:jpj-1))
-lon=reform(glamt(0:jpi-1,0))
-time=timegen(7670, start=julday(1,1,1989,0), units='days')
-jpt=n_elements(time)
-;
-cda0=string(jul2date(time(0)),format='(i8.8)')
-cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
-;
-time=time-julday(1,1,1950)
-jpt=n_elements(time)
+lat=reform(gphit[0,0:jpj-1])
+lon=reform(glamt[0:jpi-1,0])
 ;
 ncfile='!' + fullfilename_out
@@ -237,11 +269,14 @@
 lwr_attr={units:'degK',missing_value:1.e20,long_name:'Air Temperature at 2m',short_name:'lwr',axis:'TYX'}
 ;
-ncfields = 'lwr[longitude,latitude,time]=lwr_new:lwr_attr; ' $
+ncfields = 'lwr[longitude,latitude,*time]=lwr_new:lwr_attr; ' $
                       + 'longitude[]=lon:lon_attr; ' $
                       + 'latitude[]=lat:lat_attr; ' $
-                      + 'time[*time]=time:time_attr ' $
+                      + 'time[]=timein:time_attr ' $
                       + ' @ globattr'
 ;
 @ncdf_quickwrite
 ;
+result = 0
+return, result
+;
 end
Index: /trunk/src/oaflux_mask_30n30s.pro
===================================================================
--- /trunk/src/oaflux_mask_30n30s.pro	(revision 174)
+++ /trunk/src/oaflux_mask_30n30s.pro	(revision 175)
@@ -62,5 +62,5 @@
 ;
 ; Following program use :func:`oaflux_mask_30n30s` output:
-; :ref:`TropFlux_19890101_20091231.pro`,
+; :func:`tropflux`,
 ; :func:`interp_erai_dewt`,
 ; :func:`interp_erai_lwr`,
Index: /trunk/src/paper01/fig11/swr_isccp_tropflux_correlation_fig10.pro
===================================================================
--- /trunk/src/paper01/fig11/swr_isccp_tropflux_correlation_fig10.pro	(revision 174)
+++ /trunk/src/paper01/fig11/swr_isccp_tropflux_correlation_fig10.pro	(revision 175)
@@ -13,5 +13,5 @@
 ; sst corrected on OAFLUX grid
 ; has been produced by
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; :file:`${PROJECT_OD}/correlation_isccp_olr.idl`
Index: /trunk/src/paper01/fig11/swr_isccp_tropflux_new_v1.pro
===================================================================
--- /trunk/src/paper01/fig11/swr_isccp_tropflux_new_v1.pro	(revision 174)
+++ /trunk/src/paper01/fig11/swr_isccp_tropflux_new_v1.pro	(revision 175)
@@ -14,5 +14,5 @@
 ; sst corrected on OAFLUX grid
 ; has been produced by
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; ++ are written in
Index: /trunk/src/paper01/fig13/net_flux_validation_scatter_2000_2007.pro
===================================================================
--- /trunk/src/paper01/fig13/net_flux_validation_scatter_2000_2007.pro	(revision 174)
+++ /trunk/src/paper01/fig13/net_flux_validation_scatter_2000_2007.pro	(revision 175)
@@ -24,5 +24,5 @@
 ; ; containing ++
 ; has been produced by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; .. graphviz::
Index: /trunk/src/paper01/fig16/fig16_timeseries_nino3.pro
===================================================================
--- /trunk/src/paper01/fig16/fig16_timeseries_nino3.pro	(revision 174)
+++ /trunk/src/paper01/fig16/fig16_timeseries_nino3.pro	(revision 175)
@@ -13,5 +13,5 @@
 ; sst corrected on OAFLUX grid
 ; has been produced by
-; :ref:`sst_correction_ncdf.pro`.
+; :func:`sst_correction_ncdf`.
 ;
 ; :file:`${PROJECT_OD}/netflux_nino3_1989_2007.idl`
Index: /trunk/src/q2m_correction_ncdf.pro
===================================================================
--- /trunk/src/q2m_correction_ncdf.pro	(revision 174)
+++ /trunk/src/q2m_correction_ncdf.pro	(revision 175)
@@ -1,5 +1,3 @@
 ;+
-;
-; .. _q2m_correction_ncdf.pro:
 ;
 ; =======================
@@ -7,4 +5,6 @@
 ; =======================
 ;
+; .. function:: q2m_correction_ncdf(yyyymmddb,yyyymmdde)
+;
 ; DESCRIPTION
 ; ===========
@@ -12,5 +12,5 @@
 ; Correction of q2m on OAFLUX grid
 ;
-; :file:`${PROJECT_OD}/erai_q2m_19890101_20091231_oafluxgrid.nc`
+; :file:`${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; containing
 ; ++
@@ -20,9 +20,9 @@
 ; Corrected q2m on OAFLUX grid
 ; is written in
-; :file:`${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc`
 ; if this file not already exists.
 ;
 ; This file will be used by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; .. only:: man
@@ -36,6 +36,6 @@
 ;        digraph q2m_correction_ncdf {
 ;
-;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_19890101_20091231_oafluxgrid.nc"];
-;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_19890101_20091231.nc"];
+;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_q2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
+;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc"];
 ;
 ;           q2m_correction_ncdf [shape=box,
@@ -52,7 +52,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :func:`d2m_to_q2m_erai`
@@ -69,11 +71,21 @@
 ; ::
 ;
-;  IDL> q2m_correction_ncdf
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)
+;  IDL> print, result
 ;
 ; TODO
 ; ====
 ;
-; work on cratos idl7 even if NaNf values in erai_q2m_19890101_20091231_oafluxgrid.nc written by
-; d2m_to_q2m.pro.
+; make it work ::
+;
+;   Writing fields:
+;   q2m[longitude,latitude,time*]=q2m_new:q2m_attr; longitude[]=lon:lon_attr; latitude[]=lat:lat_attr; time[]=timein:time_attr  @ globattr
+;   % NCDF_DIMDEF: Unable to create dimension. (NC_ERROR=-59)
+;   % NCDF_VARDEF: Unable to define variable, bad dimension id .
+;   % NCDF_VARPUT: Variable Inquiry failed, -1 is not a valid variable id.
+;   % Stop encountered: Q2M_CORRECTION_NCDF    1
+;   	  /.autofs/lodyc/incas/fplod/tropflux/tropflux_ws/src/q2m_correction_ncdf.pro
 ;
 ; No way ... NaNf also in this output !!
@@ -88,4 +100,12 @@
 ; $URL$
 ;
+; - fplod 20120322
+;
+;   * taking project_overwite into account
+;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
+;   * pro -> function
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * get rid of timegen
+;
 ; - fplod 20110808T143129Z aedon.locean-ipsl.upmc.fr (Darwin)
 ;
@@ -106,5 +126,9 @@
 ;
 ;-
-pro q2m_correction_ncdf
+function q2m_correction_ncdf $
+         , yyyymmddb $
+	 , yyyymmdde
+;
+;++compile_opt idl2, strictarrsubs, logical_predicate
 ;
 @cm_4cal
@@ -114,4 +138,18 @@
 @cm_project
 ;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = q2m_correction_ncdf(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+
 ; test if ${PROJECT_OD} defined
 CASE project_od_env OF
@@ -119,5 +157,5 @@
          msg = 'eee : ${PROJECT_OD} is not defined'
          ras = report(msg)
-       STOP
+       return, result
        END
   ELSE: BEGIN
@@ -134,5 +172,5 @@
    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -141,12 +179,9 @@
     msg = 'eee : the directory' + iodirout  + ' was not found.'
     ras = report(msg)
-    STOP
-ENDIF
-;
-da1=19880101
-da2=20101231
+    return, result
+ENDIF
 ;
 ; build data filename
-filename='erai_q2m_19890101_20091231_oafluxgrid.nc'
+filename='erai_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
 ;
 ; check if this file exists
@@ -157,19 +192,28 @@
    msg = 'eee : the file ' + fullfilename + ' was not found.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 ; build output filename
-filename_out = 'TropFlux_q2m_19890101_20091231.nc'
+filename_out = 'TropFlux_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
 fullfilename_out = iodirout + filename_out
 ; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 initncdf, fullfilename
-q2m=read_ncdf('q2m',da1,da2,file=fullfilename,/nostr)
+q2m=read_ncdf('q2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'q2m in q2m_correction_ncdf first date ', cda0
+print, 'q2m in q2m_correction_ncdf last date ' , cda1
+;
 help, q2m
 ;
@@ -182,7 +226,7 @@
 ;
 for jt=0,jpt-1 do begin
-  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
-  q=reform(q2m_mean(*,*))
-  q2m_m(*,*,jt)=q
+  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
+  q=reform(q2m_mean[*,*])
+  q2m_m[*,*,jt]=q
 endfor
 help, q2m_m
@@ -203,14 +247,6 @@
 ;
 ;writing field
-lat=reform(gphit(0,0:jpj-1))
-lon=reform(glamt(0:jpi-1,0))
-time=timegen(7670, start=julday(1,1,1989,0), units='days')
-jpt=n_elements(time)
-;
-cda0=string(jul2date(time(0)),format='(i8.8)')
-cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
-;
-time=time-julday(1,1,1950)
-jpt=n_elements(time)
+lat=reform(gphit[0,0:jpj-1])
+lon=reform(glamt[0:jpi-1,0])
 ;
 ncfile='!' + fullfilename_out
@@ -221,11 +257,14 @@
 q2m_attr={units:'g/kg',missing_value:1.e20,long_name:'Specific humidity at 2m height',short_name:'q2m',axis:'TYX'}
 ;
-ncfields = 'q2m[longitude,latitude,time]=q2m_new:q2m_attr; ' $
+ncfields = 'q2m[longitude,latitude,time*]=q2m_new:q2m_attr; ' $
                       + 'longitude[]=lon:lon_attr; ' $
                       + 'latitude[]=lat:lat_attr; ' $
-                      + 'time[*time]=time:time_attr ' $
+                      + 'time[]=timein:time_attr ' $
                       + ' @ globattr'
 ;
 @ncdf_quickwrite
 ;
+result = 0
+return, result
+;
 end
Index: /trunk/src/sst_correction_ncdf.pro
===================================================================
--- /trunk/src/sst_correction_ncdf.pro	(revision 174)
+++ /trunk/src/sst_correction_ncdf.pro	(revision 175)
@@ -1,5 +1,3 @@
 ;+
-;
-; .. _sst_correction_ncdf.pro:
 ;
 ; =======================
@@ -7,7 +5,12 @@
 ; =======================
 ;
+; .. function:: sst_correction_ncdf(yyyymmddb,yyyymmdde)
+;
+; DESCRIPTION
+; ===========
+;
 ; Correction of sst on OAFLUX grid
 ;
-; :file:`${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc`
+; :file:`${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; containing
 ; ++
@@ -17,16 +20,16 @@
 ; Corrected sst on OAFLUX grid
 ; is written in
-; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc`
 ; if this file not already exists.
 ;
 ; This output file
-; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc`
 ; will be used by
 ; :func:`cronin_gustiness_ncdf`
 ; and
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; This output file
-; :file:`${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc`
 ; is one of the deliverable of TropFlux.
 ;
@@ -41,6 +44,6 @@
 ;        digraph sst_correction_ncdf {
 ;
-;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_19890101_20091231_oafluxgrid.nc"];
-;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_19890101_20091231.nc"];
+;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_sst_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
+;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc"];
 ;
 ;           sst_correction_ncdf [shape=box,
@@ -57,7 +60,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :func:`interp_erai_sst`
@@ -74,5 +79,8 @@
 ; ::
 ;
-;  IDL> sst_correction_ncdf
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = sst_correction_ncdf(yyyymmddb, yyyymmdde)
+;  IDL> print, result
 ;
 ; TODO
@@ -80,5 +88,5 @@
 ;
 ; make it work on loholt1 idl8:
-; reach end whtiout error but with bad values (9.96921e+36 on time and sst, nb timestep  5716
+; reach end whithout error but with bad values (9.96921e+36 on time and sst, nb timestep  5716
 ;
 ; see commands::
@@ -156,4 +164,12 @@
 ; $URL$
 ;
+; - fplod 20120322
+;
+;   * taking project_overwite into account
+;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
+;   * pro -> function
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * get rid of timegen
+;
 ; - fplod 20110808T124236Z cratos (Linux)
 ;
@@ -175,5 +191,9 @@
 ;
 ;-
-pro sst_correction_ncdf
+function sst_correction_ncdf $
+         , yyyymmddb $
+         , yyyymmdde
+;
+;++compile_opt idl2, strictarrsubs, logical_predicate
 ;
 @cm_4cal
@@ -183,4 +203,18 @@
 @cm_project
 ;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = sst_correction_ncdf(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+;
 ; test if ${PROJECT_OD} defined
 CASE project_od_env OF
@@ -188,5 +222,5 @@
          msg = 'eee : ${PROJECT_OD} is not defined'
          ras = report(msg)
-       STOP
+       return, result
        END
   ELSE: BEGIN
@@ -203,5 +237,5 @@
    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -210,12 +244,9 @@
     msg = 'eee : the directory' + iodirout  + ' was not found.'
     ras = report(msg)
-    STOP
-ENDIF
-;
-da1=19880101
-da2=20091231
+    return, result
+ENDIF
 ;
 ; build data filename
-filename='erai_sst_19890101_20091231_oafluxgrid.nc'
+filename='erai_sst_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_oafluxgrid.nc'
 ;
 ; check if this file exists
@@ -226,19 +257,28 @@
    msg = 'eee : the file ' + fullfilename + ' was not found.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 ; build output filename
-filename_out = 'TropFlux_sst_19890101_20091231.nc'
+filename_out = 'TropFlux_sst_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
 fullfilename_out = iodirout + filename_out
 ; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 initncdf, fullfilename
-sst=read_ncdf('sst',da1,da2,file=fullfilename,/nostr)
+sst=read_ncdf('sst',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'sst in sst_correction_ncdf first date ', cda0
+print, 'sst in sst_correction_ncdf last date ' , cda1
+;
 sst=sst-273.15
 help, sst
@@ -250,13 +290,13 @@
 caldat, time,mon,day,yea
 ;
-; debug to understand some time value 9.9692100e+36 on idl 6 lohloht1
-print, time[7080:7090]
+;++ debug to understand some time value 9.9692100e+36 on idl 6 lohloht1
+; print, time[7080:7090] when working on [19890101,19891231]
 ;
 sst_m=sst*0.
 ;
 for jt=0,jpt-1 do begin
-  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
-  t=reform(sst_mean(*,*))
-  sst_m(*,*,jt)=t
+  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
+  t=reform(sst_mean[*,*])
+  sst_m[*,*,jt]=t
 endfor
 help, sst_m
@@ -278,14 +318,6 @@
 ;
 ;writing field
-lat=reform(gphit(0,0:jpj-1))
-lon=reform(glamt(0:jpi-1,0))
-time=timegen(7670, start=julday(1,1,1989,0), units='days')
-jpt=n_elements(time)
-;
-cda0=string(jul2date(time(0)),format='(i8.8)')
-cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
-;
-time=time-julday(1,1,1950)
-jpt=n_elements(time)
+lat=reform(gphit[0,0:jpj-1])
+lon=reform(glamt[0:jpi-1,0])
 ;
 ncfile='!' + fullfilename_out
@@ -296,11 +328,14 @@
 sst_attr={units:'degK',missing_value:1.e20,long_name:'Sea Surface Temperature',short_name:'sst',axis:'TYX'}
 ;
-ncfields = 'sst[longitude,latitude,time]=sst_new:sst_attr; ' $
+ncfields = 'sst[longitude,latitude,*time]=sst_new:sst_attr; ' $
                       + 'longitude[]=lon:lon_attr; ' $
                       + 'latitude[]=lat:lat_attr; ' $
-                      + 'time[*time]=time:time_attr ' $
+                      + 'time[]=timein:time_attr ' $
                       + ' @ globattr'
 ;
 @ncdf_quickwrite
 ;
+result = 0
+return, result
+;
 end
Index: /trunk/src/t2m_correction_ncdf.pro
===================================================================
--- /trunk/src/t2m_correction_ncdf.pro	(revision 174)
+++ /trunk/src/t2m_correction_ncdf.pro	(revision 175)
@@ -1,5 +1,3 @@
 ;+
-;
-; .. _t2m_correction_ncdf.pro:
 ;
 ; =======================
@@ -7,8 +5,13 @@
 ; =======================
 ;
+; .. function:: t2m_correction_ncdf(yyyymmddb,yyyymmdde)
+;
+; DESCRIPTION
+; ===========
+;
 ; Mean correction for air temperature bias and correction for variability are
 ; applied.
 ;
-; :file:`${PROJECT_ID}/erai_t2m_19890101_20091231_oafluxgrid.nc`
+; :file:`${PROJECT_ID}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; containing
 ; air temperature at 2 m height from ERA-I interpolated on OAFLUX grid
@@ -18,11 +21,11 @@
 ; Corrected air temperature at 2 m height
 ; is written in
-; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc`
 ; if this file not already exists.
 ;
 ; This output file
-; :file:`${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc`
 ; will be used by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; .. only:: man
@@ -36,6 +39,6 @@
 ;        digraph t2m_correction_ncdf {
 ;
-;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_19890101_20091231_oafluxgrid.nc"];
-;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_19890101_20091231.nc"];
+;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_t2m_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
+;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc"];
 ;
 ;           t2m_correction_ncdf [shape=box,
@@ -52,7 +55,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :func:`interp_erai_t2m`
@@ -72,5 +77,8 @@
 ; ::
 ;
-;  IDL> t2m_correction_ncdf
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = t2m_correction_ncdf(yyyymmddb, yyyymmdde)
+;  IDL> print, result
 ;
 ; TODO
@@ -97,6 +105,4 @@
 ; check time values
 ;
-; hard coded time in module name and in output filename
-;
 ; hard coded correction values
 ;
@@ -121,4 +127,12 @@
 ;
 ; $URL$
+;
+; - fplod 20120322
+;
+;   * taking project_overwite into account
+;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
+;   * pro -> function
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * replace t2m=ncdf_lec(... by a t2m=read_ncdf(
 ;
 ; - fplod 20110822T112525Z aedon.locean-ipsl.upmc.fr (Darwin)
@@ -156,5 +170,9 @@
 ;
 ;-
-pro t2m_correction_ncdf
+function t2m_correction_ncdf $
+         , yyyymmddb $
+	 , yyyymmdde
+;
+;++compile_opt idl2, strictarrsubs, logical_predicate
 ;
 @cm_4cal
@@ -164,4 +182,18 @@
 @cm_project
 ;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = sst_correction_ncdf(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+
 ; test if ${PROJECT_OD} defined
 CASE project_id_env OF
@@ -169,5 +201,5 @@
      msg = 'eee : ${PROJECT_OD} is not defined'
      ras = report(msg)
-     STOP
+     return, result
            END
  ELSE: BEGIN
@@ -184,5 +216,5 @@
    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -191,15 +223,12 @@
     msg = 'eee : the directory' + iodirout  + ' was not found.'
     ras = report(msg)
-    STOP
-ENDIF
-;
-da1=19890101
-da2=20091231
+    return, result
+ENDIF
 ;
 ; build uncorrected t2 filename
 filename_t2_uncor = 'erai_t2m_' $
-    + string(da1,format='(i8.8)') $
+    + string(yyyymmddb,format='(i8.8)') $
     + '_' $
-    + string(da2,format='(i8.8)') $
+    + string(yyyymmdde,format='(i8.8)') $
     + '_oafluxgrid.nc'
 ;
@@ -211,20 +240,20 @@
    msg = 'eee : the file ' + fullfilename_t2_uncor + ' was not found.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 ; build output filename
 filename_out = 'TropFlux_t2m_' $
-    + string(da1,format='(i8.8)') $
+    + string(yyyymmddb,format='(i8.8)') $
     + '_' $
-    + string(da2,format='(i8.8)') $
+    + string(yyyymmdde,format='(i8.8)') $
     + '.nc'
 ;
 fullfilename_out = iodirout + filename_out
 ; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -239,14 +268,22 @@
 ;
 ; find first and last dates yyyymmdd
-; they will be written in global attributes of output file
 da=jul2date(julday(01, 01, 1957,timein[0]))
 cda0=string(da,format='(i8.8)')
 da=jul2date(julday(01, 01, 1957,timein[jptin-1]))
 cda1=string(da,format='(i8.8)')
-print, 'first date ', cda0
-print, 'last date ' , cda1
+print, 'for time checking first date ', cda0
+print, 'for time checking last date ' , cda1
 ;
 ; read t2 data
-t2m=ncdf_lec(fullfilename_t2_uncor,var='t2m')
+initncdf, fullfilename_t2_uncor
+t2m=read_ncdf('t2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2_uncor,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 't2m in t2m_correction_ncdf first date ', cda0
+print, 't2m in t2m_correction_ncdf last date ' , cda1
 ;
 t2m=t2m-273.15
@@ -267,7 +304,7 @@
   ;++print,day
   jtt=(julday(01, 01, 1957,timein[jt])-julday(1,1,yea)) < 364
-  t=reform(t2m_mean(*,*))
-  t2m_m(*,*,jt)=t
-  bias_cor(*,*,jt)=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4     ; (2000-2009)
+  t=reform(t2m_mean[*,*])
+  t2m_m[*,*,jt]=t
+  bias_cor[*,*,jt]=(((t-22.6)*0.4004896/(28-22.6)) > 0.) <0.4     ; (2000-2009)
 endfor
 help, t2m_m,bias_cor
@@ -290,12 +327,6 @@
 ;
 ;writing field
-lat=reform(gphit(0,0:jpj-1))
-lon=reform(glamt(0:jpi-1,0))
-cda0=string(da1)
-cda1=string(da2)
-;
-; conversion for hours since 19570101 to days from 19500101
-time=julday(01, 01, 1957,timein)-julday(1,1,1950)
-jpt=n_elements(time)
+lat=reform(gphit[0,0:jpj-1])
+lon=reform(glamt[0:jpi-1,0])
 ;
 ncfile='!' + fullfilename_out
@@ -313,11 +344,14 @@
 t2m_attr={units:units,missing_value:1.e20,long_name:long_name,short_name:'t2m',axis:'TYX'}
 ;
-ncfields = 't2m[longitude,latitude,time]=t2m_new:t2m_attr; ' $
+ncfields = 't2m[longitude,latitude,*time]=t2m_new:t2m_attr; ' $
                       + 'longitude[]=lon:lon_attr; ' $
                       + 'latitude[]=lat:lat_attr; ' $
-                      + 'time[*time]=time:time_attr ' $
+                      + 'time[]=timein:time_attr ' $
                       + ' @ globattr'
 ;
 @ncdf_quickwrite
 ;
+result = 0
+return, result
+;
 end
Index: /trunk/src/tropflux.pro
===================================================================
--- /trunk/src/tropflux.pro	(revision 175)
+++ /trunk/src/tropflux.pro	(revision 175)
@@ -0,0 +1,682 @@
+;+
+;
+; ============
+; tropflux.pro
+; ============
+;
+; .. function:: tropflux(yyyymmddb,yyyymmdde)
+;
+; DESCRITION
+; ==========
+;
+; This program computes net heat flux components on the 1° oaflux grid.
+;
+; all input variables are corrected for mean bias and variability.
+;
+; gustiness correction is applied for wind speed based on cronin's climatological
+; gustiness values.
+;
+; :file:`${PROJECT_ID}/mask_oaflux_30N30S.nc`
+; containing
+; OAFLUX grid
+; has been produced by
+; :func:`oaflux_mask_30n30s`.
+;
+; :file:`${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc`
+; containing
+; sst corrected on OAFLUX grid
+; has been produced by
+; :func:`sst_correction_ncdf`.
+;
+; :file:`${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc`
+; containing
+; ws corrected on OAFLUX grid
+; has been produced by
+; :func:`ws_correction_ncdf`.
+;
+; :file:`${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc`
+; containing
+; ++
+; has been produced by
+; :func:`cronin_gustiness_ncdf`.
+;
+; :file:`${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc`
+; containing
+; ws corrected on OAFLUX grid
+; has been produced by
+; :func:`tropflux_swr_blnd`.
+;
+; :file:`${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc`
+; containing
+; lwr corrected on OAFLUX grid
+; has been produced by
+; :func:`lwr_correction_ncdf`.
+;
+; containing
+; t2m corrected on OAFLUX grid
+; has been produced by
+; :func:`t2m_correction_ncdf`.
+;
+; :file:`${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc`
+; containing
+; q2m corrected on OAFLUX grid
+; has been produced by
+; :func:`d2m_to_q2m_erai`.
+;
+; net heat flux components are written
+; in :file:`${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}_coarev3.nc`
+; if this file not already exists.
+;
+; This output file
+; :file:`${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}_coarev3.nc`
+; will be used by
+; :ref:`TropFlux_NRT_ncdf.pro`.
+;
+;     .. graphviz::
+;
+;        digraph tropflux {
+;
+;           mask [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/mask_oaflux_30N30S.nc"];
+;           file_sst [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_sst_{yyyymmdd}_{yyyymmdd}.nc"];
+;           file_ws [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc"];
+;           file_wg [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_gustiness_{yyyymmdd}_{yyyymmdd}.nc"];
+;           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_swr_{yyyymmdd}_{yyyymmdd}_BLND.nc"];
+;           file_lwr [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_lwr_{yyyymmdd}_{yyyymmdd}.nc"];
+;           file_t2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_t2m_{yyyymmdd}_{yyyymmdd}.nc"];
+;           file_q2m [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_q2m_{yyyymmdd}_{yyyymmdd}.nc"];
+;
+;           file_out[shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_{yyyymmdd}_{yyyymmdd}_coarev3.nc"];
+;
+;           tropflux [shape=box,
+;           fontname=Courier,
+;           color=blue,
+;           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/tropflux.pro",
+;           label="${PROJECT}/src/tropflux.pro"];
+;
+;           {mask file_sst file_ws file_wg file_swr file_lwr file_t2m file_q2m} -> {tropflux} -> {file_out}
+;
+;        }
+;
+; SEE ALSO
+; ========
+;
+; :ref:`project_profile.sh`
+;
+; Used by :ref:`tropflux.sh`
+;
+; :func:`report <saxo:report>`
+; :func:`isadirectory <saxo:isadirectory>`
+; :func:`isafile <saxo:isafile>`
+; :func:`initncdf <saxo:initncdf>`
+; :func:`ncdf_lec <saxo:ncdf_lec>`
+; :func:`read_ncdf <saxo:read_ncdf>`
+; :func:`caldat <saxo:caldat>`
+; :func:`julday <saxo:julday>`
+; :func:`ncdf_quickwrite <saxo:ncdf_quickwrite>`
+;
+; :func:`qsee`
+; :func:`lwnet_clark`
+; :func:`calc_claud_vlat`
+; :func:`cor30a`
+;
+; .. note::
+;
+;    :func:`lwdown_clark` is not used here but available.
+;
+; EXAMPLES
+; ========
+;
+; ::
+;
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = tropflux(yyyymmddb, yyyymmdde)
+;  IDL> print, result
+
+; TODO
+; ====
+;
+; describe usage of tau
+;
+; compare time between all inputs after reading
+;
+; make it work ::
+;
+;     % Compiled module: EXTRAPOLATE.
+;     % Attempt to subscript LAND with OK is out of range.
+;     % Execution halted at: EXTRAPOLATE       176
+;       /usr/home/fplod/SAXO_DIR/SRC/Interpolation/extrapolate.pro
+;     %                      TROPFLUX_19890101_20091231  450
+;       /usr/home/fplod/incas/tropflux/tropflux_ws/src/TropFlux_19890101_20091231.p
+;       ro
+;     %                      $MAIN$
+;     % Program caused arithmetic error: Floating overflow
+;     % Program caused arithmetic error: Floating illegal operand
+;
+; the incriminated line is ::
+;
+;     tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y(*,1)) & tab(ocean)=x & m=fi    nite(tab) & tab=extrapolate(tab,m) & lwr(*,*,jt)=tab*msk+valmask*(1-msk)
+;
+; to make progress I DO NOT extrapolate anymore lwr, sen and lat
+; !!!!! must be reactivated
+;
+; when I DO NOT extrapolate lwr, sen and lat , program end with ::
+;
+;     Written to
+;     !/usr/work/incas/fplod/tropflux_d/TropFlux_19890101_20091231_coarev3.nc
+;     -------------------------
+;     % Program caused arithmetic error: Floating divide by 0
+;     % Program caused arithmetic error: Floating underflow
+;     % Program caused arithmetic error: Floating overflow
+;     % Program caused arithmetic error: Floating illegal operand
+;
+; explain why :func:`lwdown_clark` is not used
+;
+; check if K or °C in input
+;
+; get rid of::
+;
+;   % date 1: 19880101 is not found in the time axis.
+;
+; why ::
+;
+;   da1=19880101
+;
+; 1st date 19890101 no ?
+;
+; why da1-1 (with da1=19880101) when reading gustiness file ::
+;
+;   wg=read_ncdf('wg',da1-1,da2,file=fullfilename_wg,/nostr)
+;
+; coding rules
+;
+; KNOWN ISSUES
+; ============
+;
+; test of existence of fullfilename_msk not very efficient because
+; MUST_EXIST keyword of :func:`isafile <saxo:isafile>` not yet implemented
+;
+; EVOLUTIONS
+; ==========
+;
+; $Id
+;
+; $URL$
+;
+; - fplod 20120322
+;
+;   * pro -> func
+;   * rename with lower case TropFlux_19890101_20091231 become tropflux
+;   * taking project_overwite into account
+;   * try to add compile_opt
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * get rid of timegen
+;
+; - fplod 20110830T135832Z cratos (Linux)
+;
+;   * replace tt by time
+;
+; - fplod 20110830T084129Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * add tau in ouptut file
+;
+; - fplod 20110822T090838Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;    * split some multiple lines statement to investigate
+;      pb of extropalation for lwr
+;
+; - fplod 20110819T144332Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * add _coarev3 to filename output
+;   * check if filename output exists
+;
+; - fplod 20110809T110911Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * complete descritption
+;   * remove v* from filenames (in and out)
+;   * usage of ${PROJECT_OD}
+;   * remove return statement
+;   * add test on IO files
+;
+; - fplod 20101217T140745Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * remove hard coded directory for mask_oaflux_30N30S.nc
+;
+; - fplod 20101214T112131Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * add graph
+;
+; - fplod 20101214T093615Z aedon.locean-ipsl.upmc.fr (Darwin)
+;
+;   * minimal header
+;
+; - pbk 2008
+;
+;   * creation
+;
+;-
+;
+function tropflux $
+         , yyyymmddb $
+	 , yyyymmdde
+;
+compile_opt idl2, strictarrsubs, logical_predicate
+;
+@cm_4cal
+@cm_4data
+@cm_4mesh
+@cm_4data
+@cm_project
+;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = tropflux_swr_nrt(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+;
+; check for input directory
+;
+; test if ${PROJECT_ID} defined
+CASE project_id_env OF
+    ''  :  BEGIN
+     msg = 'eee : ${PROJECT_ID} is not defined'
+     ras = report(msg)
+     return, result
+           END
+ ELSE: BEGIN
+     msg = 'iii : ${PROJECT_ID} is ' + project_id_env
+     ras = report(msg)
+       END
+ENDCASE
+;
+iodirin = isadirectory(project_id_env)
+;
+; existence and protection of ${PROJECT_ID}
+IF (FILE_TEST(iodirin, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
+   msg = 'eee : the directory' + iodirin  + ' is not accessible.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build mask filename
+filename_msk='mask_oaflux_30N30S.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_msk
+ras = report(msg)
+fullfilename_msk = isafile(iodirin + filename_msk, NEW=0, /MUST_EXIST)
+IF fullfilename_msk[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_msk + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; test if ${PROJECT_OD} defined
+CASE project_od_env OF
+  '' : BEGIN
+         msg = 'eee : ${PROJECT_OD} is not defined'
+         ras = report(msg)
+       return, result
+       END
+  ELSE: BEGIN
+          msg = 'iii : ${PROJECT_OD} is ' + project_od_env
+          ras = report(msg)
+        END
+ ENDCASE
+;
+; check if output data will be possible
+iodirout = isadirectory(project_od_env)
+;
+; existence and protection for reading
+IF (FILE_TEST(iodirout, /DIRECTORY, /EXECUTABLE, /READ) EQ 0) THEN BEGIN
+   msg = 'eee : the directory' + iodirout  + ' is not accessible.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; existence and protection for writing
+IF (FILE_TEST(iodirout, /DIRECTORY, /WRITE) EQ 0) THEN BEGIN
+    msg = 'eee : the directory' + iodirout  + ' was not found.'
+    ras = report(msg)
+    return, result
+ENDIF
+;
+; build sst data filename
+filename_sst='TropFlux_sst_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_sst
+ras = report(msg)
+fullfilename_sst = isafile(iodirout + filename_sst, NEW=0, /MUST_EXIST)
+IF fullfilename_sst[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_sst + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build ws data filename
+filename_ws='TropFlux_ws_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_ws
+ras = report(msg)
+fullfilename_ws = isafile(iodirout + filename_ws, NEW=0, /MUST_EXIST)
+IF fullfilename_ws[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_ws + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build swr data filename
+filename_swr='TropFlux_swr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_BLND.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_swr
+ras = report(msg)
+fullfilename_swr = isafile(iodirout + filename_swr, NEW=0, /MUST_EXIST)
+IF fullfilename_swr[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_swr + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build lwr data filename
+filename_lwr='TropFlux_lwr_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_lwr
+ras = report(msg)
+fullfilename_lwr = isafile(iodirout + filename_lwr, NEW=0, /MUST_EXIST)
+IF fullfilename_lwr[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_lwr + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build t2m data filename
+filename_t2m='TropFlux_t2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_t2m
+ras = report(msg)
+fullfilename_t2m = isafile(iodirout + filename_t2m, NEW=0, /MUST_EXIST)
+IF fullfilename_t2m[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_t2m + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build q2m data filename
+filename_q2m='TropFlux_q2m_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_q2m
+ras = report(msg)
+fullfilename_q2m = isafile(iodirout + filename_q2m, NEW=0, /MUST_EXIST)
+IF fullfilename_q2m[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_q2m + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build wg data filename
+filename_wg='TropFlux_gustiness_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '.nc'
+;
+; check if this file exists
+msg='iii : looking for ' + filename_wg
+ras = report(msg)
+fullfilename_wg = isafile(iodirout + filename_wg, NEW=0, /MUST_EXIST)
+IF fullfilename_wg[0] EQ '' THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_wg + ' was not found.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+; build output filename
+filename_out = 'TropFlux_' +  string(yyyymmddb,format='(I8.8)') + '_' + string(yyyymmdde,format='(I8.8)') + '_coarev3.nc'
+fullfilename_out = iodirout + filename_out
+; in order to avoid unexpected overwritten
+IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+   msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
+   ras = report(msg)
+   return, result
+ENDIF
+;
+initncdf, fullfilename_msk
+msk=ncdf_lec(fullfilename_msk,var='msk')
+;
+initncdf, fullfilename_sst
+;
+ws=read_ncdf('ws',yyyymmddb-.5d,yyyymmdde,file=fullfilename_ws,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'ws in tropflux first date ', cda0
+print, 'ws in ws_correction_ncdf last date ' , cda1
+;
+wg=read_ncdf('wg',yyyymmddb-.5d-1,yyyymmdde,file=fullfilename_wg,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'wg in tropflux first date ', cda0
+print, 'wg in ws_correction_ncdf last date ' , cda1
+tt=time
+jpt=n_elements(time)
+sst=read_ncdf('sst',yyyymmddb-.5d,yyyymmdde,file=fullfilename_sst,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'sst in tropflux first date ', cda0
+print, 'sst in ws_correction_ncdf last date ' , cda1
+sst=reform(sst-273.15)
+swd=read_ncdf('swr',yyyymmddb-.5d,yyyymmdde,file=fullfilename_swr,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'swr in tropflux first date ', cda0
+print, 'swr in ws_correction_ncdf last date ' , cda1
+lw=read_ncdf('lwr',yyyymmddb-.5d,yyyymmdde,file=fullfilename_lwr,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'lwr in tropflux first date ', cda0
+print, 'lwr in ws_correction_ncdf last date ' , cda1
+swd=swd/0.94  ; converting from net swr to downward swr
+;
+t2m=read_ncdf('t2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename_t2m,/nostr)-273.15   ; in C
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 't2m in tropflux first date ', cda0
+print, 't2m in ws_correction_ncdf last date ' , cda1
+q2m=read_ncdf('q2m',yyyymmddb-.5d,yyyymmdde,file=fullfilename_q2m,/nostr)    ; in g/kg
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'q2m in tropflux first date ', cda0
+print, 'q2m in ws_correction_ncdf last date ' , cda1
+;
+w=sqrt(ws*ws+wg*wg)  ; wind corrected for gustiness
+w=ws
+tmask=msk
+help, ws,w,wg,u,sst,swd,t2m,q2m
+ocean=where(msk eq 1,compl=land)
+valmask=1.e20
+time=tt
+jpt=n_elements(time)
+;
+; Constants for flux computation
+;
+zu=10.                          ; height of wind speed measurement (m)
+us=0.                           ; surf current (m/s)
+zt=2.                           ; Height of air T measurement (m)
+zq=2.                           ; height of humidity measurement (m)
+P=1008.                         ; Pressure
+zi=600.                         ; Inversion height (m)
+jcool=0                         ; Compute cool-skin
+jwave=0                         ; No waves
+twave=5.
+hwave=1.
+;
+caldat, time,mon,day,yea
+swr=fltarr(jpi,jpj,jpt)+1.e20
+lwr=fltarr(jpi,jpj,jpt)+1.e20
+lat=fltarr(jpi,jpj,jpt)+1.e20
+sen=fltarr(jpi,jpj,jpt)+1.e20
+lwnet_clrk=fltarr(jpi,jpj,jpt)+1.e20
+;Ch=fltarr(jpi,jpj,jpt)+1.e20
+;Ce=fltarr(jpi,jpj,jpt)+1.e20
+junk=fltarr(jpi,jpj,jpt)+1.e20
+;
+for jt=0,jpt-1 do begin
+  jday=time[jt]-julday(1,1,yea[jt])
+  print, 'Computing Fluxes ',jt,' / ',jpt-1
+;
+;  P=msl(*,*,jt)
+;  P=P(ocean)
+;
+  ; wind speed (m/s)
+  wn=w[*,*,jt]
+  wn=wn[ocean]
+  ; Bulk sst (°C)
+  ts=sst[*,*,jt]
+  ts=ts[ocean]
+  ; 2m Air T (°C)
+  t=t2m[*,*,jt]
+  t=t[ocean]
+  ; Sea surface sat. spec. humidity (g/kg)
+  qs=qsee(ts,P)
+  ; 2m AIr specific humidity  (g/kg)
+  q=q2m[*,*,jt]
+  q=q[ocean]
+  ; Downward solar flux (W/m2)
+  Rs=swd[*,*,jt]
+  Rs=Rs[ocean]
+  ylat=gphit[ocean]
+  ;  cld=calc_cloud(jday,Rs,ylat)
+  cld=calc_cloud_vlat(jday,Rs,ylat)
+  ; Downward IR flux (W/m2)
+  ;  Rl=lwdown_clark(ts,q,cld,t,P)
+  Rl=lw[*,*,jt]
+  Rl=Rl[ocean]
+  rain=0.
+  lw_clrk=-lwnet_clark(ts,q,cld,t,P)
+;  junk[*,*,jt]=lw_clrk
+;
+;stop
+  y=cor30a(wn,us,ts,t,Qs,Q,Rs,Rl,rain,zi,P,zu,zt,zq,ylat,jcool,jwave,twave,hwave)
+; A few punctual missing values (coare does not converge): filled by spatial extrapolation
+  tab=fltarr(jpi,jpj)+!values.f_nan
+  x=reform(y[*,0])
+  tab[ocean]=x
+  m=finite(tab)
+  help, tab, m, swr
+  tab=extrapolate(tab,m)
+  swr[*,*,jt]=tab*msk+valmask*(1-msk)
+;
+  tab=fltarr(jpi,jpj)+!values.f_nan
+  x=reform(y[*,1])
+  tab[ocean]=x
+  m=finite(tab)
+  help, tab, m, lwr
+  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
+  print, 'www : extrapolation for lwr is not done'
+  tab=tab
+  lwr[*,*,jt]=tab*msk+valmask*(1-msk)
+;
+  tab=fltarr(jpi,jpj)+!values.f_nan
+  x=reform(y[*,2])
+  tab[ocean]=x
+  m=finite(tab)
+  help, tab, m, lat
+  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
+  print, 'www : extrapolation for lat is not done'
+  tab=tab
+  lat[*,*,jt]=tab*msk+valmask*(1-msk)
+  tab=fltarr(jpi,jpj)+!values.f_nan
+  x=reform(y[*,3])
+  tab[ocean]=x
+  m=finite(tab)
+  help, tab, m, sen
+  ;!!!!!!!!!!!!+++++++++++++++  tab=extrapolate(tab,m)
+  print, 'www : extrapolation for sen is not done'
+  tab=tab
+  sen[*,*,jt]=tab*msk+valmask*(1-msk)
+  ;  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)
+  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y[*,5]) & tab[ocean]=x & m=finite(tab) & tab=extrapolate(tab,m) & tau[*,*,jt]=tab*msk+valmask*(1-msk)
+  ;  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)
+  ;  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)
+  tab=fltarr(jpi,jpj)+!values.f_nan & x=reform(y[*,8]) & tab[ocean]=x & m=finite(tab) & tab=extrapolate(tab,m) & wg[*,*,jt]=tab*msk+valmask*(1-msk)
+endfor
+jpt=n_elements(time)
+;
+cda0=string(jul2date(time[0]),format='(i8.8)')
+cda1=string(jul2date(time[jpt-1]),format='(i8.8)')
+time=time-julday(1,1,1950,00,00,00)
+xlon=reform(glamt[*,0])
+ylat=reform(gphit[0,*])
+;
+ncfile='!' + fullfilename_out
+lon_attr={units:'degrees_east',long_name:'Longitude'}
+lat_attr={units:'degrees_north',long_name:'Latitude'}
+time_attr={units:'days since 1950-01-01 00:00:00',long_name:'Time axis',time_origin:'1950-JAN-01 00:00:00'}
+globattr={source:'Fluxes for the Global Tropical Ocean - TropFlux',timerange:cda0+' - '+cda1}
+swr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net shortwave radiation',short_name:'swr',axis:'TYX'}
+lwr_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation',short_name:'lwr',axis:'TYX'}
+lwr_clrk_attr={units:'W/m2',missing_value:valmask,long_name:'Surface net longwave radiation from clark',short_name:'lwr',axis:'TYX'}
+lhf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface latent flux',short_name:'lhf',axis:'TYX'}
+shf_attr={units:'W/m2',missing_value:valmask,long_name:'Surface sensible flux',short_name:'shf',axis:'TYX'}
+wg_attr={units:'m/s',missing_value:valmask,long_name:'COARE convective gustiness',short_name:'wg',axis:'TYX'}
+tau_attr={units:'N/m2',missing_value:valmask,long_name:'Wind stress magnitude',short_name:'tau',axis:'TYX'}
+;
+help, swr,lwr,lat,sen,time,xlon,ylat
+;
+ncfields = 'tau[longitude,latitude,time]=tau:tau_attr; ' $
+         + 'wg[longitude,latitude,time]=wg:wg_attr; ' $
+         + 'swr[longitude,latitude,time]=swr:swr_attr; ' $
+;         +'lwr_coare[longitude,latitude,time]=lwr:lwr_attr; ' $
+         +'lwr[longitude,latitude,time]=lwnet_clrk:lwr_clrk_attr; ' $
+         +'lhf[longitude,latitude,time]=lat:lhf_attr; ' $
+         +'shf[longitude,latitude,time]=sen:shf_attr; ' $
+;         +'Ch[longitude,latitude,time]=Ch:Ch_attr; ' $
+;         +'Ce[longitude,latitude,time]=Ce:Ce_attr; ' $
+         + 'longitude[]=xlon:lon_attr; ' $
+         + 'latitude[]=ylat:lat_attr; ' $
+         + 'time[*time]=time:time_attr ' $
+         + ' @ globattr'
+;
+@ncdf_quickwrite
+;
+result = 0
+return, result
+;
+end
Index: /trunk/src/tropflux.sh
===================================================================
--- /trunk/src/tropflux.sh	(revision 174)
+++ /trunk/src/tropflux.sh	(revision 175)
@@ -89,8 +89,11 @@
 #
 # Use :
-# :func:`oaflux_mask_30n30s`, :func:`interp_erai_t2m`, 
+# :func:`oaflux_mask_30n30s`, :func:`interp_erai_t2m`,
 # :func:`interp_erai_msl`, :func:`interp_erai_dewt`, :func:`interp_erai_lwr`,
-# :func:`interp_erai_sst`, :func:`interp_erai_ws`, :func:`interp_olr_30n30s`, 
-# :func:`d2m_to_q2m_erai`,
+# :func:`interp_erai_sst`, :func:`interp_erai_ws`, :func:`interp_olr_30n30s`,
+# :func:`d2m_to_q2m_erai`, :func:`sst_correction_ncdf`,
+# :func:`lwr_correction_ncdf`, :func:`q2m_correction_ncdf`,
+# :func:`t2m_correction_ncdf`, :func:`ws_correction_ncdf`,
+# :func:`tropflux_swr_dt`, :func:`tropflux_swr_nrt`, :func:`tropflux_swr_blnd`,
 # etc.
 #
@@ -114,4 +117,12 @@
 #
 # $URL$
+#
+# - pinsard 20120322
+#
+#   * handling error of sst_correction_ncdf (now function)
+#   * handling error of lwr_correction_ncdf (now function)
+#   * handling error of q2m_correction_ncdf (now function)
+#   * handling error of t2m_correction_ncdf (now function)
+#   * handling error of ws_correction_ncdf (now function)
 #
 # - pinsard 20120321
@@ -382,21 +393,53 @@
    exit
 ENDIF
-;sst_correction_ncdf
+result = sst_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after sst_correction_ncdf ' + string(result)
+   err = report(msg)
+   exit
+ENDIF
 result = cronin_gustiness_ncdf(${yyyymmddb}, ${yyyymmdde})
 IF result < 0 THEN BEGIN
    msg = 'eee : pb after cronin_gustiness_ncdf ' + string(result)
-  err = report(msg)
-exit
+   err = report(msg)
+   exit
+ENDIF
 result = tropflux_swr_blnd(${yyyymmddb}, ${yyyymmdde})
 IF result < 0 THEN BEGIN
    msg = 'eee : pb after tropflux_swr_blnd ' + string(result)
-  err = report(msg)
-exit
-;lwr_correction_ncdf
-;q2m_correction_ncdf
-;t2m_correction_ncdf
-;ws_correction_ncdf
+   err = report(msg)
+   exit
+ENDIF
+result = lwr_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after lwr_correction_ncdf ' + string(result)
+   err = report(msg)
+   exit
+ENDIF
+result = q2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after q2m_correction_ncdf ' + string(result)
+   err = report(msg)
+   exit
+ENDIF
+result = t2m_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after t2m_correction_ncdf ' + string(result)
+   err = report(msg)
+   exit
+ENDIF
+result = ws_correction_ncdf(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after ws_correction_ncdf ' + string(result)
+   err = report(msg)
+   exit
+ENDIF
 ;.compile TropFlux_19890101_20091231
-;tropflux_19890101_20091231
+result = tropflux(${yyyymmddb}, ${yyyymmdde})
+IF result < 0 THEN BEGIN
+   msg = 'eee : pb after tropflux' + string(result)
+   err = report(msg)
+   exit
+ENDIF
 ;.compile TropFlux_NRT_ncdf
 ;tropflux_nrt_ncdf
Index: /trunk/src/tropflux_swr_blnd.pro
===================================================================
--- /trunk/src/tropflux_swr_blnd.pro	(revision 174)
+++ /trunk/src/tropflux_swr_blnd.pro	(revision 175)
@@ -53,7 +53,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :ref:`data_in_swr`
Index: /trunk/src/tropflux_swr_nrt.pro
===================================================================
--- /trunk/src/tropflux_swr_nrt.pro	(revision 174)
+++ /trunk/src/tropflux_swr_nrt.pro	(revision 175)
@@ -47,10 +47,12 @@
 ; ========
 ;
-; :ref:`project_profile.sh`
-;
 ; :ref:`mooring_corrections`
 ;
 ; :ref:`data_in_swr`
 ; :ref:`data_in_olr`
+;
+; Used by :ref:`tropflux.sh`
+;
+; :ref:`project_profile.sh`
 ;
 ; :func:`initncdf <saxo:initncdf>`
Index: /trunk/src/ws_correction_ncdf.pro
===================================================================
--- /trunk/src/ws_correction_ncdf.pro	(revision 174)
+++ /trunk/src/ws_correction_ncdf.pro	(revision 175)
@@ -1,5 +1,3 @@
 ;+
-;
-; .. _ws_correction_ncdf.pro:
 ;
 ; ======================
@@ -7,7 +5,12 @@
 ; ======================
 ;
+; .. function:: ws_correction_ncdf(yyyymmddb,yyyymmdde)
+;
+; DESCRIPTION
+; ===========
+;
 ; Correction of ws on OAFLUX grid
 ;
-; :file:`${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc`
+; :file:`${PROJECT_OD}/erai_ws_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc`
 ; containing
 ; ++
@@ -17,11 +20,11 @@
 ; Corrected ws on OAFLUX grid
 ; is written in
-; :file:`${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc`
 ; if this file not already exists.
 ;
 ; This output file
-; :file:`${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc`
+; :file:`${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc`
 ; will be used by
-; :ref:`TropFlux_19890101_20091231.pro`.
+; :func:`tropflux`.
 ;
 ; .. only:: man
@@ -35,6 +38,6 @@
 ;        digraph ws_correction_ncdf {
 ;
-;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_ws_19890101_20091231_oafluxgrid.nc"];
-;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_19890101_20091231.nc"];
+;           file_in [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/erai_ws_{yyyymmdd}_{yyyymmdd}_oafluxgrid.nc"];
+;           file_out [shape=ellipse,fontname=Courier,label="${PROJECT_OD}/TropFlux_ws_{yyyymmdd}_{yyyymmdd}.nc"];
 ;
 ;           ws_correction_ncdf [shape=box,
@@ -51,7 +54,9 @@
 ; ========
 ;
+; :ref:`mooring_corrections`
+;
+; Used by :ref:`tropflux.sh`
+;
 ; :ref:`project_profile.sh`
-;
-; :ref:`mooring_corrections`
 ;
 ; :func:`interp_erai_ws`
@@ -69,5 +74,8 @@
 ; ::
 ;
-;  IDL> ws_correction_ncdf
+;  IDL> yyyymmddb = 20000101L
+;  IDL> yyyymmdde = 20001231L
+;  IDL> result = ws_correction_ncdf(yyyymmddb, yyyymmdde)
+;  IDL> print, result
 ;
 ; TODO
@@ -90,4 +98,12 @@
 ;
 ; $URL$
+;
+; - fplod 20120322
+;
+;   * taking project_overwite into account
+;   * try to add compile_opt seems to be incompatible with ncdf_quickwrite
+;   * pro -> function
+;   * hard coded da1 and da2 replaced by yyyymmddb and yyyymmdde parameters
+;   * get rid of timegen
 ;
 ; - fplod 20110808T131954Z aedon.locean-ipsl.upmc.fr (Darwin)
@@ -110,7 +126,10 @@
 ;
 ;-
-pro ws_correction_ncdf
-;
-@cm_4cal
+function ws_correction_ncdf $
+         , yyyymmddb $
+	 , yyyymmdde
+;
+;++compile_opt idl2, strictarrsubs, logical_predicate
+;
 @cm_4data
 @cm_4mesh
@@ -118,4 +137,19 @@
 @cm_project
 ;
+; Return to caller if errors
+ON_ERROR, 2
+;
+result = -1
+;
+usage = 'result = ws_correction_ncdf(yyyymmddb, yyyymmdde)'
+nparam = N_PARAMS()
+IF (nparam NE 2) THEN BEGIN
+    ras = report(['Incorrect number of arguments.' $
+          + '!C' $
+          + 'Usage : ' + usage])
+    return, result
+ENDIF
+;
+@cm_4cal
 ; test if ${PROJECT_OD} defined
 CASE project_od_env OF
@@ -123,5 +157,5 @@
          msg = 'eee : ${PROJECT_OD} is not defined'
          ras = report(msg)
-       STOP
+       return, result
        END
   ELSE: BEGIN
@@ -138,5 +172,5 @@
    msg = 'eee : the directory' + iodirout  + ' is not accessible.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
@@ -145,12 +179,13 @@
     msg = 'eee : the directory' + iodirout  + ' was not found.'
     ras = report(msg)
-    STOP
-ENDIF
-;
-da1=19880101
-da2=20101231
+    return, result
+ENDIF
 ;
 ; build data filename
-filename='erai_ws_19890101_20091231_oafluxgrid.nc'
+filename='erai_ws_' $
+    + string(yyyymmddb,format='(i8.8)') $
+    + '_' $
+    + string(yyyymmdde,format='(i8.8)') $
+    + '_oafluxgrid.nc'
 ;
 ; check if this file exists
@@ -161,20 +196,42 @@
    msg = 'eee : the file ' + fullfilename + ' was not found.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 ; build output filename
-filename_out = 'TropFlux_ws_19890101_20091231.nc'
+filename_out = 'TropFlux_ws_' $
+    + string(yyyymmddb,format='(i8.8)') $
+    + '_' $
+    + string(yyyymmdde,format='(i8.8)') $
+    + '.nc'
 fullfilename_out = iodirout + filename_out
 ; in order to avoid unexpected overwritten
-IF (FILE_TEST(fullfilename_out) EQ 1) THEN BEGIN
+IF ((FILE_TEST(fullfilename_out) EQ 1)  AND (project_overwrite EQ 0)) THEN BEGIN
    msg = 'eee : the file ' + fullfilename_out  + ' already exists.'
    ras = report(msg)
-   STOP
+   return, result
 ENDIF
 ;
 initncdf, fullfilename
-u=read_ncdf('u10',da1,da2,file=fullfilename,/nostr)
-v=read_ncdf('v10',da1,da2,file=fullfilename,/nostr)
+u=read_ncdf('u10',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'u10 in ws_correction_ncdf first date ', cda0
+print, 'u10 in ws_correction_ncdf last date ' , cda1
+;
+v=read_ncdf('v10',yyyymmddb-.5d,yyyymmdde,file=fullfilename,/nostr)
+timein=24.d*(time-julday(1,1,1957,0,0,0))
+jpt=n_elements(timein)
+da=jul2date(time[0])
+cda0=string(da,format='(i8.8)')
+da=jul2date(time[jpt-1])
+cda1=string(da,format='(i8.8)')
+print, 'v10 in ws_correction_ncdf first date ', cda0
+print, 'v10 in ws_correction_ncdf last date ' , cda1
+;
 w=sqrt(u*u+v*v)
 ;
@@ -189,7 +246,7 @@
 ;
 for jt=0,jpt-1 do begin
-  jtt=(time(jt)-julday(1,1,yea(jt))) < 364
-  q=reform(w_mean(*,*))
-  w_m(*,*,jt)=q
+  jtt=(time[jt]-julday(1,1,yea[jt])) < 364
+  q=reform(w_mean[*,*])
+  w_m[*,*,jt]=q
 endfor
 help, w_m
@@ -211,14 +268,6 @@
 ;
 ;writing field
-lat=reform(gphit(0,0:jpj-1))
-lon=reform(glamt(0:jpi-1,0))
-time=timegen(7670, start=julday(1,1,1989,0), units='days')
-jpt=n_elements(time)
-;
-cda0=string(jul2date(time(0)),format='(i8.8)')
-cda1=string(jul2date(time(jpt-1)),format='(i8.8)')
-;
-time=time-julday(1,1,1950)
-jpt=n_elements(time)
+lat=reform(gphit[0,0:jpj-1])
+lon=reform(glamt[0:jpi-1,0])
 ;
 ncfile='!' + fullfilename_out
@@ -229,11 +278,14 @@
 w_attr={units:'m/s',missing_value:1.e20,long_name:'mean wind speed',short_name:'w',axis:'TYX'}
 ;
-ncfields = 'ws[longitude,latitude,time]=w_new:w_attr; ' $
+ncfields = 'ws[longitude,latitude,*time]=w_new:w_attr; ' $
                       + 'longitude[]=lon:lon_attr; ' $
                       + 'latitude[]=lat:lat_attr; ' $
-                      + 'time[*time]=time:time_attr ' $
+                      + 'time[]=timein:time_attr ' $
                       + ' @ globattr'
 ;
 @ncdf_quickwrite
 ;
+result = 0
+return, result
+;
 end
