IS-ENES/core2_cmip: time_series.sh.clima

File time_series.sh.clima, 4.6 KB (added by flavoni, 10 years ago)
Line 
1#!/bin/sh
2#
3# AUTHOR - date
4# ===========
5# Simona Flavoni  - 02/2010 - LOCEAN
6#
7# DESCRIPTION
8# ===========
9# Graphics outputs files are written in my_IDL/PS/ps_ts/.
10#
11# A global document with all plots in Postscript, PDF or HTML file can be produced.
12#
13# EXAMPLES
14# ========
15# $ ./time_series.sh -exp1 sEXP1 -exp2 sEXP2 -ystart year1 -yend year2 -format pdf
16#
17# PROBLEMS
18# ========
19# no batch processing possible because of SAXO interactiviy Seb is working on it ...
20#
21# TODO
22# ====
23# portability on linux
24# define overriding policy
25# finalize ps and pdf production
26#
27usage=" Usage : ${command} -exp1 exp1 -exp2 exp2 -ystart start -yend end -format pdf
28 exp1 is your experience name
29 exp2 is name of experience of reference
30 ystart is the first year from which you want to compute Time Series
31 yend is the last year for which you want to compute Time Series
32 example:  ./time_series.sh -exp1 core2000 -exp2 core2000 -ystart 1 -yend 2000 -format pdf "
33#
34minargcount=10
35if [ ${#} -lt ${minargcount} ]; then
36 echo "Not enought arguments"
37 echo "${usage}"
38 exit 1
39fi
40#
41while [ ! -z "${1}" ] # ++ pb bash
42do
43 case ${1} in
44     -exp1)  exp1=${2}        shift  ;;
45     -exp2)  exp2=${2}        shift  ;;
46     -ystart)   start=${2}   shift   ;;
47     -yend)  end=${2}     shift   ;;
48     -format)   format=${2}     shift   ;;
49     -h) 
50    echo "${usage}"
51    exit
52    ;;
53     *) # other choice
54    echo "${usage}"
55    exit 1
56    ;;
57 esac
58 shift # next flag
59done
60#
61# ++ check parameters
62set -u
63#
64# define output directory for POSTCRIPT files
65#++ change directory
66psdir=/Users/sflod/TOOLS/my_IDL/PS/CLIMATO/ts_ps
67pdfdir=/Users/sflod/TOOLS/my_IDL/PS/CLIMATO/ts_pdf
68htmldir=/Users/sflod/TOOLS/my_IDL/HTML
69# test if ${psdir} already exists
70if [ -d ${psdir} ]; then
71 echo "${psdir} already exist"
72 #+++exit 1
73else
74 mkdir -p ${psdir}
75fi 
76# test if ${pdfdir} already exists
77if [ -d ${pdfdir} ]; then
78 echo "${psdir} already exist"
79 #+++exit 1
80else
81 mkdir -p ${pdfdir}
82fi 
83
84# memorize current IDL_STARTUP file
85memo_idl_startup=${IDL_STARTUP}
86
87# generation of IDL commands file to launch several std_plots commands
88rm /tmp/time_series_multi.pro 2> /dev/null
89cat << EOF >> /tmp/time_series_multi.pro
90 psdir='${psdir}'
91 std_ts,'${exp1}','${exp2}',${start},${end},/postscript
92 exit
93EOF
94#
95idl_command='/Applications/itt/idl64/bin/idl'  # !! only on my mac
96#
97# check if IDL available
98type ${idl_command}
99status_type=${?}
100if [ ${status_type} -ne 0 ]
101then
102 echo "eee : idl not found"
103 exit 1
104fi
105# debug
106more /tmp/time_series_multi.pro
107#
108# launch IDL
109${idl_command} /tmp/time_series_multi.pro
110status_idl=${?}
111# test if idl returns ok
112# echo "iii : ${status_idl}"
113#
114# restore IDL_STARTUP file
115IDL_STARTUP=${memo_idl_startup}
116export IDL_STARTUP
117
118# produce the final document
119case ${format} in
120    pdf)
121   rm ${pdfdir}/all_ts.pdf 2> /dev/null
122   echo "psdir: ${psdir}"
123   for file in ${psdir}/*.ps ; do
124       echo "ps2pdf"
125      ps2pdf -sPAPERSIZE=a4 ${file}
126   done
127   ls ${pdfdir}
128   mv *.pdf ${pdfdir}/.
129   texexec --pdfarrange --result=/tmp/all_ts.pdf ${pdfdir}/*.pdf
130   rm -rf *.aux *.log /tmp/*.log
131   mv /tmp/all_ts.pdf ${pdfdir}/all_ts.pdf
132#commented because convert gives images of bad quality
133#  convert ${psdir}/*.ps /tmp/all_ts.pdf
134#       convert -resize 800x600 ${psdir}/${exp1}_${exp2}/ps/*.ps /tmp/all_ts.pdf
135   ;;
136    html)
137   rm /tmp/time_series.html 2> /dev/null
138# check if convert available
139   convert_command='/sw/bin/convert'  # !! only on my mac
140   type ${convert_command}
141   status_type=${?}
142   if [ ${status_type} -ne 0 ]
143   then
144       echo "eee : convert not found"
145       exit 1
146   fi
147# debug
148   
149   for file in `ls ${psdir}/*.ps | sed -e "s/\.ps//"` ; do
150       ${convert_command} -antialias  ${file}.ps  ${file}.png
151   done
152    # creation of a HTML file
153   cat << EOF > /tmp/time_series.html
154   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
155   <html xmlns="http://www.w3.org/1999/xhtml">
156   <head>
157   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
158        <hr>
159         </head>
160   <body>
161EOF
162   cat /tmp/time_series.txt >>  /tmp/time_series.html
163   cat << EOF >> /tmp/time_series.html
164<hr/>
165EOF
166   
167   cat << EOF >> /tmp/time_series.html
168
169  </body>
170  </html>
171EOF
172   more /tmp/time_series.html
173   ;;
174    *)   
175   echo " format ${format} not implemented"
176   exit 1
177   ;;
178esac
179
180    #
181#=====================
182# prepare to put images on dods
183# +++ to finish it
184#LOGIN=xxxx
185#Tag_Name=ORCA2_LIM2
186#rsh ${LOGIN}@gaya.idris.fr exec /bin/ksh <<EOF
187#       cd ${homegaya}/IGCM_OUT/${Tag_Name}/CORE2/CLIMA/ts_pdf/${exp1}
188#       /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${Tag_Name}/CORE2/CLIMA/ts_pdf/${exp1} > /dev/null 2>&1
189#       /usr/local/bin/dods_cp ${exp1} DODS/pub/${LOGIN}/${Tag_Name}/CORE2/CLIMA/ts_pdf/${exp1} > /dev/null 2>&1
190#EOF
191#=====================
192# end
193exit 0