Index: trunk/NEMOGCM/TOOLS/COMPILE/Fcheck_archfile.sh
===================================================================
--- trunk/NEMOGCM/TOOLS/COMPILE/Fcheck_archfile.sh	(revision 3922)
+++ trunk/NEMOGCM/TOOLS/COMPILE/Fcheck_archfile.sh	(revision 3925)
@@ -75,6 +75,5 @@
 }
 # cleaning related to the old version
-myarch=$( find ${MAIN_DIR}/ARCH -type l -name arch-${3}.fcm -print )
-[ ${#myarch} -ne 0 ] && rm -f $myarch
+rm -f $( find ${COMPIL_DIR} -type l -name $1 -print )
 #
 if [ ${#3} -eq 0 ]; then # arch not specified
@@ -95,10 +94,16 @@
 	else
 	    if [ -f ${COMPIL_DIR}/$1 ]; then
+		# has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}?
+		mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" )
+		if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then
+		    echo $mycpp > ${COMPIL_DIR}/cpp.history
+		    cpeval ${myarch} ${COMPIL_DIR}/$1
+		fi
+		# has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}?
+		mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
+		[ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
+		# has myarch file been updated since we copied it in ${COMPIL_DIR}?
 		myarchdir=$( dirname ${myarch} )
 		myarchname=$( basename ${myarch} )
-		# have the cpp keys been updated since we copy the arch file in ${COMPIL_DIR}?
-		mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
-		[ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
-		# has myarch been updated since we copy it in ${COMPIL_DIR}?
 		myarch=$( find -L $myarchdir -cnewer ${COMPIL_DIR}/$1 -name $myarchname -print )
 		[ ${#myarch} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
@@ -109,23 +114,6 @@
     fi
 else 
-    myarch=$( find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print )
-    if [ ${#myarch} -gt 0 ]; then # the arch file specified by the use exists
-	# we were already using this arch file
-	if [ "$myarch" == "$( cat ${COMPIL_DIR}/arch.history )" ]; then 
-	    if [ -f ${COMPIL_DIR}/$1 ]; then
-	    	# have the cpp keys been updated since we copy the arch file in ${COMPIL_DIR}?
-		mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
-		[ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
-		# has myarch been updated since we copy it in ${COMPIL_DIR}?
-		myarch=$( find -L ${MAIN_DIR}/ARCH -cnewer ${COMPIL_DIR}/$1 -name arch-${3}.fcm -print )
-		[ ${#myarch} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
-	    else
-		cpeval ${myarch} ${COMPIL_DIR}/$1
-	    fi
-	else
-	    echo ${myarch} > ${COMPIL_DIR}/arch.history
-	    cpeval ${myarch} ${COMPIL_DIR}/$1
-	fi
-    else
+    nb=$( find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print | wc -l )
+    if [ $nb -eq 0 ]; then # no arch file found
 	echo "Warning !!!"
 	echo "Compiler not existing"
@@ -133,5 +121,37 @@
 	echo "EXITING..."
 	exit 1       
-    fi   
+    fi
+    if [ $nb -gt 1 ]; then # more than 1 arch file found
+	echo "Warning !!!"
+	echo "more than 1 arch file for the same compiler have been found"
+	find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print
+	echo "keep only 1"
+	echo "EXITING..."
+	exit 1       
+    fi
+    myarch=$( find ${MAIN_DIR}/ARCH -name arch-${3}.fcm -print )
+    # we were already using this arch file ?
+    if [ "$myarch" == "$( cat ${COMPIL_DIR}/arch.history )" ]; then 
+	if [ -f ${COMPIL_DIR}/$1 ]; then
+	    # has the cpp keys file been changed since we copied the arch file in ${COMPIL_DIR}?
+	    mycpp=$( ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" )
+	    if [ "$mycpp" != "$( cat ${COMPIL_DIR}/cpp.history )" ]; then
+		echo $mycpp > ${COMPIL_DIR}/cpp.history
+		cpeval ${myarch} ${COMPIL_DIR}/$1
+	    fi
+	    # has the cpp keys file been updated since we copied the arch file in ${COMPIL_DIR}?
+	    mycpp=$( find -L ${COMPIL_DIR} -cnewer ${COMPIL_DIR}/$1 -name $2 -print )
+	    [ ${#mycpp} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
+	    # has myarch file been updated since we copied it in ${COMPIL_DIR}?
+	    myarch=$( find -L ${MAIN_DIR}/ARCH -cnewer ${COMPIL_DIR}/$1 -name arch-${3}.fcm -print )
+	    [ ${#myarch} -ne 0 ] && cpeval ${myarch} ${COMPIL_DIR}/$1
+	else
+	    cpeval ${myarch} ${COMPIL_DIR}/$1
+	fi
+    else
+	ls -l ${COMPIL_DIR}/$2 | sed -e "s/.* -> //" > ${COMPIL_DIR}/cpp.history
+	echo ${myarch} > ${COMPIL_DIR}/arch.history
+	cpeval ${myarch} ${COMPIL_DIR}/$1
+    fi
 fi
 
