7 int drop_comment( char *);
8 int change_to_lower( char *, int );
11 main( int argc
, char *argv
[] )
15 char lineo
[8*LINELEN
] ;
16 char wrf_error_fatal_str
[STRINGLEN
] ;
17 char surface_driver_str
[STRINGLEN
] ;
18 char radiation_driver_str
[STRINGLEN
] ;
19 char cumulus_driver_str
[STRINGLEN
] ;
20 char pbl_driver_str
[STRINGLEN
] ;
29 fprintf(stderr
,"usage: %s file\n",argv
[0]) ;
31 if ((fp
= fopen(argv
[1],"r"))==NULL
) {
32 fprintf(stderr
,"cannot open %s for reading\n",argv
[1]) ;
35 while ( fgets( linei
, LINELEN
, fp
) != NULL
) {
37 if ( linei
[0] != '#' ) drop_comment( linei
) ;
39 for ( p
= linei
, q
= lineo
, firstp
= *p
; *p
; p
++ ) {
40 if ( !inacall
&& (*(p
+0) == 'c' || *(p
+0) == 'C' ) &&
41 (*(p
+1) == 'a' || *(p
+1) == 'A' ) &&
42 (*(p
+2) == 'l' || *(p
+2) == 'L' ) &&
43 (*(p
+3) == 'l' || *(p
+3) == 'L' ) && firstp
!= '#' )
46 strncpy(q
,p
,4) ; q
+=4 ;
47 ns
= 1 ; while ( *(p
+3+ns
) && *(p
+3+ns
) != '\n' &&
49 *(p
+3+ns
) == '\t' )) { *q
++ = *(p
+3+ns
) ; ns
++ ; }
51 strncpy(wrf_error_fatal_str
, p
+3+ns
,15+1) ; change_to_lower(wrf_error_fatal_str
,15+1 ) ; /* 15, but add one to check for '3' */
52 strncpy(surface_driver_str
, p
+3+ns
,14) ; change_to_lower(surface_driver_str
,14) ;
53 strncpy(radiation_driver_str
, p
+3+ns
,16) ; change_to_lower(radiation_driver_str
,16) ;
54 strncpy(cumulus_driver_str
, p
+3+ns
,14) ; change_to_lower(cumulus_driver_str
,14) ;
55 strncpy(pbl_driver_str
, p
+3+ns
,10) ; change_to_lower(pbl_driver_str
,10) ;
57 if ( !strncmp( wrf_error_fatal_str
, "wrf_error_fatal", 15 ) && wrf_error_fatal_str
[15] != '3' )
59 ns2
= 1 ; while ( *(p
+3+ns
+14+ns2
) && *(p
+3+ns
+14+ns2
) != '\n' &&
60 (*(p
+3+ns
+14+ns2
) == ' ' ) ) ns2
++ ;
61 if ( *(p
+3+ns
+14+ns2
) == '(' ) {
64 printf("wrf_error_fatal3(__FILE__,__LINE__,&\n") ;
65 ns2
= 1 ; while ( *(p
+3+ns
+14+ns2
) && *(p
+3+ns
+14+ns2
) != '\n' &&
66 (*(p
+3+ns
+14+ns2
) == ' ' ||
67 *(p
+3+ns
+14+ns2
) == '(' ||
68 *(p
+3+ns
+14+ns2
) == '\t' ||
69 *(p
+3+ns
+14+ns2
) == '&' )) ns2
++ ;
70 if( *(p
+3+ns
+14+ns2
) != '\n') printf("%s",(p
+3+ns
+14+ns2
)) ;
76 } else if ( !strncmp ( surface_driver_str
, "surface_driver", 14 ) ||
77 !strncmp ( radiation_driver_str
, "radiation_driver", 16) ||
78 !strncmp ( cumulus_driver_str
, "cumulus_driver", 14) ||
79 !strncmp ( pbl_driver_str
, "pbl_driver", 10)
81 strcpy(lineo
,p
+3+ns
) ;
83 while ( fgets( linei
, LINELEN
, fp
) != NULL
) {
84 for ( q
= linei
; *q
; q
++ ) {
85 if (*q
=='!') { *q
= '\n' ; *(q
+1) = '\0' ; break ; }
87 for ( q
= linei
; *q
; q
++ ) {
88 if ( *q
== '(' ) inparen
++ ;
89 else if ( *q
== ')' ) inparen
-- ;
96 for(q
=lineo
,r
=lineo
;*q
;q
++) {
97 if (*q
== '#' && *(q
-1) == '\n') { /* CPP def. copy as is*/
102 if ( *q
== '\n' ) break ;
105 if ( *q
== ' ' || *q
== '\n' || *q
== '&' ) continue ;
110 for(q
=lineo
,col
=130-5;*q
;q
++) {
112 if ( *q
== '\n' ) { if (*(q
+1) != '#') { putchar('&') ; } ; col
= 131 ; }
116 if (*q
!=')' || *(q
+1) ) { putchar('&') ; putchar('\n') ; putchar('&') ; }
139 drop_comment( char * linei
)
142 char inquote
= '\0' ;
144 for ( p
= linei
; *p
; p
++ )
146 if ( *p
== '\'' ) { if ( inquote
== *p
) { inquote
= '\0' ; } else { inquote
= *p
; } }
147 if ( *p
== '"' ) { if ( inquote
== *p
) { inquote
= '\0' ; } else { inquote
= *p
; } }
148 if ( !inquote
&& *p
== '!' ) {
149 /* let us make sure this is not an OMP directive shall we? */
150 for ( q
= p
; *q
; q
++ ) {
152 (*(q
+1) == 'o' || *(q
+1) == 'O') &&
153 (*(q
+2) == 'm' || *(q
+2) == 'M') &&
154 (*(q
+3) == 'p' || *(q
+3) == 'P') ) return(0) ;
155 /* nor an intel compiler directive, what? */
156 if ((*(q
+3) == '$') &&
157 (*(q
) == 'd' || *(q
) == 'D') &&
158 (*(q
+1) == 'e' || *(q
+1) == 'E') &&
159 (*(q
+2) == 'c' || *(q
+2) == 'C') ) return(0) ;
160 /* nor an intel compiler directive, just so. quite. */
161 if ((*(q
+3) == '$') &&
162 (*(q
) == 'd' || *(q
) == 'D') &&
163 (*(q
+1) == 'i' || *(q
+1) == 'I') &&
164 (*(q
+2) == 'r' || *(q
+2) == 'R') ) return(0) ;
165 /* nor a pgi accelerator directive */
167 (*(q
+1) == 'a' || *(q
+1) == 'A') &&
168 (*(q
+2) == 'c' || *(q
+2) == 'C') &&
169 (*(q
+3) == 'c' || *(q
+3) == 'C') ) return(0) ;
170 /* nor a fujitsu compiler directive */
171 if ((*(q
+1) == 'o' || *(q
+1) == 'O') &&
172 (*(q
+2) == 'c' || *(q
+2) == 'C') &&
173 (*(q
+3) == 'l' || *(q
+3) == 'L') ) return(0) ;
175 *p
= '\n' ; *(p
+1) = '\0' ; return(0) ;
178 return 0; /* SamT: bug fix: return a value */
182 change_to_lower( char * s
, int n
)
185 for ( i
= 0 ; i
< n
; i
++ )
187 if ( s
[i
] >= 'A' && s
[i
] <= 'Z' ) s
[i
] = s
[i
] - 'A' + 'a' ;
189 return 0; /* SamT: bug fix: return a value */