Index: trunk/AGRIF/LIB/UtilAgrif.c
===================================================================
--- trunk/AGRIF/LIB/UtilAgrif.c	(revision 396)
+++ trunk/AGRIF/LIB/UtilAgrif.c	(revision 530)
@@ -3,15 +3,33 @@
 /*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
 /*                                                                            */
-/*     Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr)             */
+/* Copyright or © or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
 /*                        Cyril Mazauric (Cyril.Mazauric@imag.fr)             */
-/*                                                                            */
-/*     This program is free software; you can redistribute it and/or modify   */
-/*    it                                                                      */
-/*                                                                            */
-/*    This program is distributed in the hope that it will be useful,         */
-/*     but WITHOUT ANY WARRANTY; without even the implied warranty of         */
-/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
-/*    GNU General Public License for more details.                            */
-/*                                                                            */
+/* This software is governed by the CeCILL-C license under French law and     */
+/* abiding by the rules of distribution of free software.  You can  use,      */
+/* modify and/ or redistribute the software under the terms of the CeCILL-C   */
+/* license as circulated by CEA, CNRS and INRIA at the following URL          */
+/* "http://www.cecill.info".                                                  */
+/*                                                                            */
+/* As a counterpart to the access to the source code and  rights to copy,     */
+/* modify and redistribute granted by the license, users are provided only    */
+/* with a limited warranty  and the software's author,  the holder of the     */
+/* economic rights,  and the successive licensors  have only  limited         */
+/* liability.                                                                 */
+/*                                                                            */
+/* In this respect, the user's attention is drawn to the risks associated     */
+/* with loading,  using,  modifying and/or developing or reproducing the      */
+/* software by the user in light of its specific status of free software,     */
+/* that may mean  that it is complicated to manipulate,  and  that  also      */
+/* therefore means  that it is reserved for developers  and  experienced      */
+/* professionals having in-depth computer knowledge. Users are therefore      */
+/* encouraged to load and test the software's suitability as regards their    */
+/* requirements in conditions enabling the security of their systems and/or   */
+/* data to be ensured and,  more generally, to use and operate it in the      */
+/* same conditions as regards security.                                       */
+/*                                                                            */
+/* The fact that you are presently reading this means that you have had       */
+/* knowledge of the CeCILL-C license and that you accept its terms.           */
+/******************************************************************************/
+/* version 1.0                                                                */
 /******************************************************************************/
 #include <stdio.h>
@@ -20,5 +38,5 @@
 #include "decl.h"
 /******************************************************************************/
-/*                      AGRIF_n_Vartonumber                                   */
+/*                      Vartonumber                                           */
 /******************************************************************************/
 /* This subroutine is used to know if Agrif_ is locate in the char            */
@@ -27,5 +45,5 @@
 /*                                                                            */
 /******************************************************************************/
