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/UKMO/dev_r5518_medusa_fix_restart/NEMOGCM/TOOLS/MISCELLANEOUS – NEMO

source: branches/UKMO/dev_r5518_medusa_fix_restart/NEMOGCM/TOOLS/MISCELLANEOUS/chk_iomput.sh @ 7850

Last change on this file since 7850 was 7850, checked in by marc, 7 years ago

Removing the SVN keywords

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