Index: trunk/AGRIF/LIB/Writedeclarations.c
===================================================================
--- trunk/AGRIF/LIB/Writedeclarations.c	(revision 530)
+++ trunk/AGRIF/LIB/Writedeclarations.c	(revision 663)
@@ -3,6 +3,6 @@
 /*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
 /*                                                                            */
-/* Copyright or © or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
-/*                        Cyril Mazauric (Cyril.Mazauric@imag.fr)             */
+/* Copyright or   or Copr. Laurent Debreu (Laurent.Debreu@imag.fr)            */
+/*                        Cyril Mazauric (Cyril_Mazauric@yahoo.fr)            */
 /* 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,      */
@@ -31,5 +31,5 @@
 /* knowledge of the CeCILL-C license and that you accept its terms.           */
 /******************************************************************************/
-/* version 1.0                                                                */
+/* version 1.6                                                                */
 /******************************************************************************/
 #include <stdio.h>
@@ -54,34 +54,40 @@
   char tmpligne[LONGLIGNE];
 
-  sprintf (ligne, "%s", v->typevar);
-  if ( v->c_star == 1 ) strcat(ligne,"*");
+  if ( !strcasecmp(v->v_typevar,"") )
+  {
+     printf("WARNING : The type of the variable %s \n",v->v_nomvar);
+     printf("          is unknown. CONV should define a type\n");
+  }
+  sprintf (ligne, "%s", v->v_typevar);
+  if ( v->v_c_star == 1 ) strcat(ligne,"*");
   /* We should give the precision of the variable if it has been given        */
