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 6020 for branches/UKMO/icebergs_restart_single_file/NEMOGCM/EXTERNAL/AGRIF/LIB/WriteInFile.c – NEMO

Ignore:
Timestamp:
2015-12-08T12:39:53+01:00 (8 years ago)
Author:
timgraham
Message:

Merged with head of trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/UKMO/icebergs_restart_single_file/NEMOGCM/EXTERNAL/AGRIF/LIB/WriteInFile.c

    r6019 r6020  
    4343/* This subroutine is used to write the string s into the fileout             */ 
    4444/******************************************************************************/ 
    45 void tofich_reste (FILE * filout, char *s,int returnlineornot) 
     45void tofich_reste (FILE * filout, const char *s, int do_returnline) 
    4646{ 
    47   char temp[61]; 
    48   char *tmp; 
    49   int size; 
    50   int val_min; 
     47    const size_t line_length = 66; 
     48    char temp[line_length+1]; 
     49    size_t s_length; 
    5150 
    52   if (strlen (s) <= 60) 
     51    s_length = strlen(s); 
     52 
     53    if ( !strcmp(&s[strlen(s)-1], "\n") ) 
     54        s_length = strlen(s)-1; 
     55 
     56    if ( s_length <= line_length ) 
    5357    { 
    54       if ( returnlineornot == 0 ) fprintf (filout, "     &%s", s); 
    55       else if ( returnlineornot == 2 ) fprintf (filout, "&%s", s); 
    56       else if ( returnlineornot == 3 ) fprintf (filout, "&%s\n", s); 
    57       else                             fprintf (filout, "     &%s\n", s); 
    58       if ( returnlineornot == 0 || 
    59            returnlineornot == 2 ) colnum=colnum+strlen(s)+6; 
    60       else colnum=0; 
     58        if ( do_returnline ) fprintf(filout, "     &%s\n", s); 
     59        else                 fprintf(filout, "&%s", s); 
    6160    } 
    62   else 
     61    else 
    6362    { 
    64       val_min = 60; 
    65       strncpy (temp, s, 60); 
    66       strcpy (&temp[60], "\0"); 
     63        strncpy(temp, s, line_length); 
     64        temp[line_length] = '\0'; 
     65        if ( retour77 == 0 && (s_length-strlen(temp) > 0) ) 
     66                fprintf(filout, "     &%s&\n", temp); 
     67        else    fprintf(filout, "     &%s\n", temp); 
    6768 
    68       tmp = strrchr(temp, '+'); 
    69       if ( tmp ) 
    70       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    71       tmp = strrchr(temp, '-'); 
    72       if ( tmp ) 
    73       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    74       tmp = strrchr(temp, '/'); 
    75       if ( tmp ) 
    76       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    77       tmp = strrchr(temp, '*'); 
    78       if ( tmp ) 
    79       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    80       tmp = strrchr(temp, '%'); 
    81       if ( tmp ) 
    82       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    83       tmp = strrchr(temp, ','); 
    84       if ( tmp ) 
    85       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    86       tmp = strrchr(temp, ')'); 
    87       if ( tmp ) 
    88       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    89       tmp = strrchr(temp, '('); 
    90       if ( tmp ) 
    91       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    92  
    93       size = val_min; 
    94  
    95       strcpy (&temp[60-size], "\0"); 
    96  
    97       if ( retour77 == 0 ) fprintf (filout, "     &%s&\n", temp); 
    98       else fprintf (filout, "     &%s\n", temp); 
    99       colnum=0; 
    100       tofich_reste (filout, (char *) &s[60-size],returnlineornot); 
     69        if ( s_length-strlen(temp) > 0 ) 
     70            tofich_reste(filout, (char *) &s[line_length], do_returnline); 
    10171    } 
    10272} 
     
    10777/* This subroutine is used to write the string s into the fileout             */ 
    10878/******************************************************************************/ 
    109 void tofich (FILE * filout, char *s, int returnlineornot) 
     79void tofich (FILE * filout, const char *s, int do_returnline) 
    11080{ 
    111   char temp[61]; 
    112   char *tmp; 
    113   int size; 
    114   int val_min; 
     81    const size_t line_length = 66; 
     82    char temp[line_length+1]; 
     83    size_t s_length; 
    11584 
    116   if (strlen (s) <= 60) 
     85    s_length = strlen(s); 
     86 
     87    if ( !strcmp(&s[strlen(s)-1], "\n") ) 
     88        s_length = strlen(s)-1; 
     89 
     90    if ( s_length <= line_length ) 
    11791    { 
    118       if ( returnlineornot == 0 ) fprintf (filout, "      %s", s); 
    119       else if ( returnlineornot == 2 ) fprintf (filout, "%s", s); 
    120       else if ( returnlineornot == 3 ) fprintf (filout, "%s\n", s); 
    121       else                             fprintf (filout, "      %s\n", s); 
    122       if ( returnlineornot == 0 || returnlineornot == 2 ) 
    123                                                       colnum=colnum+strlen(s)+6; 
    124       else colnum=0; 
     92        if ( do_returnline ) fprintf(filout, "      %s\n", s); 
     93        else                 fprintf(filout, "%s", s); 
    12594    } 
    126   else 
     95    else 
    12796    { 
    128       val_min = 60; 
    129       strncpy (temp, s, 60); 
    130       strcpy (&temp[60], "\0"); 
     97        strncpy(temp, s, line_length); 
     98        temp[line_length] = '\0'; 
    13199 
    132       tmp = strrchr(temp, '+'); 
    133       if ( tmp ) 
    134       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    135       tmp = strrchr(temp, '-'); 
    136       if ( tmp ) 
    137       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    138       tmp = strrchr(temp, '/'); 
    139       if ( tmp ) 
    140       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    141       tmp = strrchr(temp, '*'); 
    142       if ( tmp ) 
    143       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    144       tmp = strrchr(temp, '%'); 
    145       if ( tmp ) 
    146       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    147       tmp = strrchr(temp, ','); 
    148       if ( tmp ) 
    149       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    150       tmp = strrchr(temp, ')'); 
    151       if ( tmp ) 
    152       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
    153       tmp = strrchr(temp, '('); 
    154       if ( tmp ) 
    155       if ( strlen(tmp) < val_min ) val_min = strlen(tmp); 
     100        if ( retour77 == 0 )    fprintf(filout, "      %s&\n", temp); 
     101        else                    fprintf(filout, "      %s\n", temp); 
    156102 
    157       size = val_min; 
    158  
    159       strcpy (&temp[60-size], "\0"); 
    160  
    161       if ( retour77 == 0 ) fprintf (filout, "      %s&\n", temp); 
    162       else fprintf (filout, "      %s\n", temp); 
    163       colnum=0; 
    164       tofich_reste (filout, (char *) &s[60-size], returnlineornot); 
     103        tofich_reste(filout, (char *) &s[line_length], do_returnline); 
    165104    } 
    166105} 
     
    173112void tofich_blanc (FILE * filout, int size) 
    174113{ 
    175   int i; 
     114    const char* empty_char = " "; 
     115    int i = 0; 
    176116 
    177   if (size <= 65) fprintf (filout, "%*s\n",size,EmptyChar); 
    178   else 
    179   { 
    180       i=0; 
    181       do 
    182       { 
    183          fprintf (filout, "%*s\n",65,EmptyChar); 
    184          i = i+1; 
    185       } while ( i <= size / 65 ); 
    186          fprintf (filout, "%*s\n",size%65,EmptyChar); 
    187   } 
     117    if (size <= 65) 
     118        fprintf(filout, "%*s\n", size, empty_char); 
     119    else 
     120    { 
     121        do 
     122        { 
     123            fprintf(filout, "%*s\n", 65, empty_char); 
     124            i++; 
     125        } 
     126        while ( i <= size / 65 ); 
    188127 
     128        fprintf(filout, "%*s\n", size%65, empty_char); 
     129    } 
    189130} 
    190 /******************************************************************************/ 
    191 /*                       tofich_line                                          */ 
    192 /******************************************************************************/ 
    193 /* This subroutine is used to write size blank into the fileout               */ 
    194 /******************************************************************************/ 
    195 void tofich_line (FILE * filout, int size, int long position) 
    196 { 
    197   int i; 
    198   int retour; 
    199  
    200   if (size <= 65) fprintf (filout, "%*s",size,EmptyChar); 
    201   else 
    202   { 
    203       i=0; 
    204       do 
    205       { 
    206          fprintf (filout, "%*s",65,EmptyChar); 
    207          i = i+1; 
    208       } while ( i <= size / 65 ); 
    209          fprintf (filout, "%*s",size%65,EmptyChar); 
    210   } 
    211  
    212    if ( !strstr(motparse1,"\n") ) retour=0; 
    213    else retour=1; 
    214  
    215    fseek(filout,position,SEEK_SET); 
    216    if (retour == 1 ) fprintf (filout, "\n"); 
    217  
    218 } 
    219  
    220131 
    221132/******************************************************************************/ 
     
    224135/* This subroutine is used to remove a sentence in the file filout            */ 
    225136/******************************************************************************/ 
    226 void RemoveWordSET_0(FILE * filout, long int position, long int sizetoremove) 
     137void RemoveWordSET_0(FILE * filout, long int position, int sizetoremove) 
    227138{ 
    228    if ( firstpass == 0 && couldaddvariable == 1 ) 
    229    { 
    230       fseek(filout,position,SEEK_SET); 
    231       tofich_line(filout,sizetoremove,position); 
     139    if ( inside_type_declare || firstpass ) return; 
    232140 
    233    } 
     141    fseek(filout, position, SEEK_SET); 
     142    tofich_blanc(filout, sizetoremove); 
     143    fseek(filout, position, SEEK_SET); 
    234144} 
    235  
    236145 
    237146/******************************************************************************/ 
     
    240149/* This subroutine is used to remove a sentence in the file filout            */ 
    241150/******************************************************************************/ 
    242 void RemoveWordCUR_0(FILE * filout, long int position, long int sizetoremove) 
     151void RemoveWordCUR_0(FILE * filout, int sizetoremove) 
    243152{ 
    244    if ( firstpass == 0  && couldaddvariable == 1 ) 
    245    { 
    246       fseek(filout,position,SEEK_CUR); 
    247       tofich_blanc(filout,sizetoremove); 
     153    if ( inside_type_declare || firstpass ) return; 
    248154 
    249    } 
     155    fseek(filout, (long int)(-sizetoremove), SEEK_CUR); 
     156    tofich_blanc(filout, sizetoremove); 
     157    fseek(filout, (long int)(-sizetoremove), SEEK_CUR); 
     158    if ( strstr(fortran_text, "\n") )   fprintf(filout, "\n"); 
    250159} 
Note: See TracChangeset for help on using the changeset viewer.