Index: trunk/LMDZ.COMMON/makelmdz
===================================================================
--- trunk/LMDZ.COMMON/makelmdz	(revision 270)
+++ trunk/LMDZ.COMMON/makelmdz	(revision 849)
@@ -544,8 +544,32 @@
 #################################################################
 
-source_code=${code}.F
-if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]]
-then
-  source_code=${code}.F90
+# find code suffix and directory where code is located
+if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F ]]
+then
+  source_code=${code}.F
+  code_dir=dyn${dimc}d${FLAG_PARA}
+else
+  if [[ -r $LMDGCM/libf/dyn${dimc}d${FLAG_PARA}/${code}.F90 ]]
+  then
+    source_code=${code}.F90
+    code_dir=dyn${dimc}d${FLAG_PARA}
+  else
+    if [[ -r $LMDGCM/libf/phy${physique}/${code}.F ]]
+    then
+      source_code=${code}.F
+      code_dir=phy${physique}
+    else
+      # last possibility:
+      if [[ -r $LMDGCM/libf/phy${physique}/${code}.F ]]
+      then
+        source_code=${code}.F90
+        code_dir=phy${physique}
+      else
+        echo "Error: cannot find ${code}.F[90]"
+        echo " neither in dyn${dimc}d${FLAG_PARA} nor in phy${physique}"
+        exit
+      fi
+    fi
+  fi
 fi
 
@@ -625,4 +649,5 @@
 MOD_SUFFIX="mod" \
 AR=$arcommand \
+DIRMAIN=$code_dir \
 SOURCE=$source_code \
 PROG=$code
@@ -654,4 +679,5 @@
 MOD_SUFFIX="mod" \
 AR=$arcommand \
+DIRMAIN=$code_dir \
 SOURCE=$source_code \
 PROG=$code
