New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 2715 for trunk/NEMOGCM/EXTERNAL/AGRIF/LIB/WorkWithlistdatavariable.c – NEMO

Ignore:
Timestamp:
2011-03-30T17:58:35+02:00 (13 years ago)
Author:
rblod
Message:

First attempt to put dynamic allocation on the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEMOGCM/EXTERNAL/AGRIF/LIB/WorkWithlistdatavariable.c

    r2528 r2715  
    4848/*                                                                            */ 
    4949/******************************************************************************/ 
    50 void Add_Data_Var_1 (char *name,char *values) 
     50void Add_Data_Var_1 (listvar **curlist,char *name,char *values) 
    5151{ 
    5252  listvar *newvar; 
     53  char ligne[LONG_C]; 
    5354 
    54   if ( firstpass == 1 ) 
    55   { 
     55//  if ( firstpass == 1 ) 
     56//  { 
    5657     newvar=(listvar *)malloc(sizeof(listvar)); 
    5758     newvar->var=(variable *)malloc(sizeof(variable)); 
     
    6869     strcpy(newvar->var->v_commoninfile,mainfile); 
    6970     Save_Length(mainfile,10); 
    70      strcpy(newvar->var->v_initialvalue,values); 
    71      Save_Length(values,14); 
     71     if (strchr(values,',') && strncasecmp(values,"'",1)) 
     72            { 
     73            sprintf(ligne,"(/%s/)",values); 
     74            } 
     75     else 
     76       strcpy(ligne,values); 
     77        
     78     strcpy(newvar->var->v_initialvalue,ligne); 
     79     Save_Length(ligne,14); 
    7280     newvar->suiv = NULL; 
    73  
    74      if ( !List_Data_Var ) 
     81     if ( ! (*curlist) ) 
    7582     { 
    76         List_Data_Var  = newvar ; 
     83        *curlist  = newvar ; 
    7784     } 
    7885     else 
    7986     { 
    80         newvar->suiv = List_Data_Var; 
    81         List_Data_Var = newvar; 
     87        newvar->suiv = *curlist; 
     88        *curlist = newvar; 
    8289     } 
     90//  } 
     91} 
     92 
     93void Add_Data_Var_Names_01 (listvar **curlist,listname *l1,listname *l2) 
     94{ 
     95  listvar *newvar; 
     96  listvar *tmpvar; 
     97  listname *tmpvar1; 
     98  listname *tmpvar2;   
     99  char ligne[LONG_C]; 
     100   
     101  tmpvar1 = l1; 
     102  tmpvar2 = l2; 
     103   
     104  while (tmpvar1) 
     105     { 
     106     newvar=(listvar *)malloc(sizeof(listvar)); 
     107     newvar->var=(variable *)malloc(sizeof(variable)); 
     108     /*                                                                       */ 
     109     Init_Variable(newvar->var); 
     110     /*                                                                       */ 
     111     if ( inmoduledeclare == 1 ) newvar->var->v_module=1; 
     112     strcpy(newvar->var->v_nomvar,tmpvar1->n_name); 
     113     Save_Length(tmpvar1->n_name,4); 
     114     strcpy(newvar->var->v_subroutinename,subroutinename); 
     115     Save_Length(subroutinename,11); 
     116     strcpy(newvar->var->v_modulename,curmodulename); 
     117     Save_Length(curmodulename,6); 
     118     strcpy(newvar->var->v_commoninfile,mainfile); 
     119     Save_Length(mainfile,10); 
     120        
     121     strcpy(newvar->var->v_initialvalue,tmpvar2->n_name); 
     122     Save_Length(tmpvar2->n_name,14); 
     123     newvar->suiv = NULL; 
     124      
     125     if ( ! (*curlist) ) 
     126     { 
     127        *curlist  = newvar ; 
     128     } 
     129     else 
     130     { 
     131        tmpvar = *curlist; 
     132        while (tmpvar->suiv) 
     133          tmpvar=tmpvar->suiv; 
     134        tmpvar->suiv = newvar; 
     135     } 
     136      
     137  tmpvar1 = tmpvar1->suiv; 
     138  tmpvar2 = tmpvar2->suiv;   
    83139  } 
     140  return; 
     141 
     142 
    84143} 
Note: See TracChangeset for help on using the changeset viewer.