Index: trunk/src/correct_terminology.sh
===================================================================
--- trunk/src/add_19890101.sh	(revision 199)
+++ trunk/src/correct_terminology.sh	(revision 202)
@@ -3,11 +3,11 @@
 #+
 #
-# .. program:: add_19890101.sh
-#
-# .. _add_19890101.sh:
-#
-# ==================
-# add_19890101.sh 
-# ==================
+# .. program:: correct_terminology.sh
+#
+# .. _correct_terminology.sh:
+#
+# =======================
+# correct_terminology.sh
+# =======================
 #
 # SYNOPSIS
@@ -16,5 +16,5 @@
 # ::
 #
-#  $ add_19890101.sh [--debug]
+#  $ correct_terminology.sh [--debug] -good goodend -bad badend -d directory
 #
 # DESCRIPTION
@@ -25,38 +25,31 @@
 #    If this option is set, :samp:`ncdump -v tt` will be added to log file
 #
-# Artificialy add 19890101 to lwr interpolated on OAFLUX grid dataset.
-#
-# :file:`${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc`
-# containing 
-# ++
-# has been produced by
-# :func:`interp_erai_lwr`.
-# repeat the first time step in 
-#
-# File :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc`
-# will be written
-# if this file not already exists.
-#
-# This output file 
-# :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc`
-# must be processed after by 
-# :func:`lwr_correction_ncdf`.
-# 
-# Log file is written on :file:`${PROJECT_LOG}/add_19890101.sh.log.{YYYYMMDDTHHMMSSZ}`
+# .. option:: -good goodend
+#
+#    good end part of the name
+#
+# .. option:: -bad badend
+#
+#    bad end part of the name
+#
+# .. option:: -d <dirin>
+#
+#    base location of the dataset to be changed
+#
+# Modify filenames in the dataset based under dirin parameter
+#
+# Log file is written on :file:`${PROJECT_LOG}/correct_terminology.sh.log.{YYYYMMDDTHHMMSSZ}`
 #
 #     .. graphviz::
 #
-#        digraph add_19890101 {
-#
-#           filein [shape=ellipse,fontname=Courier,label="$PROJECT_OD/erai_lwr_19890102_20091231_oafluxgrid.nc"];
-#           fileout [shape=ellipse,fontname=Courier,label="$PROJECT_OD/erai_lwr_19890101_20091231_oafluxgrid.nc"];
-#
-#           add_19890101 [shape=box,
+#        digraph correct_terminology {
+#
+#           correct_terminology [shape=box,
 #           fontname=Courier,
 #           color=blue,
-#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/add_19890101.sh",
-#           label="${PROJECT}/src/add_19890101.sh"];
-#
-#           {filein} -> {add_19890101} -> {fileout}
+#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/correct_terminology.sh",
+#           label="${PROJECT}/src/correct_terminology.sh"];
+#
+#           {filein} -> {correct_terminology} -> {fileout}
 #
 #       }
@@ -65,49 +58,19 @@
 # ========
 #
-# To produce $PROJECT_OD/erai_lwr_19890101_20091231_oafluxgrid.nc 
-# from $PROJECT_OD/erai_lwr_19890102_20091231_oafluxgrid.nc ::
-#
-#  $ add_19890101.sh --debug
+# To modify files under /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ because files are not named
+# :file:`var_tropflux_1d_${yyyy}_{yyyy}.nc` but :file:`var_tropflux_1d_{yyyy}_{month}{yyyy}.nc`::
+#
+#  $ correct_terminology.sh -d /usr/lodyc/incas/fplod/tropflux_d/to_be_published/ -good "1979_2013" -bad "1979_march2013"
 #
 # And look at log file with ::
 #
-#  $ tlogd.sh add_19890101
-#
-# and of course on files in ${PROJECT_OD}.
-#
-# TIPS
-# ====
-#
-# To see the 3 first time values in input and files::
-#
-#  $ ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc 
-#    14246.0000000005
-#    14247.0000000005
-#    14248.0000000005
-#
-#  $ ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc 
-#    14245.0000000005
-#    14246.0000000005
-#    14247.0000000005
-#
-# while :
-#
-#   $ idl
-#   print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0)
-#   14245.500
-#   print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) +1
-#   14246.500
+#  $ tlogd.sh correct_terminology
 #
 # SEE ALSO
 # ========
 #
+# :ref:`updatedata`
+#
 # :ref:`project_profile.sh`
-#
-# :func:`ncks <nco:ncks>`
-# :func:`ncrcat <nco:ncrcat>`
-# :func:`ncatted <nco:ncatted>`
-# :func:`ncap2 <nco:ncap2>`
-#
-# :ref:`lwr_correction_ncdf.pro`
 #
 # TODO
