[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] | 95 | system=$(uname) |
---|
| 96 | case "${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 | ;; |
---|
| 112 | esac |
---|
| 113 | unset system |
---|
| 114 | # |
---|
| 115 | LANG=POSIX |
---|
| 116 | # |
---|
| 117 | command=$(basename ${0}) |
---|
| 118 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
| 119 | # |
---|
| 120 | usage=" Usage : ${command}" |
---|
| 121 | # |
---|
| 122 | hostname=$(hostname) |
---|
| 123 | # |
---|
| 124 | # default |
---|
| 125 | # N.A. because no parameters |
---|
| 126 | # |
---|
| 127 | set -u |
---|
| 128 | # |
---|
| 129 | # test if wget available |
---|
| 130 | tool=wget |
---|
| 131 | type ${tool} 1> /dev/null 2>&1 |
---|
| 132 | status=${?} |
---|
| 133 | if [ ${status} -ne 0 ] |
---|
| 134 | then |
---|
| 135 | echo "${command} : eee : tool ${tool} not found" |
---|
| 136 | exit 1 |
---|
| 137 | fi |
---|
| 138 | unset status |
---|
| 139 | unset tool |
---|
| 140 | # |
---|
[50] | 141 | # check for ${PROJECT_LOG} definition |
---|
| 142 | if [ "${PROJECT_LOG}" = "" ] |
---|
[48] | 143 | then |
---|
[50] | 144 | echo "${command} : eee : \${PROJECT_LOG} not defined" |
---|
[48] | 145 | exit 1 |
---|
| 146 | fi |
---|
| 147 | # |
---|
[50] | 148 | # check for ${PROJECT_LOG} existence |
---|
| 149 | if [ ! -d ${PROJECT_LOG} ] |
---|
[48] | 150 | then |
---|
[50] | 151 | echo "${command} : eee : ${PROJECT_LOG} not found" |
---|
[48] | 152 | exit 1 |
---|
| 153 | fi |
---|
| 154 | # |
---|
[50] | 155 | # check for permission access on PROJECT_LOG |
---|
| 156 | if [ ! -x ${PROJECT_LOG} ] |
---|
[48] | 157 | then |
---|
[50] | 158 | echo "${command} : eee : ${PROJECT_LOG} not reachable" |
---|
[48] | 159 | exit 1 |
---|
| 160 | fi |
---|
| 161 | # |
---|
[50] | 162 | # check for write permission on PROJECT_LOG |
---|
| 163 | if [ ! -w ${PROJECT_LOG} ] |
---|
[48] | 164 | then |
---|
[50] | 165 | echo "${command} : eee : ${PROJECT_LOG} not writable" |
---|
[48] | 166 | exit 1 |
---|
| 167 | fi |
---|
| 168 | # |
---|
[50] | 169 | log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} |
---|
[48] | 170 | echo "[Context]" 1>> ${log} |
---|
| 171 | echo "command=$(basename ${0})" 1>>${log} |
---|
| 172 | echo "hostname=${hostname}" 1>> ${log} |
---|
| 173 | echo "runtime=${log_date}" 1>> ${log} |
---|
| 174 | unset log_date |
---|
| 175 | echo "" 1>> ${log} |
---|
| 176 | # |
---|
[81] | 177 | yearmin=1985 |
---|
| 178 | yearmax=2007 |
---|
[48] | 179 | # |
---|
[81] | 180 | varlist="sw" |
---|
[3] | 181 | # |
---|
[81] | 182 | locref="ftp://ftp.whoi.edu/pub/science/oaflux/data_v3/daily/radiation_1985-2007/" |
---|
[3] | 183 | # |
---|
[48] | 184 | list_url="" |
---|
| 185 | # |
---|
[81] | 186 | # build URL = f(year,var) |
---|
| 187 | yyyy=${yearmin} |
---|
| 188 | while [ ${yyyy} -le ${yearmax} ] |
---|
[48] | 189 | do |
---|
| 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] | 196 | done |
---|
| 197 | unset varlist |
---|
| 198 | unset locref |
---|
| 199 | # |
---|
[81] | 200 | # if file_gz is not already in ${PROJECT_ID}, get it |
---|
[48] | 201 | for url in ${list_url} |
---|
| 202 | do |
---|
[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] | 227 | done |
---|
[81] | 228 | unset file_gz |
---|
[48] | 229 | unset file |
---|
| 230 | unset url |
---|
| 231 | unset list_url |
---|
| 232 | # |
---|
| 233 | unset command |
---|
| 234 | unset log |
---|
| 235 | unset hostname |
---|
| 236 | unset usage |
---|
| 237 | # |
---|
| 238 | # end |
---|
| 239 | set |
---|
| 240 | exit 0 |
---|