source: trunk/src/get_swr.sh @ 82

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

progress on swr and olr processing

File size: 4.5 KB
RevLine 
[4]1#! /bin/sh
2#+
3#
[81]4# .. program:: get_swr.sh
[4]5#
[81]6# .. _get_swr.sh:
[4]7#
[81]8# ==========
9# get_swr.sh
10# ==========
[4]11#
12# SYNOPSIS
13# ========
14#
15# ::
16#
[81]17#  $ get_swr.sh
[4]18#
19# DESCRIPTION
20# ===========
21#
[81]22# ``get_swr.sh`` get SWR reference files.
[4]23#
[81]24# Log file is written on :file:`${PROJECT_LOG}/get_swr.log.{YYYYMMDDTHHMMSSZ}`
[48]25#
26#     .. graphviz::
27#
[81]28#        digraph get_swr {
[48]29#           graph [
30#           rankdir="TB",
31#           ]
32#
[81]33#           swr_ref [shape=diamond,fontname=Courier,label="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/sw_icssp_yyyy.nc.gz"];
[48]34#
[81]35#           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/sw_icssp_yyyy.nc"];
[48]36#
[81]37#           get_swr [shape=box,
[48]38#           fontname=Courier,
39#           color=blue,
[81]40#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_swr.sh"
41#           label="${PROJECT}/src/get_swr.sh"];
[48]42#
[81]43#           {swr_ref} -> {get_swr} -> {file_swr}
[48]44#
45#          }
46#
47# EXAMPLES
48# ========
49#
50# You don't have any RAMA reference data, you just have to run this tool ::
51#
[81]52#  $ get_swr.sh
[48]53#
54# And look at log file with ::
55#
[81]56#  $ tlogd.sh get_swr
[48]57#
[50]58# and of course on files in ${PROJECT_ID}.
[48]59#
[4]60# SEE ALSO
61# ========
62#
[81]63# :ref:`data_in_swr`
[4]64#
[50]65# :ref:`project_profile.sh`
[48]66#
[4]67# TODO
68# ====
69#
[81]70# complete description
[4]71#
[81]72# Eventually: we should retrieve them from ISCCP page
73# (ftp://isccp.giss.nasa.gov/pub/data/FC/ ) and interpolate them we need FD${YYYY}${MM}__${SS}${FF}SFC.EQ files where:
[4]74#
[81]75#  - YYYY and MM are year and month
76#  - SS is LW (longwave) and SW (shortwave)
[4]77#
[48]78# study wget status (no exit now on non null wget status)
79#
[81]80# chain to concatenation and geobox reduction .. and rename sw\_ to swr file
81# variable name ?? to swr
82#
[4]83# EVOLUTIONS
84# ==========
85#
[48]86# $Id$
87#
[81]88# $URL$
[48]89#
[81]90# - fplod 20110811T153513Z aedon.locean-ipsl.upmc.fr (Darwin)
[48]91#
[4]92#   * creation
93#
94#-
[48]95system=$(uname)
96case "${system}" in
97   AIX|IRIX64)
98      echo "www : no specific posix checking"
[81]99      date_cmd=date
[48]100   ;;
[81]101   Darwin)
102      set -o posix
103      date_cmd=gdate
104   ;;
105   Linux)
106      set -o posix
107      date_cmd=date
108   ;;
[48]109   *)
110     set -o posix
111   ;;
112esac
113unset system
114#
115LANG=POSIX
116#
117command=$(basename ${0})
118log_date=$(date -u +"%Y%m%dT%H%M%SZ")
119#
120usage=" Usage : ${command}"
121#
122hostname=$(hostname)
123#
124# default
125# N.A. because no parameters
126#
127set -u
128#
129# test if wget available
130tool=wget
131type ${tool} 1> /dev/null 2>&1
132status=${?}
133if [ ${status} -ne 0 ]
134then
135   echo "${command} : eee : tool ${tool} not found"
136   exit 1
137fi
138unset status
139unset tool
140#
[50]141# check for ${PROJECT_LOG} definition
142if [ "${PROJECT_LOG}" = "" ]
[48]143then
[50]144   echo "${command} : eee : \${PROJECT_LOG} not defined"
[48]145   exit 1
146fi
147#
[50]148# check for ${PROJECT_LOG} existence
149if [ ! -d ${PROJECT_LOG} ]
[48]150then
[50]151   echo "${command} : eee : ${PROJECT_LOG} not found"
[48]152   exit 1
153fi
154#
[50]155# check for permission access on PROJECT_LOG
156if [ ! -x ${PROJECT_LOG} ]
[48]157then
[50]158   echo "${command} : eee : ${PROJECT_LOG} not reachable"
[48]159   exit 1
160fi
161#
[50]162# check for write permission on PROJECT_LOG
163if [ ! -w ${PROJECT_LOG} ]
[48]164then
[50]165   echo "${command} : eee : ${PROJECT_LOG} not writable"
[48]166   exit 1
167fi
168#
[50]169log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
[48]170echo "[Context]" 1>> ${log}
171echo "command=$(basename ${0})" 1>>${log}
172echo "hostname=${hostname}" 1>> ${log}
173echo "runtime=${log_date}" 1>> ${log}
174unset log_date
175echo "" 1>> ${log}
176#
[81]177yearmin=1985
178yearmax=2007
[48]179#
[81]180varlist="sw"
[3]181#
[81]182locref="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/"
[3]183#
[48]184list_url=""
185#
[81]186# build URL = f(year,var)
187yyyy=${yearmin}
188while [ ${yyyy} -le ${yearmax} ]
[48]189do
190   for var in ${varlist}
191   do
[81]192       list_url="${list_url} ${locref}/${var}_isccp_${yyyy}.nc.gz"
[48]193   done
[81]194   unset var
195   yyyy=$(( ${yyyy} + 1 ))
[48]196done
197unset varlist
198unset locref
199#
[81]200# if file_gz is not already in ${PROJECT_ID}, get it
[48]201for url in ${list_url}
202do
[81]203  file_gz=${PROJECT_ID}/$(basename ${url})
204  file=${PROJECT_ID}/$(basename ${file_gz} .gz)
[48]205  if [ ! -f ${file} ]
206  then
[81]207      if [ ! -f ${file_gz} ]
208      then
209         wget --tries=1 --no-verbose -P ${PROJECT_ID} \
210            ${url} >> ${log} 2>&1
211         wget_status=${?}
212         if [ ${wget_status} -ne 0 ]
213         then
214            echo "${command} : eee : ${url} not found" >> ${log} 2>&1
215            # ++ exit 1
216         else
217            echo "${command} : iii : ${url} found" >> ${log} 2>&1
218         fi
219         unset wget_status
220      else
221         echo "iii : ${file_gz} exists" >> ${log}
222         gunzip -c ${file_gz} > ${file}
223      fi
224   else
225      echo "iii : ${file} exists" >> ${log}
226   fi
[48]227done
[81]228unset file_gz
[48]229unset file
230unset url
231unset list_url
232#
233unset command
234unset log
235unset hostname
236unset usage
237#
238# end
239set
240exit 0
Note: See TracBrowser for help on using the repository browser.