Index: branches/2015/dev_r5151_UKMO_ISF/NEMOGCM/EXTERNAL/AGRIF/LIB/UtilListe.c
===================================================================
--- branches/2015/dev_r5151_UKMO_ISF/NEMOGCM/EXTERNAL/AGRIF/LIB/UtilListe.c	(revision 5152)
+++ branches/2015/dev_r5151_UKMO_ISF/NEMOGCM/EXTERNAL/AGRIF/LIB/UtilListe.c	(revision 5956)
@@ -41,18 +41,18 @@
 void Init_Variable(variable *var)
 {
-   strcpy(var->v_typevar            ,"");
-   strcpy(var->v_nomvar             ,"");
-   strcpy(var->v_oldname            ,"");
-   strcpy(var->v_dimchar            ,"");
-   strcpy(var->v_modulename         ,"");
-   strcpy(var->v_commonname         ,"");
-   strcpy(var->v_vallengspec        ,"");
-   strcpy(var->v_nameinttypename    ,"");
-   strcpy(var->v_commoninfile       ,"");
-   strcpy(var->v_subroutinename     ,"");
-   strcpy(var->v_precision          ,"");
-   strcpy(var->v_initialvalue       ,"");
-   strcpy(var->v_IntentSpec         ,"");
-   strcpy(var->v_readedlistdimension,"");
+   strcpy(var->v_typevar            , "");
+   strcpy(var->v_nomvar             , "");
+   strcpy(var->v_oldname            , "");
+   strcpy(var->v_dimchar            , "");
+   strcpy(var->v_modulename         , "");
+   strcpy(var->v_commonname         , "");
+   strcpy(var->v_vallengspec        , "");
+   strcpy(var->v_nameinttypename    , "");
+   strcpy(var->v_commoninfile       , "");
+   strcpy(var->v_subroutinename     , "");
+   strcpy(var->v_precision          , "");
+   strcpy(var->v_initialvalue       , "");
+   strcpy(var->v_IntentSpec         , "");
+   strcpy(var->v_readedlistdimension, "");
    var->v_nbdim               = 0 ;
    var->v_common              = 0 ;
@@ -60,4 +60,5 @@
    var->v_module              = 0 ;
    var->v_save                = 0 ;
+   var->v_catvar              = 0 ;
    var->v_VariableIsParameter = 0 ;
    var->v_PublicDeclare       = 0 ;
@@ -74,5 +75,5 @@
    var->v_target              = 0 ;
    var->v_dimsempty           = 0 ;
-   var->v_dimension = (listdim *)NULL;
+   var->v_dimension = (listdim *) NULL;
 }
 /******************************************************************************/
@@ -89,18 +90,19 @@
 /*                                                                            */
 /******************************************************************************/
