source: trunk/src/get_swr.sh

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

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