Index: trunk/AGRIF/LIB/fortran.y
===================================================================
--- trunk/AGRIF/LIB/fortran.y	(revision 530)
+++ trunk/AGRIF/LIB/fortran.y	(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                                                                */
 /******************************************************************************/
 %{
@@ -49,5 +49,7 @@
 typedim c_selectordim;
 listcouple *coupletmp;
+listdim *parcoursdim;
 int removeline=0;
+listvar *test;
 %}
 
@@ -56,5 +58,4 @@
        listdim  *d;
        listvar  *l;
-       listvarcommon *lcom;
        listnom  *ln;
        listcouple  *lc;
@@ -81,5 +82,4 @@
 %token TOK_NEXTLINE
 %token TOK_PARAMETER
-%token TOK_KIND
 %token TOK_RESULT
 %token TOK_ONLY
@@ -103,4 +103,6 @@
 %token TOK_SELECTCASE
 %token TOK_FILE
+%token TOK_END
+%token TOK_ERR
 %token TOK_DONOTTREAT
 %token TOK_ENDDONOTTREAT
@@ -123,9 +125,9 @@
 %token TOK_TAN
 %token TOK_ATAN
+%token TOK_RECURSIVE
 %token TOK_ABS
 %token TOK_MOD
 %token TOK_SIGN
 %token TOK_MINLOC
-/*%token TOK_REC*/
 %token TOK_MAXLOC
 %token TOK_EXIT
@@ -168,6 +170,6 @@
 %token TOK_INTENT
 %token TOK_INTRINSIC
-%token TOK_NAMELIST 
-%token TOK_CASEDEFAULT 
+%token TOK_NAMELIST
+%token TOK_CASEDEFAULT
 %token TOK_OPTIONAL
 %token TOK_POINTER
@@ -175,6 +177,4 @@
 %token TOK_SAVE
 %token TOK_TARGET
-%token TOK_POINT
-%token TOK_DATA 
 %token TOK_QUOTE
 %token TOK_IMPLICIT
@@ -185,8 +185,8 @@
 %token TOK_COMMON
 %token TOK_GLOBAL
-%token TOK_INTERFACE 
-%token TOK_ENDINTERFACE 
-%token TOK_LEFTAB 
-%token TOK_RIGHTAB 
+%token TOK_INTERFACE
+%token TOK_ENDINTERFACE
+%token TOK_LEFTAB
+%token TOK_RIGHTAB
 %token TOK_PAUSE
 %token TOK_PROCEDURE
@@ -207,8 +207,9 @@
 %token <na> TOK_NOT
 %token <na> TOK_AND
-%token <na> TOK_TRUE 
-%token <na> TOK_FALSE 
+%token <na> TOK_TRUE
+%token <na> TOK_FALSE
 %token <na> TOK_LABEL
 %token <na> TOK_TYPE
+%token <na> TOK_TYPEPAR
 %token <na> TOK_ENDTYPE
 %token <na> TOK_REAL
@@ -224,10 +225,11 @@
 %token <na> TOK_CHAR_CONSTANT
 %token <na> TOK_CHAR_CUT
+%token <na> TOK_DATA
 %token <na> TOK_CHAR_INT
-%token <na> TOK_CHAR_MESSAGE 
+%token <na> TOK_CHAR_MESSAGE
 %token <na> TOK_CSTREAL
 %token <na> TOK_CSTREALDP
 %token <na> TOK_CSTREALQP
-%token <na> TOK_SFREAL 
+%token <na> TOK_SFREAL
 %token <na> TOK_COMPLEX
 %token <na> TOK_DOUBLECOMPLEX
@@ -242,5 +244,5 @@
 %token <na> TOK_OP
 %token <na> TOK_CSTINT
-%token <na> TOK_COMMENT 
+%token <na> TOK_COMMENT
 %token <na> TOK_FILENAME
 %token ','
@@ -248,22 +250,21 @@
 %token ':'
 %token '('
-%token ')'   
+%token ')'
 %token '['
 %token ']'
 %token '!'
-%token '_' 
-%token '<' 
-%token '>' 
+%token '_'
+%token '<'
+%token '>'
 %type <l> dcl
+%type <l> after_type
 %type <l> dimension
 %type <l> paramlist
-%type <l> args  
+%type <l> args
+%type <l> arglist
 %type <lc> only_list
 %type <lc> only_name
 %type <lc> rename_list
 %type <lc> rename_name
-%type <lcom> common
-%type <lcom> var_common
-%type <lcom> var_common_list
 %type <d> dims
 %type <d> dimlist
@@ -286,28 +287,32 @@
 %type <na> simple_const
 %type <na> vec
-%type <na> outlist 
-%type <na> out2 
-%type <na> other 
-%type <na> dospec 
-%type <na> expr_data 
-%type <na> beforefunctionuse 
-%type <na> ident 
-%type <na> structure_component 
-%type <na> array_ele_substring_func_ref  
-%type <na> funarglist  
-%type <na> funarg  
-%type <na> funargs  
-%type <na> triplet  
-%type <na> substring  
-%type <na> string_constant  
-%type <na> opt_substring  
-%type <na> opt_expr  
-%type <na> optexpr  
-%type <na> datavallist  
-%type <na> after_slash  
+%type <na> outlist
+%type <na> out2
+%type <na> other
+%type <na> dospec
+%type <na> expr_data
+%type <na> beforefunctionuse
+%type <na> ident
+%type <na> structure_component
+%type <na> array_ele_substring_func_ref
+%type <na> funarglist
+%type <na> funarg
+%type <na> funargs
+%type <na> triplet
+%type <na> substring
+%type <na> string_constant
+%type <na> opt_substring
+%type <na> opt_expr
+%type <na> optexpr
+%type <na> datavallist
+%type <na> after_slash
 %type <na> after_equal
 %type <na> predefinedfunction
-%type <na> do_var  
+%type <na> do_var
 %type <na> expr
+%type <na> word_endsubroutine
+%type <na> word_endfunction
+%type <na> word_endprogram
+%type <na> word_endunit
 %type <na> intent_spec
 %type <na> ubound
@@ -328,5 +333,5 @@
       | keyword cmnt writedeclar
       | error writedeclar nulcurbuf
-                   {yyerrok;yyclearin;}    
+                   {yyerrok;yyclearin;}
       ;
 suite_line_list : suite_line
@@ -337,6 +342,5 @@
       | before_include filename fin_line
                   {
-                     if (inmoduledeclare == 0 && 
-                         couldaddvariable == 1 )
+                     if (inmoduledeclare == 0 )
                      {
                         pos_end = setposcur();
@@ -346,5 +350,5 @@
                   }
       | exec cmnt writedeclar /* if, do etc ...                               */
-      | instr fin_line    /* instruction ident : do i = 1 ...                 */
+      | instr fin_line    /* instruction ident  : do i = 1 ...                */
       ;
 instr : ident ':'
@@ -352,12 +356,12 @@
 fin_line : position cmnt
       ;
-keyword : TOK_DONOTTREAT 
+keyword : TOK_DONOTTREAT
          {
-            /* we should ignore the declaration until the keyword   */
-            /*    TOK_ENDDONOTTREAT                                 */
+            /* we should ignore the declaration until the keyword             */
+            /*    TOK_ENDDONOTTREAT                                           */
             couldaddvariable = 0 ;
             RemoveWordCUR_0(fortranout,-20,20);
          }
-      | TOK_ENDDONOTTREAT 
+      | TOK_ENDDONOTTREAT
          {
              couldaddvariable = 1 ;
@@ -369,5 +373,5 @@
 position: {pos_cur = setposcur();}
       ;
-thislabel: 
+thislabel:
       | TOK_LABEL nulcurbuf
       ;
@@ -381,137 +385,129 @@
                    {if (incom !=1) {strcpy(curbuf,"");incom=0;}}
       ;
-entry: 
-      | TOK_SUBROUTINE name_routine arglist
-                   {
-                      Listofvariableinagriffunction=(listnom *)NULL;
-                      strcpy(subroutinename,$2);
+opt_recursive :
+      | TOK_RECURSIVE
+      ;
+entry:
+      | opt_recursive TOK_SUBROUTINE name_routine arglist
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$3);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
+                      Add_SubroutineArgument_Var_1($4);
                       if ( inmodulemeet == 1 )
                       {
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
                          insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
                          /* in the second step we should write the head of    */
                          /*    the subroutine sub_loop_<subroutinename>       */
                          writeheadnewsub_0(1);
-                         adduseagrifutil = 0 ; 
                       }
                       else
                       {
-                            tmpdeclaration_everdone = 0;
-                            paramdeclaration_everdone = 0;
                             insubroutinedeclare = 1;
-                            AddUseAgrifUtil_0();
                             writeheadnewsub_0(1);
-                            adduseagrifutil = 0 ; 
+                      }
                       }
                    }
       | TOK_PROGRAM name_routine
                    {
-                      Listofvariableinagriffunction=(listnom *)NULL;
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+
+                      }
                       strcpy(subroutinename,$2);
                       /* Common case                                          */
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
-                         insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
-                         /* in the second step we should write the head of    */
-                         /*    the subroutine sub_loop_<subroutinename>       */
-                         writeheadnewsub_0(1);
-                         adduseagrifutil = 0 ;                       
+                      insubroutinedeclare = 1;
+                      /* in the second step we should write the head of       */
+                      /*    the subroutine sub_loop_<subroutinename>          */
+                      writeheadnewsub_0(1);
                    }
       | TOK_FUNCTION name_routine arglist TOK_RESULT arglist1
                    {
-                      Listofvariableinagriffunction=(listnom *)NULL;
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
                       strcpy(subroutinename,$2);
                       if ( inmodulemeet == 1 )
                       {
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
                          insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
                          /* we should to list of the subroutine argument the  */
                          /*    name of the function which has to be defined   */
-                         if ( firstpass == 1 ) 
-                         {
-                            curvar=createvar($2,NULL);
-                            curlistvar=insertvar(NULL,curvar);
-                            listargsubroutine = AddListvarToListvar(curlistvar,listargsubroutine,1);
-                         }
+                         Add_SubroutineArgument_Var_1($3);
+                         strcpy(DeclType,"");
                          /* in the second step we should write the head of    */
                          /*    the subroutine sub_loop_<subroutinename>       */
                          writeheadnewsub_0(2);
-                         adduseagrifutil = 0 ; 
                       }
                       else
                       {
-                            tmpdeclaration_everdone = 0;
-                            paramdeclaration_everdone = 0;
                             insubroutinedeclare = 1;
-                            AddUseAgrifUtil_0();
                             /* we should to list of the subroutine argument   */
                             /* name of the function which has to be defined   */
-                            if ( firstpass == 1 ) 
-                            {
-                               curvar=createvar($2,NULL);
-                               curlistvar=insertvar(NULL,curvar);
-                               listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
-                            }
+                            Add_SubroutineArgument_Var_1($3);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1($2);
                             writeheadnewsub_0(2);
-                            adduseagrifutil = 0 ; 
                       }
                    }
       | TOK_FUNCTION name_routine arglist
                    {
-                      Listofvariableinagriffunction=(listnom *)NULL;
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
                       strcpy(subroutinename,$2);
                       if ( inmodulemeet == 1 )
                       {
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
                          insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
                          /* we should to list of the subroutine argument the  */
                          /*    name of the function which has to be defined   */
-                         if ( firstpass == 1 ) 
-                         {
-                            curvar=createvar($2,NULL);
-                            curlistvar=insertvar(NULL,curvar);
-                            listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
-                         }
+                         Add_SubroutineArgument_Var_1($3);
+                         strcpy(DeclType,"");
+                         Add_FunctionType_Var_1($2);
                          /* in the second step we should write the head of    */
                          /*    the subroutine sub_loop_<subroutinename>       */
                          writeheadnewsub_0(2);
-                         adduseagrifutil = 0 ; 
                       }
                       else
                       {
-                            tmpdeclaration_everdone = 0;
-                            paramdeclaration_everdone = 0;
                             insubroutinedeclare = 1;
-                            AddUseAgrifUtil_0();
                             /* we should to list of the subroutine argument   */
                             /* name of the function which has to be defined   */
-                            if ( firstpass == 1 ) 
-                            {
-                               curvar=createvar($2,NULL);
-                               curlistvar=insertvar(NULL,curvar);
-                               listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
-                            }
+                            Add_SubroutineArgument_Var_1($3);
+                            strcpy(DeclType,"");
+                            Add_FunctionType_Var_1($2);
                             writeheadnewsub_0(2);
-                            adduseagrifutil = 0 ; 
                       }
                    }
       | TOK_MODULE TOK_NAME
                    {
+                      GlobalDeclaration = 0;
                       strcpy(curmodulename,$2);
-                      Add_ModuleTo_Modulelist_1($2);
+                      strcpy(subroutinename,"");
+                      Add_NameOfModule_1($2);
                       if ( inmoduledeclare == 0 )
-                      { 
-                         /* Alloc should be create ?                          */
-                         FillInlistmodule_1();   
+                      {
                          /* To know if there are in the module declaration    */
                          inmoduledeclare = 1;
@@ -520,10 +516,14 @@
                          /* to know if we are after the keyword contains      */
                          aftercontainsdeclare = 0 ;
-                      }      
-                      /* WE should use Agrif_Util if it is necessary          */
-                      AddUseAgrifInModuleDeclaration_0();
-                   }
-      ;
-name_routine : TOK_NAME {strcpy($$,$1);strcpy(subroutinename,$1);}
+                      }
+                   }
+      ;
+name_routine : TOK_NAME
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,$1);strcpy(subroutinename,$1);
+                      }
+                   }
 writedeclar :
       ;
