source: trunk/src/get_swr.sh @ 81

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

progress on swr and olr processing

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#           graph [
30#           rankdir="TB",
31#           ]
32#
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"];
34#
35#           file_swr [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/sw_icssp_yyyy.nc"];
36#
37#           get_swr [shape=box,
38#           fontname=Courier,
39#           color=blue,
40#           URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/get_swr.sh"
41#           label="${PROJECT}/src/get_swr.sh"];
42#
43#           {swr_ref} -> {get_swr} -> {file_swr}
44#
45#          }
46#
47# EXAMPLES
48# ========
49#
50# You don't have any RAMA reference data, you just have to run this tool ::
51#
52#  $ get_swr.sh
53#
54# And look at log file with ::
55#
56#  $ tlogd.sh get_swr
57#
58# and of course on files in ${PROJECT_ID}.
59#
60# SEE ALSO
61# ========
62#
63# :ref:`data_in_swr`
64#
65# :ref:`project_profile.sh`
66#
67# TODO
68# ====
69#
70# complete description
71#
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:
74#
75#  - YYYY and MM are year and month
76#  - SS is LW (longwave) and SW (shortwave)
77#
78# study wget status (no exit now on non null wget status)
79#
80# chain to concatenation and geobox reduction .. and rename sw\_ to swr file
81# variable name ?? to swr
82#
83# EVOLUTIONS
84# ==========
85#
86# $Id$
87#
88# $URL$
89#
90# - fplod 20110811T153513Z aedon.locean-ipsl.upmc.fr (Darwin)
91#
92#   * creation
93#
94#-
95system=$(uname)
96case "${system}" in
97   AIX|IRIX64)
98      echo "www : no specific posix checking"
99      date_cmd=date
100   ;;
101   Darwin)
102      set -o posix
103      date_cmd=gdate
104   ;;
105   Linux)
106      set -o posix
107      date_cmd=date
108   ;;
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#
141# check for ${PROJECT_LOG} definition
142if [ "${PROJECT_LOG}" = "" ]
143then
144   echo "${command} : eee : \${PROJECT_LOG} not defined"
145   exit 1
146fi
147#
148# check for ${PROJECT_LOG} existence
149if [ ! -d ${PROJECT_LOG} ]
150then
151   echo "${command} : eee : ${PROJECT_LOG} not found"
152   exit 1
153fi
154#
155# check for permission access on PROJECT_LOG
156if [ ! -x ${PROJECT_LOG} ]
157then
158   echo "${command} : eee : ${PROJECT_LOG} not reachable"
159   exit 1
160fi
161#
162# check for write permission on PROJECT_LOG
163if [ ! -w ${PROJECT_LOG} ]
164then
165   echo "${command} : eee : ${PROJECT_LOG} not writable"
166   exit 1
167fi
168#
169log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date}
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#
177yearmin=1985
178yearmax=2007
179#
180varlist="sw"
181#
182locref="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/"
183#
184list_url=""
185#
186# build URL = f(year,var)
187yyyy=${yearmin}
188while [ ${yyyy} -le ${yearmax} ]
189do
190   for var in ${varlist}
191   do
192       list_url="${list_url} ${locref}/${var}_isccp_${yyyy}.nc.gz"
193   done
194   unset var
195   yyyy=$(( ${yyyy} + 1 ))
196done
197unset varlist
198unset locref
199#
200# if file_gz is not already in ${PROJECT_ID}, get it
201for url in ${list_url}
202do
203  file_gz=${PROJECT_ID}/$(basename ${url})
204  file=${PROJECT_ID}/$(basename ${file_gz} .gz)
205  if [ ! -f ${file} ]
206  then
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
227done
228unset file_gz
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.