IS-ENES/core2_cmip: std_plots.sh.clima

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