source: LMDZ6/branches/LMDZ_ECRad/tools/diffdef.sh @ 5411

Last change on this file since 5411 was 4727, checked in by idelkadi, 14 months ago

Merged trunk changes -r4488:4726 LMDZ_ECRad branch

  • Property svn:executable set to *
File size: 2.4 KB
RevLine 
[2082]1# This is a script in Bash.
2# Author: Lionel GUEZ
3
[4727]4# This script compares files "*.def" other than "traceur.def",
5# "tracer.def", "isotopes_params.def" and "out.def" in two directories.
[2082]6
[2412]7# This script uses GNU versions of the utilities cut, sort and uniq,
8# and calls a Python script.
9
[2082]10# See guide:
[4727]11# http://lmdz.lmd.jussieu.fr/utilisateurs/utilisation-de-lmdz#section-5
[2082]12
13USAGE="usage: `basename $0` directory_1 directory_2"
14
15if (($# != 2))
[4727]16then
[2082]17    echo "$USAGE" >&2
18    exit 1
19fi
20
21##set -x
22set -e
23
24script_dir=`dirname $0`
25
26# Let us make sure we know what the sort order is:
27export LC_ALL=C
28
29# Enable extended pattern matching features:
30shopt -s extglob
31
32for my_directory in $*
[4727]33do
34    cd $my_directory
35    rm -f all.def
36    echo "def files in $my_directory:"
37    ls !(traceur|tracer|out|isotopes_params).def
[2082]38
[4727]39    # Concatenate and format the def files:
40    cat !(traceur|tracer|out|isotopes_params).def | tr -d " \t" \
41        | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \
42        | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \
43        | sed 's/=[YT]$/=TRUE/' | sort >all.def
[2082]44
[4727]45    # Check that no variable is repeated:
46   
47    cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$
48   
49    if [[ -s plouf_$$ ]]
50    then
51        echo
52        echo "Error: a variable is repeated in directory \"$my_directory\"."
53        echo
54        echo "Here is the list of repeated variables in directory " \
55             "\"$my_directory\":"
56        echo
57        cat plouf_$$
58        rm plouf_$$
59        rm all.def
60        exit 1
61    fi
62   
63    rm plouf_$$
64    cd - >/dev/null
[2082]65done
66
67sort $1/all.def $2/all.def | uniq --repeated >common_lines
68
69for my_directory in $*
[4727]70do
71    sort $my_directory/all.def common_lines | uniq --unique \
72                                                   >$my_directory/uniq_lines
[2082]73done
74
75sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \
76    | sort - $2/uniq_lines | uniq --unique >$1/uniq_var
77sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \
78    | sort - $1/uniq_lines | uniq --unique >$2/uniq_var
79
80for my_directory in $*
[4727]81do
82    cd $my_directory
83    echo "Created file \"$my_directory/uniq_var\"."
84    sort uniq_lines uniq_var | uniq --unique >common_var
85    rm uniq_lines
86    cd - >/dev/null
[2082]87done
88
[4727]89$script_dir/compare_real.py $*
[2082]90sort common_lines --output=common_lines # was modified by the Python script
91echo "Created files \"./common_lines\" and \"./uniq_val\"."
92
93# Clean up:
94for my_directory in $*
[4727]95do
[2082]96    rm $my_directory/common_var $my_directory/all.def
97done
Note: See TracBrowser for help on using the repository browser.