-listvar * AddListvarToListvar(listvar *l,listvar *glob,int ValueFirstpass)
-{
-   listvar *newvar;
-   if ( firstpass == ValueFirstpass )
-   {
-      if ( !glob) glob = l ;
-      else
-      {
-         newvar=glob;
-         while (newvar->suiv) newvar = newvar->suiv;
-         newvar->suiv = l;
-      }
-   }
-   return glob;
+listvar * AddListvarToListvar ( listvar *l, listvar *glob, int ValueFirstpass )
+{
+    listvar *newvar;
+    if ( firstpass == ValueFirstpass )
+    {
+        if ( !glob ) glob = l;
+        else
+        {
+            newvar = glob;
+            while (newvar->suiv)
+                newvar = newvar->suiv;
+            newvar->suiv = l;
+        }
+    }
+    return glob;
 }
 
@@ -113,65 +115,81 @@
 /*                                                                            */
 /******************************************************************************/
-void CreateAndFillin_Curvar(char *type,variable *curvar)
-{
-   if (!strcasecmp(type,"character") && strcasecmp(CharacterSize,"") )
-   {
-      strcpy(curvar->v_dimchar,CharacterSize);
-      Save_Length(CharacterSize,5);
-   }
-
-  /* On donne la precision de la variable si elle a ete donnee                */
-  curvar->v_c_star = 0;
-  if ( c_star == 1 ) curvar->v_c_star = 1;
-  /*                                                                          */
-  strcpy(curvar->v_vallengspec,"");
-  if ( strcasecmp(vallengspec,"") )
-  {
-     strcpy(curvar->v_vallengspec,vallengspec);
-     Save_Length(vallengspec,8);
-  }
-
-  strcpy(curvar->v_precision,"");
-  if ( strcasecmp(NamePrecision,"") )
-  {
-     strcpy(curvar->v_precision,NamePrecision);
-     Save_Length(NamePrecision,12);
-  }
-  /* Si cette variable a ete declaree dans un module on met curvar->module=1  */
-  if ( inmoduledeclare == 1 || SaveDeclare == 1)
-  {
-      curvar->v_module = 1;
-   }
-   /* Puis on donne le nom du module dans curvar->v_modulename                */
-   strcpy(curvar->v_modulename,curmodulename);
-   Save_Length(curmodulename,6);
-   /* Si cette variable a ete initialisee                                     */
-/*RB*/
-   if ( ! strcmp(InitialValueGiven,"=")  ) 
-/*RBend*/
-   {
-      strcpy(curvar->v_initialvalue,InitValue);
-      Save_Length(InitValue,14);
-   }
-   /* Si cette variable est declaree en save                                  */
-/*RB*/
-   if (SaveDeclare == 1 &&  !strcasecmp(curvar->v_typevar,"type")) {
-/*RBend*/
-   curvar->v_save = 1;
-   }
-
-   /* Si cette variable est v_allocatable                                     */
-   if (Allocatabledeclare == 1 ) curvar->v_allocatable=1;
-   
-   /* Si cette variable est v_targer                                     */
-   if (Targetdeclare == 1 ) curvar->v_target=1;
-   /* if INTENT spec has been given                                           */
-   if ( strcasecmp(IntentSpec,"") )
-   {
-      strcpy(curvar->v_IntentSpec,IntentSpec);
-      Save_Length(IntentSpec,13);
-   }
-}
-
+void CreateAndFillin_Curvar(const char *type, variable *curvar)
+{
+    if ( !strcasecmp(type, "character") && strcasecmp(CharacterSize, "") )
+    {
+        strcpy(curvar->v_dimchar, CharacterSize);
+    }
+
+    /* On donne la precision de la variable si elle a ete donnee                */
+    curvar->v_c_star = 0;
+    if ( c_star == 1 )  curvar->v_c_star = 1;
+
+    strcpy(curvar->v_vallengspec,"");
+    if ( strcasecmp(vallengspec,"") )
+    {
+        strcpy(curvar->v_vallengspec,vallengspec);
+        Save_Length(vallengspec,8);
+    }
+
+    strcpy(curvar->v_precision,"");
+    if ( strcasecmp(NamePrecision,"") )
+    {
+        strcpy(curvar->v_precision,NamePrecision);
+        addprecision_derivedfromkind(curvar);
+        Save_Length(NamePrecision,12);
+    }
+    /* Si cette variable a ete declaree dans un module on met curvar->module=1  */
+    if ( inmoduledeclare == 1 || SaveDeclare == 1 )
+    {
+        curvar->v_module = 1;
+    }
+    /* Puis on donne le nom du module dans curvar->v_modulename                */
+    strcpy(curvar->v_modulename,curmodulename);
+    /* Si cette variable a ete initialisee                                     */
+    if (InitialValueGiven == 1 )
+    {
+        strcpy(curvar->v_initialvalue,InitValue);
+        Save_Length(InitValue,14);
+    }
+    /* Si cette variable est declaree en save                                  */
+    if (SaveDeclare == 1 && !strcasecmp(curvar->v_typevar,"type")) curvar->v_save = 1;
+
+    /* Si cette variable est v_allocatable                                     */
+    if (Allocatabledeclare == 1 ) curvar->v_allocatable=1;
+
+    /* Si cette variable est v_target                                     */
+    if (Targetdeclare == 1 ) curvar->v_target=1;
+
+    /* if INTENT spec has been given                                           */
+    if ( strcasecmp(IntentSpec,"") )
+    {
+        strcpy(curvar->v_IntentSpec,IntentSpec);
+        Save_Length(IntentSpec,13);
+    }
+}
+
+
+void addprecision_derivedfromkind(variable *curvar)
+{
+    listnom *parcours;
+    char kind[LONG_VNAME];
+    char kind_val[LONG_C];
+
+    sscanf(curvar->v_precision, "%100s =", kind_val);
+
+    if ( !strcasecmp(kind_val, "kind") )
+        sscanf(curvar->v_precision, "%50s = %50s", kind, kind_val);
+
+    parcours = listofkind;
+    while (parcours)
+    {
+        if ( !strcasecmp(parcours->o_nom, kind_val) )
+        {
+            sprintf(curvar->v_nameinttypename, "%d", parcours->o_val);
+        }
+        parcours=parcours->suiv;
+    }
+}
 
 /******************************************************************************/
@@ -180,79 +198,74 @@
 /*                                                                            */
 /******************************************************************************/
-void duplicatelistvar(listvar *orig)
-{
-   listvar *parcours;
-   listvar *tmplistvar;
-   listvar *tmplistvarprec;
-   listdim *tmplistdim;
-   variable *tmpvar;
-
-   tmplistvarprec = (listvar *)NULL;
-   parcours = orig;
-   while ( parcours )
-   {
-      tmplistvar = (listvar *)malloc(sizeof(listvar));
-      tmpvar = (variable *)malloc(sizeof(variable));
-      /*                                                                      */
-      Init_Variable(tmpvar);
-      /*                                                                      */
-      strcpy(tmpvar->v_typevar,parcours->var->v_typevar);
-      strcpy(tmpvar->v_nomvar,parcours->var->v_nomvar);
-      strcpy(tmpvar->v_oldname,parcours->var->v_oldname);
-      strcpy(tmpvar->v_dimchar,parcours->var->v_dimchar);
-      if ( parcours->var->v_dimension )
-      {
-         tmplistdim = (listdim *)malloc(sizeof(listdim));
-         tmplistdim = parcours->var->v_dimension;
-         tmpvar->v_dimension = tmplistdim;
-      }
-      tmpvar->v_nbdim=parcours->var->v_nbdim;
-      tmpvar->v_common=parcours->var->v_common;
-      tmpvar->v_positioninblock=parcours->var->v_positioninblock;
-      tmpvar->v_module=parcours->var->v_module;
-      tmpvar->v_save=parcours->var->v_save;
-      tmpvar->v_VariableIsParameter=parcours->var->v_VariableIsParameter;
-      printf("QLKDF\n");
-      tmpvar->v_indicetabvars=parcours->var->v_indicetabvars;
-      strcpy(tmpvar->v_modulename,parcours->var->v_modulename);
-      strcpy(tmpvar->v_commonname,parcours->var->v_commonname);
-      strcpy(tmpvar->v_vallengspec,parcours->var->v_vallengspec);
-
-      strcpy(tmpvar->v_nameinttypename,parcours->var->v_nameinttypename);
-            
-      tmpvar->v_pointedvar=parcours->var->v_pointedvar;
-      strcpy(tmpvar->v_commoninfile,mainfile);
-      Save_Length(mainfile,10);
-      strcpy(tmpvar->v_subroutinename,parcours->var->v_subroutinename);
-      tmpvar->v_dimensiongiven=parcours->var->v_dimensiongiven;
-      tmpvar->v_c_star=parcours->var->v_c_star;
-      strcpy(tmpvar->v_precision,parcours->var->v_precision);
-      strcpy(tmpvar->v_initialvalue,parcours->var->v_initialvalue);
-      tmpvar->v_pointerdeclare=parcours->var->v_pointerdeclare;
-      tmpvar->v_optionaldeclare=parcours->var->v_optionaldeclare;
-      tmpvar->v_allocatable=parcours->var->v_allocatable;
-      tmpvar->v_target=parcours->var->v_target;
-      strcpy(tmpvar->v_IntentSpec,parcours->var->v_IntentSpec);
-      tmpvar->v_dimsempty=parcours->var->v_dimsempty;
-      strcpy(tmpvar->v_readedlistdimension,
-                                          parcours->var->v_readedlistdimension);
-      /*                                                                      */
-      tmplistvar->var = tmpvar;
-      tmplistvar->suiv = NULL;
-      /*                                                                      */
-      if ( !listduplicated )
-      {
-         listduplicated = tmplistvar;
-         tmplistvarprec = listduplicated;
-      }
-      else
-      {
-         tmplistvarprec->suiv = tmplistvar;
-         tmplistvarprec = tmplistvar;
-      }
-      /*                                                                      */
-      parcours = parcours->suiv;
-   }
-}
+// void duplicatelistvar(listvar *orig)
+// {
+//    listvar *parcours;
+//    listvar *tmplistvar;
+//    listvar *tmplistvarprec;
+//    listdim *tmplistdim;
+//    variable *tmpvar;
+//
+//    tmplistvarprec = (listvar *)NULL;
+//    parcours = orig;
+//    while ( parcours )
+//    {
+//       tmplistvar = (listvar *)calloc(1,sizeof(listvar));
+//       tmpvar = (variable *)calloc(1,sizeof(variable));
+//       /*                                                                      */
+//       Init_Variable(tmpvar);
+//       /*                                                                      */
+//       strcpy(tmpvar->v_typevar, parcours->var->v_typevar);
+//       strcpy(tmpvar->v_nomvar,  parcours->var->v_nomvar);
+//       strcpy(tmpvar->v_oldname, parcours->var->v_oldname);
+//       strcpy(tmpvar->v_dimchar, parcours->var->v_dimchar);
+//       if ( parcours->var->v_dimension )
+//       {
+//          tmplistdim = (listdim*) calloc(1,sizeof(listdim));
+//          tmplistdim = parcours->var->v_dimension;
+//          tmpvar->v_dimension = tmplistdim;
+//       }
+//       tmpvar->v_nbdim  = parcours->var->v_nbdim;
+//       tmpvar->v_common = parcours->var->v_common;
+//       tmpvar->v_module = parcours->var->v_module;
+//       tmpvar->v_save   = parcours->var->v_save;
+//       tmpvar->v_positioninblock = parcours->var->v_positioninblock;
+//       tmpvar->v_VariableIsParameter = parcours->var->v_VariableIsParameter;
+//       tmpvar->v_indicetabvars = parcours->var->v_indicetabvars;
+//       tmpvar->v_pointedvar    = parcours->var->v_pointedvar;
+//       tmpvar->v_dimensiongiven = parcours->var->v_dimensiongiven;
+//       tmpvar->v_c_star = parcours->var->v_c_star;
+//       tmpvar->v_catvar = parcours->var->v_catvar;
+//       tmpvar->v_pointerdeclare = parcours->var->v_pointerdeclare;
+//       tmpvar->v_optionaldeclare = parcours->var->v_optionaldeclare;
+//       tmpvar->v_allocatable = parcours->var->v_allocatable;
+//       tmpvar->v_target      = parcours->var->v_target;
+//       tmpvar->v_dimsempty   = parcours->var->v_dimsempty;
+//       strcpy(tmpvar->v_modulename,  parcours->var->v_modulename);
+//       strcpy(tmpvar->v_commonname,  parcours->var->v_commonname);
+//       strcpy(tmpvar->v_vallengspec, parcours->var->v_vallengspec);
+//       strcpy(tmpvar->v_nameinttypename, parcours->var->v_nameinttypename);
+//       strcpy(tmpvar->v_commoninfile, cur_filename);
+//       strcpy(tmpvar->v_subroutinename, parcours->var->v_subroutinename);
+//       strcpy(tmpvar->v_precision, parcours->var->v_precision);
+//       strcpy(tmpvar->v_initialvalue, parcours->var->v_initialvalue);
+//       strcpy(tmpvar->v_IntentSpec, parcours->var->v_IntentSpec);
+//       strcpy(tmpvar->v_readedlistdimension, parcours->var->v_readedlistdimension);
+//
+//       tmplistvar->var = tmpvar;
+//       tmplistvar->suiv = NULL;
+//
+//       if ( !listduplicated )
+//       {
+//          listduplicated = tmplistvar;
+//          tmplistvarprec = listduplicated;
+//       }
+//       else
+//       {
+//          tmplistvarprec->suiv = tmplistvar;
+//          tmplistvarprec = tmplistvar;
+//       }
+//       parcours = parcours->suiv;
+//    }
+// }
 
 /******************************************************************************/
@@ -273,5 +286,5 @@
    listdim *parcours ;
 
-   newdim=(listdim *) malloc (sizeof (listdim));
+   newdim=(listdim *) calloc(1,sizeof(listdim));
    newdim->dim=nom;
    newdim->suiv=NULL;
@@ -310,7 +323,6 @@
    while(parcours_var)
    {
-      v=parcours_var->var;
+      v = parcours_var->var;
       strcpy(v->v_dimchar,(lin->dim).last);
-      Save_Length((lin->dim).last,5);
       parcours_var=parcours_var->suiv;
    }
@@ -319,24 +331,24 @@
 
 /******************************************************************************/
-/*                                num_dims                                    */
+/*                              get_num_dims                                  */
 /******************************************************************************/
 /* This subroutine is used to know the dimension of a table                   */
 /******************************************************************************/
 /*                                                                            */
-/*             Dimension(jpi,jpj,jpk) ----------> num_dims = 3                */
-/*                                                                            */
-/******************************************************************************/
-int num_dims(listdim *d)
-{
-   listdim *parcours;
-   int compteur = 0;
-
-   parcours = d;
-   while(parcours)
-   {
-     compteur++;
-     parcours=parcours->suiv;
-   }
-   return compteur;
+/*             Dimension(jpi,jpj,jpk) ----------> get_num_dims = 3            */
+/*                                                                            */
+/******************************************************************************/
+int get_num_dims ( const listdim *d )
+{
+    listdim *parcours;
+    int compteur = 0;
+
+    parcours = (listdim *) d;
+    while(parcours)
+    {
+        compteur++;
+        parcours = parcours->suiv;
+    }
+    return compteur;
 }
 
@@ -348,69 +360,62 @@
 /*      struct : variable                                                     */
 /******************************************************************************/
-variable * createvar(char *nom,listdim *d)
-{
-  variable *var;
-  listdim *dims;
-  char ligne[LONG_C];
-  char listdimension[LONG_C];
-
-   var=(variable *) malloc(sizeof(variable));
-   /*                                                                         */
-   Init_Variable(var);
-   /*                                                                         */
-   strcpy(var->v_nomvar,nom);
-   Save_Length(nom,4);
-   /*                                                                         */
-   strcpy(listdimension,"");
-   strcpy(var->v_modulename,curmodulename);
-   Save_Length(curmodulename,6);
-   strcpy(var->v_commoninfile,mainfile);
-   Save_Length(mainfile,10);
-   strcpy(var->v_subroutinename,subroutinename);
-   Save_Length(subroutinename,11);
-   /*                                                                         */
-   if ( strcasecmp(nameinttypename,"") )
-   {
-      strcpy(var->v_nameinttypename,nameinttypename);
-      Save_Length(nameinttypename,9);
-   }
-         
-   if ( optionaldeclare     == 1 ) var->v_optionaldeclare = 1;
-   if ( pointerdeclare      == 1 ) var->v_pointerdeclare = 1;
-   if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ;
-   if ( PublicDeclare       == 1 ) var->v_PublicDeclare = 1 ;
-   if ( PrivateDeclare      == 1 ) var->v_PrivateDeclare = 1;
-   if ( ExternalDeclare     == 1 ) var->v_ExternalDeclare = 1;
-   /*                                                                         */
-   var->v_dimension=d;
+variable * createvar(const char *nom, listdim *d)
+{
+    variable *var;
+    listdim *dims;
+    char ligne[LONG_M];
+    char listdimension[LONG_M];
+
+    var = (variable *) calloc(1,sizeof(variable));
+
+    Init_Variable(var);
+
+    strcpy(listdimension,"");
+    strcpy(var->v_nomvar,nom);
+    strcpy(var->v_modulename,curmodulename);
+    strcpy(var->v_commoninfile,cur_filename);
+    strcpy(var->v_subroutinename,subroutinename);
+
+    if ( strcasecmp(nameinttypename,"") )
+    {
+        strcpy(var->v_nameinttypename,nameinttypename);
+    }
+
+    if ( optionaldeclare     == 1 ) var->v_optionaldeclare = 1;
+    if ( pointerdeclare      == 1 ) var->v_pointerdeclare = 1;
+    if ( VariableIsParameter == 1 ) var->v_VariableIsParameter = 1 ;
+    if ( PublicDeclare       == 1 ) var->v_PublicDeclare = 1 ;
+    if ( PrivateDeclare      == 1 ) var->v_PrivateDeclare = 1;
+    if ( ExternalDeclare     == 1 ) var->v_ExternalDeclare = 1;
+
+   var->v_dimension = d;
 
    /* Creation of the string for the dimension of this variable               */
-   dimsempty = 1;
-   if ( d )
-   {
-      var->v_dimensiongiven=1;
-      dims = d;
-      while (dims)
-      {
-         if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
-                                                                  dimsempty = 0;
-         sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
-         strcat(listdimension,ligne);
-         if ( dims->suiv )
-         {
-            strcat(listdimension,",");
-         }
-         dims = dims->suiv;
-      }
-/*RB*/
-      if ( dimsempty == 1 || GlobalDeclarationType == 1 ) var->v_dimsempty=1;
-/*RBend*/
-   }
-   strcpy(var->v_readedlistdimension,listdimension);
-   Save_Length(listdimension,15);
-   /*                                                                         */
-   var->v_nbdim=num_dims(d);
-   /*                                                                         */
-   return var;
+    dimsempty = 1;
+    if ( d )
+    {
+        var->v_dimensiongiven = 1;
+        dims = d;
+        while (dims)
+        {
+            if ( strcasecmp(dims->dim.first,"") || strcasecmp(dims->dim.last,""))
+            {
+                dimsempty = 0;
+            }
+            sprintf(ligne,"%s:%s",dims->dim.first,dims->dim.last);
+            strcat(listdimension,ligne);
+            if ( dims->suiv )
+            {
+                strcat(listdimension,",");
+            }
+            dims = dims->suiv;
+        }
+        if ( dimsempty == 1 || GlobalDeclarationType == 1 ) var->v_dimsempty = 1;
+    }
+    strcpy(var->v_readedlistdimension,listdimension);
+    Save_Length(listdimension,15);
+    var->v_nbdim = get_num_dims(d);
+
+    return var;
 }
 
@@ -433,5 +438,5 @@
    listvar *tmpvar ;
 
-   newvar=(listvar *) malloc (sizeof (listvar));
+   newvar=(listvar *) calloc(1,sizeof(listvar));
    newvar->var=v;
    newvar->suiv = NULL;
@@ -466,18 +471,18 @@
 /*                                                                            */
 /******************************************************************************/
-listvar *settype(char *nom,listvar *lin)
+listvar *settype(const char *nom, listvar *lin)
 {
    listvar *newvar;
    variable *v;
 
-   newvar=lin;
+   newvar = lin;
    while (newvar)
    {
-      v=newvar->var;
+      v = newvar->var;
       strcpy(v->v_typevar,nom);
-      Save_Length(nom,3);
-      newvar=newvar->suiv;
-   }
-   newvar=lin;
+      v->v_catvar = get_cat_var(v);
+      newvar = newvar->suiv;
+   }
+   newvar = lin;
    return newvar ;
 }
@@ -511,5 +516,5 @@
    variable *v;
    int out ;
-   
+
    newvar=lin;
    out = 0;
@@ -531,5 +536,5 @@
    listname *tmpvar;
 
-   newvar=(listname *) malloc (sizeof (listname));
+   newvar=(listname *) calloc(1,sizeof(listname));
    strcpy(newvar->n_name,nom);
    newvar->suiv = NULL;
@@ -549,5 +554,5 @@
       }
       tmpvar -> suiv = newvar;
-   }
+      }
       else
       {
@@ -568,22 +573,23 @@
     tmpvar = tmpvar->suiv;
    }
