source: LMDZ5/branches/IPSLCM5A2.1_ISO/tools/diffdef.sh @ 5440

Last change on this file since 5440 was 2426, checked in by lguez, 9 years ago

Make the script more robust.

  • 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" and
5# "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/outils/utilisation-de-lmdz#section-5
12
13USAGE="usage: `basename $0` directory_1 directory_2"
14
15if (($# != 2))
16    then
17    echo "$USAGE" >&2
18    exit 1
19fi
20
21##set -x
22
23type python3 >/dev/null 2>&1
24if (($? == 0))
25then
26    my_python=python3
27else
28    my_python=python
29fi
30
31set -e
32
33script_dir=`dirname $0`
34
35# Let us make sure we know what the sort order is:
36export LC_ALL=C
37
38# Enable extended pattern matching features:
39shopt -s extglob
40
41for my_directory in $*
42  do
43  cd $my_directory
44  rm -f all.def
45  echo "def files in $my_directory:"
46  ls !(*traceur|out).def
47
48  # Concatenate and format the def files:
49  cat !(*traceur|out).def | tr '\r' '\n' | tr -d " " \
50      | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \
51      | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \
52      | sed 's/=[YT]$/=TRUE/' | sort >all.def
53
54  # Check that no variable is repeated:
55  cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$
56  if [[ -s plouf_$$ ]]
57      then
58      echo
59      echo "Error: a variable is repeated in directory \"$my_directory\"."
60      echo
61      echo "Here is the list of repeated variables in directory \"$my_directory\":"
62      echo
63      cat plouf_$$
64      rm plouf_$$
65      rm all.def
66      exit 1
67  fi
68  rm plouf_$$
69
70  cd - >/dev/null
71done
72
73
74sort $1/all.def $2/all.def | uniq --repeated >common_lines
75
76for my_directory in $*
77  do
78  sort $my_directory/all.def common_lines | uniq --unique \
79      >$my_directory/uniq_lines
80done
81
82sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \
83    | sort - $2/uniq_lines | uniq --unique >$1/uniq_var
84sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \
85    | sort - $1/uniq_lines | uniq --unique >$2/uniq_var
86
87for my_directory in $*
88  do
89  cd $my_directory
90  echo "Created file \"$my_directory/uniq_var\"."
91  sort uniq_lines uniq_var | uniq --unique >common_var
92  rm uniq_lines
93  cd - >/dev/null
94done
95
96$my_python $script_dir/compare_real.py $*
97sort common_lines --output=common_lines # was modified by the Python script
98echo "Created files \"./common_lines\" and \"./uniq_val\"."
99
100# Clean up:
101for my_directory in $*
102  do
103    rm $my_directory/common_var $my_directory/all.def
104done
Note: See TracBrowser for help on using the repository browser.