New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
chk_iomput.sh in branches/nemo_v3_3_beta/NEMOGCM/TOOLS/MISCELLANEOUS – NEMO

source: branches/nemo_v3_3_beta/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh @ 2280

Last change on this file since 2280 was 2280, checked in by smasson, 14 years ago

add chk_iomput.sh that was lost in the FCM version

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.7 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 ' -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$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.
53done
54#
55[ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
56for i in $srcdir
57do
58    [ ! -d $i ] && echo "$i is not a directory, we stop..." && exit
59done
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#
71srclist=$( find $srcdir -name "*.[Ffh]90" -exec grep -il "^[^\!]*call  *iom_put *(" {} \; )
72#
73# list of variables used in "CALL iom_put"
74#
75varlistsrc=$( 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#
79varlistxml=$( 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#
83varlistout=$( grep "< *field * ref *=" $xmlfile  | sed -e "s/^.*< *field * ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
84#
85echo "--------------------------------------------------"
86echo  check if all iom_put found in $srcdir
87echo  have a corresponding variable definition in $xmlfile
88echo "--------------------------------------------------"
89for var in $varlistsrc
90do
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
101done
102#
103echo "--------------------------------------------------"
104echo  check if all variables defined in $xmlfile
105echo  have a corresponding \"call iom_put\" in sources found in $srcdir
106echo "--------------------------------------------------"
107#
108for var in $varlistxml
109do
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
117done
118#
119echo "--------------------------------------------------"
120echo  ${xmlfile}: check if all variables to be outputed in files are really defined...
121echo "--------------------------------------------------"
122#
123# list of variables defined in the xml file
124for var in $varlistout
125do
126    found=$( echo " "$varlistxml" " | grep -c " $var " )
127    [ $found -eq 0 ] && echo variable to be outputed but not defined: $var 
128done
129
130
131
132exit
Note: See TracBrowser for help on using the repository browser.