Index: /trunk/LMDZ.MARS/README
===================================================================
--- /trunk/LMDZ.MARS/README	(revision 518)
+++ /trunk/LMDZ.MARS/README	(revision 519)
@@ -1378,2 +1378,10 @@
    Also updated "phymars/comdiurn.h", "aeronomars/conc.h" and 
    "aeronomars/chimiedata.h" to be fixed/free form compatible.
+
+== 09/02/12 == EM
+>> Updated the makegcm(s) so that default behaviour is to set LMDGCM env variable
+   to be the directory in which the makegcm script is. Updated the makegcm_*
+   to use "SOURCE" to identify main program to compile
+>> Adapted "create_make_gcm" script so that it can compile a main program that
+   is either something.F or something.F90. Also added that object files are
+   removed from archive before compiling a new version.
Index: /trunk/LMDZ.MARS/create_make_gcm
===================================================================
--- /trunk/LMDZ.MARS/create_make_gcm	(revision 518)
+++ /trunk/LMDZ.MARS/create_make_gcm	(revision 519)
@@ -109,5 +109,5 @@
 echo '	cd $(LIBO) ; $(RANLIB) lib*.a ; cd $(GCM) ;\'
 echo '	cd $(LOCAL_DIR); \'
-echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(PROG).F -o $(PROG).o ; \'
+echo '	$(COMPILE90) $(LIBF)/$(DIRMAIN)/$(SOURCE) -o $(PROG).o ; \'
 if [ "$CRAY" = '0' ] ; then
 echo '	$(LINK) $(PROG).o -L$(LIBO) $(L_DYN) $(L_ADJNT) $(L_FILTRE) $(L_AERONOMARS) $(L_PHY) $(L_BIBIO) $(L_DYN) $(L_AERONOMARS) $(OPLINK) $(OPTION_LINK) -o $(LOCAL_DIR)/$(PROG).e ; $(RM) $(PROG).o '
@@ -219,14 +219,22 @@
          done
          echo $str1
+         # Compile in LOCAL_DIR directory, and before compiling,
+         # remove the object from the library
+         echo '	cd $(LOCAL_DIR); \'
+         echo '	$(AR) d $(LIBO)/lib'$diri'.a '$fili'.o ; \'
 	 if [ "$F90" -eq '0' ] ; then
-           echo '	cd $(LOCAL_DIR); \'
+         ## Fixed Form Fortran 77
 	   echo '	$(COMPILE) $(LIBF)/'$diri'/'$trufile' ; \'
 	 else
+         ## Fortran 90
            echo '	cd $(LOCAL_DIR); \'
            if [ -f $fili.F90 ] ; then
-	      echo '	$(COMPTRU90) $(LIBF)/'$diri'/'$trufile' ; \'
+	   ## Free Form Fortran 90
+              echo '	$(COMPTRU90) $(LIBF)/'$diri'/'$trufile' ; \'
            else
-	      echo '	$(COMPILE90) $(LIBF)/'$diri'/'$trufile' ; \'
+	   ## Fixed Form Fortran 90
+              echo '	$(COMPILE90) $(LIBF)/'$diri'/'$trufile' ; \'
            fi
+           ## If a module, handle created module descriptor file
            MODU=0; egrep -i '^ *module ' $trufile> /dev/null 2>&1 && MODU=1
             if [ "$MODU" -eq '1' -a "$CRAY" != '1' ] ; then
@@ -242,4 +250,5 @@
            echo '	sxar r $(LIBO)/libsx'$diri'.a '$fili'.o ; \'
          fi
+         # Put generated object in library
          echo '	$(AR) r $(LIBO)/lib'$diri'.a '$fili'.o ; $(RM) '$fili'.o ; \'
          echo '	cd $(GCM)'
Index: /trunk/LMDZ.MARS/makegcm
===================================================================
--- /trunk/LMDZ.MARS/makegcm	(revision 518)
+++ /trunk/LMDZ.MARS/makegcm	(revision 519)
@@ -21,12 +21,13 @@
 ####  relying on the C-shell environment variables)
 # default LMDGCM to where makegcm script is located:
-#setenv LMDGCM "`dirname $0`"
+set scriptdir=`dirname $0`
+setenv LMDGCM `readlink -f $scriptdir`
 # You may set LIBOGCM to something else; otherwise we default to:
-#setenv LIBOGCM $LMDGCM/libo
+setenv LIBOGCM $LMDGCM/libo
 ## NetCDF Libraries: what follows is OK for LMD 32 and 64bit Linux Machines
 #if ( `uname -m` == "x86_64" ) then
 ## 64 bit machines
-#  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_pgi/lib
-#  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_pgi/include
+  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_pgi/lib
+  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_pgi/include
 #else
 #  setenv NCDFLIB /donnees/emlmd/netcdf-4.0.1_pgi/lib
@@ -735,4 +736,27 @@
 cd $localdir
 
+## locate main program (could be in dyn3d or phy$physique
+##                      and could be .F or .F90)
+set source_code=${code}.F
+if ( -f $LMDGCM/libf/dyn3d/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F ) then
+  set source_code=${code}.F
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+
+## locate directory where main program is located
+if ( $dimension == 3 ) then
+  if ( -f $LMDGCM/libf/dyn3d/${source_code} ) then
+    set dyn="DIRMAIN=dyn3d "
+  endif
+  if ( -f $LMDGCM/libf/phy${physique}/${source_code} ) then
+    set dyn="DIRMAIN=phy${physique} "
+  endif
+endif
+
 echo $make -f $LMDGCM/makefile \
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
@@ -757,4 +781,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
@@ -782,4 +807,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
Index: /trunk/LMDZ.MARS/makegcm_g95
===================================================================
--- /trunk/LMDZ.MARS/makegcm_g95	(revision 518)
+++ /trunk/LMDZ.MARS/makegcm_g95	(revision 519)
@@ -21,12 +21,13 @@
 ####  relying on the C-shell environment variables)
 # default LMDGCM to where makegcm script is located:
-#setenv LMDGCM "`dirname $0`"
+set scriptdir=`dirname $0`
+setenv LMDGCM `readlink -f $scriptdir`
 # You may set LIBOGCM to something else; otherwise we default to:
-#setenv LIBOGCM $LMDGCM/libo
+setenv LIBOGCM $LMDGCM/libo
 ## NetCDF Libraries: what follows is OK for LMD 32 and 64bit Linux Machines
 #if ( `uname -m` == "x86_64" ) then
 ## 64 bit machines
-#  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_g95/lib
-#  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_g95/include
+  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_g95/lib
+  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_g95/include
 #else
 #  setenv NCDFLIB /donnees/emlmd/netcdf-4.0.1_g95/lib
@@ -736,4 +737,27 @@
 cd $localdir
 
+## locate main program (could be in dyn3d or phy$physique
+##                      and could be .F or .F90)
+set source_code=${code}.F
+if ( -f $LMDGCM/libf/dyn3d/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F ) then
+  set source_code=${code}.F
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+
+## locate directory where main program is located
+if ( $dimension == 3 ) then
+  if ( -f $LMDGCM/libf/dyn3d/${source_code} ) then
+    set dyn="DIRMAIN=dyn3d "
+  endif
+  if ( -f $LMDGCM/libf/phy${physique}/${source_code} ) then
+    set dyn="DIRMAIN=phy${physique} "
+  endif
+endif
+
 echo $make -f $LMDGCM/makefile \
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
@@ -758,4 +782,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
@@ -783,4 +808,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
Index: /trunk/LMDZ.MARS/makegcm_gfortran
===================================================================
--- /trunk/LMDZ.MARS/makegcm_gfortran	(revision 518)
+++ /trunk/LMDZ.MARS/makegcm_gfortran	(revision 519)
@@ -21,12 +21,13 @@
 ####  relying on the C-shell environment variables)
 # default LMDGCM to where makegcm script is located:
-#setenv LMDGCM "`dirname $0`"
+set scriptdir=`dirname $0`
+setenv LMDGCM `readlink -f $scriptdir`
 # You may set LIBOGCM to something else; otherwise we default to:
-#setenv LIBOGCM $LMDGCM/libo
+setenv LIBOGCM $LMDGCM/libo
 ## NetCDF Libraries: what follows is OK for LMD 32 and 64bit Linux Machines
 #if ( `uname -m` == "x86_64" ) then
 # 64 bit machines
-#  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_gfortran/lib
-#  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_gfortran/include
+  setenv NCDFLIB /donnees/emlmd/netcdf64-4.0.1_gfortran/lib
+  setenv NCDFINC /donnees/emlmd/netcdf64-4.0.1_gfortran/include
 #else
 #  setenv NCDFLIB /donnees/emlmd/netcdf-4.0.1_gfortran/lib
@@ -734,4 +735,27 @@
 cd $localdir
 
+## locate main program (could be in dyn3d or phy$physique
+##                      and could be .F or .F90)
+set source_code=${code}.F
+if ( -f $LMDGCM/libf/dyn3d/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F ) then
+  set source_code=${code}.F
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+
+## locate directory where main program is located
+if ( $dimension == 3 ) then
+  if ( -f $LMDGCM/libf/dyn3d/${source_code} ) then
+    set dyn="DIRMAIN=dyn3d "
+  endif
+  if ( -f $LMDGCM/libf/phy${physique}/${source_code} ) then
+    set dyn="DIRMAIN=phy${physique} "
+  endif
+endif
+
 echo $make -f $LMDGCM/makefile \
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
@@ -756,4 +780,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
@@ -781,4 +806,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
Index: /trunk/LMDZ.MARS/makegcm_ifort
===================================================================
--- /trunk/LMDZ.MARS/makegcm_ifort	(revision 518)
+++ /trunk/LMDZ.MARS/makegcm_ifort	(revision 519)
@@ -21,5 +21,6 @@
 ####  relying on the C-shell environment variables)
 # default LMDGCM to where makegcm script is located:
-#setenv LMDGCM "`dirname $0`"
+set scriptdir=`dirname $0`
+setenv LMDGCM `readlink -f $scriptdir`
 # You may set LIBOGCM to something else; otherwise we default to:
 setenv LIBOGCM $LMDGCM/libo
@@ -740,4 +741,27 @@
 cd $localdir
 
+## locate main program (could be in dyn3d or phy$physique
+##                      and could be .F or .F90)
+set source_code=${code}.F
+if ( -f $LMDGCM/libf/dyn3d/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F ) then
+  set source_code=${code}.F
+endif
+if ( -f $LMDGCM/libf/phy${physique}/${code}.F90 ) then
+  set source_code=${code}.F90
+endif
+
+## locate directory where main program is located
+if ( $dimension == 3 ) then
+  if ( -f $LMDGCM/libf/dyn3d/${source_code} ) then
+    set dyn="DIRMAIN=dyn3d "
+  endif
+  if ( -f $LMDGCM/libf/phy${physique}/${source_code} ) then
+    set dyn="DIRMAIN=phy${physique} "
+  endif
+endif
+
 echo $make -f $LMDGCM/makefile \
 OPTION_DEP="$opt_dep" OPTION_LINK="$opt_link" \
@@ -762,4 +786,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
@@ -787,4 +812,5 @@
 MOD_SUFFIX=$mod_suffix \
 AR=$ar \
+SOURCE=$source_code \
 PROG=$code
 