-  if ( strcasecmp(v->precision,"") )
-  {
-     sprintf(tmpligne,"(%s)",v->precision);
+  if ( strcasecmp(v->v_precision,"") )
+  {
+     sprintf(tmpligne,"(%s)",v->v_precision);
      strcat(ligne,tmpligne);
   }
-  if (strcasecmp(v->dimchar,""))
-  {
-     sprintf(tmpligne,"(%s)",v->dimchar);
+  if (strcasecmp(v->v_dimchar,""))
+  {
+     sprintf(tmpligne,"(%s)",v->v_dimchar);
      strcat(ligne,tmpligne);
   }
-  if ( strcasecmp(v->nameinttypename,"") )
-  {
-     sprintf(tmpligne,"*%s",v->nameinttypename);
+  if ( strcasecmp(v->v_nameinttypename,"") )
+  {
+     sprintf(tmpligne,"*%s",v->v_nameinttypename);
      strcat(ligne,tmpligne);
   }
-  if (strcasecmp (v->IntentSpec, ""))
-  {
-     sprintf(tmpligne,",INTENT(%s) ",v->IntentSpec);
+  if (strcasecmp (v->v_IntentSpec, ""))
+  {
+     sprintf(tmpligne,",INTENT(%s) ",v->v_IntentSpec);
      strcat(ligne,tmpligne);
-  }   
-  if ( v->VariableIsParameter == 1 ) strcat(ligne, ", PARAMETER");
-  if ( v->PublicDeclare       == 1 ) strcat(ligne, ", PUBLIC");  
-  if ( v->PrivateDeclare      == 1 ) strcat(ligne, ", PRIVATE"); 
-  if ( v->ExternalDeclare     == 1 ) strcat(ligne, ", EXTERNAL");  
-  if ( v->allocatable == 1 && v->save ==0 ) strcat(ligne,", ALLOCATABLE");
-  if ( v->optionaldeclare == 1 ) strcat(ligne,", OPTIONAL");
-  if ( v->pointerdeclare == 1 ) strcat(ligne,", POINTER");
+  }
+  if ( v->v_VariableIsParameter == 1 ) strcat(ligne, ", PARAMETER");
+  if ( v->v_PublicDeclare       == 1 ) strcat(ligne, ", PUBLIC");
+  if ( v->v_PrivateDeclare      == 1 ) strcat(ligne, ", PRIVATE");
+  if ( v->v_ExternalDeclare     == 1 ) strcat(ligne, ", EXTERNAL");
+  if ( v->v_allocatable         == 1 &&
+       v->v_save                == 0 ) strcat(ligne,", ALLOCATABLE");
+  if ( v->v_optionaldeclare     == 1 ) strcat(ligne,", OPTIONAL");
+  if ( v->v_pointerdeclare      == 1 ) strcat(ligne,", POINTER");
 }
 
@@ -98,14 +104,14 @@
 /*                                                                            */
 /******************************************************************************/
-void  WriteScalarDeclaration(variable *v,char ligne[LONGLIGNE])
+void WriteScalarDeclaration(variable *v,char ligne[LONGLIGNE])
 {
 
   strcat (ligne, " :: ");
-  strcat (ligne, v->nomvar);
-  if ( strcasecmp(v->vallengspec,"") ) strcat(ligne,v->vallengspec);
-  if ( v->VariableIsParameter == 1 ) 
+  strcat (ligne, v->v_nomvar);
+  if ( strcasecmp(v->v_vallengspec,"") ) strcat(ligne,v->v_vallengspec);
+  if ( v->v_VariableIsParameter == 1 )
   {
      strcat(ligne," = ");
-     strcat(ligne,v->initialvalue);
+     strcat(ligne,v->v_initialvalue);
   }
 }
@@ -124,22 +130,29 @@
 /*                                                                            */
 /******************************************************************************/
-void  WriteTableDeclaration(variable * v,char ligne[LONGLIGNE],int tmpok)
+void WriteTableDeclaration(variable * v,char ligne[LONGLIGNE],int tmpok)
 {
   char newname[LONGNOM];
 
   strcat (ligne, ", Dimension(");
-  if ( v->dimensiongiven == 1 && tmpok == 1 )
-                                           strcat(ligne,v->readedlistdimension);
-  if ( v->dimensiongiven == 1 && tmpok == 0 )
+  if ( v->v_dimensiongiven == 1 && tmpok == 1 )
+                                         strcat(ligne,v->v_readedlistdimension);
+  if ( v->v_dimensiongiven == 1 && tmpok == 0 )
   {
      strcpy(newname,ChangeTheInitalvaluebyTabvarsName
-                                          (v->readedlistdimension,globliste,0));
-     if ( !strcasecmp(newname,v->readedlistdimension) )
-     {
-        strcpy(newname,"");     
+                                  (v->v_readedlistdimension,List_Global_Var,0));
+     if ( !strcasecmp(newname,v->v_readedlistdimension) )
+     {
+        strcpy(newname,"");
+        strcpy(newname,ChangeTheInitalvaluebyTabvarsName
+                                 (v->v_readedlistdimension,List_Common_Var,0));
+        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
+     }
+     if ( !strcasecmp(newname,v->v_readedlistdimension) )
+     {
+        strcpy(newname,"");
         /* la liste des use de cette subroutine                               */
         strcpy(newname,ChangeTheInitalvaluebyTabvarsName
-                                 (v->readedlistdimension,globalvarofusefile,0));
-        if ( !strcasecmp(newname,"") ) strcat(newname,v->readedlistdimension);
+                              (v->v_readedlistdimension,List_ModuleUsed_Var,0));
+        if ( !strcasecmp(newname,"") ) strcat(newname,v->v_readedlistdimension);
      }
      strcat(ligne,newname);
@@ -147,7 +160,13 @@
   strcat (ligne, ")");
   strcat (ligne, " :: ");
-  strcat (ligne, v->nomvar);  
-  if ( strcasecmp(vallengspec,"") ) strcat(ligne,v->vallengspec);
-  if ( !strcasecmp (v->typevar, "character") ) strcat(ligne,vargridparam(v,0));
+  strcat (ligne, v->v_nomvar);
+  if ( strcasecmp(vallengspec,"") ) strcat(ligne,v->v_vallengspec);
+/*  if ( !strcasecmp (v->v_typevar, "character") )
+                              strcat(ligne,vargridparam(v,0));*/
+  if ( v->v_VariableIsParameter == 1 )
+  {
+     strcat(ligne," = ");
+     strcat(ligne,v->v_initialvalue);
+  }
 }
 
@@ -164,5 +183,5 @@
 /*                                                                            */
 /******************************************************************************/
-void writevardeclaration (listvar * var_record, FILE *fileout)
+void writevardeclaration (listvar * var_record, FILE *fileout, int value)
 {
   FILE *filecommon;
@@ -174,16 +193,16 @@
   newvar = var_record;
 
-  if ( newvar->var->save == 0 || inmodulemeet == 0 )
+  if ( newvar->var->v_save == 0 || inmodulemeet == 0 )
   {
      v = newvar->var;
      WriteBeginDeclaration(v,ligne);
-     if ( v->nbdim == 0 ) WriteScalarDeclaration(v,ligne);
-     else WriteTableDeclaration(v,ligne,0);
-
-     if ( strcasecmp(v->initialvalue,"") )
+     if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
+     else WriteTableDeclaration(v,ligne,value);
+
+     if ( v->v_VariableIsParameter != 1 && strcasecmp(v->v_initialvalue,"") )
      {
         strcat(ligne," = ");
-        strcat(ligne,v->initialvalue);
-     }  
+        strcat(ligne,v->v_initialvalue);
+     }
      tofich (filecommon, ligne,1);
   }
@@ -191,143 +210,159 @@
 
 
-/******************************************************************************/
-/*                      NonGridDepDeclaration                                 */
-/******************************************************************************/
-/* This subroutine is used to change the variables declaration                */
-/*                                                                            */
-/******************************************************************************/
-/*                                                                            */
-/*  integer variable(nb) ----------->                                         */
-/*                      INTEGER, DIMENSION(:),Pointer :: variable             */
-/*                                                                            */
-/******************************************************************************/
-void NonGridDepDeclaration(listvar * deb_common)
-{
-  listvar *newvar;
-
-  if ( ( SaveDeclare == 0 || aftercontainsdeclare == 0 ) && listenotgriddepend ) 
-  {
-     newvar = deb_common;
-     while (newvar)
-     {
-        if ( VarIsNonGridDepend(newvar->var->nomvar) == 1 ) 
-                                       writevardeclaration (newvar, fortranout);
-        newvar = newvar->suiv;
-     }
-  }
-}
-
-
-/******************************************************************************/
-/*                       writedeclaration                                     */
-/******************************************************************************/
-/* This subroutine is used to write the declaration if variable present in    */
-/*    the deb_common and also in the presentinthislist list file              */
-/******************************************************************************/
-/*                                                                            */
-/*  integer variable(nb) ----------->                                         */
-/*                      INTEGER, DIMENSION(1:nb),Pointer :: variable          */
-/*                                                                            */
-/******************************************************************************/
-void writedeclaration (listvar * deb_common, FILE *fileout, listvar *presentinthislist)
-{
-  FILE *filecommon;
-  listvar *newvar;
-  listvar *parcours;
-  variable *v;
-  char ligne[LONGLIGNE];
-  int out;
-
-  filecommon=fileout;
-
-  newvar = deb_common;
-  while (newvar)
-  {
-     if ( newvar->var->save == 0 || inmodulemeet == 0 )
-     {
-        parcours = presentinthislist;
-        /* we should write declaration of variable present in the list        */
-        /* presentinthislist                                                  */
-        /* if presentinthislist is empty we should write all declarations     */
-        out = 0 ;
-        while ( parcours && out == 0 )
-        {
-            /* if we find this variable in the presentinthislist, we          */
-            /* could write it                                                 */
-           if ( !strcasecmp(parcours->var->nomvar,newvar->var->nomvar) &&
-                !strcasecmp(parcours->var->subroutinename,
-                                          newvar->var->subroutinename) 
-               ) out = 1;
-           else parcours =parcours ->suiv;
-        }
-        if ( out == 0 || !presentinthislist)
-        {
-           /* if the variable has not been found or if the                    */
-           /* presentinthislist is empty, we do not write the declaration     */
-        }
-        else
-        {
-           /* else we could write it                                          */
-           v = newvar->var;
-           WriteBeginDeclaration(v,ligne);
-           if ( v->nbdim == 0 ) WriteScalarDeclaration(v,ligne);
-           else WriteTableDeclaration(v,ligne,0);
-            
-           if ( strcasecmp(v->initialvalue,"") )
-           {
-              strcat(ligne, "=");
-              strcat(ligne, v->initialvalue);
-           }
-           tofich (filecommon, ligne,1);
-        }
-     }
-     newvar = newvar->suiv;
-  }
-}
-
-/******************************************************************************/
-/*                       writesub_loopdeclaration                             */
-/******************************************************************************/
-/* This subroutine is used to write the declaration part of subloop           */
-/*    subroutines                                                             */
-/******************************************************************************/
-/*                                                                            */
-/*  integer variable(nb) ----------->                                         */
-/*                                                                            */
-/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
-/*                                                                            */
-/******************************************************************************/
-void writesub_loopdeclaration (listvar * deb_common, FILE *fileout)
-{
-  listvar *newvar;
-  variable *v;
-  char ligne[LONGLIGNE];
-  int changeval;
-
-  tofich (fileout, "",1);
-  newvar = deb_common;
-  while (newvar)
-  {
-     if ( !strcasecmp(newvar->var->modulename,subroutinename) )
-     {
-        changeval = 0;
-        v = newvar->var;
-        if ( v->allocatable == 1 && fortran77 == 0 ) 
-        {
-           changeval = 1;
-           v->allocatable = 0; 
-        }
-        WriteBeginDeclaration(v,ligne);
-        if ( v->nbdim == 0 ) WriteScalarDeclaration(v,ligne);
-        else WriteTableDeclaration(v,ligne,1);
-
-        tofich (fileout, ligne,1);
-        if ( changeval == 1 ) 
-        {
-           v->allocatable = 1;
-        }
-     }
-     newvar = newvar->suiv;
-  }
+void WriteLocalParamDeclaration()
+{
+   listvar *parcours;
+
+   parcours = List_Parameter_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) )
+      {
+         writevardeclaration(parcours,fortranout,0);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteFunctionDeclaration()
+{
+   listvar *parcours;
+
+   parcours = List_FunctionType_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+            strcasecmp(parcours->var->v_typevar,"")
+         )
+      {
+         writevardeclaration(parcours,fortranout,0);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteSubroutineDeclaration(int value)
+{
+   listvar *parcours;
+
+   parcours = List_SubroutineDeclaration_Var;
+   while ( parcours )
+   {
+      if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+           parcours->var->v_save == 0                                  &&
+           parcours->var->v_allocatable == 0                           &&
+           parcours->var->v_pointerdeclare == 0                        &&
+           parcours->var->v_VariableIsParameter == 0                   &&
+           parcours->var->v_common == 0
+         )
+      {
+         writevardeclaration(parcours,fortranout,value);
+      }
+      else if ( !strcasecmp(parcours->var->v_subroutinename,subroutinename) &&
+           parcours->var->v_save == 0                                  &&
+           parcours->var->v_VariableIsParameter == 0                   &&
+           parcours->var->v_common == 0
+              )
+      {
+         writevardeclaration(parcours,fortranout,value);
+      }
+      parcours = parcours -> suiv;
+   }
+}
+
+void WriteArgumentDeclaration_beforecall()
+{
+   variable *v;
+   int position;
+   listnom *neededparameter;
+   FILE *paramtoamr;
+   listvar *newvar;
+   char ligne[LONGLIGNE];
+   int out;
+   int writeit;
+   listnom *parcours;
+
+   fprintf(fortranout,"#include \"Param_BeforeCall_%s.h\" \n",subroutinename);
+   /*                                                                         */
+   sprintf(ligne,"Param_BeforeCall_%s.h",subroutinename);
+   paramtoamr = associate (ligne);
+   /*                                                                         */
+   neededparameter = (listnom * )NULL;
+   /*                                                                         */
+   position = 1;
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == position
+         )
+      {
+         position = position + 1;
+         writevardeclaration(newvar,fortranout,0);
+         neededparameter = writedeclarationintoamr(List_Parameter_Var,
+                   paramtoamr,newvar->var,newvar->var->v_subroutinename,
+                   neededparameter,subroutinename);
+
+         newvar = List_SubroutineArgument_Var;
+      }
+      else newvar = newvar -> suiv;
+   }
+   fclose(paramtoamr);
+}
+
+void WriteArgumentDeclaration_Sort()
+{
+   variable *v;
+   int position;
+/*   listnom *neededparameter;*/
+   FILE *paramtoamr;
+   listvar *newvar;
+   char ligne[LONGLIGNE];
+   int out;
+   int writeit;
+   listnom *parcours;
+
+   /*                                                                         */
+   position = 1;
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == position
+         )
+      {
+         position = position + 1;
+         writevardeclaration(newvar,fortranout,1);
+         /*                                                                   */
+         newvar = List_SubroutineArgument_Var;
+      }
+      else newvar = newvar -> suiv;
+   }
+   /*                                                                         */
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == 0           &&
+                       newvar->var->v_nbdim == 0
+         )
+      {
+         writevardeclaration(newvar,fortranout,1);
+      }
+      newvar = newvar -> suiv;
+   }
+   /*                                                                         */
+   newvar = List_SubroutineArgument_Var;
+   while ( newvar )
+   {
+      if ( !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+                       newvar->var->v_positioninblock == 0           &&
+                       newvar->var->v_nbdim != 0
+         )
+      {
+         writevardeclaration(newvar,fortranout,1);
+      }
+      newvar = newvar -> suiv;
+   }
 }
 
