source: LMDZ5/trunk/tools/diffdef.sh @ 2082

Last change on this file since 2082 was 2082, checked in by lguez, 10 years ago

Script to compare def files. Documentation at:
http://lmdz.lmd.jussieu.fr/utilisateurs/outils/utilisation-de-lmdz#section-5

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