| 1 | #!/bin/sh | 
|---|
| 2 | # | 
|---|
| 3 | # ======================================================================== | 
|---|
| 4 | # | 
|---|
| 5 | # * | 
|---|
| 6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction | 
|---|
| 7 | # * Software. It is distributed to you in the hope that it can be a useful | 
|---|
| 8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes. | 
|---|
| 9 | # * It is distributed WITHOUT ANY WARRANTY. | 
|---|
| 10 | # * | 
|---|
| 11 | # * Permission to use, copy, modify and distribute this software and its | 
|---|
| 12 | # * documentation for any purpose is hereby granted without fee, | 
|---|
| 13 | # * provided that the above copyright notice appear in all copies and | 
|---|
| 14 | # * that both that copyright notice and this permission notice appear | 
|---|
| 15 | # * in supporting documentation. It is provided "as is" without express | 
|---|
| 16 | # * or implied warranty. | 
|---|
| 17 | # * | 
|---|
| 18 | # | 
|---|
| 19 | # | 
|---|
| 20 | #   Author(s): Daniela Dorner  08/2005 <mailto:dorner@astro.uni-wuerzburg.de> | 
|---|
| 21 | # | 
|---|
| 22 | #   Copyright: MAGIC Software Development, 2000-2006 | 
|---|
| 23 | # | 
|---|
| 24 | # | 
|---|
| 25 | # ======================================================================== | 
|---|
| 26 | # | 
|---|
| 27 | # This script produces the plots from all root-files in the web directory | 
|---|
| 28 | # | 
|---|
| 29 | # After checking, if the script is already running, the plots are produced: | 
|---|
| 30 | # With the programm showplot a ps-file is written, from which the png | 
|---|
| 31 | # files are produced. | 
|---|
| 32 | # | 
|---|
| 33 |  | 
|---|
| 34 | source `dirname $0`/sourcefile | 
|---|
| 35 | printprocesslog "INFO starting $0" | 
|---|
| 36 | program=dowebplots | 
|---|
| 37 |  | 
|---|
| 38 | set -C | 
|---|
| 39 |  | 
|---|
| 40 | scriptlog=$runlogpath/$program-$datetime.log | 
|---|
| 41 | date >> $scriptlog 2>&1 | 
|---|
| 42 |  | 
|---|
| 43 | while getopts p: opts | 
|---|
| 44 | do | 
|---|
| 45 | case $opts in | 
|---|
| 46 | p)  type=$OPTARG | 
|---|
| 47 | echo "got programname: $type"  >> $scriptlog 2>&1 | 
|---|
| 48 | ;; | 
|---|
| 49 | ?)  echo "usage: $(basename $0) -p programname"  >> $scriptlog 2>&1 | 
|---|
| 50 | ;; | 
|---|
| 51 | esac | 
|---|
| 52 | done | 
|---|
| 53 |  | 
|---|
| 54 | if [ "$type" = "" ] | 
|---|
| 55 | then | 
|---|
| 56 | echo "no program name given -> exit"  >> $scriptlog 2>&1 | 
|---|
| 57 | echo "usage: $(basename $0) -p programname"   >> $scriptlog 2>&1 | 
|---|
| 58 | date  >> $scriptlog 2>&1 | 
|---|
| 59 | printprocesslog "INFO finished $0" | 
|---|
| 60 | exit | 
|---|
| 61 | fi | 
|---|
| 62 |  | 
|---|
| 63 | # check if script is already running | 
|---|
| 64 | lockfile=$lockpath/lock-$program-$type.txt | 
|---|
| 65 | checklock  >> $scriptlog 2>&1 | 
|---|
| 66 |  | 
|---|
| 67 | #finding all rootfiles in the data directory, that were modified in the last 3 days | 
|---|
| 68 | #this are all statusdisplays | 
|---|
| 69 | rootfiles=`find $datapath/$type/ -maxdepth 10 -name '*.root' -mtime -3 | grep -v '_I_' | grep -v '_Y_' | grep -v 'summary'` | 
|---|
| 70 |  | 
|---|
| 71 | #exit if no rootfiles are found | 
|---|
| 72 | if [ "$rootfiles" = "" ] | 
|---|
| 73 | then | 
|---|
| 74 | echo "nothing to do -> exit"  >> $scriptlog 2>&1 | 
|---|
| 75 | finish >> $scriptlog 2>&1 | 
|---|
| 76 | fi | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | cd $mars | 
|---|
| 80 |  | 
|---|
| 81 | #produce plots for each rootfile | 
|---|
| 82 | printprocesslog "INFO procduing plots for each $type rootfile" | 
|---|
| 83 | for rootfile in ${rootfiles[@]} | 
|---|
| 84 | do | 
|---|
| 85 | date >> $scriptlog 2>&1 | 
|---|
| 86 | #get names of the psfile and the | 
|---|
| 87 | #pngfiles (1 per tab in the statusdiplay) | 
|---|
| 88 | psfile=`echo $rootfile | sed -e 's/.root$/.ps/g'` | 
|---|
| 89 | tabfile=`echo $rootfile | sed -e 's/.root$/-tab/g'` | 
|---|
| 90 | echo "rootfile: $rootfile" >> $scriptlog 2>&1 | 
|---|
| 91 | echo "psfile:   $psfile"   >> $scriptlog 2>&1 | 
|---|
| 92 | echo "tabfile:  $tabfile"  >> $scriptlog 2>&1 | 
|---|
| 93 |  | 
|---|
| 94 | #get date of root- and psfile | 
|---|
| 95 | daterootfile=`date +%Y%m%d -r $rootfile` >> $scriptlog 2>&1 | 
|---|
| 96 | datepsfile=`date +%Y%m%d -r $psfile` >> $scriptlog 2>&1 | 
|---|
| 97 | if [ "$datepsfile" = "" ] | 
|---|
| 98 | then | 
|---|
| 99 | echo "date of psfile is empty, i.e. the file $psfile doesn't exist" >> $scriptlog 2>&1 | 
|---|
| 100 | echo " -> setting date to 0 and producing psfile..." >> $scriptlog 2>&1 | 
|---|
| 101 | datepsfile=0 | 
|---|
| 102 | fi | 
|---|
| 103 |  | 
|---|
| 104 | echo "checking date..."  >> $scriptlog 2>&1 | 
|---|
| 105 | echo "date of rootfile: $daterootfile" >> $scriptlog 2>&1 | 
|---|
| 106 | echo "date of psfile:   $datepsfile"   >> $scriptlog 2>&1 | 
|---|
| 107 | #if the psfile is newer than the rootfile | 
|---|
| 108 | #no plots have to be done -> continue | 
|---|
| 109 | if [ "$datepsfile" -gt "$daterootfile" ] >> $scriptlog 2>&1 | 
|---|
| 110 | then | 
|---|
| 111 | echo "psfile is newer than rootfile -> continue " >> $scriptlog 2>&1 | 
|---|
| 112 | continue | 
|---|
| 113 | fi | 
|---|
| 114 |  | 
|---|
| 115 | printprocesslog "INFO procduing plots for $rootfile" | 
|---|
| 116 | echo "producing psfile..." >> $scriptlog 2>&1 | 
|---|
| 117 | ./showplot -b --save-as-ps=$psfile $rootfile >> $scriptlog 2>&1 | 
|---|
| 118 |  | 
|---|
| 119 | echo "creating temporary dir for pstoimg..." >> $scriptlog 2>&1 | 
|---|
| 120 | temppath=`dirname $rootfile` | 
|---|
| 121 | tempwebplotspath=$temppath/tempwebplots | 
|---|
| 122 | makedir $tempwebplotspath >> $scriptlog 2>&1 | 
|---|
| 123 |  | 
|---|
| 124 | echo "converting plots to png..." >> $scriptlog 2>&1 | 
|---|
| 125 | pstoimg -antialias -flip r270 -density 100 -tmp $tempwebplotspath -type png -multipage -out=$tabfile $psfile >> $scriptlog 2>&1 | 
|---|
| 126 |  | 
|---|
| 127 | echo "removing temporary dir..." >> $scriptlog 2>&1 | 
|---|
| 128 | rmdir -v $tempwebplotspath >> $scriptlog 2>&1 | 
|---|
| 129 | done | 
|---|
| 130 |  | 
|---|
| 131 | finish >> $scriptlog 2>&1 | 
|---|
| 132 |  | 
|---|