Index: trunk/src/get_rama_netcdf.sh
===================================================================
--- trunk/src/get_rama_netcdf.sh	(revision 4)
+++ trunk/src/get_rama_netcdf.sh	(revision 48)
@@ -10,5 +10,4 @@
 # ==============================================
 #
-#
 # SYNOPSIS
 # ========
@@ -23,4 +22,61 @@
 # ``get_rama_netcdf.sh`` get RAMA reference files
 #
+# bf
+#   buoyancy flux
+# d
+#   sigma-theta
+# dyn
+#   dynamic height
+# emp
+#   e-p
+# iso
+#   20C depth
+# met
+#   wind (u,v,speed,direction),  airT, hum rel, SST   (= w + airt + rh)
+# pos
+#   lon, lat
+# rad
+#   shortwave down
+# rf
+#   rain heat flux
+# w
+#   wind
+#
+# Log file is written on :file:`${TROPFLUX_LOG}/get_rama_netcdf.log.{YYYYMMDDTHHMMSSZ}`
+#
+#     .. graphviz::
+#
+#        digraph get_rama_netcdf {
+#           graph [
+#           rankdir="TB",
+#           ]
+#
+#           rama_ref [shape=diamond,fontname=Courier,label="ftp://ftp.pmel.noaa.gov/cdf/sites/daily/*_*_dy.cdf"];
+#
+#           file_rama  [shape=ellipse,fontname=Courier,label="${TROPFLUX_ID}/*_*_dy.cdf"];
+#
+#           get_rama_netcdf [shape=box,
+#           fontname=Courier,
+#           color=blue,
+#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_rama_netcdf.sh"
+#           label="${TROPFLUX}/src/get_rama_netcdf.sh"];
+#
+#           {rama_ref} -> {get_rama_netcdf} -> {file_rama}
+#
+#          }
+#
+# EXAMPLES
+# ========
+#
+# You don't have any RAMA reference data, you just have to run this tool ::
+#
+#  $ get_rama_netcdf.sh
+#
+# And look at log file with ::
+#
+#  $ tlogd.sh get_rama_netcdf
+#
+# and of course on files in ${TROPFLUX_ID}.
+#
 # SEE ALSO
 # ========
@@ -28,16 +84,33 @@
 # :ref:`guide data RAMA <data_in_rama>`
 #
+# :ref:`tropflux_profile.sh`
+#
 # TODO
 # ====
 #
-# trace
-#
-# hard coded directory - usage of ${TROPFLUX_ID}
-#
-# coding rules
+# list of variables and sites in DESCRIPTION
+#
+# do we really need all these variables and sites
+#
+# Liste complète de RAMA::
+#
+#  sitelist="                   16s55e    12s55e    8s55e    4s55e    1.5s55e    0n55e    1.5n55e    4n55e"
+#  sitelist="${sitelist}                                                                               15n65e"
+#  sitelist="${sitelist}                    12s67e     8s67e    4s67e    1.5s67e    0n67e     1.5n67e    4n67e    8n67e"
+#  sitelist="${sitelist}  16s80.5e 12s80.5e 8s80.5e 4s80.5e 1.5s80.5e 0n80.5e 1.5n80.5e 4n80.5e"
+#  sitelist="${sitelist}               1.5s90e 0n90e 1.5n90e 4n90e 8n90e 12n90e 15n90e
+#  sitelist="${sitelist}  16s95e 12s95e 8s95e  5s95e"
+#
+# study wget status (no exit now on non null wget status)
 #
 # EVOLUTIONS
 # ==========
 #
+# $Id$
+#
+# - fplod 20110421T133632Z aedon.locean-ipsl.upmc.fr (Darwin)
+#
+#   * consolidation
+#
 # - fplod 20101213T160928Z aedon.locean-ipsl.upmc.fr (Darwin)
 #
@@ -49,38 +122,142 @@
 #
 #-
