source: NEMO/releases/release-3.4/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh @ 9594

Last change on this file since 9594 was 2404, checked in by smasson, 11 years ago

bugfix on chk_iomput.sh

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1#!/bin/bash
2#------------------------------------------------
3#$Id$
4#------------------------------------------------
5#
6set -u
7#
8# if not argument -> get the help
9[ $# -eq 0 ] && ./$0 --help && exit
10#
11inxml=0
12insrc=0
13while [ $# -gt 0 ]   # Until you run out of parameters . . .
14do   
15    case "$1" in
16   -h|--help)
17       echo
18       echo 'Description:'
19       echo '      check that an xml file is coherant with the source code:'
20       echo '         - all variable ids defined by "call iom_put" must have their counterpart'
21       echo '           in the variable definition in xml file'
22       echo '         - list variable ids defined in xml file without any corresponding call'
23       echo '           to iom_put. This can be done but it is useless as iom will only ouput zeros'
24       echo '         - all variable ids used in the files definition in xml file must have'
25       echo '           their counterpart in the variable definition in xml file'
26       echo 'Usage:'
27       echo '      chk_iomput.sh [OPTION]'
28       echo '  or  chk_iomput.sh [OPTION] xmlfile DIRECTORIES'
29       echo '         with:'
30       echo '           xmlfile:  the xml file to test'
31       echo '           DIRECTORIES: a list of directories containing the source code'
32       echo 'Options'
33       echo ' -h, --help           to get this help'
34       echo ' --inxml              only print all variable definitions found in the xml file'
35       echo ' --insrc              only print all variable definitions found in the source code'
36       echo 'Examples'
37       echo '      chk_iomput.sh'
38       echo '      chk_iomput.sh --help'
39       echo '      chk_iomput.sh ../../CONFIG/ORCA2_LIM/EXP00/iodef.xml "../../NEMO/OPA_SRC/ ../../NEMO/LIM_SRC_2/"'
40       echo
41       exit ;;
42        --inxml) inxml=1 ;;
43        --insrc) insrc=1 ;;
44   -*) echo ; echo "illegal option" ; ./$0 --help && exit ;;
45   *) [ $# -ne 2 ] && echo && echo "wrong number of arguments" && ./$0 --help && exit
46       xmlfile=${1}
47       srcdir=${2}
48      shift
49    esac
50    shift       # Check next set of parameters.
51done 
52#
53[ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
54for i in $srcdir 
55do
56    [ ! -d $i ] && echo "$i is not a directory, we stop..." && exit
57done
58#
59#------------------------------------------------
60#
61[ $inxml -eq 1 ] && grep "< *field * id *=" $xmlfile
62[ $insrc -eq 1 ] && find $srcdir -name "*.[Ffh]90" -exec grep -iH "^[^\!]*call  *iom_put *(" {} \;
63[ $(( $insrc + $inxml )) -ge 1 ] && exit
64#
65#------------------------------------------------
66#
67# list of file containing "CALL iom_put" in $srcdir
68#
69srclist=$( find $srcdir -name "*.[Ffh]90" -exec grep -il "^[^\!]*call  *iom_put *(" {} \; )
70#
71# list of variables used in "CALL iom_put"
72#
73varlistsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i  "^[^\!]*call  *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | sort -d )
74#
75# list of variables defined in the xml file
76#
77varlistxml=$( grep "< *field * id *=" $xmlfile  | sed -e "s/^.*< *field * id *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
78#
79# list of variables to be outputed in the xml file
80#
81varlistout=$( grep "< *field * ref *=" $xmlfile  | sed -e "s/^.*< *field * ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
82#
83echo "--------------------------------------------------"
84echo  check if all iom_put found in $srcdir
85echo  have a corresponding variable definition in $xmlfile
86echo "--------------------------------------------------"
87for var in $varlistsrc
88do
89    tst=$( echo " "$varlistxml" " | grep -c " $var " )
90    if [ $tst -ne 1 ] 
91    then
92   echo "problem with $var: $tst lines corresponding to its definition in $xmlfile, but defined in the code in"
93   for f in $srclist
94   do
95       grep -iH "^[^\!]*call  *iom_put *( *[\"\']${var}[\"\'] *," $f
96   done
97   echo
98    fi
99done
100#
101echo "--------------------------------------------------"
102echo  check if all variables defined in $xmlfile
103echo  have a corresponding \"call iom_put\" in sources found in $srcdir
104echo "--------------------------------------------------"
105#
106for var in $varlistxml
107do
108    found=$( echo " "$varlistsrc" " | grep -c " $var " )
109    if [ $found -eq 0 ] 
110    then
111   echo \"call iom_put\" not found for variable $var
112   grep "< *field * id *= *[\"\']${var}[\"\']" $xmlfile
113   echo
114    fi
115done
116#
117echo "--------------------------------------------------"
118echo  ${xmlfile}: check if all variables to be outputed in files are really defined...
119echo "--------------------------------------------------"
120#
121# list of variables defined in the xml file
122for var in $varlistout
123do
124    found=$( echo " "$varlistxml" " | grep -c " $var " )
125    [ $found -eq 0 ] && echo variable to be outputed but not defined: $var 
126done
127
128
129
130exit
Note: See TracBrowser for help on using the repository browser.