Index: trunk/src/compute_erai_daily_region_2d.sh
===================================================================
--- trunk/src/compute_erai_daily_region_2d.sh	(revision 50)
+++ trunk/src/compute_erai_daily_region_2d.sh	(revision 51)
@@ -16,5 +16,5 @@
 # ::
 #
-#  $ compute_erai_daily_region_2d.sh [--debug] [--diff_cmd arg]
+#  $ compute_erai_daily_region_2d.sh [--debug] [--diff_cmd arg] -b yyyymmdd -e yyyymmdd
 #
 # DESCRIPTION
@@ -23,14 +23,16 @@
 # .. option:: --diff_cmd <arg>
 #
-#    by default :samp:`ncflint` command is used to compute difference between NetCDF files
-#
-#    if :samp:`cdo` is specified here, this command will be used instead.
+#    By default :samp:`ncflint` command is used to compute difference between NetCDF files
+#
+#    If :samp:`cdo` is specified here, this command will be used instead.
 #
 # .. option:: --debug
 #
-#    if this option is set, :samp:`ncdump -v time` will be added to log file
-#
-#
-# Put in ${PROJECT_ID} ERA-Intermin reference files
+#    If this option is set, :samp:`ncdump -v time` will be added to log file
+#
+# .. option:: -b beginning date <yyyymmdd>
+# .. option:: -e end date <yyyymmdd>
+#
+# Put in ${PROJECT_ID} ERA-Intermin reference files.
 #
 # Log file is written on :file:`${PROJECT_LOG}/compute_erai_daily_region_2d.log.{YYYYMMDDTHHMMSSZ}`
@@ -78,5 +80,5 @@
 # you just have to run this tool ::
 #
-#  $ compute_erai_daily_region_2d.sh
+#  $ compute_erai_daily_region_2d.sh -b 19890101 -e 20091231
 #
 # And look at log file with ::
@@ -85,5 +87,4 @@
 #
 # and of course on files in ${PROJECT_ID}.
-#
 #
 # SEE ALSO
@@ -115,10 +116,10 @@
 # ====
 #
+# adjust yyyymmddb_min and yyyymmddb_max
+#
 # trouble with cdo reference (extra %23name in generated url using sphinx1.0.7)
 #
 # minimize use of generic characters (*) to avoid ambiguity
 #
-# parametrisation of year min and year max
-#
 # split get and process files
 #
@@ -135,7 +136,5 @@
 #  ncrcat: WARNING Intra-file non-monotonicity. Record coordinate "time" does not monotonically decrease between (input file /homedata/pinsard/log//compute_erai_daily_region_2d.20110126T154235Z.temp//temp_int_str_199012.nc record indices: 29, 30) (output file /homedata/pinsard/tropflux_d//erai_TROP_1d_19900101_19901231_str_gridOrig.nc record indices 363, 364) record coordinate values -0.000278, -0.000278
 #
-#
 #  this seems to be solved by using cdo instead of ncflint. to be confirmed !
-#
 #
 # no files *19890101* in /bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/FC_SF/1989/01/ :
@@ -157,4 +156,8 @@
 #
 # $URL$
+#
+# - fplod 20110429T114649Z aedon.locean-ipsl.upmc.fr (Darwin)
+#
+#   * add -b and -e parameters
 #
 # - fplod 20110203T101720Z aedon.locean-ipsl.upmc.fr (Darwin)
@@ -214,4 +217,13 @@
    AIX|IRIX64)
       echo "www : no specific posix checking"
+      date_cmd=date
+   ;;
+   Darwin)
+      set -o posix
+      date_cmd=gdate
+   ;;
+   Linux)
+      set -o posix
+      date_cmd=date
    ;;
    *)
@@ -226,12 +238,18 @@
 log_date=$(date -u +"%Y%m%dT%H%M%SZ")
 #
-usage=" Usage : ${command} --debug --diff_cmd [ncflint|cdo]"
+usage=" Usage : ${command} [--debug] [--diff_cmd [ncflint|cdo]] -b yyyymmdd -e yyyymmdd"
 #
 hostname=$(hostname)
+#
+yyyymmddb_min=19890101
+yyyymmdde_max=20091231
+#
 # default
 diff_cmd=ncflint
 debug=0
-#
-minargcount=0
+yyyymmddb=19890101
+yyyymmdde=20091231
+#
+minargcount=4
 if [ ${#} -lt ${minargcount} ]
 then
@@ -250,4 +268,14 @@
       --diff_cmd)
          diff_cmd=${2}
+         shift
+      ;;
+      -b)
+         # first date to get
+         yyyymmddb=${2}
+         shift
+      ;;
+      -e)
+         # last date to get
+         yyyymmdde=${2}
          shift
       ;;
@@ -264,4 +292,43 @@
 #
 set -u
+# check parameters
+#
+${date_cmd} -d "${yyyymmddb}" > /dev/null
+status_date=${?}
+if [ ${status_date} -ne 0 ]
+then
+     echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid"
+     exit 1
+fi
+unset status_date
+#
+if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]]
+then
+     echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than ${yyyymmddb_min}"
+     exit 1
+fi
+#
+${date_cmd} -d "${yyyymmdde}" > /dev/null
+status_date=${?}
+if [ ${status_date} -ne 0 ]
+then
+     echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid"
+     exit 1
+fi
+unset status_date
+#
+if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]]
+then
+     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to ${yyyymmdde_max}"
+     exit 1
+fi
+#
+#
+if [[ "${yyyymmdde}" < "${yyyymmddb}" ]]
+then
+     echo "${command} : eee : yyyymmdde ${yyyymmdde} must be equal or greater than yyyymmddb ${yyyymmddb}"
+     exit 1
+fi
+# 
 # test if diff_cmd valid
 case ${diff_cmd} in
@@ -344,8 +411,8 @@
 maxlon=360.
 reg=TROP
-yearmin=1989
-yearmax=2009
-monthmin=1
-monthmax=12
+yearmin=$(${date_cmd} -d "${yyyymmddb}" +%Y)
+yearmax=$(${date_cmd} -d "${yyyymmdde}" +%Y)
+monthmin=$(${date_cmd} -d "${yyyymmddb}" +%m)
+monthmax=$(${date_cmd} -d "${yyyymmdde}" +%m)
 cmonthmin=$(printf "%2.2d" ${monthmin})
 cmonthmax=$(printf "%2.2d" ${monthmax})
