source: TOOLS/MultiMonitoring/script.bash @ 3055

Last change on this file since 3055 was 1526, checked in by mmaipsl, 11 years ago

Add short usage and examples in multi-monitoring_script and change title in script.

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1#!/bin/bash
2
3#Download the ferret script run :
4tmpfname=$1
5shift 1
6#Download a shell script to run this ferret script for all files:</B>
7fh="${tmpfname}_prod.bash"
8[ -f $fh ] && \rm -f $fh
9
10DIRS=($@)
11NDIRS=${#DIRS[@]}
12echo "Nb simul " $NDIRS
13
14for thisdir in ${DIRS[@]} ; do
15    echo ""
16    leadding_sl=$( echo ${thisdir} | grep '.*/$' )
17    if [ X"${leadding_sl}" != X ] ; then
18        thisdir=$( echo ${thisdir} | sed -e 's&\(.*\)/$&\1&' )
19    fi
20    echo "dir : " ${thisdir}
21    wget -nd ${thisdir}/MONITORING/files 2> /dev/null
22    RET=$?
23    if [ ${RET} -gt 0 ] ; then
24        \ls ${thisdir}/MONITORING/files > files
25        RET=$?
26        if [ ${RET} -gt 0 ] ; then
27            echo "Error : can't read ${thisdir} !"
28            exit 1
29        fi
30    fi
31    shortdir=$( basename $thisdir ) 
32    list_list=(${list_list[@]} ${shortdir}_list)
33    mv files ${shortdir}_files
34    cat ${shortdir}_files | grep '.*\.nc.*'  | sed -e 's/.*">\(.*\)\.nc<.*/\1.nc/' | sort > ${shortdir}_list
35    cat ${shortdir}_list >> allfiles
36    if [ X"${listsimus[0]}" = X"" ] ; then
37        listsimus[0]=${shortdir}
38    else
39        listsimus=( ${listsimus[@]} ' vs ' ${shortdir} )
40    fi
41done
42echo ""
43listfiles=( $( cat allfiles | sort -u ) )
44# if [ ${NDIRS} -eq 2 ] ; then
45#     diff -C 0 ${list_list[@]} > difffiles
46# else
47#     i=0
48#     echo $(( NDIRS - 1 ))
49#     while [ $i -lt $(( NDIRS - 1 )) ] ; do
50#       diff ${list_list[$i]} ${list_list[$i+1]} > diff_$i
51#       i=$i+1
52#     done
53# fi
54echo "Monitoring comparison: ${listsimus[@]}"
55
56# clean
57for thisdir in ${DIRS[@]} ; do
58    shortdir=$( basename $thisdir ) 
59    \rm -f ${shortdir}_list ${shortdir}_files
60done
61\rm allfiles
62
63cmd="#!/bin/bash"
64printf "$cmd\n" >> $fh
65cmd="# Script generated by FEGGsh (Ferret in an EGG in bash)"
66printf "$cmd\n\n" >> $fh
67cmd="#====================================="
68printf "$cmd\n" >> $fh
69cmd="#### Please modify if needed"
70printf "$cmd\n" >> $fh
71cmd="#. /web/igcmg/.atlas_env_eole3_bash               # LSCE (eole3)"
72printf "$cmd\n" >> $fh
73cmd="#. /home/cont003/p86ipsl/.atlas_env_mercure_ksh   # CCRT (mercure)"
74printf "$cmd\n" >> $fh
75cmd="#. /home/rech/psl/rpsl035/.atlas_env_ulam_bash    # IDRIS (ulam)"
76printf "$cmd\n" >> $fh
77cmd="#. /home/users/brock/.atlas_env_asterix_bash      # LSCE (asterix)"
78printf "$cmd\n" >> $fh
79cmd="#. /home/brocksce/.atlas_env_calcul_ksh           # IPSL (calcul2)"
80printf "$cmd\n\n" >> $fh
81cmd="#====================================="
82printf "$cmd\n" >> $fh
83cmd="#### Please modify if needed"
84printf "$cmd\n" >> $fh
85cmd="scriptname=$tmpfname.jnl"
86printf "$cmd\n" >> $fh
87cmd="if ! [[ -f \$scriptname && -s \$scriptname ]] ; then"
88printf "$cmd\n" >> $fh
89cmd="   echo \"Please download the ferret script \$scriptname\""
90printf "$cmd\n" >> $fh
91cmd="exit"
92printf "$cmd\n" >> $fh
93cmd="fi"
94printf "$cmd\n\n" >> $fh
95cmd="#====================================="
96printf "$cmd\n" >> $fh
97cmd="colors_keys=( ATM    ICE    OCE    SBG    SRF    CHM )"
98printf "$cmd\n" >> $fh
99cmd="colors_vals=( AECDFF D4E3E6 6D80FF EEE8AA E7FFAB F0D5F4 )"
100printf "$cmd\n\n" >> $fh
101cmd="function findcolor() {"
102printf "$cmd\n" >> $fh
103cmd="local i=0"
104printf "$cmd\n" >> $fh
105cmd="while [ \$i -lt \${#colors_keys[*]} ] ; do"
106printf "$cmd\n" >> $fh
107cmd="        if [ \"\${colors_keys[\$i]}\" = \"\$1\" ] ; then"
108printf "$cmd\n" >> $fh
109cmd="                findcolor=\${colors_vals[\$i]}"
110printf "$cmd\n" >> $fh
111cmd="                return 1"
112printf "$cmd\n" >> $fh
113cmd="        fi"
114printf "$cmd\n" >> $fh
115cmd="        let i=i+1"
116printf "$cmd\n" >> $fh
117cmd="done"
118printf "$cmd\n" >> $fh
119cmd="findcolor=FFFFFF"
120printf "$cmd\n" >> $fh
121cmd="return 0"
122printf "$cmd\n" >> $fh
123cmd="}"
124printf "$cmd\n\n" >> $fh
125cmd="#====================================="
126printf "$cmd\n" >> $fh
127cmd="listfiles=("
128echo "$cmd \\" >> $fh
129for file1 in ${listfiles[*]} ; do
130    cmd="$file1 "
131    echo "$cmd \\" >> $fh
132done
133cmd=")"
134printf "$cmd\n\n" >> $fh
135cmd="#====================================="
136printf "$cmd\n" >> $fh
137cmd="outputdir=\${scriptname%%%%.jnl}_prod/images"
138printf "$cmd\n" >> $fh
139cmd="rm -rf \${outputdir}"
140printf "$cmd\n" >> $fh
141cmd="mkdir -p \${outputdir}"
142printf "$cmd\n\n" >> $fh
143cmd="#====================================="
144printf "$cmd\n" >> $fh
145cmd="for file in \${listfiles[*]} ; do"
146printf "$cmd\n" >> $fh
147cmd="        echo ferret -batch \${outputdir}/\${file%%%%.nc}.gif -script \${scriptname} \${file}"
148printf "$cmd\n" >> $fh
149cmd="        ferret -batch \${outputdir}/\${file%%%%.nc}.gif -script \${scriptname} \${file}"
150printf "$cmd\n\n" >> $fh
151cmd="        prefix=\`echo \${file} | cut -f 1 -d _\`"
152printf "$cmd\n" >> $fh
153cmd="        findcolor \$prefix"
154printf "$cmd\n" >> $fh
155cmd="        convert -geometry 50%%x50%% -bordercolor \"#\${findcolor}\" -border 15x15 \${outputdir}/\${file%%%%.nc}.gif \${outputdir}/\${file%%%%.nc}.jpg"
156printf "$cmd\n" >> $fh
157cmd="done"
158printf "$cmd\n\n" >> $fh
159cmd="#====================================="
160printf "$cmd\n" >> $fh
161cmd="monitoring01_createindex -t '${listsimus[@]}' \${scriptname%%%%.jnl}_prod"
162# printf "$cmd\n" >> $fh
163# cmd="mv \${scriptname%%%%.jnl}_prod/\${scriptname%%%%.jnl} \${scriptname%%%%.jnl}_prod/index.html"
164printf "$cmd\n\n" >> $fh
165cmd="#====================================="
166printf "$cmd\n" >> $fh
167cmd="#### Please modify if needed"
168printf "$cmd\n" >> $fh
169cmd="#cp -fR \${scriptname%%%%.jnl}_prod /somewhere/dir"
170printf "$cmd\n\n" >> $fh
171chmod u+x $fh
Note: See TracBrowser for help on using the repository browser.