@@ -531,102 +531,107 @@
                    {
                       pos_curinclude = setposcur()-9;
-                   }      
+                   }
 filename: TOK_CHAR_CONSTANT
                    {
-                      if ( couldaddvariable == 1 )
-                      {
-                         Addincludetothelist_1($1);
-                      }                   
-                   }
-      ;
-arglist: 
+                      if ( couldaddvariable == 1 ) Add_Include_1($1);
+                   }
+      ;
+arglist:           {
+                      if ( firstpass == 1 && couldaddvariable == 1) $$=NULL;
+                   }
       | '(' ')'    {
-                      if ( firstpass == 1 ) listargsubroutine=NULL;
+                      if ( firstpass == 1 && couldaddvariable == 1 ) $$=NULL;
                    }
       | '(' args ')'
                    {
-                       if ( firstpass == 1 ) listargsubroutine=$2;
-                   }
-      ;
-arglist1: 
+                       if ( firstpass == 1 && couldaddvariable == 1 ) $$=$2;
+                   }
+      ;
+arglist1:
       | '(' ')'
       | '(' args ')'
                    {
-                       listargsubroutine = AddListvarToListvar
-                                                       ($2,listargsubroutine,1);
+                      if ( couldaddvariable == 1 )
+                      {
+                         Add_SubroutineArgument_Var_1($2);
+                      }
                    }
       ;
 args:arg           {
-                      if ( firstpass == 1 )
-                      {
-                         curvar=createvar($1,curdim);
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar($1,NULL);
                          curlistvar=insertvar(NULL,curvar);
-                         $$=settype($1,curlistvar);
-                      }
-                   }
-      | args ',' arg 
-                   {
-                      if ( firstpass == 1 )
-                      {
-                         curvar=createvar($3,curdim);
+                         $$=settype("",curlistvar);
+                      }
+                   }
+      | args ',' arg
+                   {
+                      if ( firstpass == 1  && couldaddvariable == 1)
+                      {
+                         curvar=createvar($3,NULL);
                          $$=insertvar($1,curvar);
                       }
                    }
       ;
-arg: TOK_NAME      {strcpy($$,$1);}
-      | '*'        {strcpy($$,"*");}
-      ; 
+arg: TOK_NAME      {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '*'        {if ( couldaddvariable == 1 ) strcpy($$,"*");}
+      ;
 spec: type after_type
                    {
-                      /* remove declaration                                   */
-                      if ( fortran77 == 1                       && 
-                           infunctiondeclare == 0               && 
-                           commonlist                           && 
-                           IsTabvarsUseInArgument_0() == 1      &&
-                           couldaddvariable == 1 ) 
-                      {
+                      if ( VarTypepar == 1 )
+                      {
+                         couldaddvariable = 1 ;
+                         VarTypepar = 0;
+                      }
+                   }
+      | TOK_TYPE opt_spec opt_sep opt_name
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         VarType = 1;
+                         couldaddvariable = 0 ;
+                      }
+                   }
+      | TOK_ENDTYPE opt_name
+                   {
+                      if ( VarType == 1 ) couldaddvariable = 1 ;
+                      VarType = 0;
+                      VarTypepar = 0;
+                   }
+      | TOK_POINTER list_couple
+      | before_parameter  '(' paramlist ')'
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($3);
+                         else Add_Parameter_Var_1($3);
                          pos_end = setposcur();
                          RemoveWordSET_0(fortranout,pos_cur_decl,
-                                               pos_end-pos_cur_decl);
-                      }
-                      infunctiondeclare = 0 ;
-                   }
-      | TOK_TYPE opt_name
-/*      {
-         couldaddvariable = 0;
-      }*/
-      | TOK_ENDTYPE opt_name
-/*      {
-         couldaddvariable = 1;
-      }*/
-      | TOK_POINTER list_couple
-      | before_parameter  '(' paramlist ')' 
-                   {
-                      AddvartoParamlist_1($3);
-                      if ( fortran77 == 1  && 
-                           commonlist      && 
-                           listvarindoloop && 
-                           IsTabvarsUseInArgument_0() == 1 )
-                      {
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
+                   }
+      | before_parameter  paramlist
+                   {
+                     if ( couldaddvariable == 1 )
+                     {
+                        if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($2);
+                         else Add_Parameter_Var_1($2);
                          pos_end = setposcur();
-                         RemoveWordSET_0(fortranout,pos_curparameter,
-                                               pos_end-pos_curparameter);
-                      }
-                   }
-      | before_parameter  paramlist 
-                   {
-                      AddvartoParamlist_1($2);
-                      if ( fortran77 == 1  && 
-                           commonlist      && 
-                           listvarindoloop && 
-                           IsTabvarsUseInArgument_0() == 1 )
-                      {
-                         pos_end = setposcur();
-                         RemoveWordSET_0(fortranout,pos_curparameter,
-                                               pos_end-pos_curparameter);
-                      }
+                         RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                    pos_end-pos_cur_decl);
+                      }
+                      VariableIsParameter =  0 ;
                    }
       | common
       | save
+                  {
+                     pos_end = setposcur();
+                     RemoveWordSET_0(fortranout,pos_cursave,
+                                                pos_end-pos_cursave);
+                  }
       | implicit
       | dimension
@@ -637,23 +642,24 @@
                       if ( couldaddvariable == 1 )
                       {
-                         ajoutevar_1($1);
-                         NonGridDepDeclaration_0($1);
-                         /* if variables has been declared in a subroutine    */
+                         Add_Globliste_1($1);
+                         /* if variableparamlists has been declared in a      */
+                         /*    subroutine                                     */
                          if ( insubroutinedeclare == 1 )
                          {
-                           ajoutvarofsubroutine_1($1);
-                           writesubroutinedeclaration_0($1);
+                            Add_Dimension_Var_1($1);
                          }
-                      }
-                      /* Case of common block                                 */
-                      indeclarationvar=0;
-                      PublicDeclare = 0;  
-                      PrivateDeclare = 0; 
-                      ExternalDeclare = 0; 
-                      strcpy(NamePrecision,"");  
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curdimension,
+                                                pos_end-pos_curdimension);
+                      }
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
                       c_star = 0;
                       InitialValueGiven = 0 ;
                       strcpy(IntentSpec,"");
-                      VariableIsParameter =  0 ; 
+                      VariableIsParameter =  0 ;
                       Allocatabledeclare = 0 ;
                       SaveDeclare = 0;
@@ -662,5 +668,6 @@
                       dimsgiven=0;
                       c_selectorgiven=0;
-                      strcpy(nameinttypename,"");  
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
                    }
       | public
@@ -668,20 +675,27 @@
       | use_stat
       | module_proc_stmt
-      | interface 
+      | interface
       | namelist
       | TOK_BACKSPACE '(' expr ')'
       | TOK_EXTERNAL opt_sep use_name_list
       | TOK_INTRINSIC opt_sep use_intrinsic_list
-      | TOK_EQUIVALENCE '(' list_expr ')'
+      | TOK_EQUIVALENCE list_expr_equi
       | before_data data '\n'
                    {
                       /* we should remove the data declaration                */
-                     if ( aftercontainsdeclare == 0 )
-                     {
+                      if ( couldaddvariable == 1 && aftercontainsdeclare == 0 )
+                      {
                         pos_end = setposcur();
                         RemoveWordSET_0(fortranout,pos_curdata,
                                               pos_end-pos_curdata);
-                     }
+                      }
                   }
+      ;
+opt_spec :
+      | access_spec
+      {
+         PublicDeclare = 0 ;
+         PrivateDeclare = 0 ;
+      }
       ;
 name_intrinsic : TOK_SUM
@@ -712,27 +726,60 @@
 use_intrinsic_list : name_intrinsic
       | use_intrinsic_list ',' name_intrinsic
-list_couple : '(' list_expr ')' 
-      | list_couple ',' '(' list_expr ')' 
+      ;
+list_couple : '(' list_expr ')'
+      | list_couple ',' '(' list_expr ')'
+      ;
+list_expr_equi : expr_equi
+      | list_expr_equi ',' expr_equi
+      ;
+expr_equi : '(' list_expr_equi1 ')'
+      ;
+list_expr_equi1 : ident dims
+      | list_expr_equi1 ',' ident dims
+      ;
 list_expr : expr
       | list_expr ',' expr
+      ;
 opt_sep :
       | ':' ':'
       ;
