Index: LMDZ5/branches/testing/libf/grid/dimension/makdim
===================================================================
--- LMDZ5/branches/testing/libf/grid/dimension/makdim	(revision 1663)
+++ LMDZ5/branches/testing/libf/grid/dimension/makdim	(revision 1665)
@@ -1,48 +1,48 @@
-for i in $* ; do
-   list=$list.$i
+#!/bin/bash
+#set -xv
+
+# sanity check: do we have the required argument ?
+if (( $# < 1 )) || (( $# > 3 ))
+then
+ echo "Wrong number of parameters in $0 !!!"
+ echo " Usage:"
+ echo "  $0 [im] [jm] lm"
+ echo " where im, jm and lm are the dimensions"
+ exit
+fi
+
+# build "fichnom", the relevant 'dimensions.im.jm.lm' file name
+for i in $*
+  do
+  list=$list.$i
 done
 fichdim=dimensions${list}
 
-if [ ! -f $fichdim ] ; then
-# si le fichier de dimensions n'existe pas, on le cree
+if [ ! -f $fichdim ]
+    then
+#    echo "$fichdim does not exist"
 
-  if [ $# -ge 3 ] ; then
-     im=$1
-     jm=$2
-     lm=$3
-     n2=$1
-     ndm=1
+    # assign values of im, jm and lm
+    if [ $# -ge 3 ]
+        then
+        im=$1
+        jm=$2
+        lm=$3
+        ndm=1
+    elif [ $# -ge 2 ]
+        then
+        im=1
+        jm=$1
+        lm=$2
+        ndm=1
+    elif [ $# -ge 1 ]
+        then
+        im=1
+        jm=1
+        lm=$1
+        ndm=1
+    fi
 
-# Le test suivant est commente car il est inutile avec le nouveau 
-# filtre filtrez. Attention avec le "vieux" filtre (F. Forget,11/1994)
-#
-#     while [ "$n2" -gt 2 ]; do
-#       n2=`expr $n2 / 2`
-#       ndm=`expr $ndm + 1`
-#       echo $n2
-#    done
-#    if [ "$n2" != 2 ] ; then
-#       echo le nombre de longitude doit etre une puissance de 2
-#       exit
-#    fi
-
-
-  else if [ $# -ge 2 ] ; then
-      im=1
-      jm=$1
-      lm=$2
-      ndm=1
-  else if [ $# -ge 1 ] ; then
-      im=1
-      jm=1
-      lm=$1
-      ndm=1
-  else
-         echo il faut au moins une dimension
-         exit
-  fi
-fi
-fi
-
+# since the file doesn't exist, we create it
 cat << EOF > $fichdim
 !-----------------------------------------------------------------------
@@ -62,4 +62,8 @@
 fi
 
+# remove 'old' dimensions.h file (if any) and replace it with new one
+if [ -f ../dimensions.h ] ; then
 \rm ../dimensions.h
+fi
 tar cf - $fichdim | ( cd .. ; tar xf - ; mv $fichdim dimensions.h )
+# line above is a trick to preserve time of creation of dimensions.h files
