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 NEMO/branches/UKMO/r8395_cpl-pressure/NEMOGCM/TOOLS/MISCELLANEOUS – NEMO

source: NEMO/branches/UKMO/r8395_cpl-pressure/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh @ 10797

Last change on this file since 10797 was 10797, checked in by jcastill, 5 years ago

Remove svn keywords

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1#!/bin/bash
2#------------------------------------------------
3#$Id: chk_iomput.sh 8309 2017-07-10 13:44:10Z timgraham $
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/context_nemo.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#
53echo $xmlfile
54echo $srcdir
55
56for i in $xmlfile
57do
58    [ ! -f "$xmlfile" ] && echo "$xmlfile not found, we stop..." && exit
59done
60for i in $srcdir 
61do
62    [ ! -d $i ] && echo "$i is not a directory, we stop..." && exit
63done
64#
65#------------------------------------------------
66#
67external=$( grep -c "<field_definition  *\([^ ].* \)*src=" $xmlfile )
68if [ $external -ge 1 ]
69then
70    xmlfield_def=$( grep "<field_definition  *\([^ ].* \)*src=" $xmlfile | sed -e 's/.*src="\([^"]*\)".*/\1/' )
71    tmp_def=""
72    for fdef in $xmlfield_def ; do tmp_def="$tmp_def $( dirname $xmlfile )/$fdef" ; done
73    xmlfield_def=$tmp_def
74    echo $xmlfield_def
75else
76    xmlfield_def=$xmlfile
77fi
78external=$( grep -c "<file_definition  *\([^ ].* \)*src=" $xmlfile )
79if [ $external -ge 1 ]
80then
81    xmlfile_def=$( grep "<file_definition  *\([^ ].* \)*src=" $xmlfile | sed -e 's/.*src="\([^"]*\)".*/\1/' )
82    tmp_def=""
83    for fdef in $xmlfile_def ; do tmp_def="$tmp_def $( dirname $xmlfile )/$fdef" ; done
84    xmlfile_def=$tmp_def
85    echo $xmlfile_def
86else
87    xmlfile_def=$xmlfile
88fi
89
90[ $inxml -eq 1 ] && grep "< *field  *\([^ ].* \)*id *=" $xmlfield_def
91[ $insrc -eq 1 ] && find $srcdir -name "*.[Ffh]90" -exec grep -iH "^[^\!]*call  *iom_put *(" {} \;
92[ $(( $insrc + $inxml )) -ge 1 ] && exit
93#
94#------------------------------------------------
95#
96# list of file containing "CALL iom_put" in $srcdir
97#
98srclist=$( find $srcdir -name "*.[Ffh]90" -exec grep -il "^[^\!]*call  *iom_put *(" {} \; )
99#
100# list of variables used in "CALL iom_put"
101#
102badvarsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i  "^[^\!]*call  *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -ic iom_put )
103if [ $badvarsrc -ne 0 ]
104then
105    echo "The following call to iom_put cannot be checked"
106    echo
107    find $srcdir -name "*.[Ffh]90" -exec grep -i  "^[^\!]*call  *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -i iom_put | sort -d
108    echo
109fi
110varlistsrc=$( find $srcdir -name "*.[Ffh]90" -exec grep -i  "^[^\!]*call  *iom_put *(" {} \; | sed -e "s/.*iom_put *( *[\"\']\([^\"\']*\)[\"\'] *,.*/\1/" | grep -vi iom_put | sort -d )
111#
112# list of variables defined in the xml file
113#
114varlistxml=$( grep "< *field  *\([^ ].* \)*id *=" $xmlfield_def  | sed -e "s/^.*< *field .*id *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
115#
116# list of variables to be outputed in the xml file
117#
118varlistout=$( grep "< *field  *\([^ ].* \)*field_ref *=" $xmlfile_def  | sed -e "s/^.*< *field .*field_ref *= *[\"\']\([^\"\']*\)[\"\'].*/\1/" | sort -d )
119#
120echo "--------------------------------------------------"
121echo  check if all iom_put found in $srcdir
122echo  have a corresponding variable definition in $xmlfield_def
123echo "--------------------------------------------------"
124for var in $varlistsrc
125do
126    tst=$( echo " "$varlistxml" " | grep -c " $var " )
127    if [ $tst -ne 1 ] 
128    then
129   echo "problem with $var: $tst lines corresponding to its definition in $xmlfield_def, but defined in the code in"
130   for f in $srclist
131   do
132       grep -iH "^[^\!]*call  *iom_put *( *[\"\']${var}[\"\'] *," $f
133   done
134   echo
135    fi
136done
137#
138echo "--------------------------------------------------"
139echo  check if all variables defined in $xmlfile
140echo  have a corresponding \"call iom_put\" in sources found in $srcdir
141echo "--------------------------------------------------"
142#
143for var in $varlistxml
144do
145    found=$( echo " "$varlistsrc" " | grep -c " $var " )
146    if [ $found -eq 0 ] 
147    then
148   echo \"call iom_put\" not found for variable $var
149   grep "< *field * id *= *[\"\']${var}[\"\']" $xmlfile
150   echo
151    fi
152done
153#
154echo "--------------------------------------------------"
155echo  ${xmlfile}: check if all variables to be outputed in files are really defined...
156echo "--------------------------------------------------"
157#
158# list of variables defined in the xml file
159for var in $varlistout
160do
161    found=$( echo " "$varlistxml" " | grep -c " $var " )
162    [ $found -eq 0 ] && echo variable to be outputed but not defined: $var 
163done
164
165
166
167exit
Note: See TracBrowser for help on using the repository browser.