-after_type : dcl nodimsgiven 
-                   {
-                   /* if the variable is a parameter we can suppose that is   */
-                   /*    value is the same on each grid. It is not useless to */
-                   /*    create a copy of it on each grid                     */
+after_type : dcl nodimsgiven
+                   {
+                      /* if the variable is a parameter we can suppose that is*/
+                      /*    value is the same on each grid. It is not useless */
+                      /*    to create a copy of it on each grid               */
                       if ( couldaddvariable == 1 )
                       {
-                         ajoutevar_1($1);
-                         if ( VariableIsParameter == 1 ) globparam =
-                                            AddListvarToListvar($1,globparam,1);
-                         NonGridDepDeclaration_0($1);
+                      pos_end = setposcur();
+                      RemoveWordSET_0(fortranout,pos_cur_decl,
+                                                 pos_end-pos_cur_decl);
+                      if ( firstpass == 0 &&
+                           GlobalDeclaration == 0 &&
+                           insubroutinedeclare == 0 )
+                      {
+                         sprintf(ligne,"\n#include \"Module_Declar_%s.h\"\n"
+                                                                ,curmodulename);
+                         tofich(fortranout,ligne,1);
+                         sprintf (ligne, "Module_Declar_%s.h",curmodulename);
+                         module_declar = associate(ligne);
+                         sprintf (ligne, " ");
+                         tofich (module_declar, ligne,1);
+                         GlobalDeclaration = 1 ;
+                      }
+                         $$ = $1;
+                         Add_Globliste_1($1);
+                         if ( insubroutinedeclare == 0 )
+                                                  Add_GlobalParameter_Var_1($1);
+                         else
+                         {
+                            if ( pointerdeclare == 1 )
+                                                Add_Pointer_Var_From_List_1($1);
+                            Add_Parameter_Var_1($1);
+                         }
+
                          /* if variables has been declared in a subroutine    */
                          if ( insubroutinedeclare == 1 )
                          {
-                           ajoutvarofsubroutine_1($1);
-                           writesubroutinedeclaration_0($1);
+                           Add_SubroutineDeclaration_Var_1($1);
                          }
                          /* If there are a SAVE declarations in module's      */
@@ -740,25 +787,20 @@
                          /*    subroutines declaration and add it in the      */
                          /*    global declarations                            */
-                         if ( aftercontainsdeclare == 1 ) 
+                         if ( aftercontainsdeclare == 1 &&
+                              SaveDeclare == 1 && firstpass == 1 )
                          {
-                            ajoutevarsave_1($1);
-                            if ( VariableIsParameter == 0 && SaveDeclare == 1) 
-                            {
-                               pos_end = setposcur();
-                               RemoveWordSET_0(fortranout,pos_cur,
-                                               pos_end-pos_cur);
-                            }
+                              if ( inmodulemeet == 0 ) Add_Save_Var_dcl_1($1);
+                              else  Add_SubroutineDeclarationSave_Var_1($1);
                          }
                       }
-                      /* Case of common block                                 */
-                      indeclarationvar=0;
-                      PublicDeclare = 0;  
-                      PrivateDeclare = 0; 
-                      ExternalDeclare = 0; 
-                      strcpy(NamePrecision,"");  
+                      /*                                                      */
+                      PublicDeclare = 0;
+                      PrivateDeclare = 0;
+                      ExternalDeclare = 0;
+                      strcpy(NamePrecision,"");
                       c_star = 0;
                       InitialValueGiven = 0 ;
                       strcpy(IntentSpec,"");
-                      VariableIsParameter =  0 ; 
+                      VariableIsParameter =  0 ;
                       Allocatabledeclare = 0 ;
                       SaveDeclare = 0;
@@ -767,90 +809,74 @@
                       dimsgiven=0;
                       c_selectorgiven=0;
-                      strcpy(nameinttypename,"");  
-                   }
-      | TOK_FUNCTION TOK_NAME arglist
-                   {
-                      infunctiondeclare = 1 ;
-                      Listofvariableinagriffunction=(listnom *)NULL;
+                      strcpy(nameinttypename,"");
+                      strcpy(c_selectorname,"");
+                   }
+      | before_function name_routine arglist
+                   {
+                      /* open param file                                      */
+                      if ( firstpass == 0 )
+                      {
+                         sprintf(ligne,"%s/ParamFile%s.h",nomdir,$2);
+                         paramout=fopen(ligne,"w");
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                      }
                       strcpy(subroutinename,$2);
                       if ( inmodulemeet == 1 )
                       {
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
                          insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
                          /* we should to list of the subroutine argument the  */
                          /*    name of the function which has to be defined   */
-                         if ( firstpass == 1 ) 
-                         {
-                            curvar=createvar($2,NULL);
-                            strcpy(curvar->typevar,DeclType);
-                            curlistvar=insertvar(NULL,curvar);
-                            listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
-                            curvar=createvar($2,NULL);
-                            strcpy(curvar->typevar,DeclType);
-                            strcpy(curvar->modulename,subroutinename);
-                            curlistvar=insertvar(NULL,curvar);        
-                            varofsubroutineliste = AddListvarToListvar
-                                            (curlistvar,varofsubroutineliste,1);
-                         }
-                         if ( firstpass == 0 )
-                         {
-                            curvar=createvar($2,NULL);
-                            strcpy(curvar->typevar,DeclType);
-                            functionlistvar=insertvar(NULL,curvar);
-                         }
+                         Add_SubroutineArgument_Var_1($3);
+                         Add_FunctionType_Var_1($2);
                          /* in the second step we should write the head of    */
                          /*    the subroutine sub_loop_<subroutinename>       */
                          writeheadnewsub_0(2);
-                         adduseagrifutil = 0 ; 
                       }
                       else
                       {
-                         tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
                          insubroutinedeclare = 1;
-                         AddUseAgrifUtil_0();
                          /* we should to list of the subroutine argument the  */
                          /*    name of the function which has to be defined   */
-                         if ( firstpass == 1 ) 
-                         {
-                            curvar=createvar($2,NULL);
-                            strcpy(curvar->typevar,DeclType);
-                            curlistvar=insertvar(NULL,curvar);
-                            listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
-                            curvar=createvar($2,NULL);
-                            strcpy(curvar->typevar,DeclType);
-                            strcpy(curvar->modulename,subroutinename);
-                            curlistvar=insertvar(NULL,curvar);        
-                            varofsubroutineliste = AddListvarToListvar
-                                            (curlistvar,varofsubroutineliste,1);
-                         }
+                         Add_SubroutineArgument_Var_1($3);
+                         Add_FunctionType_Var_1($2);
                          /* in the second step we should write the head of    */
                          /*    the subroutine sub_loop_<subroutinename>       */
                          writeheadnewsub_0(2);
-                         adduseagrifutil = 0 ; 
-                      }
-                   }
-      ;
+                      }
+                   }
+      ;
+before_function : TOK_FUNCTION
+                   {
+                       functiondeclarationisdone = 1;
+                   }
+                   ;
+
 before_parameter : TOK_PARAMETER
                    {
+                      VariableIsParameter = 1;
                       pos_curparameter = setposcur()-9;
-                   }      
+                   }
 before_data : TOK_DATA
                    {
-                      pos_curdata = setposcur()-4;
+                      pos_curdata = setposcur()-strlen($1);
                    }
 data: TOK_NAME TOK_SLASH datavallist TOK_SLASH
                    {
-                      sprintf(ligne,"(/ %s /)",$3);
-                      CompleteDataList($1,ligne);
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",$3);
+                      Add_Data_Var_1($1,ligne);
+                      }
                    }
       | data opt_comma TOK_NAME TOK_SLASH datavallist TOK_SLASH
                    {
-                      sprintf(ligne,"(/ %s /)",$5);
-                      CompleteDataList($3,ligne);
+                      if ( couldaddvariable == 1 )
+                      {
+                      if ( aftercontainsdeclare == 1 ) strcpy(ligne,"");
+                      else sprintf(ligne,"(/ %s /)",$5);
+                      Add_Data_Var_1($3,ligne);
+                      }
                    }
       | datanamelist TOK_SLASH datavallist TOK_SLASH
@@ -865,43 +891,61 @@
                    }
       ;
+datavallist : expr_data
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         strcpy($$,$1);
+                      }
+                   }
+      | expr_data ',' datavallist
+                   {
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf($$,"%s,%s",$1,$3);
+                      }
+                   }
+      ;
+
+save:  before_save varsave
+      | before_save  comblock varsave
+      | save opt_comma comblock opt_comma varsave
+      | save ',' varsave
+      ;
+before_save : TOK_SAVE
+                  {
+                     pos_cursave = setposcur()-4;
+                  }
+      ;
+varsave:
+      | TOK_NAME dims
+                  {
+                     if ( couldaddvariable == 1 ) Add_Save_Var_1($1,$2);
+                  }
+      ;
 datanamelist : TOK_NAME
-      | datanamelist ',' TOK_NAME
-      ;
-datavallist : expr_data
-                   {
-                      strcpy($$,$1);
-                   }
-      | expr_data ',' datavallist 
-                   {
-                      sprintf($$,"%s,%s",$1,$3);
-                   }
+      | TOK_NAME '(' expr ')'
+      | datanamelist ',' datanamelist
       ;
 expr_data : opt_signe simple_const