@@ -116,38 +79,9 @@
 # coding rules
 #
-# won't it be more conveniant to add this articifial time step in 
-# the IDL creation tool interp_erai_lwr_1989_2009.pro.
-# It will allow to avoid a shell interruption in the IDL processing chain.
-#
-# improve global attributes with ... creation_date and so on
-#
-# check if the first time step is really 19890102 in the input file
-#
-# change tt to ttt to complete time correction
-#
-# remove hard coded end time
-#
-# get rid of this long mesage on cratos::
-#
-#    ncrcat: WARNING Variable lwr has attribute "missing_value" but not "_FillValue". To 
-#    comply with netCDF conventions, NCO ignores values that equal the _FillValue attribu
-#    te when performing arithmetic. Confusingly, values equal to the missing_value should
-#     also be neglected. However, it is tedious and (possibly) computationally expensive 
-#    to check each value against multiple missing values during arithmetic on large varia
-#    bles. So NCO thinks that processing variables with a "missing_value" attribute and n
-#    o "_FillValue" attribute may produce undesired arithmetic results (i.e., where value
-#    s that were intended to be neglected were not, in fact, neglected). We suggest you r
-#    ename all "missing_value" attributes to "_FillValue" or include both "missing_value"
-#     and "_FillValue" attributes (with the _same values_) for all variables that have ei
-#    ther attribute. Because it is long, this message is only printed once per operator e
-#    ven though multiple variables may have the same attribute configuration. More inform
-#    ation on missing values is given at:
-#    http://nco.sf.net/nco.html#mss_val
-#    Examples of renaming attributes are at:
-#    http://nco.sf.net/nco.html#xmp_ncrename
-#
-# ... on a déjà une idee de la solution : convention CF et meilleure gestion des
-# valeurs manquantes dans les softs IDL !!!
-#
+# overwrite : may be an other option to avoid scratch
+#
+# debug not used
+#
+# build file name according to time in the file instead of parameter
 #
 # EVOLUTIONS
@@ -158,8 +92,7 @@
 # $URL$
 #
-# - fplod 20110819T091143Z aedon.locean-ipsl.upmc.fr (Darwin)
-#
-#   * creation from pk email 20110811 "lwr first timestep"
-#   * include time correction and timerange modificaton
+# - fplod 20130726T112836Z cratos.locean-ipsl.upmc.fr (Linux)
+#
+#   * creation
 #
 #-
@@ -191,5 +124,5 @@
 log_date=$(date -u +"%Y%m%dT%H%M%SZ")
 #
-usage=" Usage : ${command} [--debug]"
+usage=" Usage : ${command} [--debug] -d dirin -good yyyymmdd_yyyymmdd -bad anything"
 #
 hostname=$(hostname)
@@ -209,4 +142,16 @@
 do
    case ${1} in
+      -good)
+         goodend=${2}
+         shift
+      ;;
+      -bad)
+         badend=${2}
+         shift
+      ;;
+      -d)
+         dirin=${2}
+         shift
+      ;;
       --debug)
          debug=1
@@ -224,43 +169,22 @@
 #
 # check parameters
-# N.A.
-#
-tool=ncrcat
-type ${tool} 1> /dev/null 2>&1
-status=${?}
-if [ ${status} -ne 0 ]
-then
-   echo "${command} : eee : tool ${tool} not found"
-   exit 1
-fi
-unset status
-unset tool
-#
-tool=ncks
-type ${tool} 1> /dev/null 2>&1
-status=${?}
-if [ ${status} -ne 0 ]
-then
-   echo "${command} : eee : tool ${tool} not found"
-   exit 1
-fi
-unset status
-unset tool
-#
-tool=ncatted
-type ${tool} 1> /dev/null 2>&1
-status=${?}
-if [ ${status} -ne 0 ]
-then
-   echo "${command} : eee : tool ${tool} not found"
-   exit 1
-fi
-unset status
-unset tool
+if [ ! -d ${dirin} ]
+then
+   echo " eee : ${dirin} not found"
+   exit 1
+fi
+#
+# check for permission on dirin
+if [ ! -x ${dirin} ]
+then
+   echo " eee : ${dirin} not reachable"
+   exit 1
+fi
+#++ check good validity
 #
 # check for ${PROJECT_LOG} definition
 if [ "${PROJECT_LOG}" = "" ]
 then
