[2709] | 1 | #!/bin/sh |
---|
[2751] | 2 | #+ |
---|
[2709] | 3 | # |
---|
[2751] | 4 | # .. program:: std_main.sh |
---|
[2709] | 5 | # |
---|
[2751] | 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 | # |
---|
[2709] | 19 | # DESCRIPTION |
---|
| 20 | # =========== |
---|
| 21 | # |
---|
[2751] | 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 | # |
---|
[2709] | 33 | # EXAMPLES |
---|
| 34 | # ======== |
---|
[2751] | 35 | # $ ./std_main.sh -ts html |
---|
| 36 | # $ ./std_main.sh -ts pdf -noidl |
---|
[2709] | 37 | # |
---|
[2751] | 38 | # $ ./std_main.sh -plot -pdf -vm |
---|
[2709] | 39 | # |
---|
[2751] | 40 | # AUTHOR - date |
---|
| 41 | # =========== |
---|
| 42 | # Françoise Pinsard - 01/2010 - LOCEAN |
---|
| 43 | # Simona Flavoni - 01/2010 - LOCEAN |
---|
| 44 | # Sebastien Masson - 04/2011 - LOCEAN |
---|
[2709] | 45 | # |
---|
[2751] | 46 | #----------------------------------------------------------- |
---|
| 47 | # Usage... |
---|
| 48 | #----------------------------------------------------------- |
---|
[2709] | 49 | # |
---|
[2751] | 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 |
---|
[2709] | 60 | # |
---|
[2751] | 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 | " |
---|
[2709] | 71 | # |
---|
[2751] | 72 | vm=0 |
---|
| 73 | noidl=0 |
---|
| 74 | format=ps |
---|
| 75 | while [ ! -z "${1}" ] |
---|
[2709] | 76 | do |
---|
[2751] | 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 |
---|
[2709] | 95 | done |
---|
| 96 | # |
---|
[2751] | 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 | # |
---|
[2709] | 105 | set -u |
---|
| 106 | # |
---|
[2751] | 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 | #----------------------------------------------------------- |
---|
[2709] | 119 | # define output directory for POSTCRIPT files |
---|
[2751] | 120 | #----------------------------------------------------------- |
---|
[2709] | 121 | # |
---|
[2751] | 122 | . ./std_${PLOTTYPE}_vardef.sh |
---|
| 123 | [ ! -d ${PS_DIR} ] && mkdir -p ${PS_DIR} |
---|
[2709] | 124 | # |
---|
[2751] | 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 |
---|
[2709] | 147 | fi |
---|
| 148 | # |
---|
[2751] | 149 | #----------------------------------------------------------- |
---|
| 150 | # produce the final document |
---|
| 151 | #----------------------------------------------------------- |
---|
[2709] | 152 | # |
---|
[2751] | 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 | # |
---|
[2709] | 156 | case ${format} in |
---|
[2751] | 157 | #__________________________________________________________ |
---|
| 158 | # PDF |
---|
[2709] | 159 | pdf) |
---|
[2751] | 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 |
---|
[2709] | 174 | done |
---|
[4320] | 175 | #pdfjam needed to use pdfjoin |
---|
| 176 | pdfjoin ${pdflist} --outfile $PDF_DIR/${filepdf} |
---|
[2751] | 177 | texexec --pdfarrange --result=$PDF_DIR/$filepdf $pdflist |
---|
| 178 | rm -f $PDF_DIR/$( basename $filepdf .pdf ).aux $PDF_DIR/$( basename $filepdf .pdf ).log |
---|
[4320] | 179 | if [ ! -e ${PDF_DIR}/$filepdf ] |
---|
| 180 | then |
---|
| 181 | echo "\n ATTENTION !!!!! \n" |
---|
| 182 | echo "${PDF_DIR}/$filepdf do not exist \n" |
---|
| 183 | else |
---|
| 184 | echo "${PDF_DIR}/$filepdf done" |
---|
| 185 | fi |
---|
[2709] | 186 | #commented because convert gives images of bad quality |
---|
[2751] | 187 | # convert ${PS_DIR}/*.ps /tmp/all_${PLOTTYPE}.pdf |
---|
| 188 | # convert -resize 800x600 ${PS_DIR}/${exp1}_${exp2}/ps/*.ps /tmp/all_${PLOTTYPE}.pdf |
---|
[2709] | 189 | ;; |
---|
[2751] | 190 | #__________________________________________________________ |
---|
| 191 | # HTML |
---|
[2709] | 192 | html) |
---|
[2751] | 193 | filehtml=all_${PLOTTYPE}.html |
---|
| 194 | [ ! -d ${HTML_DIR} ] && mkdir -p ${HTML_DIR} |
---|
[2709] | 195 | # check if convert available |
---|
[2751] | 196 | convert_command=$( which convert ) |
---|
| 197 | tstexe ${convert_command} "convert not found" |
---|
| 198 | # convert each ps to png |
---|
| 199 | for file in ${pslist} ; do |
---|
| 200 | ${convert_command} -antialias ${PS_DIR}/${file}ps ${HTML_DIR}/${file}png |
---|
[2709] | 201 | done |
---|
[2751] | 202 | # creation of the HTML file |
---|
| 203 | cat << EOF > ${HTML_DIR}/$filehtml |
---|
| 204 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
---|
| 205 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
| 206 | <head> |
---|
| 207 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
| 208 | </head> |
---|
| 209 | <body> |
---|
[2709] | 210 | EOF |
---|
[2751] | 211 | cat ${PS_DIR}/std_${PLOTTYPE}_html_body.txt >> ${HTML_DIR}/$filehtml |
---|
| 212 | cat << EOF >> ${HTML_DIR}/$filehtml |
---|
| 213 | <hr> |
---|
| 214 | </body> |
---|
| 215 | </html> |
---|
[2709] | 216 | EOF |
---|
[2751] | 217 | echo ${HTML_DIR}/$filehtml done |
---|
[2709] | 218 | ;; |
---|
[2751] | 219 | ps) ;; # nothing to do... |
---|
[2709] | 220 | *) |
---|
| 221 | echo " format ${format} not implemented" |
---|
| 222 | exit 1 |
---|
| 223 | ;; |
---|
| 224 | esac |
---|
| 225 | |
---|
| 226 | # |
---|
| 227 | #===================== |
---|
| 228 | # prepare to put images on dods |
---|
| 229 | # +++ to finish it |
---|
| 230 | #LOGIN=xxxx |
---|
| 231 | #Tag_Name=ORCA2_LIM2 |
---|
| 232 | #rsh ${LOGIN}@gaya.idris.fr exec /bin/ksh <<EOF |
---|
[2751] | 233 | # cd ${homegaya}/IGCM_OUT/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} |
---|
| 234 | # /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} > /dev/null 2>&1 |
---|
| 235 | # /usr/local/bin/dods_cp ${exp1} DODS/pub/${LOGIN}/${Tag_Name}/CORE2/INTERAN/${PLOTTYPE}_pdf/${exp1} > /dev/null 2>&1 |
---|
[2709] | 236 | #EOF |
---|
| 237 | #===================== |
---|
| 238 | # end |
---|
| 239 | exit 0 |
---|