1 | #!/bin/sh |
---|
2 | #+ |
---|
3 | # |
---|
4 | # .. program:: std_main.sh |
---|
5 | # |
---|
6 | # ================ |
---|
7 | # std_main.sh |
---|
8 | # ================ |
---|
9 | # |
---|
10 | # ------------------------------------- |
---|
11 | # launch idl scripts to produce graphics diagnostics in Postscript, PDF or HTML document |
---|
12 | # ------------------------------------- |
---|
13 | # |
---|
14 | # SYNOPSIS |
---|
15 | # ======== |
---|
16 | # |
---|
17 | # ``std_main.sh -ts`` or ``std_main.sh -plot`` |
---|
18 | # |
---|
19 | # DESCRIPTION |
---|
20 | # =========== |
---|
21 | # |
---|
22 | # .. option:: -ts to produce time series |
---|
23 | # .. option:: -plot to produce maps and sections |
---|
24 | # .. option:: -html to produce html document |
---|
25 | # .. option:: -pdf to produce pdf document |
---|
26 | # .. option:: -noidl to skip the call to IDL and the production of Postscript |
---|
27 | # .. option:: -vm to use IDL virtual machine (free) instead of IDL |
---|
28 | # .. option:: -help to get help! |
---|
29 | # |
---|
30 | # variables have to be defined in std_plot_vardef.sh (or std_ts_vardef.sh) |
---|
31 | # before calling std_main.sh -plot (or std_main.sh -ts) |
---|
32 | # |
---|
33 | # EXAMPLES |
---|
34 | # ======== |
---|
35 | # $ ./std_main.sh -ts html |
---|
36 | # $ ./std_main.sh -ts pdf -noidl |
---|
37 | # |
---|
38 | # $ ./std_main.sh -plot -pdf -vm |
---|
39 | # |
---|
40 | # AUTHOR - date |
---|
41 | # =========== |
---|
42 | # Françoise Pinsard - 01/2010 - LOCEAN |
---|
43 | # Simona Flavoni - 01/2010 - LOCEAN |
---|
44 | # Sebastien Masson - 04/2011 - LOCEAN |
---|
45 | # |
---|
46 | #----------------------------------------------------------- |
---|
47 | # Usage... |
---|
48 | #----------------------------------------------------------- |
---|
49 | # |
---|
50 | #- |
---|
51 | system=$(uname) |
---|
52 | case "${system}" in |
---|
53 | AIX|IRIX64) |
---|
54 | echo " www : no specific posix checking" |
---|
55 | ;; |
---|
56 | *) |
---|
57 | set -o posix |
---|
58 | ;; |
---|
59 | esac |
---|
60 | # |
---|
61 | usage="Usage: std_main.sh [OPTION] |
---|
62 | Options |
---|
63 | -ts to produce time series |
---|
64 | -plot to produce maps and sections |
---|
65 | -html to produce html document |
---|
66 | -pdf to produce pdf document |
---|
67 | -noidl to skip the call to IDL and the production of Postscript |
---|
68 | -vm to use IDL virtual machine (free) instead of IDL |
---|
69 | -help to get this help |
---|
70 | " |
---|
71 | # |
---|
72 | vm=0 |
---|
73 | noidl=0 |
---|
74 | format=ps |
---|
75 | while [ ! -z "${1}" ] |
---|
76 | do |
---|
77 | case ${1} in |
---|
78 | -plot|--plot) PLOTTYPE=plot ;; |
---|
79 | -ts|--ts) PLOTTYPE=ts ;; |
---|
80 | -f|-format|--format) format=${2} shift ;; |
---|
81 | -html|--html) format=html ;; |
---|
82 | -pdf|--pdf) format=pdf ;; |
---|
83 | -h|-help|--help) |
---|
84 | echo "${usage}" |
---|
85 | exit 0 |
---|
86 | ;; |
---|
87 | -ni|--ni|-noidl|--noidl) noidl=1 ;; |
---|
88 | -vm|--vm|-virtual_machine|--virtual_machine) vm=1 ;; |
---|
89 | *) # other choice |
---|
90 | echo "${usage}" |
---|
91 | exit 1 |
---|
92 | ;; |
---|
93 | esac |
---|
94 | shift # next flag |
---|
95 | done |
---|
96 | # |
---|
97 | PLOTTYPE=${PLOTTYPE:-NG} |
---|
98 | if [[ ( "$PLOTTYPE" != "plot" ) && ( "$PLOTTYPE" != "ts" ) ]] |
---|
99 | then |
---|
100 | echo 'the type of plot must be defined with the option -plot or -ts' |
---|
101 | exit 1 |
---|
102 | fi |
---|
103 | export PLOTTYPE |
---|
104 | # |
---|
105 | set -u |
---|
106 | # |
---|
107 | # |
---|
108 | tstexe () { |
---|
109 | type ${1} |
---|
110 | status_type=${?} |
---|
111 | if [ ${status_type} -ne 0 ] |
---|
112 | then |
---|
113 | echo "eee : ${2}" |
---|
114 | exit 1 |
---|
115 | fi |
---|
116 | } |
---|
117 | # |
---|
118 | #----------------------------------------------------------- |
---|
119 | # define output directory for POSTCRIPT files |
---|
120 | #----------------------------------------------------------- |
---|
121 | # |
---|
122 | . ./std_${PLOTTYPE}_vardef.sh |
---|
123 | [ ! -d ${PS_DIR} ] && mkdir -p ${PS_DIR} |
---|
124 | # |
---|
125 | #----------------------------------------------------------- |
---|
126 | # run IDL |
---|
127 | #----------------------------------------------------------- |
---|
128 | # |
---|
129 | if [ $noidl -eq 0 ] |
---|
130 | then |
---|
131 | tstexe ${idl_command} "idl not found" |
---|
132 | # |
---|
133 | if [ $vm -eq 1 ] |
---|
134 | then |
---|
135 | ${idl_command} -vm=std_main.sav |
---|
136 | else |
---|
137 | ${idl_command} -IDL_STARTUP 'initenv' << EOF |
---|
138 | std_${PLOTTYPE}_all, /postscript |
---|
139 | EOF |
---|
140 | fi |
---|
141 | status_idl=${?} |
---|
142 | if [ ${status_idl} -ne 0 ] |
---|
143 | then |
---|
144 | echo "eee : error in the execution of IDL" |
---|
145 | exit 1 |
---|
146 | fi |
---|
147 | fi |
---|
148 | # |
---|
149 | #----------------------------------------------------------- |
---|
150 | # produce the final document |
---|
151 | #----------------------------------------------------------- |
---|
152 | # |
---|
153 | # build the list of ps that has been created by IDL |
---|
154 | pslist=$( grep "img width" ${PS_DIR}/std_${PLOTTYPE}_html_body.txt | sed -e "s/.*src=\(.*\)png.*/\1/" ) |
---|
155 | # |
---|
156 | case ${format} in |
---|
157 | #__________________________________________________________ |
---|
158 | # PDF |
---|
159 | pdf) |
---|
160 | # check if ps2pdf available |
---|
161 | ps2pdf_command=$( which ps2pdf ) |
---|
162 | tstexe ${ps2pdf_command} "ps2pdf not found" |
---|
163 | # check if texexec available |
---|
164 | texexec_command=$( which texexec ) |
---|
165 | tstexe ${texexec_command} "texexec not found" |
---|
166 | # |
---|
167 | filepdf=all_${PLOTTYPE}.pdf |
---|
168 | [ ! -d ${PDF_DIR} ] && mkdir -p ${PDF_DIR} |
---|
169 | pdflist='' |
---|
170 | for file in ${pslist} ; do |
---|
171 | ps2pdf -sPAPERSIZE=a4 ${PS_DIR}/${file}ps ${PDF_DIR}/${file}pdf |
---|
172 | echo "ps2pdf ${file}ps done" |
---|
173 | pdflist=${pdflist}' '${PDF_DIR}/${file}pdf |
---|
174 | done |
---|
175 | texexec --pdfarrange --result=$PDF_DIR/$filepdf $pdflist |
---|
176 | rm -f $PDF_DIR/$( basename $filepdf .pdf ).aux $PDF_DIR/$( basename $filepdf .pdf ).log |
---|
177 | echo ${PDF_DIR}/$filepdf done |
---|
178 | #commented because convert gives images of bad quality |
---|
179 | # convert ${PS_DIR}/*.ps /tmp/all_${PLOTTYPE}.pdf |
---|
180 | # convert -resize 800x600 ${PS_DIR}/${exp1}_${exp2}/ps/*.ps /tmp/all_${PLOTTYPE}.pdf |
---|
181 | ;; |
---|
182 | #__________________________________________________________ |
---|
183 | # HTML |
---|
184 | html) |
---|
185 | filehtml=all_${PLOTTYPE}.html |
---|
186 | [ ! -d ${HTML_DIR} ] && mkdir -p ${HTML_DIR} |
---|
187 | # check if convert available |
---|
188 | convert_command=$( which convert ) |
---|
189 | tstexe ${convert_command} "convert not found" |
---|
190 | # convert each ps to png |
---|
191 | for file in ${pslist} ; do |
---|
192 | ${convert_command} -antialias ${PS_DIR}/${file}ps ${HTML_DIR}/${file}png |
---|
193 | done |
---|
194 | # creation of the HTML file |
---|
195 | cat << EOF > ${HTML_DIR}/$filehtml |
---|
196 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
---|
197 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
198 | <head> |
---|
199 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
200 | </head> |
---|
201 | <body> |
---|
202 | EOF |
---|
203 | cat ${PS_DIR}/std_${PLOTTYPE}_html_body.txt >> ${HTML_DIR}/$filehtml |
---|
204 | cat << EOF >> ${HTML_DIR}/$filehtml |
---|
205 | <hr> |
---|
206 | </body> |
---|
207 | </html> |
---|
208 | EOF |
---|
209 | echo ${HTML_DIR}/$filehtml done |
---|
210 | ;; |
---|
211 | ps) ;; # nothing to do... |
---|
212 | *) |
---|
213 | echo " format ${format} not implemented" |
---|
214 | exit 1 |
---|
215 | ;; |
---|
216 | esac |
---|
217 | |
---|
218 | # |
---|
219 | #===================== |
---|
220 | # prepare to put images on dods |
---|
221 | # +++ to finish it |
---|
222 | #LOGIN=xxxx |
---|
223 | #Tag_Name=ORCA2_LIM2 |
---|
224 | #rsh ${LOGIN}@gaya.idris.fr exec /bin/ksh <<EOF |
---|
225 | # cd ${homegaya}/IGCM_OUT/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} |
---|
226 | # /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} > /dev/null 2>&1 |
---|
227 | # /usr/local/bin/dods_cp ${exp1} DODS/pub/${LOGIN}/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} > /dev/null 2>&1 |
---|
228 | #EOF |
---|
229 | #===================== |
---|
230 | # end |
---|
231 | exit 0 |
---|