wrf svn trunk commit r4103
[wrffire.git] / wrfv2_fire / tools / standard.c
blob1ceecb2ba5ef6e5d65e2eff0965a9bd57874bcce
1 #include <stdio.h>
2 #include <stdlib.h>
4 int drop_comment( char *);
5 int change_to_lower( char *, int );
7 int
8 main( int argc , char *argv[] )
10 FILE *fp ;
11 char linei[2048] ;
12 char lineo[8*2048] ;
13 char wrf_error_fatal_str[256] ;
14 char surface_driver_str[256] ;
15 char radiation_driver_str[256] ;
16 char cumulus_driver_str[256] ;
17 char pbl_driver_str[256] ;
18 char *p, *q, *r ;
19 char firstp ;
20 int state, ns, ns2 ;
21 int inparen ;
22 int inacall ;
23 int col ;
25 if ( argc != 2 ) {
26 fprintf(stderr,"usage: %s file\n",argv[0]) ;
28 if ((fp = fopen(argv[1],"r"))==NULL) {
29 fprintf(stderr,"cannot open %s for reading\n",argv[1]) ;
30 exit(2) ;
32 while ( fgets( linei, 2048, fp ) != NULL ) {
33 lineo[0] = '\0' ;
34 if ( linei[0] != '#' ) drop_comment( linei ) ;
35 inacall = 0 ;
36 for ( p = linei, q = lineo , firstp = *p ; *p ; p++ ) {
37 if ( !inacall && (*(p+0) == 'c' || *(p+0) == 'C' ) &&
38 (*(p+1) == 'a' || *(p+1) == 'A' ) &&
39 (*(p+2) == 'l' || *(p+2) == 'L' ) &&
40 (*(p+3) == 'l' || *(p+3) == 'L' ) && firstp != '#' )
42 inacall = 1 ;
43 strncpy(q,p,4) ; q+=4 ;
44 ns = 1 ; while ( *(p+3+ns) && *(p+3+ns) != '\n' &&
45 (*(p+3+ns) == ' ' ||
46 *(p+3+ns) == '\t' )) { *q++ = *(p+3+ns) ; ns++ ; }
48 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' */
49 strncpy(surface_driver_str, p+3+ns,14) ; change_to_lower(surface_driver_str,14) ;
50 strncpy(radiation_driver_str, p+3+ns,16) ; change_to_lower(radiation_driver_str,16) ;
51 strncpy(cumulus_driver_str, p+3+ns,14) ; change_to_lower(cumulus_driver_str,14) ;
52 strncpy(pbl_driver_str, p+3+ns,10) ; change_to_lower(pbl_driver_str,10) ;
54 if ( !strncmp( wrf_error_fatal_str, "wrf_error_fatal", 15 ) && wrf_error_fatal_str[15] != '3' )
56 ns2 = 1 ; while ( *(p+3+ns+14+ns2) && *(p+3+ns+14+ns2) != '\n' &&
57 (*(p+3+ns+14+ns2) == ' ' ) ) ns2++ ;
58 if ( *(p+3+ns+14+ns2) == '(' ) {
59 *q='\0';
60 printf("%s",lineo) ;
61 printf("wrf_error_fatal3(__FILE__,__LINE__,&\n") ;
62 ns2 = 1 ; while ( *(p+3+ns+14+ns2) && *(p+3+ns+14+ns2) != '\n' &&
63 (*(p+3+ns+14+ns2) == ' ' ||
64 *(p+3+ns+14+ns2) == '(' ||
65 *(p+3+ns+14+ns2) == '\t' ||
66 *(p+3+ns+14+ns2) == '&' )) ns2++ ;
67 if( *(p+3+ns+14+ns2) != '\n') printf("%s",(p+3+ns+14+ns2)) ;
68 goto next_line ;
69 } else {
70 printf("%s",linei) ;
71 goto next_line ;
73 } else if ( !strncmp ( surface_driver_str, "surface_driver", 14 ) ||
74 !strncmp ( radiation_driver_str, "radiation_driver", 16) ||
75 !strncmp ( cumulus_driver_str, "cumulus_driver", 14) ||
76 !strncmp ( pbl_driver_str, "pbl_driver", 10)
77 ) {
78 strcpy(lineo,p+3+ns) ;
79 inparen = 1 ;
80 while ( fgets( linei, 2048, fp ) != NULL ) {
81 for ( q = linei ; *q ; q++ ) {
82 if (*q=='!') { *q = '\n' ; *(q+1) = '\0' ; break ; }
84 for ( q = linei ; *q ; q++ ) {
85 if ( *q == '(' ) inparen++ ;
86 else if ( *q == ')' ) inparen-- ;
88 strcat(lineo,linei) ;
89 if ( inparen == 0 ) {
90 break ;
93 for(q=lineo,r=lineo;*q;q++) {
94 if (*q == '#' && *(q-1) == '\n') { /* CPP def. copy as is*/
95 *r++ = '&' ;
96 *r++ = '\n' ;
97 for (; *q; q++) {
98 *r++ = *q;
99 if ( *q == '\n' ) break ;
102 if ( *q == ' ' || *q == '\n' || *q == '&' ) continue ;
103 *r++ = *q ;
105 *r = '\0' ;
106 printf("CALL ") ;
107 for(q=lineo,col=130-5;*q;q++) {
108 putchar(*q) ;
109 if ( *q == '\n' ) { if (*(q+1) != '#') { putchar('&') ; } ; col = 131 ; }
110 col-- ;
111 if ( col <= 0 ) {
112 col = 130 ;
113 if (*q!=')' || *(q+1) ) { putchar('&') ; putchar('\n') ; putchar('&') ; }
116 putchar('\n') ;
117 goto next_line ;
118 } else {
119 p += 3+ns ;
120 *q++ = *p ;
122 } else {
123 *q++ = *p ;
126 *q='\0';
127 printf("%s",lineo) ;
128 next_line:
129 state = 0 ;
131 fclose(fp) ;
132 exit(0) ;
136 drop_comment( char * linei )
138 char *p, *q ;
139 char inquote = '\0' ;
141 for ( p = linei ; *p ; p++ )
143 if ( *p == '\'' ) { if ( inquote == *p ) { inquote = '\0' ; } else { inquote = *p ; } }
144 if ( *p == '"' ) { if ( inquote == *p ) { inquote = '\0' ; } else { inquote = *p ; } }
145 if ( !inquote && *p == '!' ) {
146 /* let us make sure this is not an OMP directive shall we? */
147 for ( q = p ; *q ; q++ ) {
148 if ((*q == '$') &&
149 (*(q+1) == 'o' || *(q+1) == 'O') &&
150 (*(q+2) == 'm' || *(q+2) == 'M') &&
151 (*(q+3) == 'p' || *(q+3) == 'P') ) return(0) ;
152 /* nor an intel compiler directive, what? */
153 if ((*(q+3) == '$') &&
154 (*(q) == 'd' || *(q) == 'D') &&
155 (*(q+1) == 'e' || *(q+1) == 'E') &&
156 (*(q+2) == 'c' || *(q+2) == 'C') ) return(0) ;
158 *p = '\n' ; *(p+1) = '\0' ; return(0) ;
163 int
164 change_to_lower( char * s , int n )
166 int i ;
167 for ( i = 0 ; i < n ; i++ )
169 if ( s[i] >= 'A' && s[i] <= 'Z' ) s[i] = s[i] - 'A' + 'a' ;