source: LMDZ6/trunk/tools/diffdef.sh @ 4984

Last change on this file since 4984 was 4512, checked in by lguez, 19 months ago

Update diffdef.sh

Updated with the version which was on LMDZ website, in [Boîte à outils
LMDZ](https://lmdz.lmd.jussieu.fr/utilisateurs/utilisation-de-lmdz). Removed
the corresponding tar file on LMDZ website, to avoid confusion.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1# This is a script in Bash.
2# Author: Lionel GUEZ
3
4# This script compares files "*.def" other than "traceur.def",
5# "tracer.def", "isotopes_params.def" and "out.def" in two directories.
6
7# This script uses GNU versions of the utilities cut, sort and uniq,
8# and calls a Python script.
9
10# See guide:
11# http://lmdz.lmd.jussieu.fr/utilisateurs/utilisation-de-lmdz#section-5
12
13USAGE="usage: `basename $0` directory_1 directory_2"
14
15if (($# != 2))
16then
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 $*
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
38
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
44
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
65done
66
67sort $1/all.def $2/all.def | uniq --repeated >common_lines
68
69for my_directory in $*
70do
71    sort $my_directory/all.def common_lines | uniq --unique \
72                                                   >$my_directory/uniq_lines
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 $*
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
87done
88
89$script_dir/compare_real.py $*
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 $*
95do
96    rm $my_directory/common_var $my_directory/all.def
97done
Note: See TracBrowser for help on using the repository browser.