-                   {sprintf($$,"%s%s",$1,$2);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
       | expr_data '+' expr_data
-                   {sprintf($$,"%s+%s",$1,$3);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s+%s",$1,$3);}
       | expr_data '-' expr_data
-                   {sprintf($$,"%s-%s",$1,$3);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s-%s",$1,$3);}
       | expr_data '*' expr_data
-                   {sprintf($$,"%s*%s",$1,$3);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s*%s",$1,$3);}
       | expr_data '/' expr_data
-                   {sprintf($$,"%s/%s",$1,$3);}
-      ;
-opt_signe : 
-                   {strcpy($$,"");}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s/%s",$1,$3);}
+      ;
+opt_signe :
+                   {if ( couldaddvariable == 1 ) strcpy($$,"");}
       | signe
-                   {strcpy($$,$1);}
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       ;
 namelist:  namelist_action after_namelist
       ;
-namelist_action : TOK_NAMELIST  ident 
+namelist_action : TOK_NAMELIST  ident
       | TOK_NAMELIST  comblock ident
-      {
-         AddNameToListNamelist_1($2);
-      }
       | namelist_action opt_comma comblock opt_comma ident
-      {
-         AddNameToListNamelist_1($3);
-      }
       | namelist_action ',' ident
       ;
@@ -911,41 +955,24 @@
       | TOK_ENDINTERFACE opt_name
       ;
-dimension: TOK_DIMENSION  opt_comma TOK_NAME dims lengspec
+before_dimension : TOK_DIMENSION
+                   {
+                      positioninblock=0;
+                      pos_curdimension = setposcur()-9;
+                   }
+
+dimension:  before_dimension opt_comma TOK_NAME dims lengspec
       {
          if ( couldaddvariable == 1 )
          {
-            if ( inmoduledeclare == 1 || SaveDeclare == 1 )
-            {
-               if ( AllocShouldMadeInModule() == 1 ) 
-               {
-                 AllocTo1InModule_1();
-               }
-            }      
             /*                                                                */
             curvar=createvar($3,$4);
             /*                                                                */
-            if ( IsVariableReal($3) == 1 )
-            {
-               /*                                                             */
-               CreateAndFillin_Curvar("REAL",$3,$4,curvar);
-               /*                                                             */
-               curlistvar=insertvar(NULL,curvar);
-               /*                                                             */
-               $$=settype("REAL",curlistvar);
-            }
-            else
-            {
-               /*                                                             */
-               CreateAndFillin_Curvar("INTEGER",$3,$4,curvar);
-               /*                                                             */
-               curlistvar=insertvar(NULL,curvar);
-               /*                                                             */
-               $$=settype("INTEGER",curlistvar);
-            }
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar(NULL,curvar);
+            /*                                                                */
+            $$=settype("",curlistvar);
+            /*                                                                */
             strcpy(vallengspec,"");
-         }
-         else
-         {
-            /* mazauric*/
          }
       }
@@ -957,27 +984,11 @@
             curvar=createvar($3,$4);
             /*                                                                */
-            if ( IsVariableReal($3) == 1 )
-            {
-               /*                                                             */
-               CreateAndFillin_Curvar("REAL",$3,$4,curvar);
-               /*                                                             */
-               curlistvar=insertvar($1,curvar);
-               /*                                                             */
-               $$=curlistvar;
-            }
-            else
-            {
-               /*                                                             */
-               CreateAndFillin_Curvar("INTEGER",$3,$4,curvar);
-               /*                                                             */
-               curlistvar=insertvar($1,curvar);
-               /*                                                             */
-               $$=curlistvar;
-            }
+            CreateAndFillin_Curvar("",curvar);
+            /*                                                                */
+            curlistvar=insertvar($1,curvar);
+            /*                                                                */
+            $$=curlistvar;
+            /*                                                                */
             strcpy(vallengspec,"");
-         }         
-         else
-         {
-            /* mazauric*/
          }
       }
@@ -987,18 +998,14 @@
       ;
 public: TOK_PUBLIC '\n'
-      | TOK_PUBLIC opt_sep use_name_list 
-      ;
-use_name_list: TOK_NAME 
+      | TOK_PUBLIC opt_sep use_name_list
+      ;
+use_name_list: TOK_NAME
       | use_name_list ',' TOK_NAME
       ;
 common: before_common var_common_list
                    {
-                         if (fortran77 == 1 &&
-                             couldaddvariable == 1 )
-                         {
-                            pos_end = setposcur();
-                            RemoveWordSET_0(fortranout,pos_curcommon,
+                         pos_end = setposcur();
+                         RemoveWordSET_0(fortranout,pos_curcommon,
                                                   pos_end-pos_curcommon);
-                         }
                    }
       | before_common comblock var_common_list
@@ -1007,11 +1014,8 @@
                          {
                             sprintf(charusemodule,"%s",$2);
-                            Add_ModuleTo_Modulelist_1($2);
-                            if ( fortran77 == 1 )
-                            {
-                               pos_end = setposcur();
-                               RemoveWordSET_0(fortranout,pos_curcommon,
-                                                     pos_end-pos_curcommon);
-                            }
+                            Add_NameOfCommon_1($2);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
                          }
                    }
@@ -1021,11 +1025,8 @@
                          {
                             sprintf(charusemodule,"%s",$3);
-                            Add_ModuleTo_Modulelist_1($3);
-                            if ( fortran77 == 1 )
-                            {
-                               pos_end = setposcur();
-                               RemoveWordSET_0(fortranout,pos_curcommon,
-                                                     pos_end-pos_curcommon);
-                            }
+                            Add_NameOfCommon_1($3);
+                            pos_end = setposcur();
+                            RemoveWordSET_0(fortranout,pos_curcommon,
+                                                       pos_end-pos_curcommon);
                          }
                    }
@@ -1044,14 +1045,14 @@
 var_common_list : var_common
                    {
-                      if ( couldaddvariable == 1 ) Addtolistvarcommon();
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
                    }
 
      | var_common_list ',' var_common
                    {
-                      if ( couldaddvariable == 1 ) Addtolistvarcommon();
-                   }
-var_common: TOK_NAME dims  
-                   {
-                      if ( couldaddvariable == 1 ) 
+                      if ( couldaddvariable == 1 ) Add_Common_var_1();
+                   }
+var_common: TOK_NAME dims
+                   {
+                      if ( couldaddvariable == 1 )
                       {
                          positioninblock = positioninblock + 1 ;
@@ -1061,7 +1062,7 @@
                    }
       ;
-comblock: TOK_DSLASH 
-                   {
-                      if ( couldaddvariable == 1 ) 
+comblock: TOK_DSLASH
+                   {
+                      if ( couldaddvariable == 1 )
                       {
                          strcpy($$,"");
@@ -1070,7 +1071,7 @@
                       }
                    }
-      | TOK_SLASH TOK_NAME TOK_SLASH 
-                   {
-                      if ( couldaddvariable == 1 ) 
+      | TOK_SLASH TOK_NAME TOK_SLASH
+                   {
+                      if ( couldaddvariable == 1 )
                       {
                          strcpy($$,$2);
@@ -1080,14 +1081,4 @@
                    }
       ;
-save: TOK_SAVE varsave
-      | TOK_SAVE  comblock varsave
-      | save opt_comma comblock opt_comma varsave
-      | save ',' varsave
-      ;
-varsave: 
-      | TOK_NAME before_dims dims 
-      {created_dimensionlist = 1;}
-      ;
-      
 opt_comma:
       | ','
@@ -1095,20 +1086,25 @@
 paramlist: paramitem
                    {
-                      if ( firstpass == 1 ) $$=insertvar(NULL,$1);
+                      if ( couldaddvariable == 1 ) $$=insertvar(NULL,$1);
                    }
       | paramlist ',' paramitem
                    {
-                      if ( firstpass == 1 ) $$=insertvar($1,$3);
+                      if ( couldaddvariable == 1 ) $$=insertvar($1,$3);
                    }
       ;
 paramitem : TOK_NAME '=' expr
                    {
-                      if ( firstpass == 1 )
-                      {
+                     if ( couldaddvariable == 1 )
+                     {
                          curvar=(variable *) malloc(sizeof(variable));
-                         strcpy(curvar->nomvar,$1);
-                         strcpy(curvar->subroutinename,subroutinename);
-                         strcpy(curvar->modulename,subroutinename);
-                         strcpy(curvar->initialvalue,$3);
+                         /*                                                   */
+                         Init_Variable(curvar);
+                         /*                                                   */
+                         curvar->v_VariableIsParameter=1;
+                         strcpy(curvar->v_nomvar,$1);
+                         strcpy(curvar->v_subroutinename,subroutinename);
+                         strcpy(curvar->v_modulename,curmodulename);
+                         strcpy(curvar->v_initialvalue,$3);
+                         strcpy(curvar->v_commoninfile,mainfile);
                          $$=curvar;
                       }
@@ -1122,15 +1118,10 @@
 implicit: TOK_IMPLICIT TOK_NONE
                     {
-                       if ( firstpass == 1 && insubroutinedeclare == 1 )
-                       {
-                           listimplicitnone = Addtolistname
-                                              (subroutinename,listimplicitnone);
-                       }
-                       if ( tmpdeclaration_everdone == 1 && 
-                            inmoduledeclare == 0 )
-                       {
-                         pos_end = setposcur();
-                         RemoveWordSET_0(fortranout,pos_end-13,
-                                               13);
+                       if ( insubroutinedeclare == 1 )
+                       {
+                          Add_ImplicitNoneSubroutine_1();
+                          pos_end = setposcur();
+                          RemoveWordSET_0(fortranout,pos_end-13,
+                                                             13);
                        }
                     }
@@ -1143,13 +1134,6 @@
                       if ( couldaddvariable == 1 )
                       {
-                         if ( inmoduledeclare == 1 || SaveDeclare == 1 )
-                         {
-                            if ( AllocShouldMadeInModule() == 1 ) 
-                            {
-                               AllocTo1InModule_1();
-                            }
-                         }      
                          /*                                                   */
-                         if (dimsgiven == 1) 
+                         if (dimsgiven == 1)
                          {
                             curvar=createvar($3,curdim);
@@ -1160,10 +1144,10 @@
                          }
                          /*                                                   */
-                         CreateAndFillin_Curvar(DeclType,$3,$4,curvar);
+                         CreateAndFillin_Curvar(DeclType,curvar);
                          /*                                                   */
                          curlistvar=insertvar(NULL,curvar);
-                         if (!strcasecmp(DeclType,"character")) 
+                         if (!strcasecmp(DeclType,"character"))
                          {
-                            if (c_selectorgiven == 1) 
+                            if (c_selectorgiven == 1)
                             {
                                strcpy(c_selectordim.first,"1");
@@ -1175,8 +1159,4 @@
                          $$=settype(DeclType,curlistvar);
                       }
-                      else
-                      {
-                         /* mazauric*/
-                      }
                       strcpy(vallengspec,"");
                    }
@@ -1185,5 +1165,5 @@
                       if ( couldaddvariable == 1 )
                       {
-                         if (dimsgiven == 1) 
+                         if (dimsgiven == 1)
                          {
                             curvar=createvar($4,curdim);
@@ -1193,13 +1173,13 @@
                             curvar=createvar($4,$5);
                          }
-                         /*                                                   */ 
-                         CreateAndFillin_Curvar($1->var->typevar,$4,$5,curvar);
                          /*                                                   */
-                         strcpy(curvar->typevar,($1->var->typevar));
+                         CreateAndFillin_Curvar($1->var->v_typevar,curvar);
+                         /*                                                   */
+                         strcpy(curvar->v_typevar,($1->var->v_typevar));
                          /*                                                   */
                          curlistvar=insertvar($1,curvar);
-                         if (!strcasecmp(DeclType,"character")) 
+                         if (!strcasecmp(DeclType,"character"))
                          {
-                            if (c_selectorgiven == 1) 
+                            if (c_selectorgiven == 1)
                             {
                                strcpy(c_selectordim.first,"1");
@@ -1211,40 +1191,41 @@
                          $$=curlistvar;
                       }
-                      else
-                      {
-                         /* mazauric*/
-                      }
                       strcpy(vallengspec,"");
                    }
-      ;      
+      ;
 nodimsgiven:       {dimsgiven=0;}
       ;
-type:typespec selector 
-                   {strcpy(DeclType,$1);indeclarationvar=1;}
-      | before_character c_selector 
-                   {
-                      indeclarationvar=1;
+type:typespec selector
+                   {strcpy(DeclType,$1);}
+      | before_character c_selector
+                   {
                       strcpy(DeclType,"CHARACTER");
-                      if (inmoduledeclare == 1 ) 
-                      {
-                         AllocShouldMadeTo1InModule_1();
-                      }
                    }
       | typename '*' TOK_CSTINT
                    {
-                      indeclarationvar=1;
                       strcpy(DeclType,$1);
                       strcpy(nameinttypename,$3);
                    }
+      | before_typepar attribute ')'
+                   {
+                      strcpy(DeclType,"TYPE");
+                   }
+      ;
+before_typepar : TOK_TYPEPAR
+                   {
+                      if ( couldaddvariable == 1 ) VarTypepar = 1 ;
+                      couldaddvariable = 0 ;
+                      pos_cur_decl = setposcur()-5;
+                   }
       ;
 c_selector:
-      | '*' TOK_CSTINT 
+      | '*' TOK_CSTINT
                    {c_selectorgiven=1;strcpy(c_selectorname,$2);}
       | '*' '(' c_attribute ')' {c_star = 1;}
-      | '(' c_attribute ')' 
-      ;
-c_attribute: TOK_NAME clause opt_clause 
-      | TOK_NAME '=' clause opt_clause 
-      | clause opt_clause 
+      | '(' c_attribute ')'
+      ;
+c_attribute: TOK_NAME clause opt_clause
+      | TOK_NAME '=' clause opt_clause
+      | clause opt_clause
       ;
 before_character : TOK_CHARACTER
@@ -1255,40 +1236,27 @@
 typespec: typename {strcpy($$,$1);}
       ;
-typename: TOK_INTEGER 
+typename: TOK_INTEGER
                    {
                       strcpy($$,"INTEGER");
                       pos_cur_decl = setposcur()-7;
-                      if (inmoduledeclare == 1 ) 
-                      {
-                         AllocShouldMadeTo1InModule_1();
-                       }
                    }
       | TOK_REAL   {
-                      strcpy($$,"REAL"); 
+                      strcpy($$,"REAL");
                       pos_cur_decl = setposcur()-4;
-                      if (inmoduledeclare == 1 ) 
-                      {
-                         AllocShouldMadeTo1InModule_1();
-                      }
-                   }
-      | TOK_COMPLEX      
+                   }
+      | TOK_COMPLEX
                    {strcpy($$,"COMPLEX");}
-      | TOK_DOUBLEPRECISION 
-                   {strcpy($$,"DOUBLE PRECISION");}
-      | TOK_DOUBLECOMPLEX 
+      | TOK_DOUBLEPRECISION
+                   {
+                      pos_cur_decl = setposcur()-16;
+                      strcpy($$,"REAL");
+                      strcpy(nameinttypename,"8");
+                   }
+      | TOK_DOUBLECOMPLEX
                    {strcpy($$,"DOUBLE COMPLEX");}
-      | TOK_LOGICAL      
+      | TOK_LOGICAL
                    {
                       strcpy($$,"LOGICAL");
                       pos_cur_decl = setposcur()-7;
-                      if (inmoduledeclare == 1 ) 
-                      {
-                         AllocShouldMadeTo1InModule_1();
-                      }
-                   }
-      | TOK_TYPE      
-                   {
-                      pos_cur_decl = setposcur()-5;
-                      strcpy($$,"TYPE");
                    }
       ;
@@ -1301,21 +1269,26 @@
 selector:
       | '*' proper_selector
-      | '(' attribute ')' 
+      | '(' attribute ')'
       ;
 proper_selector: expr
       | '(' '*' ')'
       ;
-attribute: TOK_NAME clause 
-      | TOK_NAME '=' clause  
-                   {
-                      sprintf(NamePrecision,"%s = %s",$1,$3);  
+attribute: TOK_NAME clause
+      | TOK_NAME '=' clause
+                   {
+                      if ( strstr($3,"0.d0") )
+                      {
+                         strcpy(nameinttypename,"8");
+                         sprintf(NamePrecision,"");
+                      }
+                      else sprintf(NamePrecision,"%s = %s",$1,$3);
                    }
       | TOK_NAME
                    {
-                      strcpy(NamePrecision,$1);  
+                      strcpy(NamePrecision,$1);
                    }
       | TOK_CSTINT
                    {
-                      strcpy(NamePrecision,$1);  
+                      strcpy(NamePrecision,$1);
                    }
       ;
@@ -1323,7 +1296,7 @@
                     strcpy($$,$1);}
       | '*'        {strcpy(CharacterSize,"*");
-                    strcpy($$,"*");} 
-      ;
-opt_clause: 
+                    strcpy($$,"*");}
+      ;
+opt_clause:
       | ',' TOK_NAME clause
       ;
@@ -1335,22 +1308,18 @@
       | attr_spec_list ',' attr_spec
       ;
-attr_spec: TOK_PARAMETER 
+attr_spec: TOK_PARAMETER
                    {
                       VariableIsParameter = 1;
-                      if (inmoduledeclare == 1 ) 
-                      {
-                         AllocShouldMadeTo0InModule_1();
-                      }
                    }
       | access_spec
-      | TOK_ALLOCATABLE 
+      | TOK_ALLOCATABLE
                    {Allocatabledeclare = 1;}
-      | TOK_DIMENSION dims 
-                   {
-                      dimsgiven=1; 
+      | TOK_DIMENSION dims
+                   {
+                      dimsgiven=1;
                       curdim=$2;
                    }
-      | TOK_EXTERNAL  
-                   {ExternalDeclare = 1;} 
+      | TOK_EXTERNAL
+                   {ExternalDeclare = 1;}
       | TOK_INTENT intent_spec
                    {strcpy(IntentSpec,$2);}
@@ -1359,10 +1328,8 @@
       | TOK_POINTER {pointerdeclare = 1 ;}
       | TOK_SAVE    {
-                       if ( inmodulemeet == 1 )
-                       {
+/*                       if ( inmodulemeet == 1 )
+                       {*/
                           SaveDeclare = 1 ;
-                          Savemeet = 1;
-                          AllocShouldMadeTo1InModule_1();
-                       }
+                     /*  }*/
                     }
       | TOK_TARGET
@@ -1371,17 +1338,24 @@
       | TOK_OUT     {sprintf($$,"out");}
       | TOK_INOUT   {sprintf($$,"inout");}
-      ; 
-access_spec: TOK_PUBLIC 
-                   {PublicDeclare = 1;} 
-      | TOK_PRIVATE 
-                   {PrivateDeclare = 1;} 
-      ;
-dims:              {if ( created_dimensionlist == 1 ) $$=(listdim *)NULL;}
-      | '(' dimlist ')'  
-                   {if ( created_dimensionlist == 1 ) $$=$2;}
-      ;
-dimlist:   dim     {if ( created_dimensionlist == 1 ) $$=insertdim(NULL,$1);}
-      | dimlist ',' dim 
-                   {if ( created_dimensionlist == 1 ) $$=insertdim($1,$3);}
+      ;
+access_spec: TOK_PUBLIC
+                   {PublicDeclare = 1;}
+      | TOK_PRIVATE
+                   {PrivateDeclare = 1;}
+      ;
+dims:              {if ( created_dimensionlist == 1 )
+                       {
+                           $$=(listdim *)NULL;
+                       }
+                   }
+      | '(' dimlist ')'
+                   {if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) $$=$2;}
+      ;
+dimlist:   dim     {if ( created_dimensionlist == 1 ||
+                         agrif_parentcall      == 1 ) $$=insertdim(NULL,$1);}
+      | dimlist ',' dim
+                   {if ( couldaddvariable == 1 )
+                         if ( created_dimensionlist == 1 ) $$=insertdim($1,$3);}
       ;
 dim:ubound         {strcpy($$.first,"1");strcpy($$.last,$1);}
@@ -1395,13 +1369,14 @@
       | expr       {strcpy($$,$1);}
       ;
-expr:  uexpr       {strcpy($$,$1);}
-      | '(' expr ')' 
-                   {sprintf($$,"(%s)",$2);}
-      | complex_const 
-                   {strcpy($$,$1);}
+expr:  uexpr       {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '(' expr ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s)",$2);}
+      | complex_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       | predefinedfunction
-      ;
-      
-predefinedfunction : TOK_SUM minmaxlist ')' 
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+
+predefinedfunction : TOK_SUM minmaxlist ')'
                    {sprintf($$,"SUM(%s)",$2);}
       | TOK_MAX minmaxlist ')'
@@ -1422,7 +1397,7 @@
                    {sprintf($$,"REAL(%s)",$3);}
       | TOK_INT '(' expr ')'
-                   {sprintf($$,"INT(%s)",$3);}                   
+                   {sprintf($$,"INT(%s)",$3);}
       | TOK_NINT '(' expr ')'
-                   {sprintf($$,"NINT(%s)",$3);}                   
+                   {sprintf($$,"NINT(%s)",$3);}
       | TOK_FLOAT '(' expr ')'
                    {sprintf($$,"FLOAT(%s)",$3);}
@@ -1459,80 +1434,81 @@
       ;
 minmaxlist : expr {strcpy($$,$1);}
-      | minmaxlist ',' expr 
-                   {strcpy($$,$1);strcat($$,",");strcat($$,$3);}
-      ;
-uexpr:  lhs        {strcpy($$,$1);} 
-      | simple_const 
-                   {strcpy($$,$1);} 
-      | vec 
-                   {strcpy($$,$1);} 
+      | minmaxlist ',' expr
+                   {if ( couldaddvariable == 1 )
+                   { strcpy($$,$1);strcat($$,",");strcat($$,$3);}}
+      ;
+uexpr:  lhs        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | simple_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | vec
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       | expr operation
-                   {sprintf($$,"%s%s",$1,$2);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
       | signe expr %prec '* ' 
-                   {sprintf($$,"%s%s",$1,$2);}
-      | TOK_NOT expr 
-                   {sprintf($$,"%s%s",$1,$2);}
-      ;
-signe : '+'        {strcpy($$,"+");}
-      | '-'        {strcpy($$,"-");}
-      ;
-operation : '+' expr %prec '+' 
-                   {sprintf($$,"+%s",$2);}
-      |  '-' expr %prec '+' 
-                   {sprintf($$,"-%s",$2);}
-      |  '*' expr 
-                   {sprintf($$,"*%s",$2);}
-      |  TOK_DASTER expr 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  TOK_EQ expr %prec TOK_EQ 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  TOK_GT expr %prec TOK_EQ 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  '>' expr %prec TOK_EQ 
-                   {sprintf($$," > %s",$2);}
-      |  TOK_LT expr %prec TOK_EQ 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  '<' expr %prec TOK_EQ 
-                   {sprintf($$," < %s",$2);}
-      |  TOK_GE expr %prec TOK_EQ 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  '>''=' expr %prec TOK_EQ 
-                   {sprintf($$," >= %s",$3);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      | TOK_NOT expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      ;
+signe : '+'        {if ( couldaddvariable == 1 ) strcpy($$,"+");}
+      | '-'        {if ( couldaddvariable == 1 ) strcpy($$,"-");}
+      ;
+operation : '+' expr %prec '+'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"+%s",$2);}
+      |  '-' expr %prec '+'
+                   {if ( couldaddvariable == 1 ) sprintf($$,"-%s",$2);}
+      |  '*' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"*%s",$2);}
+      |  TOK_DASTER expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_EQ expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_GT expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '>' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," > %s",$2);}
+      |  TOK_LT expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '<' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," < %s",$2);}
+      |  TOK_GE expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '>''=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," >= %s",$3);}
       |  TOK_LE expr %prec TOK_EQ
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  '<''=' expr %prec TOK_EQ 
-                   {sprintf($$," <= %s",$3);}
-      |  TOK_NE expr %prec TOK_EQ 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  TOK_XOR expr 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  TOK_OR expr 
-                   {sprintf($$,"%s%s",$1,$2);}
-      |  TOK_AND expr 
-                   {sprintf($$,"%s%s",$1,$2);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  '<''=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$," <= %s",$3);}
+      |  TOK_NE expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_XOR expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_OR expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
+      |  TOK_AND expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
       |  TOK_SLASH after_slash
-                   {sprintf($$,"%s",$2);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s",$2);}
       |  '=' after_equal
-                   {sprintf($$,"%s",$2);}
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s",$2);}
 
 after_slash : {strcpy($$,"");}
-      | expr 
+      | expr
                    {sprintf($$,"/%s",$1);}
-      | '=' expr %prec TOK_EQ 
+      | '=' expr %prec TOK_EQ
                    {sprintf($$,"/= %s",$2);}
       | TOK_SLASH expr
                    {sprintf($$,"//%s",$2);}
       ;
-after_equal : '=' expr %prec TOK_EQ 
-                   {sprintf($$,"==%s",$2);}
+after_equal : '=' expr %prec TOK_EQ
+                   {if ( couldaddvariable == 1 ) sprintf($$,"==%s",$2);}
       | expr
-                   {sprintf($$,"= %s",$1);}
-      ;
-      
-lhs: ident         {strcpy($$,$1);} 
-      | structure_component 
-                   {strcpy($$,$1);} 
-      | array_ele_substring_func_ref 
-                   {strcpy($$,$1);} 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"= %s",$1);}
+      ;
+
+lhs: ident         {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | structure_component
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | array_ele_substring_func_ref
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       ;
 beforefunctionuse : {
@@ -1541,7 +1517,8 @@
                                                             agrif_parentcall =1;
                       if ( Agrif_in_Tok_NAME(identcopy) == 1 )
-                      { 
+                      {
                          inagrifcallargument = 1;
-                         AddsubroutineTolistsubwhereagrifused();
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
                       }
                    }
@@ -1552,50 +1529,65 @@
                      if ( incalldeclare == 0 ) inagrifcallargument = 0;
                    }
-      | begin_array substring 
-                   {sprintf($$," %s %s ",$1,$2);}
-      | structure_component '(' funarglist ')' 
-                   {sprintf($$," %s ( %s )",$1,$3);}
-      | structure_component '(' funarglist ')' substring 
-                   {sprintf($$," %s ( %s ) %s ",$1,$3,$5);}
+      | begin_array substring
+                   {if ( couldaddvariable == 1 ) sprintf($$," %s %s ",$1,$2);}
+      | structure_component '(' funarglist ')'
+                   {if ( couldaddvariable == 1 )
+                                                sprintf($$," %s ( %s )",$1,$3);}
+      | structure_component '(' funarglist ')' substring
+                   {if ( couldaddvariable == 1 )
+                                         sprintf($$," %s ( %s ) %s ",$1,$3,$5);}
       ;
 begin_array : ident '(' funarglist ')'
                    {
-                      sprintf($$," %s ( %s )",$1,$3);
-                      ModifyTheAgrifFunction_0($3);
-                     agrif_parentcall =0; 
-                   }
-      ;
-structure_component: lhs '%' lhs 
+                      if ( couldaddvariable == 1 )
+                      {
+                         sprintf($$," %s ( %s )",$1,$3);
+                         ModifyTheAgrifFunction_0($3);
+                         agrif_parentcall =0;
+                      }
+                   }
+      ;
+structure_component: lhs '%' lhs
                    {
                       sprintf($$," %s %% %s ",$1,$3);
-                     if ( incalldeclare == 0 ) inagrifcallargument = 0;
-                   }
-      ;
-vec:  TOK_LEFTAB outlist TOK_RIGHTAB 
-                   {sprintf($$,"(/%s/)",$2);} 
+                      if ( incalldeclare == 0 ) inagrifcallargument = 0;
+                   }
+      ;
+vec:  TOK_LEFTAB outlist TOK_RIGHTAB
+                   {sprintf($$,"(/%s/)",$2);}
       ;
 funarglist: beforefunctionuse    {strcpy($$," ");}
-      | beforefunctionuse funargs  
+      | beforefunctionuse funargs
                    {strcpy($$,$2);}
       ;
-funargs: funarg     {strcpy($$,$1);}
-      | funargs ',' funarg 
-                    {sprintf($$,"%s,%s",$1,$3);} 
+funargs: funarg     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | funargs ',' funarg
+                    {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
       ;
 funarg: expr       {strcpy($$,$1);}
       | triplet    {strcpy($$,$1);}
       ;
-triplet: expr ':' expr 
-                    {sprintf($$,"%s:%s",$1,$3);} 
-      | expr ':' expr ':' expr 
-                    {sprintf($$,"%s:%s:%s",$1,$3,$5);} 
-      | ':' expr ':' expr 
-                    {sprintf($$,":%s:%s",$2,$4);} 
-      | ':' ':' expr{sprintf($$,": : %s",$3);} 
-      | ':' expr    {sprintf($$,":%s",$2);} 
-      | expr ':'     {sprintf($$,"%s:",$1);} 
-      | ':'         {sprintf($$,":");} 
-      ;
-ident : TOK_NAME    {  
+triplet: expr ':' expr
+                    {if ( couldaddvariable == 1 ) sprintf($$,"%s:%s",$1,$3);}
+      | expr ':' expr ':' expr
+                    {if ( couldaddvariable == 1 )
+                                               sprintf($$,"%s:%s:%s",$1,$3,$5);}
+      | ':' expr ':' expr
+                    {if ( couldaddvariable == 1 ) sprintf($$,":%s:%s",$2,$4);}
+      | ':' ':' expr{if ( couldaddvariable == 1 ) sprintf($$,": : %s",$3);}
+      | ':' expr    {if ( couldaddvariable == 1 ) sprintf($$,":%s",$2);}
+      | expr ':'    {if ( couldaddvariable == 1 ) sprintf($$,"%s:",$1);}
+      | ':'         {if ( couldaddvariable == 1 ) sprintf($$,":");}
+      ;
+ident : TOK_NAME    {
+                       if ( couldaddvariable == 1 )
+                       {
+                       if ( Vartonumber($1) == 1 )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if (!strcasecmp($1,"Agrif_Parent") )
+                                                            agrif_parentcall =1;
                        if ( VariableIsNotFunction($1) == 0 )
                        {
@@ -1611,6 +1603,5 @@
                           pointedvar=0;
                           if ( VarIsNonGridDepend($1) == 0 &&
-                               formatdeclare == 0 
-                             )
+                               Variableshouldberemove($1) == 0 )
                           {
                              if ( inagrifcallargument == 1 ||
@@ -1620,56 +1611,63 @@
                                 ModifyTheVariableName_0($1);
                              }
-                             if ( inagrifcallargument != 1 || sameagrifargument ==1 )
-                                  ajoutevarindoloop_1($1);
+                             if ( inagrifcallargument != 1 ||
+                                  sameagrifargument ==1 )
+                                  Add_UsedInSubroutine_Var_1($1);
                           }
                           NotifyAgrifFunction_0($1);
                        }
-		    }
-      ;
-simple_const: TOK_TRUE 
-                     {strcpy($$,".TRUE.");}
-      | TOK_FALSE    {strcpy($$,".FALSE.");}
-      | TOK_CSTINT   {strcpy($$,$1);}
-      | TOK_CSTREAL  {strcpy($$,$1);}
-      | TOK_CSTREALDP{strcpy($$,$1);}
-      | TOK_CSTREALQP{strcpy($$,$1);}
-      | simple_const TOK_NAME 
-                     {sprintf($$,"%s%s",$1,$2);}
+                       }
+                    }
+      ;
+simple_const: TOK_TRUE
+                     {if ( couldaddvariable == 1 ) strcpy($$,".TRUE.");}
+      | TOK_FALSE    {if ( couldaddvariable == 1 ) strcpy($$,".FALSE.");}
+      | TOK_CSTINT   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREAL  {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREALDP{if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | TOK_CSTREALQP{if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | simple_const TOK_NAME
+                     {if ( couldaddvariable == 1 ) sprintf($$,"%s%s",$1,$2);}
       | string_constant opt_substring
       ;
-string_constant: TOK_CHAR_CONSTANT 
-                     {strcpy($$,$1);}
-      | string_constant TOK_CHAR_CONSTANT 
-      | TOK_CHAR_MESSAGE 
-                     {strcpy($$,$1);}
+string_constant: TOK_CHAR_CONSTANT
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | string_constant TOK_CHAR_CONSTANT
+      | TOK_CHAR_MESSAGE
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       | TOK_CHAR_CUT
-                     {strcpy($$,$1);}
-      ;
-opt_substring:      {strcpy($$," ");}
-      | substring   {strcpy($$,$1);}
-      ;
-substring: '(' optexpr ':' optexpr ')' 
-                    {sprintf($$,"(%s:%s)",$2,$4);} 
-      ;
-optexpr:           {strcpy($$," ");}
-      | expr        {strcpy($$,$1);}
-      ;
-opt_expr: '\n'          {strcpy($$," ");}
-      | expr        {strcpy($$,$1);}
+                     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+opt_substring:      {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | substring   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+substring: '(' optexpr ':' optexpr ')'
+                    {if ( couldaddvariable == 1 ) sprintf($$,"(%s:%s)",$2,$4);}
+      ;
+optexpr:           {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | expr        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+opt_expr: '\n'          {if ( couldaddvariable == 1 ) strcpy($$," ");}
+      | expr        {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       ;
 initial_value:      {InitialValueGiven = 0;}
-      | before_initial '=' expr    
+      | before_initial '=' expr
                     {
-                       strcpy(InitValue,$3);
-                       InitialValueGiven = 1;
-                    } 
+                       if ( couldaddvariable == 1 )
+                       {
+                          strcpy(InitValue,$3);
+                          InitialValueGiven = 1;
+                       }
+                    }
       ;
 before_initial : {pos_curinit = setposcur();}
       ;
-complex_const: '(' uexpr ',' uexpr ')' 
-                    {sprintf($$,"(%s,%s)",$2,$4);} 
+complex_const: '(' uexpr ',' uexpr ')'
+                    {sprintf($$,"(%s,%s)",$2,$4);}
       ;
 use_stat: word_use  module_name
                     {
+                      if ( couldaddvariable == 1 )
+                      {
                       /* if variables has been declared in a subroutine       */
                       if (insubroutinedeclare == 1)
@@ -1678,5 +1676,5 @@
                       }
                       sprintf(charusemodule,"%s",$2);
-                      Addmoduletothelist_1($2);
+                      Add_NameOfModuleUsed_1($2);
 
                       if ( inmoduledeclare == 0 )
@@ -1686,12 +1684,15 @@
                                                pos_end-pos_curuse);
                       }
-                    }    
+                      }
+                    }
       | word_use  module_name ',' rename_list
                     {
+                       if ( couldaddvariable == 1 )
+                       {
                       if (insubroutinedeclare == 1)
                       {
-                         completelistvarpointtovar_1($2,$4);
-                      }
-                      if ( firstpass == 1 ) 
+                         Add_CouplePointed_Var_1($2,$4);
+                      }
+                      if ( firstpass == 1 )
                       {
                          if ( insubroutinedeclare == 1 )
@@ -1701,7 +1702,7 @@
                             while ( coupletmp )
                             {
-                               strcat(ligne,coupletmp->namevar);
+                               strcat(ligne,coupletmp->c_namevar);
                                strcat(ligne," => ");
-                               strcat(ligne,coupletmp->namepointedvar);
+                               strcat(ligne,coupletmp->c_namepointedvar);
                                coupletmp = coupletmp->suiv;
                                if ( coupletmp ) strcat(ligne,",");
@@ -1709,5 +1710,5 @@
                             sprintf(charusemodule,"%s",$2);
                          }
-                         Addmoduletothelist_1($2);
+                         Add_NameOfModuleUsed_1($2);
                       }
                       if ( inmoduledeclare == 0 )
@@ -1717,7 +1718,10 @@
                                                pos_end-pos_curuse);
                       }
-                    }    
+                      }
+                    }
       | word_use  module_name ',' TOK_ONLY ':' '\n'
                     {
+                       if ( couldaddvariable == 1 )
+                       {
                       /* if variables has been declared in a subroutine       */
                       if (insubroutinedeclare == 1)
@@ -1726,5 +1730,5 @@
                       }
                       sprintf(charusemodule,"%s",$2);
-                      Addmoduletothelist_1($2);
+                      Add_NameOfModuleUsed_1($2);
 
                        if ( inmoduledeclare == 0 )
@@ -1734,13 +1738,16 @@
                                                 pos_end-pos_curuse);
                        }
