123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #!/bin/bash
- #------------------------------------------------
- #$Id: chk_iomput.sh 4162 2013-11-07 10:19:49Z cetlod $
- #------------------------------------------------
- #
- set -u
- #
- # if not argument -> get the help
- [ $# -eq 0 ] && ./$0 --help && exit
- #
- inxml=0
- insrc=0
- while [ $# -gt 0 ] # Until you run out of parameters . . .
- do
- case "$1" in
- -h|--help)
- echo
- echo 'Description:'
- echo ' check that an xml file is coherant with the source code:'
- echo ' - all variable ids defined by "call iom_put" must have their counterpart'
- echo ' in the variable definition in xml file'
- echo ' - list variable ids defined in xml file without any corresponding call'
- echo ' to iom_put. This can be done but it is useless as iom will only ouput zeros'
- echo ' - all variable ids used in the files definition in xml file must have'
- echo ' their counterpart in the variable definition in xml file'
- echo 'Usage:'
- echo ' chk_iomput.sh [OPTION]'
- echo ' or chk_iomput.sh [OPTION] xmlfile DIRECTORIES'
- echo ' with:'
- echo ' xmlfile: the xml file to test'
- echo ' DIRECTORIES: a list of directories containing the source code'
- echo 'Options'
- echo ' -h, --help to get this help'
- echo ' --inxml only print all variable definitions found in the xml file'
- echo ' --insrc only print all variable definitions found in the source code'
- echo 'Examples'
- echo ' ./chk_iomput.sh'
- echo ' ./chk_iomput.sh --help'
- echo ' ./chk_iomput.sh ../../CONFIG/ORCA2_LIM/EXP00/iodef.xml "../../NEMO/OPA_SRC/ ../../NEMO/LIM_SRC_2/"'
- echo
- exit ;;
- --inxml) inxml=1 ;;
- --insrc) insrc=1 ;;
- -*) echo ; echo "illegal option" ; ./$0 --help && exit ;;
- *) [ $# -ne 2 ] && echo && echo "wrong number of arguments" && ./$0 --help && exit
- xmlfile=${1}
- srcdir=${2}
- shift
- esac
- shift # Check next set of parameters.
- done
- #
- [ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
- for i in $srcdir
- do
- [ ! -d $i ] && echo "$i is not a directory, we stop..." && exit
- done
- #
- #------------------------------------------------
- #
- external=$( grep -c "<field_definition *\([^ ].* \)*src=" $xmlfile )
- if [ $external -eq 1 ]
- then
- xmlfield_def=$( grep "<field_definition *\([^ ].* \)*src=" $xmlfile | sed -e 's/.*src="\([^"]*\)".*/\1/' )
- xmlfield_def=$( dirname $xmlfile )/$xmlfield_def
- else
- xmlfield_def=$xmlfile
- fi
- [ $inxml -eq 1 ] && grep "< *field *\([^ ].* \)*id *=" $xmlfield_def
- [ $insrc -eq 1 ] && find $srcdir -name "*.[Ffh]90" -exec grep -iH "^[^\!]*call *iom_put *(" {} \;
- [ $(( $insrc + $inxml )) -ge 1 ] && exit
- #
- #------------------------------------------------
- #
- # list of file containing "CALL iom_put" in $srcdir
- #
- srclist=$( find $srcdir -name "*.[Ffh]90" -exec grep -il "^[^\!]*call *iom_put *(" {} \; )
- #
- # list of variables used in "CALL iom_put"
- #
- badvarsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i "^[^\!]*call *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -ic iom_put )
- if [ $badvarsrc -ne 0 ]
- then
- echo "The following call to iom_put cannot be checked"
- echo
- find $srcdir -name "*.[Ffh]90" -exec grep -i "^[^\!]*call *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -i iom_put | sort -d
- echo
- fi
- varlistsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i "^[^\!]*call *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -vi iom_put | sort -d )
- #
- # list of variables defined in the xml file
- #
- varlistxml=$( grep "< *field *\([^ ].* \)*id *=" $xmlfield_def | sed -e "s/^.*< *field .*id *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
- #
- # list of variables to be outputed in the xml file
- #
- varlistout=$( grep "< *field *\([^ ].* \)*field_ref *=" $xmlfile | sed -e "s/^.*< *field .*field_ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
- #
- echo "--------------------------------------------------"
- echo check if all iom_put found in $srcdir
- echo have a corresponding variable definition in $xmlfield_def
- echo "--------------------------------------------------"
- for var in $varlistsrc
- do
- tst=$( echo " "$varlistxml" " | grep -c " $var " )
- if [ $tst -ne 1 ]
- then
- echo "problem with $var: $tst lines corresponding to its definition in $xmlfield_def, but defined in the code in"
- for f in $srclist
- do
- grep -iH "^[^\!]*call *iom_put *( *[\"\']${var}[\"\'] *," $f
- done
- echo
- fi
- done
- #
- echo "--------------------------------------------------"
- echo check if all variables defined in $xmlfile
- echo have a corresponding \"call iom_put\" in sources found in $srcdir
- echo "--------------------------------------------------"
- #
- for var in $varlistxml
- do
- found=$( echo " "$varlistsrc" " | grep -c " $var " )
- if [ $found -eq 0 ]
- then
- echo \"call iom_put\" not found for variable $var
- grep "< *field * id *= *[\"\']${var}[\"\']" $xmlfile
- echo
- fi
- done
- #
- echo "--------------------------------------------------"
- echo ${xmlfile}: check if all variables to be outputed in files are really defined...
- echo "--------------------------------------------------"
- #
- # list of variables defined in the xml file
- for var in $varlistout
- do
- found=$( echo " "$varlistxml" " | grep -c " $var " )
- [ $found -eq 0 ] && echo variable to be outputed but not defined: $var
- done
- exit
|