@@ -341,6 +376,7 @@
 /*                                                                            */
 /******************************************************************************/
-void writedeclarationintoamr (listvar * deb_common, FILE *fileout,
-                              listvar *listin , char commonname[LONGNOM])
+listnom *writedeclarationintoamr (listvar * deb_common, FILE *fileout,
+                              variable *var , char commonname[LONGNOM],
+                           listnom *neededparameter, char name_common[LONGNOM])
 {
   listvar *newvar;
@@ -350,26 +386,13 @@
   char firstmodule[LONGNOM];
   int out;
-  listnom *neededparameter;
   int writeit;
   listnom *parcours;
   listnom *parcoursprec;
-  
+
   parcoursprec = (listnom * )NULL;
-  neededparameter = (listnom * )NULL;
   /* we should list the needed parameter                                      */
-  newvar = listin;
-  out = 0 ;
-  while ( newvar && out == 0 )
-  {
-     if ( strcasecmp(newvar->var->commonname,commonname) ) out = 1;
-     else 
-     {
-        /* add the name to the list of needed parameter                       */
-        neededparameter = DecomposeTheNameinlistnom(
-                 newvar->var->readedlistdimension,
-                 neededparameter );
-        newvar = newvar->suiv;
-     }
-  }
+  if ( !strcasecmp(name_common,commonname) )
+     neededparameter = DecomposeTheNameinlistnom(var->v_readedlistdimension,
+                                                               neededparameter);
   /*                                                                          */
   parcours = neededparameter;
@@ -380,10 +403,10 @@
      while ( newvar && out == 0 )
      {
-        if ( !strcasecmp(parcours->nom,newvar->var->nomvar) ) 
-        {
-           out=1; 
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
+        {
+           out=1;
         /* add the name to the list of needed parameter                       */
            neededparameter = DecomposeTheNameinlistnom(
-                 newvar->var->initialvalue,
+                 newvar->var->v_initialvalue,
                  neededparameter );
         }
@@ -391,5 +414,5 @@
      }
      parcours=parcours->suiv;
-   }     
+   }
   /*                                                                          */
   parcours = neededparameter;