-                    }    
+                       }
+                    }
       | word_use  module_name ',' TOK_ONLY ':' only_list
                     {
+                       if ( couldaddvariable == 1 )
+                       {
                        /* if variables has been declared in a subroutine      */
                        if (insubroutinedeclare == 1)
                        {
-                          completelistvarpointtovar_1($2,$6);
+                          Add_CouplePointed_Var_1($2,$6);
                        }
-                       if ( firstpass == 1 ) 
+                       if ( firstpass == 1 )
                        {
                          if ( insubroutinedeclare == 1 )
@@ -1750,8 +1757,8 @@
                              while ( coupletmp )
                              {
-                                strcat(ligne,coupletmp->namevar);
-                                if ( strcasecmp(coupletmp->namepointedvar,"") )
+                                strcat(ligne,coupletmp->c_namevar);
+                               if ( strcasecmp(coupletmp->c_namepointedvar,"") )
                                                            strcat(ligne," => ");
-                                strcat(ligne,coupletmp->namepointedvar);
+                                strcat(ligne,coupletmp->c_namepointedvar);
                                 coupletmp = coupletmp->suiv;
                                 if ( coupletmp ) strcat(ligne,",");
@@ -1759,8 +1766,8 @@
                              sprintf(charusemodule,"%s",$2);
                           }
-                          Addmoduletothelist_1($2);
+                          Add_NameOfModuleUsed_1($2);
                        }
                        if ( firstpass == 0 )
-		       {
+                       {
                           if ( inmoduledeclare == 0 )
                           {
@@ -1769,12 +1776,13 @@
                                                    pos_end-pos_curuse);
                           }
-		          else
-		          {
-   		             /* if we are in the module declare and if the    */
-	   	             /* onlylist is a list of global variable         */
-		             variableisglobalinmodule($6, $2, fortranout);
-		          }
+                          else
+                          {
+                             /* if we are in the module declare and if the    */
+                             /* onlylist is a list of global variable         */
+                             variableisglobalinmodule($6, $2, fortranout);
+                          }
                        }
-                    }    
+                       }
+                    }
       ;
 word_use : TOK_USE