-   
+
    tmpvar->suiv = l2;
-   
+
    return l1;
 }
 
-void *createstringfromlistname(char *ligne, listname *lin)
-{
-listname *tmpvar;
-
-strcpy(ligne,"");
-tmpvar = lin;
-while(tmpvar)
-{
-  strcat(ligne,tmpvar->n_name);
-  if (tmpvar->suiv) strcat(ligne,",");
-  tmpvar=tmpvar->suiv;
-}
+void createstringfromlistname(char *ligne, listname *lin)
+{
+    listname *tmpvar;
+
+    strcpy(ligne,"");
+    tmpvar = lin;
+
+    while(tmpvar)
+    {
+        strcat(ligne,tmpvar->n_name);
+        if (tmpvar->suiv) strcat(ligne,",");
+        tmpvar=tmpvar->suiv;
+    }
 }
 
@@ -607,13 +613,12 @@
 void removeglobfromlist(listname **lin)
 {
-  listname *listemp;
   listname *parcours1;
   listvar *parcours2;
   listname * parcourspres;
   int out;
-  
+
   parcours1 = *lin;
   parcourspres = (listname *)NULL;
-  
+
   while (parcours1)
   {
@@ -644,5 +649,5 @@
    {
    parcourspres = parcours1;
-    parcours1 = parcours1->suiv;  
+    parcours1 = parcours1->suiv;
     }
   }
@@ -651,41 +656,51 @@
 void writelistpublic(listname *lin)
 {
-  listname *parcours1;
-  char ligne[LONG_40M];
-  char tempname[LONG_4M];
-  
-  if (lin)
-  {
-  sprintf(ligne,"public :: ");
-  parcours1 = lin;
-  
-  while (parcours1)
-  {
-    strcat(ligne,parcours1->n_name);
-    if (parcours1->suiv) strcat(ligne,", ");
-    parcours1 = parcours1->suiv;  
-  }
-  tofich(fortranout,ligne,1);
-  }
-
+    listname *parcours1;
+    char ligne[LONG_M];
+
+    if (lin)
+    {
+        sprintf(ligne,"public :: ");
+        parcours1 = lin;
+
+        while ( parcours1 )
+        {
+            strcat(ligne, parcours1->n_name);
+            if ( parcours1->suiv ) strcat(ligne,", ");
+            parcours1 = parcours1->suiv;
+        }
+        tofich(fortran_out,ligne,1);
+    }
 }
 
 void Init_List_Data_Var()
 {
-listvar *parcours;
-
-parcours = List_Data_Var_Cur;
-
-if (List_Data_Var_Cur)
-{
-while (parcours)
-{
- List_Data_Var_Cur = List_Data_Var_Cur->suiv;
- free(parcours);
- parcours = List_Data_Var_Cur;
-}
-}
-
-List_Data_Var_Cur = NULL;
-
-}
+    listvar *parcours;
+
+    parcours = List_Data_Var_Cur;
+
+    if (List_Data_Var_Cur)
+    {
+        while (parcours)
+        {
+            List_Data_Var_Cur = List_Data_Var_Cur->suiv;
+            free(parcours);
+            parcours = List_Data_Var_Cur;
+        }
+    }
+    List_Data_Var_Cur = NULL;
+}
+
+int get_cat_var(variable *var)
+{
+    if (!strcasecmp(var->v_typevar, "CHARACTER"))
+        return 1;
+    else if ((var->v_nbdim == 0 ) && (!strcasecmp(var->v_typevar, "REAL")))
+        return 2;
+    else if (!strcasecmp(var->v_typevar, "LOGICAL"))
+        return 3;
+    else if (!strcasecmp(var->v_typevar, "INTEGER"))
+        return 4;
+    else
+        return 0;
+}
