[2292] | 1 | #!/bin/bash |
---|
| 2 | #------------------------------------------------ |
---|
| 3 | #$Id: chk_iomput.sh 2280 2010-10-15 13:42:58Z smasson $ |
---|
| 4 | #------------------------------------------------ |
---|
| 5 | # |
---|
| 6 | set -u |
---|
| 7 | # |
---|
| 8 | # if not argument -> get the help |
---|
| 9 | [ $# -eq 0 ] && ./$0 --help && exit |
---|
| 10 | # |
---|
| 11 | inxml=0 |
---|
| 12 | insrc=0 |
---|
| 13 | while [ $# -gt 0 ] # Until you run out of parameters . . . |
---|
| 14 | do |
---|
| 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 ' -v, --version to get the version number' |
---|
| 35 | echo ' --inxml only print all variable definitions found in the xml file' |
---|
| 36 | echo ' --insrc only print all variable definitions found in the source code' |
---|
| 37 | echo 'Examples' |
---|
| 38 | echo ' chk_iomput.sh' |
---|
| 39 | echo ' chk_iomput.sh --help' |
---|
| 40 | echo ' chk_iomput.sh ../../CONFIG/ORCA2_LIM/EXP00/iodef.xml "../../NEMO/OPA_SRC/ ../../NEMO/LIM_SRC_2/"' |
---|
| 41 | echo |
---|
| 42 | exit ;; |
---|
| 43 | -v|--version) grep "^#\$Id: chk_iomput.sh 2280 2010-10-15 13:42:58Z smasson $0 ; exit ;; |
---|
| 44 | --inxml) inxml=1 ;; |
---|
| 45 | --insrc) insrc=1 ;; |
---|
| 46 | -*) echo ; echo "illegal option" ; ./$0 --help && exit ;; |
---|
| 47 | *) [ $# -ne 2 ] && echo && echo "wrong number of arguments" && ./$0 --help && exit |
---|
| 48 | xmlfile=${1} |
---|
| 49 | srcdir=${2} |
---|
| 50 | shift |
---|
| 51 | esac |
---|
| 52 | shift # Check next set of parameters. |
---|
| 53 | done |
---|
| 54 | # |
---|
| 55 | [ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit |
---|
| 56 | for i in $srcdir |
---|
| 57 | do |
---|
| 58 | [ ! -d $i ] && echo "$i is not a directory, we stop..." && exit |
---|
| 59 | done |
---|
| 60 | # |
---|
| 61 | #------------------------------------------------ |
---|
| 62 | # |
---|
| 63 | [ $inxml -eq 1 ] && grep "< *field * id *=" $xmlfile |
---|
| 64 | [ $insrc -eq 1 ] && find $srcdir -name "*.[Ffh]90" -exec grep -iH "^[^\!]*call *iom_put *(" {} \; |
---|
| 65 | [ $(( $insrc + $inxml )) -ge 1 ] && exit |
---|
| 66 | # |
---|
| 67 | #------------------------------------------------ |
---|
| 68 | # |
---|
| 69 | # list of file containing "CALL iom_put" in $srcdir |
---|
| 70 | # |
---|
| 71 | srclist=$( find $srcdir -name "*.[Ffh]90" -exec grep -il "^[^\!]*call *iom_put *(" {} \; ) |
---|
| 72 | # |
---|
| 73 | # list of variables used in "CALL iom_put" |
---|
| 74 | # |
---|
| 75 | varlistsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i "^[^\!]*call *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | sort -d ) |
---|
| 76 | # |
---|
| 77 | # list of variables defined in the xml file |
---|
| 78 | # |
---|
| 79 | varlistxml=$( grep "< *field * id *=" $xmlfile | sed -e "s/^.*< *field * id *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d ) |
---|
| 80 | # |
---|
| 81 | # list of variables to be outputed in the xml file |
---|
| 82 | # |
---|
| 83 | varlistout=$( grep "< *field * ref *=" $xmlfile | sed -e "s/^.*< *field * ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d ) |
---|
| 84 | # |
---|
| 85 | echo "--------------------------------------------------" |
---|
| 86 | echo check if all iom_put found in $srcdir |
---|
| 87 | echo have a corresponding variable definition in $xmlfile |
---|
| 88 | echo "--------------------------------------------------" |
---|
| 89 | for var in $varlistsrc |
---|
| 90 | do |
---|
| 91 | tst=$( echo " "$varlistxml" " | grep -c " $var " ) |
---|
| 92 | if [ $tst -ne 1 ] |
---|
| 93 | then |
---|
| 94 | echo "problem with $var: $tst lines corresponding to its definition in $xmlfile, but defined in the code in" |
---|
| 95 | for f in $srclist |
---|
| 96 | do |
---|
| 97 | grep -iH "^[^\!]*call *iom_put *( *[\"\']${var}[\"\'] *," $f |
---|
| 98 | done |
---|
| 99 | echo |
---|
| 100 | fi |
---|
| 101 | done |
---|
| 102 | # |
---|
| 103 | echo "--------------------------------------------------" |
---|
| 104 | echo check if all variables defined in $xmlfile |
---|
| 105 | echo have a corresponding \"call iom_put\" in sources found in $srcdir |
---|
| 106 | echo "--------------------------------------------------" |
---|
| 107 | # |
---|
| 108 | for var in $varlistxml |
---|
| 109 | do |
---|
| 110 | found=$( echo " "$varlistsrc" " | grep -c " $var " ) |
---|
| 111 | if [ $found -eq 0 ] |
---|
| 112 | then |
---|
| 113 | echo \"call iom_put\" not found for variable $var |
---|
| 114 | grep "< *field * id *= *[\"\']${var}[\"\']" $xmlfile |
---|
| 115 | echo |
---|
| 116 | fi |
---|
| 117 | done |
---|
| 118 | # |
---|
| 119 | echo "--------------------------------------------------" |
---|
| 120 | echo ${xmlfile}: check if all variables to be outputed in files are really defined... |
---|
| 121 | echo "--------------------------------------------------" |
---|
| 122 | # |
---|
| 123 | # list of variables defined in the xml file |
---|
| 124 | for var in $varlistout |
---|
| 125 | do |
---|
| 126 | found=$( echo " "$varlistxml" " | grep -c " $var " ) |
---|
| 127 | [ $found -eq 0 ] && echo variable to be outputed but not defined: $var |
---|
| 128 | done |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | exit |
---|