source: trunk/src/get_swr.sh @ 199

Last change on this file since 199 was 199, checked in by pinsard, 11 years ago

fix svn properties

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