@@ -1783,16 +1791,19 @@
                    }
       ;
-module_name: TOK_NAME 
+module_name: TOK_NAME
                     {strcpy($$,$1);}
       ;
 rename_list: rename_name
                     {
-                       $$ = $1;
-                    }                    
+                       if ( couldaddvariable == 1 ) $$ = $1;
+                    }
       | rename_list ',' rename_name
                     {
+                        if ( couldaddvariable == 1 )
+                        {
                         /* insert the variable in the list $1                 */
                         $3->suiv = $1;
                         $$ = $3;
+                        }
                     }
       ;
@@ -1800,35 +1811,38 @@
                     {
                        coupletmp =(listcouple *)malloc(sizeof(listcouple));
-                       strcpy(coupletmp->namevar,$1);
-                       strcpy(coupletmp->namepointedvar,$3);
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,$3);
                        coupletmp->suiv = NULL;
                        $$ = coupletmp;
                      }
       ;
-only_list: only_name 
+only_list: only_name
                     {
-                       $$ = $1;
-                    }                    
+                       if ( couldaddvariable == 1 ) $$ = $1;
+                    }
       | only_list ',' only_name
                     {
+                        if ( couldaddvariable == 1 )
+                        {
                         /* insert the variable in the list $1                 */
                         $3->suiv = $1;
                         $$ = $3;
+                        }
                     }
       ;
-only_name: TOK_NAME TOK_POINT_TO TOK_NAME 
+only_name: TOK_NAME TOK_POINT_TO TOK_NAME
                     {
                        coupletmp =(listcouple *)malloc(sizeof(listcouple));
-                       strcpy(coupletmp->namevar,$1);
-                       strcpy(coupletmp->namepointedvar,$3);
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,$3);
                        coupletmp->suiv = NULL;
                        $$ = coupletmp;
                        pointedvar=1;
-                       ajoutevarindoloop_1($1);
+                       Add_UsedInSubroutine_Var_1($1);
                     }
       | TOK_NAME    {
                        coupletmp =(listcouple *)malloc(sizeof(listcouple));
-                       strcpy(coupletmp->namevar,$1);
-                       strcpy(coupletmp->namepointedvar,"");
+                       strcpy(coupletmp->c_namevar,$1);
+                       strcpy(coupletmp->c_namepointedvar,"");
                        coupletmp->suiv = NULL;
                        $$ = coupletmp;
@@ -1837,8 +1851,28 @@
 exec: iffable
       | TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'
+                     {
+                         Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
       | TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                         curmodulename);
+                     }
       | TOK_NULLIFY '(' pointer_name_list ')'