-   echo "${command} : eee : \${PROJECT_LOG} not defined"
+   echo "${command} : ${LINENO} : eee : \${PROJECT_LOG} not defined"
    exit 1
 fi
@@ -297,92 +221,60 @@
 echo "" 1>> ${log}
 echo "[Parameters]" 1>> ${log}
-echo "N.A." 1>> ${log}
+echo "dirin=${dirin}" 1>> ${log}
+echo "good=${goodend}" 1>> ${log}
+echo "bad=${badend}" 1>> ${log}
 echo "" 1>> ${log}
 #
-filein=${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc
-if [ ! -f ${filein} ]
-then
-    echo " eee : ${filein} not found" 1>> ${log}
-    exit 1 
-fi
-fileout=${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc
-if [ -f ${fileout} ]
-then
-      echo "eee : ${fileout} already exists" 1>>${log}
-      exit 1
-fi
-#
-rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null
-rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null
-#
-# extraction of the first time step 19890102
-ncks -h -d time,0,0 ${filein} ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
-status=${?}
-if [ ${status} -ne 0 ]
-then
-    echo "eee : pb with ncks" >> ${log} 2>&1
-    ncdump -h ${filein} >> ${log} 2>&1
-    exit 1
-fi
-unset status
-#
-# ++ check if tt[0] is really 19890102
-#
-# substract 1 to tt to simulate 19890101
-ncap2 -h -s "tt=tt-1" \
-    ${PROJECT_OD}/erai_lwr_step19890102.nc \
-    ${PROJECT_OD}/erai_lwr_step19890101.nc
-status=${?}
-if [ ${status} -ne 0 ] 
-then
-    echo "eee : pb with ncap2" >> ${log} 2>&1
-    ncdump -h ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
-    exit 1
-fi  
-unset status
-ls -l ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1
-ls -l ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1
-#
-# ++ check if tt[0] is really 19890101
-# 
-rm ${fileout}_bad_timerange 2> /dev/null
-ncrcat -h \
-       ${PROJECT_OD}/erai_lwr_step19890101.nc \
-       ${filein} \
-       ${fileout}_bad_timerange >> ${log} 2>&1
-status=${?}
-if [ ${status} -ne 0 ] 
-then
-    echo "eee : pb with ncrcat" >> ${log} 2>&1
-    ncdump -h ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1
-    ncdump -h ${filein} >> ${log} 2>&1
-    exit 1
-fi  
-unset status
-#
-ncatted -h -a timerange,global,o,c,"19890101 - 20091231" \
-       ${fileout}_bad_timerange \
-       ${fileout} >> ${log} 2>&1
-status=${?}
-if [ ${status} -ne 0 ]
-then
-    echo "eee : pb with ncatted" >> ${log} 2>&1
-    ncdump -h ${fileout}_bad_timerange >> ${log} 2>&1
-    exit 1
-fi 
-unset status
-#
-if [ ${debug} -eq 1 ]
-then
-    ncdump -v tt ${fileout} >> ${log} 2>&1
-fi
+# build list files
+varlist="lhf lwr netflux q2m shf sst swr t2m tau taux tauy ws"
+period_list="daily monthly"
+list_filein=""
+for var in $varlist
+do
+     for period in ${period_list}
+     do
+         if [ "${period}" == "daily" ]
+         then
+            suffix=1d
+         else
+            suffix=1m
+         fi
+         filein=${dirin}/${period}/${var}_tropflux_${suffix}_${badend}.nc
+         if [ ! -f ${filein} ]
+         then
+             echo " eee : ${filein} not found" 1>> ${log}
+             exit 1
+         else
+             list_filein=${list_filein}" ${filein}"
+         fi
+     done
+     unset period
+done
+unset period_list
+unset var
+unset varlist
+#
+# rename all files
+for filein in ${list_filein}
+do
+    echo "iii : rename ${filein}" >> ${log} 2>&1
+    bfileout=$(basename ${filein} ${badend}.nc)"${goodend}.nc"
+    fileout=$(dirname ${filein})/${bfileout}
+    unset bfileout
+    mv ${filein} ${fileout} >> ${log} 2>&1
+    status=${?}
+    if [ ${status} -ne 0 ]
+    then
+        echo "eee : pb with mv" >> ${log} 2>&1
+        ncdump -h ${filein} >> ${log} 2>&1
+        exit 1
+    fi
+    unset status
+    unset fileout
+done
+unset filein
 #
 # cleanning
-#++rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null
-#++rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null
-#++rm -f ${PROJECT_OD}/${fileout}_bad_timerange 2> /dev/null
-#
-unset fileout
-unset filein
+#++
 #++ set
 # end