-int AGRIF_n_Vartonumber(char *tokname)
+int Vartonumber(char *tokname)
 {
    int agrifintheword;
@@ -53,5 +71,5 @@
 
 /******************************************************************************/
-/*                      AGRIF_n_Agrif_in_Tok_NAME                             */
+/*                              Agrif_in_Tok_NAME                             */
 /******************************************************************************/
 /* This subroutine is used to know if Agrif_ is locate in the char            */
@@ -63,5 +81,5 @@
 /*                                                                            */
 /******************************************************************************/
-int AGRIF_n_Agrif_in_Tok_NAME(char *tokname)
+int Agrif_in_Tok_NAME(char *tokname)
 {
    int agrifintheword;
@@ -75,5 +93,5 @@
 
 /******************************************************************************/
-/*          AGRIF_1_completeListofvariableinagriffunction                     */
+/*          completeListofvariableinagriffunction_1                           */
 /******************************************************************************/
 /* Firstpass 1                                                                */
@@ -91,5 +109,5 @@
 /*                                                                            */
 /******************************************************************************/
-void AGRIF_1_completeListofvariableinagriffunction(char *ident)
+void completeListofvariableinagriffunction_1(char *ident)
 {
    listnom *listnomtmp;
@@ -125,5 +143,5 @@
 
 /******************************************************************************/
-/*                     AGRIF_0_ModifyTheVariableName                          */
+/*                     ModifyTheVariableName_0                                */
 /******************************************************************************/
 /* Firstpass 0                                                                */
@@ -133,5 +151,5 @@
 /*                                                                            */
 /******************************************************************************/
-void AGRIF_0_ModifyTheVariableName(char *ident)
+void ModifyTheVariableName_0(char *ident)
 {
    listvar *newvar;
@@ -156,5 +174,5 @@
       {
          /* remove the variable                                               */
-         RemoveWordCUR(fortranout,(long)(-strlen(ident)),
+         RemoveWordCUR_0(fortranout,(long)(-strlen(ident)),
                                strlen(ident));
          fseek(fortranout,(long)(-strlen(ident)),SEEK_CUR);
@@ -164,6 +182,4 @@
          else
          {
-            fprintf(fortranout,"%s",vargridcurgridtabvars(newvar->var,0));
-            colnum = strlen(vargridcurgridtabvars(newvar->var,0));
             if ( colnum >= 25 ) 
             {
@@ -177,4 +193,6 @@
               }
             }
+            fprintf(fortranout,"%s",vargridcurgridtabvars(newvar->var,0));
+            colnum = strlen(vargridcurgridtabvars(newvar->var,0));
          }
       }
@@ -193,5 +211,5 @@
             {
                /* remove the variable                                         */
-               RemoveWordCUR(fortranout,(long)(-strlen(ident)),
+               RemoveWordCUR_0(fortranout,(long)(-strlen(ident)),
                                      strlen(ident));
                fseek(fortranout,(long)(-strlen(ident)),SEEK_CUR);
@@ -218,5 +236,5 @@
 
 /******************************************************************************/
-/*             AGRIF_n_AddsubroutineTolistsubwhereagrifused                   */
+/*                     AddsubroutineTolistsubwhereagrifused                   */
 /******************************************************************************/
 /* This subroutine is used to add a record to                                 */
@@ -234,5 +252,5 @@
 /*                                                                            */
 /******************************************************************************/
-void  AGRIF_n_AddsubroutineTolistsubwhereagrifused()
+void  AddsubroutineTolistsubwhereagrifused()
 {
   listnom *listnomtmp;
@@ -264,5 +282,5 @@
 
 /******************************************************************************/
-/*                          AGRIF_n_AddUseAgrifUtil                           */
+/*                                AddUseAgrifUtil_0                           */
 /******************************************************************************/
 /* Add use Agrif_Util at the beginning of the subroutine definition           */
@@ -280,5 +298,5 @@
 /*                                                                            */
 /******************************************************************************/
-void  AGRIF_n_AddUseAgrifUtil()
+void  AddUseAgrifUtil_0()
 {
   listnom *parcours;
@@ -286,4 +304,7 @@
   int out;
 
+  if ( firstpass == 0 )
+  {
+  adduseagrifutil = 0 ;
   parcours = listofsubroutinewhereagrifisused;
   while ( parcours && strcasecmp(parcours->nom,subroutinename) )  
@@ -312,9 +333,10 @@
      }
   }
-}
-
-
-/******************************************************************************/
-/*                         AGRIF_0_AgrifParentNotify                          */
+  }
+}
+
+
+/******************************************************************************/
+/*                         AgrifParentNotify_0                                */
 /******************************************************************************/
 /* Firstpass 0                                                                */
@@ -324,5 +346,5 @@
 /*                                                                            */
 /******************************************************************************/
-void AGRIF_0_NotifyAgrifFunction(char *ident)
+void NotifyAgrifFunction_0(char *ident)
 {
    if ( firstpass == 0 ) 
@@ -482,5 +504,5 @@
 
 /******************************************************************************/
-/*                       AGRIF_0_ModifyTheAgrifFunction                       */
+/*                       ModifyTheAgrifFunction_0                             */
 /******************************************************************************/
 /* Firstpass 0                                                                */
@@ -490,8 +512,8 @@
 /*                                                                            */
 /******************************************************************************/
-void AGRIF_0_ModifyTheAgrifFunction(char *ident)
+void ModifyTheAgrifFunction_0(char *ident)
 {
    if ( InAgrifParentDef != 0 )
-          AGRIF_0_AgriffunctionModify(ident,InAgrifParentDef);
+          AgriffunctionModify_0(ident,InAgrifParentDef);
    /*                                                                         */
    InAgrifParentDef = 0;
@@ -500,5 +522,5 @@
 
 /******************************************************************************/
-/*                         AGRIF_0_AgriffunctionModify                        */
+/*                         AgriffunctionModify_0                              */
 /******************************************************************************/
 /* Firstpass 0                                                                */
@@ -566,5 +588,5 @@
 /*                                                                            */
 /******************************************************************************/
-void AGRIF_0_AgriffunctionModify(char *ident,int whichone)
+void AgriffunctionModify_0(char *ident,int whichone)
 {
    char toprint[LONGNOM];
@@ -716,5 +738,5 @@
 
 /******************************************************************************/
-/*                          AGRIF_0_AddUseAgrifInModuleDeclaration            */
+/*                   AddUseAgrifInModuleDeclaration_0                         */
 /******************************************************************************/
 /* Add use Agrif_Util at the beginning of the subroutine definition           */
@@ -732,5 +754,5 @@
 /*                                                                            */
 /******************************************************************************/
-void  AGRIF_0_AddUseAgrifInModuleDeclaration()
+void  AddUseAgrifInModuleDeclaration_0()
 {
   listusemodule *newmodule;
@@ -760,2 +782,55 @@
    }
 }
+
+
+/******************************************************************************/
+/*                             Instanciation_0                                */
+/******************************************************************************/
+/* Firstpass 0                                                                */
+/******************************************************************************/
+/*                                                                            */
+/*               Agrif_<toto>(variable) ====>     Agrif_<toto>(variable)      */
+/*                                                                            */
+/******************************************************************************/
+void Instanciation_0(char *ident)
+{
+   listvar *newvar;
+   int out;
+
+   if ( firstpass == 0 && sameagrifargument == 1 ) 
+   {
+      if ( fortran77 == 0 ) newvar = globalvarofusefile;
+      else newvar = globliste;
+
+      out=0;
+      while ( newvar && out == 0 ) 
+      {
+         if ( !strcasecmp(newvar->var->nomvar,ident) ) out = 1;
+         else newvar=newvar->suiv;      
+      }
+      if ( out == 1 ) 
+      {
+         /* then write the instanciation                                      */
+         fprintf(fortranout,"\n      %s = %s",ident,vargridcurgridtabvars(newvar->var,3));
+         colnum = 0;
+      }
+      else
+      {
+         newvar = globalvarofusefile;
+
+         out=0;
+         while ( newvar && out == 0 ) 
+         {
+            if ( !strcasecmp(newvar->var->nomvar,ident) ) out = 1;
+            else newvar=newvar->suiv;      
+         }
+         if ( out == 1 ) 
+         {
+            /* then write the instanciation                                      */
+            fprintf(fortranout,"\n      %s = %s",ident,vargridcurgridtabvars(newvar->var,3));
+            colnum = 0;
+         }
+      }
+   }
+   sameagrifargument = 0;
+}