@@ -400,10 +423,10 @@
      while ( newvar && out == 0 )
      {
-        if ( !strcasecmp(parcours->nom,newvar->var->nomvar) ) 
-        {
-           out=1; 
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) )
+        {
+           out=1;
         /* add the name to the list of needed parameter                       */
            neededparameter = DecomposeTheNameinlistnom(
-                 newvar->var->initialvalue,
+                 newvar->var->v_initialvalue,
                  neededparameter );
         }
@@ -411,52 +434,91 @@
      }
      parcours=parcours->suiv;
-   }     
+   }
   /*                                                                          */
   strcpy(firstmodule,"");
   tofich (fileout, "",1);
+  parcours = neededparameter;
+  while (parcours)
+  {
+     writeit = 0;
+     newvar = deb_common;
+     while ( newvar && writeit == 0 )
+     {
+        if ( !strcasecmp(parcours->o_nom,newvar->var->v_nomvar) &&
+             parcours->o_val == 0 )
+        {
+           writeit=1;
+           parcours->o_val = 1;
+        }
+        else newvar = newvar->suiv;
+     }
+
+     if ( writeit == 1  )
+     {
+        changeval = 0;
+        v = newvar->var;
+        if ( v->v_allocatable == 1  )
+        {
+           changeval = 1;
+           v->v_allocatable = 0;
+        }
+        WriteBeginDeclaration(v,ligne);
+        if ( v->v_nbdim == 0 ) WriteScalarDeclaration(v,ligne);
+        else WriteTableDeclaration(v,ligne,1);
+
+        tofich (fileout, ligne,1);
+        if ( changeval == 1 )
+        {
+           v->v_allocatable = 1;
+        }
+     }
+     else
+     {
+        if (  strncasecmp(parcours->o_nom,"mpi_",4) == 0 &&
+              shouldincludempif                     == 1 )
+        {
+           shouldincludempif = 0;
+           fprintf(fileout,"      include \'mpif.h\' \n");
+        }
+     }
+     parcours=parcours->suiv;
+  }
+  return neededparameter;
+}
+
+
+/******************************************************************************/
+/*                       writesub_loopdeclaration_scalar                      */
+/******************************************************************************/
+/* This subroutine is used to write the declaration part of subloop           */
+/*    subroutines                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                                                                            */
+/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
+/*                                                                            */
+/******************************************************************************/
+void writesub_loopdeclaration_scalar (listvar * deb_common, FILE *fileout)
+{
+  listvar *newvar;
+  variable *v;
+  char ligne[LONGLIGNE];
+
+  tofich (fileout, "",1);
   newvar = deb_common;
   while (newvar)
   {
-     writeit = 0;
-     parcours = neededparameter;
-     while ( parcours && writeit == 0 )
-     {
-        if ( !strcasecmp(parcours->nom,newvar->var->nomvar) )
-        {
-           writeit=1;
-           if ( parcours == neededparameter )
-           {
-              neededparameter = neededparameter->suiv;
-           }
-           else
-           {
-              parcoursprec->suiv= parcours->suiv;           
-           }
-        }
-        else
-        {
-           parcoursprec=parcours;
-           parcours=parcours->suiv;
-        }
-     }
-     
-     if ( writeit == 1  )
-     {
-        changeval = 0;
+     if ( newvar->var->v_nbdim == 0 &&
+          !strcasecmp(newvar->var->v_subroutinename,subroutinename)  &&
+           newvar->var->v_allocatable == 0                           &&
+           newvar->var->v_pointerdeclare == 0
+         )
+     {
         v = newvar->var;
-        if ( v->allocatable == 1 && fortran77 == 0 ) 
-        {
-           changeval = 1;
-           v->allocatable = 0; 
-        }
+
         WriteBeginDeclaration(v,ligne);
-        if ( v->nbdim == 0 ) WriteScalarDeclaration(v,ligne);
-        else WriteTableDeclaration(v,ligne,1);
-
+        WriteScalarDeclaration(v,ligne);
         tofich (fileout, ligne,1);
-        if ( changeval == 1 ) 
-        {
-           v->allocatable = 1;
-        }
      }
      newvar = newvar->suiv;
@@ -464,18 +526,17 @@
 }
 
-
-
-/******************************************************************************/
-/*                     writedeclarationsubroutinedeclaration                  */
-/******************************************************************************/
-/* This subroutine is used to write the declaration of parameters needed in   */
-/*    in the table definition. This subroutine is used for the declaration    */
-/*    part of original subroutines                                            */
-/******************************************************************************/
-/*                                                                            */
-/*                                                                            */
-/******************************************************************************/
-void  writedeclarationsubroutinedeclaration(listvar * deb_common, FILE *fileout,
-                              listvar *listin)
+/******************************************************************************/
+/*                       writesub_loopdeclaration_tab                         */
+/******************************************************************************/
+/* This subroutine is used to write the declaration part of subloop           */
+/*    subroutines                                                             */
+/******************************************************************************/
+/*                                                                            */
+/*  integer variable(nb) ----------->                                         */
+/*                                                                            */
+/*          INTEGER, DIMENSION(1:nb)         :: variable                      */
+/*                                                                            */
+/******************************************************************************/
+void writesub_loopdeclaration_tab (listvar * deb_common, FILE *fileout)
 {
   listvar *newvar;
@@ -483,93 +544,26 @@
   char ligne[LONGLIGNE];
   int changeval;
-  char firstmodule[LONGNOM];
-  int out;
-  listnom *neededparameter;
-  int writeit;
-  listnom *parcours;
-  listnom *parcoursprec;
-  
-  parcoursprec = (listnom * )NULL;
-  neededparameter = (listnom * )NULL;
-  /* we should list the needed parameter                                      */
-  newvar = listin;
-  while ( newvar )
-  {
-     if ( !strcasecmp(newvar->var->subroutinename,subroutinename) )
-     {
-        /* add the name to the list of needed parameter                       */
-        neededparameter = DecomposeTheNameinlistnom(
-                 newvar->var->readedlistdimension,
-                 neededparameter );
-     }
-     newvar = newvar->suiv;
-  }
-  /*                                                                          */
-  parcours = neededparameter;
-  while (parcours)
-  {
-     newvar = deb_common;
-     out = 0 ;
-     while ( newvar && out == 0 )
-     {
-        if ( !strcasecmp(parcours->nom,newvar->var->nomvar) ) 
-        {
-           out=1; 
-        /* add the name to the list of needed parameter                       */
-           neededparameter = DecomposeTheNameinlistnom(
-                 newvar->var->initialvalue,
-                 neededparameter );
-        }
-        else newvar=newvar->suiv;
-     }
-     parcours=parcours->suiv;
-   }     
-   /*                                                                         */
-  strcpy(firstmodule,"");
+
   tofich (fileout, "",1);
   newvar = deb_common;
   while (newvar)
   {
-     writeit = 0;
-     parcours = neededparameter;
-     while ( parcours && writeit == 0 )
-     {
-        if ( !strcasecmp(parcours->nom,newvar->var->nomvar) )
-        {
-           writeit=1;
-           if ( parcours == neededparameter )
-           {
-              neededparameter = neededparameter->suiv;
-           }
-           else
-           {
-              parcoursprec->suiv= parcours->suiv;           
-           }
-        }
-        else
-        {
-           parcoursprec=parcours;
-           parcours=parcours->suiv;
-        }
-     }
-     
-     if ( writeit == 1  )
+     if ( newvar->var->v_nbdim != 0                                 &&
+          !strcasecmp(newvar->var->v_subroutinename,subroutinename) &&
+          newvar->var->v_allocatable == 0                           &&
+          newvar->var->v_pointerdeclare == 0
+        )
      {
         changeval = 0;
         v = newvar->var;
-        if ( v->allocatable == 1 && fortran77 == 0 ) 
+        if ( v->v_allocatable == 1 )
         {
            changeval = 1;
-           v->allocatable = 0; 
+           v->v_allocatable = 0;
         }
         WriteBeginDeclaration(v,ligne);
-        if ( v->nbdim == 0 ) WriteScalarDeclaration(v,ligne);
-        else WriteTableDeclaration(v,ligne,1);
-
+        WriteTableDeclaration(v,ligne,1);
         tofich (fileout, ligne,1);
-        if ( changeval == 1 ) 
-        {
-           v->allocatable = 1;
-        }
+        if ( changeval == 1 ) v->v_allocatable = 1;
      }
      newvar = newvar->suiv;