-
-
-dir=/Users/jv/data/RAMA/data/
-
-# bf  : buoyancy flux
-# d   : sigma-theta
-# dyn : dynamic height
-# emp : e-p
-# iso : 20C depth
-# met : wind (u,v,speed,direction),  airT, hum rel, SST   (= w + airt + rh)
-# pos : lon, lat
-# rad : shortwave down
-# rf  : rain heat flux
-# w   : wind
-
+system=$(uname)
+case "${system}" in
+   AIX|IRIX64)
+      echo "www : no specific posix checking"
+   ;;
+   *)
+     set -o posix
+   ;;
+esac
+unset system
+#
+LANG=POSIX
+#
+command=$(basename ${0})
+log_date=$(date -u +"%Y%m%dT%H%M%SZ")
+#
+usage=" Usage : ${command}"
+#
+hostname=$(hostname)
+#
+# default
+# N.A. because no parameters
+#
+set -u
+#
+# test if wget available
+tool=wget
+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
+#
+# check for ${TROPFLUX_LOG} definition
+if [ "${TROPFLUX_LOG}" = "" ]
+then
+   echo "${command} : eee : \${TROPFLUX_LOG} not defined"
+   exit 1
+fi
+#
+# check for ${TROPFLUX_LOG} existence
+if [ ! -d ${TROPFLUX_LOG} ]
+then
+   echo "${command} : eee : ${TROPFLUX_LOG} not found"
+   exit 1
+fi
+#
+# check for permission access on TROPFLUX_LOG
+if [ ! -x ${TROPFLUX_LOG} ]
+then
+   echo "${command} : eee : ${TROPFLUX_LOG} not reachable"
+   exit 1
+fi
+#
+# check for write permission on TROPFLUX_LOG
+if [ ! -w ${TROPFLUX_LOG} ]
+then
+   echo "${command} : eee : ${TROPFLUX_LOG} not writable"
+   exit 1
+fi
+#
+log=${TROPFLUX_LOG}/$(basename ${0} .sh).log.${log_date}
+echo "[Context]" 1>> ${log}
+echo "command=$(basename ${0})" 1>>${log}
+echo "hostname=${hostname}" 1>> ${log}
+echo "runtime=${log_date}" 1>> ${log}
+unset log_date
+echo "" 1>> ${log}
+#
 varlist="adcp airt bf bp cur d dyn emp evap heat iso lw lwnet met pos qlat qnet qsen rad rain rf rh s ssd sss sst swnet t tau w"
+#
 sitelist="12s55e 8s55e 8s67e 8s80.5e 4s80.5e 1.5s80.5e 0n80.5e 1.5n80.5e 1.5s90e 0n90e 1.5n90e 4n90e 8n90e 12n90e 15n90e 5s95e"
 
-cd $dir
-for site in $sitelist ; do
- for var in $varlist ; do
-  wget --password=G10b@LCh@Ng3 ftp://taopmelftp@ftp.pmel.noaa.gov/cdf/sites/daily/${var}${site}_dy.cdf
- done
-done
-
-ls -l
-
 #
 #Liste complète de RAMA:
 #sitelist="                   16s55e    12s55e    8s55e    4s55e    1.5s55e    0n55e    1.5n55e    4n55e"
-#siteliste="$sitelist                                                                               15n65e"
-#siteliste="$sitelist                    12s67e     8s67e    4s67e    1.5s67e    0n67e     1.5n67e    4n67e    8n67e"
-#siteliste="$sitelist  16s80.5e 12s80.5e 8s80.5e 4s80.5e 1.5s80.5e 0n80.5e 1.5n80.5e 4n80.5e"
-#siteliste="$sitelist               1.5s90e 0n90e 1.5n90e 4n90e 8n90e 12n90e 15n90e
-#siteliste="$sitelist  16s95e 12s95e 8s95e  5s95e"
-#
+#sitelist="${sitelist}                                                                               15n65e"
+#sitelist="${sitelist}                    12s67e     8s67e    4s67e    1.5s67e    0n67e     1.5n67e    4n67e    8n67e"
+#sitelist="${sitelist}  16s80.5e 12s80.5e 8s80.5e 4s80.5e 1.5s80.5e 0n80.5e 1.5n80.5e 4n80.5e"
+#sitelist="${sitelist}               1.5s90e 0n90e 1.5n90e 4n90e 8n90e 12n90e 15n90e
+#sitelist="${sitelist}  16s95e 12s95e 8s95e  5s95e"
+#
+#
+locref="ftp://ftp.pmel.noaa.gov/cdf/sites/daily"
+#
+list_url=""
+#
+# build URL = f(site,var)
+for site in ${sitelist}
+do
+   for var in ${varlist}
+   do
+       list_url="${list_url} ${locref}/${var}${site}_dy.cdf"
+   done
+done
+unset site
+unset var
+unset varlist
+unset sitelist
+unset locref
+#
+# if file is not already in ${TROPFLUX_ID}, get it
+for url in ${list_url}
+do
+  file=${TROPFLUX_ID}/$(basename ${url})
+  if [ ! -f ${file} ]
+  then
+     wget --tries=1 --no-verbose -P ${TROPFLUX_ID} \
+        --user=taopmelftp \
+        --password=G10b@LCh@Ng3 \
+        ${url} >> ${log} 2>&1
+     wget_status=${?}
+     if [ ${wget_status} -ne 0 ]
+     then
+        echo "${command} : eee : ${url} not found" >> ${log} 2>&1
+        # ++ exit 1
+     else
+        echo "${command} : iii : ${url} found" >> ${log} 2>&1
+     fi
+     unset wget_status
+  else
+     echo "iii : ${file} exists" >> ${log}
+  fi
+done
+unset file
+unset url
+unset list_url
+#
+unset command
+unset log
+unset hostname
+unset usage
+#
+# end
+set
+exit 0