-      | TOK_ENDUNIT /* end                                                    */
+      | word_endunit /* end                                                   */
                     {
+                       GlobalDeclaration = 0 ;
+                       if ( firstpass == 0 &&
+                            strcasecmp(subroutinename,"") )
+                       {
+                          if ( module_declar && insubroutinedeclare == 0 )
+                          {
+                              fclose(module_declar);
+                          }
+                       }
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
                        if ( inmodulemeet == 1 )
                        {
@@ -1848,98 +1882,118 @@
                             /* it is like an end subroutine <name>            */
                             insubroutinedeclare = 0 ;
-                            paramdeclaration_everdone = 0;
-                            tmpdeclaration_everdone = 0;
                             /*                                                */
-                            closeandcallsubloopandincludeit_0(1,$1,"");
-                            /* at the end of the firstpas  we should remove   */
-                            /*    from the listvarindoloop all variables      */
-                            /*    which has not been declared as table in the */
-                            /*    globliste                                   */
-                            cleanlistvarfordoloop_1(1);
+                            pos_cur = setposcur();
+                            closeandcallsubloopandincludeit_0(1,$1);
+                            functiondeclarationisdone = 0;
                          }
                          else
                          {
-                            /* if we never meet the contains keyword          */
-                            if ( inmoduledeclare == 1 )
-                            {
-                               if ( aftercontainsdeclare == 0 )
-                               {
-                                 CompleteGlobListeWithDatalist_1();
-                                 addsubroutine_alloc_0(1);
-                               }
-                            }
                             /* it is like an end module <name>                */
-                            inmoduledeclare = 0 ; 
-                            inmodulemeet = 0 ; 
+                            inmoduledeclare = 0 ;
+                            inmodulemeet = 0 ;
                          }
                        }
                        else
                        {
-                          paramdeclaration_everdone = 0;
-                          tmpdeclaration_everdone = 0;
                           insubroutinedeclare = 0;
                           /*                                                  */
-                          closeandcallsubloopandincludeit_0(2,$1,"");
-                          /* it is like end subroutine or end program         */
-                          /*  Common case                                     */
-                          /* at the end of the firstpas  we should remove     */
-                          /*    from the listvarindoloop all variables which  */
-                          /*    has not been declared as table in the         */
-                          /*    globliste                                     */
-                          cleanlistvarfordoloop_1(1);
-                       }
+                          pos_cur = setposcur();
+                          closeandcallsubloopandincludeit_0(2,$1);
+                            functiondeclarationisdone = 0;
+                          if ( firstpass == 0 )
+                          {
+                             if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                             else fprintf(paramout,"C\n");
+                             fclose(paramout);
+                           }
+                        }
+                      }
+                      strcpy(subroutinename,"");
                     }
-      | TOK_ENDPROGRAM opt_name
+      | word_endprogram opt_name
                     {
-                       tmpdeclaration_everdone = 0;
-                         paramdeclaration_everdone = 0;
+                       if ( couldaddvariable == 1 )
+                       {
                        insubroutinedeclare = 0;
                        /*                                                     */
-                       closeandcallsubloopandincludeit_0(3,$1,$2);
-                       /*  Common case                                        */
-                       /* at the end of the firstpas  we should remove from   */
-                       /*    the listvarindoloop all variables which has not  */
-                       /*    been declared as table in the globliste          */
-                       cleanlistvarfordoloop_1(3);
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(3,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
                     }
-      | TOK_ENDSUBROUTINE opt_name
+      | word_endsubroutine opt_name
                     {
-                       tmpdeclaration_everdone = 0;
-                       paramdeclaration_everdone = 0;
+                       if ( couldaddvariable == 1 &&
+                            strcasecmp(subroutinename,"") )
+                       {
                        insubroutinedeclare = 0;
                        /*                                                     */
-                       closeandcallsubloopandincludeit_0(1,$1,$2);
-                       /*  Common case                                        */
-                       /* at the end of the firstpas  we should remove from   */
-                       /*    the listvarindoloop all variables which has not  */
-                       /*    been declared as table in the globliste          */
-                       cleanlistvarfordoloop_1(1);
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(1,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
                     }
-      | TOK_ENDFUNCTION opt_name
+      | word_endfunction opt_name
                     {
-                       tmpdeclaration_everdone = 0;
-                       paramdeclaration_everdone = 0;
+                       if ( couldaddvariable == 1 )
+                       {
                        insubroutinedeclare = 0;
                        /*                                                     */
-                       closeandcallsubloopandincludeit_0(0,$1,$2);
-                       /*  Common case                                        */
-                       /* at the end of the firstpas  we should remove from   */
-                       /*    the listvarindoloop all variables which has not  */
-                       /*    been declared as table in the globliste          */
-                       cleanlistvarfordoloop_1(0);
+                       pos_cur = setposcur();
+                       closeandcallsubloopandincludeit_0(0,$1);
+                            functiondeclarationisdone = 0;
+                      if ( firstpass == 0 )
+                      {
+                         if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                         else fprintf(paramout,"C\n");
+                         fclose(paramout);
+                      }
+                      strcpy(subroutinename,"");
+                      }
                     }
       | TOK_ENDMODULE opt_name
                     {
+                       if ( couldaddvariable == 1 )
+                       {
                        /* if we never meet the contains keyword               */
+                      Remove_Word_end_module_0();
                        if ( inmoduledeclare == 1 )
                        {
                           if ( aftercontainsdeclare == 0 )
                           {
-                             CompleteGlobListeWithDatalist_1();
-                             addsubroutine_alloc_0(1);
+                             Write_GlobalParameter_Declaration_0();
+                             Write_NotGridDepend_Declaration_0();
+                             Write_Alloc_Subroutine_For_End_0();
                           }
                        }
-                       inmoduledeclare = 0 ; 
-                       inmodulemeet = 0 ; 
+                       inmoduledeclare = 0 ;
+                       inmodulemeet = 0 ;
+
+                      Write_Word_end_module_0();
+                      strcpy(curmodulename,"");
+                      aftercontainsdeclare = 1;
+                      if ( firstpass == 0 )
+                      {
+                         if ( module_declar && insubroutinedeclare == 0)
+                         {
+                           fclose(module_declar);
+                         }
+                      }
+                      GlobalDeclaration = 0 ;
+                      }
                   }
       | boucledo
@@ -1950,7 +2004,7 @@
       | logif TOK_THEN
       | TOK_ELSEIF  '(' expr ')' TOK_THEN
-      | TOK_ELSE 
-      | TOK_ENDIF
-      | TOK_CASE '(' caselist ')'
+      | TOK_ELSE
+      | TOK_ENDIF opt_name
+      | TOK_CASE caselist ')'
       | TOK_SELECTCASE '(' expr ')'
       | TOK_CASEDEFAULT
@@ -1960,23 +2014,83 @@
                       if (inmoduledeclare == 1 )
                       {
-                         CompleteGlobListeWithDatalist_1();
-                         addsubroutine_alloc_0(0);
-                      }
-                      inmoduledeclare = 0 ; 
-                      aftercontainsdeclare = 1;
-                   }
-      ;
-
+                         Remove_Word_Contains_0();
+                         Write_GlobalParameter_Declaration_0();
+                         Write_NotGridDepend_Declaration_0();
+                         Write_Alloc_Subroutine_0();
+                         inmoduledeclare = 0 ;
+                         aftercontainsdeclare = 1;
+                      }
+                      else
+                      {
+                       if ( couldaddvariable == 1 )
+                       {
+                          if ( firstpass == 1 ) List_ContainsSubroutine =
+                                                Addtolistnom(subroutinename,
+                                                     List_ContainsSubroutine,0);
+                          insubroutinedeclare = 0;
+                          /*                                                  */
+                          closeandcallsubloop_contains_0();
+                            functiondeclarationisdone = 0;
+                         if ( firstpass == 0 )
+                         {
+                            if ( retour77 == 0 ) fprintf(paramout,"!\n");
+                            else fprintf(paramout,"C\n");
+                            fclose(paramout);
+                         }
+                         }
+                         strcpy(subroutinename,"");
+                      }
+                   }
+      ;
+word_endsubroutine: TOK_ENDSUBROUTINE
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       functiondeclarationisdone = 0;
+                       }
+                    }
+      ;
+word_endunit: TOK_ENDUNIT
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
+word_endprogram:  TOK_ENDPROGRAM
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
+word_endfunction: TOK_ENDFUNCTION
+                    {
+                      if ( couldaddvariable == 1 )
+                      {
+                       strcpy($$,$1);
+                       pos_endsubroutine = setposcur()-strlen($1);
+                       }
+                    }
+      ;
 caselist: expr
       | caselist ',' expr
       | caselist ':' expr
       ;
-boucledo : worddo opt_int do_var '=' expr ',' expr
-      | worddo opt_int do_var '=' expr ',' expr ',' expr
+boucledo : worddo opt_int do_arg
       | wordwhile expr
       | TOK_ENDDO optname
       ;
-opt_int : 
-      | TOK_CSTINT
+do_arg :
+      | do_var '=' expr ',' expr
+      | do_var '=' expr ',' expr ',' expr
+opt_int :
+      | TOK_CSTINT opt_comma
       ;
 opt_name : '\n'  {strcpy($$,"");}
@@ -1989,5 +2103,5 @@
       ;
 wordwhile :TOK_DOWHILE
-      ;     
+      ;
 
 dotarget:
@@ -1999,7 +2113,15 @@
       | goto
       | io
-      | call 
+      | call
       | TOK_ALLOCATE '(' allocation_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
       | TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')'
+                     {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                     }
       | TOK_EXIT optexpr
       | TOK_RETURN opt_expr
@@ -2010,5 +2132,13 @@
 before_dims : {if ( couldaddvariable == 1 ) created_dimensionlist = 0;}
 ident_dims : ident before_dims dims dims
-      {created_dimensionlist = 1;}
+              {
+                  created_dimensionlist = 1;
+                  if  ( agrif_parentcall == 1 )
+                  {
+                      ModifyTheAgrifFunction_0($3->dim.last);
+                      agrif_parentcall =0;
+                      fprintf(fortranout," = ");
+                  }
+              }
       | ident_dims '%' ident before_dims dims dims
       {created_dimensionlist = 1;}
@@ -2016,13 +2146,13 @@
       | int_list ',' TOK_CSTINT
       ;
-after_ident_dims : '=' expr 
-      | TOK_POINT_TO expr 
-      ;
-call: keywordcall opt_call 
+after_ident_dims : '=' expr
+      | TOK_POINT_TO expr
+      ;
+call: keywordcall opt_call
                    {
                       inagrifcallargument = 0 ;
                       incalldeclare=0;
-                      if ( oldfortranout && 
-                           !strcasecmp(meetagrifinitgrids,subroutinename) && 
+                      if ( oldfortranout &&
+                           !strcasecmp(meetagrifinitgrids,subroutinename) &&
                            firstpass == 0 &&
                            callmpiinit == 1)
@@ -2034,6 +2164,6 @@
                                                                    ,mpiinitvar);
                       }
-                      if ( oldfortranout           && 
-                           callagrifinitgrids == 1 && 
+                      if ( oldfortranout           &&
+                           callagrifinitgrids == 1 &&
                            firstpass == 0 )
                       {
@@ -2041,6 +2171,5 @@
                          RemoveWordSET_0(fortranout,pos_curcall,
                                                pos_end-pos_curcall);
-                         fprintf(oldfortranout,
-                                           "      Call Agrif_Init_Grids () \n");
+
                          strcpy(subofagrifinitgrids,subroutinename);
                       }
@@ -2048,5 +2177,5 @@
                    }
       ;
-opt_call : 
+opt_call :
       | '(' opt_callarglist  ')'
       ;
@@ -2054,10 +2183,9 @@
       | callarglist
       ;
-keywordcall : before_call TOK_NAME 
+keywordcall : before_call TOK_NAME
                     {
-                       if (!strcasecmp($2,"MPI_Init") ) 
+                       if (!strcasecmp($2,"MPI_Init") )
                        {
                           callmpiinit = 1;
-                          strcpy(meetmpiinit,subroutinename);
                        }
                        else
@@ -2065,5 +2193,5 @@
                           callmpiinit = 0;
                        }
-                       if (!strcasecmp($2,"Agrif_Init_Grids") ) 
+                       if (!strcasecmp($2,"Agrif_Init_Grids") )
                        {
                           callagrifinitgrids = 1;
@@ -2071,9 +2199,15 @@
                        }
                        else callagrifinitgrids = 0;
