Changeset 6225 for branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/EXTERNAL/AGRIF/LIB/WriteInFile.c
- Timestamp:
- 2016-01-08T10:35:19+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2014/dev_r4704_NOC5_MPP_BDY_UPDATE/NEMOGCM/EXTERNAL/AGRIF/LIB/WriteInFile.c
r2715 r6225 43 43 /* This subroutine is used to write the string s into the fileout */ 44 44 /******************************************************************************/ 45 void tofich_reste (FILE * filout, c har *s,int returnlineornot)45 void tofich_reste (FILE * filout, const char *s, int do_returnline) 46 46 { 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; 51 50 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 ) 53 57 { 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); 61 60 } 62 else61 else 63 62 { 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); 67 68 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); 101 71 } 102 72 } … … 107 77 /* This subroutine is used to write the string s into the fileout */ 108 78 /******************************************************************************/ 109 void tofich (FILE * filout, c har *s, int returnlineornot)79 void tofich (FILE * filout, const char *s, int do_returnline) 110 80 { 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; 115 84 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 ) 117 91 { 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); 125 94 } 126 else95 else 127 96 { 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'; 131 99 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); 156 102 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); 165 104 } 166 105 } … … 173 112 void tofich_blanc (FILE * filout, int size) 174 113 { 175 int i; 114 const char* empty_char = " "; 115 int i = 0; 176 116 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 ); 188 127 128 fprintf(filout, "%*s\n", size%65, empty_char); 129 } 189 130 } 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 else202 {203 i=0;204 do205 {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 220 131 221 132 /******************************************************************************/ … … 224 135 /* This subroutine is used to remove a sentence in the file filout */ 225 136 /******************************************************************************/ 226 void RemoveWordSET_0(FILE * filout, long int position, longint sizetoremove)137 void RemoveWordSET_0(FILE * filout, long int position, int sizetoremove) 227 138 { 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; 232 140 233 } 141 fseek(filout, position, SEEK_SET); 142 tofich_blanc(filout, sizetoremove); 143 fseek(filout, position, SEEK_SET); 234 144 } 235 236 145 237 146 /******************************************************************************/ … … 240 149 /* This subroutine is used to remove a sentence in the file filout */ 241 150 /******************************************************************************/ 242 void RemoveWordCUR_0(FILE * filout, long int position, longint sizetoremove)151 void RemoveWordCUR_0(FILE * filout, int sizetoremove) 243 152 { 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; 248 154 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"); 250 159 }
Note: See TracChangeset
for help on using the changeset viewer.