-                       if ( Vartonumber($2) == 1 ) 
+                       if ( !strcasecmp($2,"Agrif_Open_File") )
+                       {
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
+                       }
+                       if ( Vartonumber($2) == 1 )
                        {
                           incalldeclare=1;
                           inagrifcallargument = 1 ;
-                          AddsubroutineTolistsubwhereagrifused();
+                          Add_SubroutineWhereAgrifUsed_1(subroutinename,
+                                                        curmodulename);
                        }
                     }
@@ -2086,13 +2220,14 @@
 
 callarg:  expr {
-                  if ( callmpiinit == 1 ) 
+                  if ( callmpiinit == 1 )
                   {
                      strcpy(mpiinitvar,$1);
-                     if ( firstpass == 1 ) 
+                     if ( firstpass == 1 )
                      {
-                        curvar=createvar($1,NULL);
+                        Add_UsedInSubroutine_Var_1 (mpiinitvar);
+/*                        curvar=createvar($1,NULL);
                         curlistvar=insertvar(NULL,curvar);
-                        listargsubroutine = AddListvarToListvar
-                                               (curlistvar,listargsubroutine,1);
+                        List_Subr outineArgument_Var = AddListvarToListvar
+                         (curlistvar,List_SubroutineAr gument_Var,1);*/
                      }
                   }
@@ -2108,39 +2243,8 @@
       | read option_read
       | TOK_REWIND after_rewind
-      | print option_print
-      | wordformat debut_format ioctl_format fin_format
-                    {formatdeclare = 0;}
-      ;
-wordformat : TOK_FORMAT
-                    {formatdeclare = 1;}
-opt_ioctlformat : 
-      | ioctl_format
-      ;
-opt_ioctl_format : 
-      | ',' ioctl_format
-      | ',' '*'
-      ;
-debut_format : TOK_LEFTAB opt_comma
-      | '('
-      ;
-ioctl_format : format_expr
-      |   ioctl_format ',' format_expr
-      ;
-format_expr : 
-      | uexpr
-      | TOK_CSTINT TOK_CHAR_INT
-      | TOK_CSTINT debut_format ioctl_format fin_format
-      | TOK_SLASH opt_CHAR_INT
-      | TOK_CHAR_INT TOK_SLASH format_expr
-      | TOK_SLASH TOK_SLASH
-      | TOK_CHAR_INT
-      | '(' format_expr ')'
-      | '(' uexpr ')'
-      ;
-opt_CHAR_INT : 
+      | TOK_FORMAT
+      ;
+opt_CHAR_INT :
       | TOK_CSTINT TOK_NAME
-      ;
-fin_format : opt_comma TOK_RIGHTAB opt_comma
-      | ')'
       ;
 idfile : '*'
@@ -2164,7 +2268,10 @@
       ;
 ioctl:  '(' ctllist ')'
-      | '(' fexpr ')' 
+      | '(' fexpr ')'
       ;
 after_rewind:  '(' ident ')'
+      | '(' TOK_CSTINT ')'
+      | TOK_CSTINT
+      | '(' uexpr ')'
       | TOK_NAME
       ;
@@ -2172,12 +2279,12 @@
       | ctllist ',' ioclause
       ;
-ioclause: fexpr 
+ioclause: fexpr
       | '*'
       | TOK_DASTER
-      | TOK_NAME expr 
+      | TOK_NAME expr
       | TOK_NAME expr '%' ident_dims
       | TOK_NAME '(' triplet ')'
-      | TOK_NAME '*' 
-      | TOK_NAME TOK_DASTER 
+      | TOK_NAME '*'
+      | TOK_NAME TOK_DASTER
       ;
 iofctl: TOK_OPEN
@@ -2191,7 +2298,5 @@
       | TOK_INQUIRE
       | TOK_WRITE
-      ;
-print: TOK_PRINT fexpr
-      | TOK_PRINT '*'
+      | TOK_PRINT
       ;
 fexpr: unpar_fexpr
@@ -2208,4 +2313,6 @@
       | TOK_FILE expr
       | TOK_EXIST expr
+      | TOK_ERR expr
+      | TOK_END expr
       | TOK_NAME '=' expr
       ;
@@ -2216,5 +2323,5 @@
       | inlist ',' inelt
       ;
-opt_lhs : 
+opt_lhs :
       | lhs
       ;
@@ -2222,5 +2329,5 @@
       | '(' inlist ')' opt_operation
       | predefinedfunction opt_operation
-      | simple_const opt_operation 
+      | simple_const opt_operation
       | '(' inlist ',' dospec ')'
       ;
@@ -2228,39 +2335,41 @@
       | operation
       | opt_operation operation
-      ;      
-outlist: other      {strcpy($$,$1);} 
-      | out2       {strcpy($$,$1);} 
+      ;
+outlist: other      {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | out2       {if ( couldaddvariable == 1 ) strcpy($$,$1);}
       ;
 out2: uexpr ',' expr
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | uexpr ',' other 
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | other ',' expr 
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | other ',' other 
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | out2 ',' expr 
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | out2 ',' other 
-                   {sprintf($$,"%s,%s",$1,$3);} 
-      | uexpr     {strcpy($$,$1);} 
-      | predefinedfunction {strcpy($$,$1);} 
-      ;
-other:  complex_const 
-                   {strcpy($$,$1);} 
-      | '(' expr ')' 
-                   {sprintf($$," (%s)",$2);} 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | uexpr ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | other ',' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | other ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | out2 ',' expr
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | out2 ',' other
+                   {if ( couldaddvariable == 1 ) sprintf($$,"%s,%s",$1,$3);}
+      | uexpr     {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | predefinedfunction {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      ;
+other:  complex_const
+                   {if ( couldaddvariable == 1 ) strcpy($$,$1);}
+      | '(' expr ')'
+                   {if ( couldaddvariable == 1 ) sprintf($$," (%s)",$2);}
       | '(' uexpr ',' dospec ')'
-                   {sprintf($$,"(%s,%s)",$2,$4);} 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
       | '(' other ',' dospec ')'
-                   {sprintf($$,"(%s,%s)",$2,$4);} 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
       | '(' out2 ',' dospec ')'
-                   {sprintf($$,"(%s,%s)",$2,$4);} 
-      ;
-
-dospec: TOK_NAME '=' expr ',' expr 
-                   {sprintf($$,"%s=%s,%s)",$1,$3,$5);} 
-      | TOK_NAME '=' expr ',' expr ',' expr 
-                   {sprintf($$,"%s=%s,%s,%s)",$1,$3,$5,$7);} 
+                   {if ( couldaddvariable == 1 ) sprintf($$,"(%s,%s)",$2,$4);}
+      ;
+
+dospec: TOK_NAME '=' expr ',' expr
+                   {if ( couldaddvariable == 1 )
+                                              sprintf($$,"%s=%s,%s)",$1,$3,$5);}
+      | TOK_NAME '=' expr ',' expr ',' expr
+                   {if ( couldaddvariable == 1 )
+                                        sprintf($$,"%s=%s,%s,%s)",$1,$3,$5,$7);}
       ;
 labellist: label
@@ -2269,5 +2378,6 @@
 label: TOK_CSTINT
       ;
-goto: TOK_PLAINGOTO label
+goto: TOK_PLAINGOTO '(' expr ',' expr ')' ',' expr
+      | TOK_PLAINGOTO label
       ;
 allocation_list: allocate_object
@@ -2276,13 +2386,13 @@
       ;
 allocate_object: ident
-                   {AddIdentToTheAllocateList_1($1);}
+                   {Add_Allocate_Var_1($1,curmodulename);}
       | structure_component
       | array_element
       ;
-array_element: ident '(' funargs ')' 
-                   {AddIdentToTheAllocateList_1($1);}
-      ;
-subscript_list: expr 
-      | subscript_list ',' expr 
+array_element: ident '(' funargs ')'
+                   {Add_Allocate_Var_1($1,curmodulename);}
+      ;
+subscript_list: expr
+      | subscript_list ',' expr
       ;
 
@@ -2317,42 +2427,42 @@
 
    /*fortrandebug = 1;*/
+   if ( mark == 1 ) printf("Firstpass == %d \n",firstpass);
 /******************************************************************************/
 /*  1-  Open input and output files                                           */
 /******************************************************************************/
-   strcpy(OriginalFileName,fichier_entree); 
    strcpy(nomfile,commondirin);
    strcat(nomfile,"/");
    strcat(nomfile,fichier_entree);
    fortranin=fopen( nomfile,"r");
-   if (! fortranin) 
+   if (! fortranin)
    {
       printf("Error : File %s does not exist\n",nomfile);
       exit(1);
    }
-   
+
    strcpy(curfile,nomfile);
    strcpy(nomfile,commondirout);
-   strcat(nomfile,"/");  
+   strcat(nomfile,"/");
    strcat(nomfile,fichier_entree);
    strcpy(nomfileoutput,nomfile);
-   if (firstpass == 1) 
+   if (firstpass == 1)
    {
-      if (checkexistcommon == 1) 
+      if (checkexistcommon == 1)
       {
-         if (fopen(nomfile,"r")) 
+         if (fopen(nomfile,"r"))
          {
             printf("Warning : file %s already exist\n",nomfile);
             confirmyes = 0;
-            while (confirmyes==0) 
+            while (confirmyes==0)
             {
                printf("Override file %s ? [Y/N]\n",nomfile);
                c=getchar();
-               getchar();    
-               if (c==79 || c==110) 
+               getchar();
+               if (c==79 || c==110)
                {
                   printf("We stop\n");
                   exit(1);
                }
-               if (c==89 || c==121) 
+               if (c==89 || c==121)
                {
                   confirmyes=1;
@@ -2361,5 +2471,5 @@
          }
       }
-   }  
+   }
 
 /******************************************************************************/
@@ -2367,25 +2477,25 @@
 /******************************************************************************/
 
-   line_num_fortran_common=1; 
+   line_num_fortran_common=1;
    line_num_fortran=1;
-   PublicDeclare = 0;  
-   PrivateDeclare = 0; 
-   formatdeclare = 0;
-   ExternalDeclare = 0; 
+   PublicDeclare = 0;
+   PrivateDeclare = 0;
+   ExternalDeclare = 0;
    SaveDeclare = 0;
-   indeclarationvar=0;
    pointerdeclare = 0;
    optionaldeclare = 0;
    incalldeclare = 0;
-   infunctiondeclare = 0 ;
+   VarType = 0;
+   VarTypepar = 0;
    Allocatabledeclare = 0 ;
-   strcpy(NamePrecision," "); 
-   VariableIsParameter =  0 ; 
-   strcpy(NamePrecision,"");  
-   c_star = 0 ; 
+   strcpy(NamePrecision," ");
+   VariableIsParameter =  0 ;
+   strcpy(NamePrecision,"");
+   c_star = 0 ;
+   functiondeclarationisdone = 0;
    insubroutinedeclare = 0 ;
-   strcpy(subroutinename," "); 
-   InitialValueGiven = 0 ; 
-   strcpy(EmptyChar," "); 
+   strcpy(subroutinename," ");
+   InitialValueGiven = 0 ;
+   strcpy(EmptyChar," ");
    inmoduledeclare = 0;
    colnum=0;
@@ -2395,14 +2505,13 @@
    /* Name of the file without format                                         */
    tmp = strchr(fichier_entree, '.');
-   strncpy(curfilename,fichier_entree,strlen(fichier_entree)-strlen(tmp)); 
+   strncpy(curfilename,fichier_entree,strlen(fichier_entree)-strlen(tmp));
 /******************************************************************************/
-/*  2-  Parsing of the input file (1 time)                                    */
+/*  3-  Parsing of the input file (1 time)                                    */
 /******************************************************************************/
-   if (firstpass == 0 ) 
+   if (firstpass == 0 )
    {
       fortranout=fopen(nomfileoutput,"w");
-      /* we should add the new module comes from common block                 */
-      if (fortran77 == 1 ) fprintf
-                      (fortranout,"#include \"NewModule_%s.h\" \n",curfilename);
+
+      NewModule_Creation_0();
    }
 
