#include #include #include #include #include #include #include void strip_blanks( char *instring, char *outstring ) { int i, j, slen; char *c; slen = strlen( instring ); strcpy( outstring,instring ); c = instring; for( i=0,j=0; i < slen; i++ ) { if( strncmp( c, " ", 1 ) ) strncpy( (outstring+(j++)), c, 1 ); c++; } c = index( outstring,'\n' ); *c = '\0'; } int main( int argc, char *argv[] ) { int Nrxt; int i,j; int slen; char *stradj = "abcdef"; char *strt, *end; char *token; char *wstrg1; char path[256]; char fname[256]; char inln[1024],winln[1024],s[1024]; char rxtstr[128]; char rxtstr_tbl[1000][128]; char buffer[128]; char rxtsym[128]; FILE *fp_eqn, *fp_reg; argv++; strcpy( fname,argv[0] ); slen = sprintf( path, "/terminator-data1/stacy/T1_DEV/WRF/chem/KPP/mechanisms/%s/%s.eqn",fname,fname ); fprintf(stderr,"Using file:\n"); fprintf(stderr,"%s\n", path); // // open input *eqn file // if( (fp_eqn = fopen( path, "r" )) == NULL ) { fprintf(stderr,"Can not open %s for reading\n", path); exit(2); } fprintf(stderr,"\n"); // // open output registry file // if( (fp_reg = fopen( "./registry.irr_diag", "w" )) == NULL ) { fprintf(stderr,"Can not open registry.irr_diag for writing\n"); exit(2); } strcpy( buffer,"\"Integrated Reaction Rate\" \"\""); fprintf(fp_reg,"state real - ikjf irr_diag_%s - - - - %s\n",fname,buffer); Nrxt = 0; // // loop over input lines // while( fgets( inln, 1024, fp_eqn ) != NULL ) { if( strncmp( inln, "//", 2 ) && strncmp( inln, "#", 1 ) ) { // // strip blanks from reaction string // strip_blanks( inln, inln ); // // concatentate lines? // if( rindex( inln,';' ) == NULL ) { do { fgets( winln, 1024, fp_eqn ); strip_blanks( winln, winln ); strcat( inln,winln ); } while( rindex( inln,';' ) == NULL ); } strt = strchr( inln,'{' ); while( strt != NULL ) { end = strchr( strt,'}' ); slen = 0; if( end != NULL ) slen = end - strt; if( slen > 0 ) { for( i = 0; i < slen; i++ ) if( !strncmp( strt+i,"=",1 ) ) *(strt+i) = '$'; } strt += slen; strt = strchr( strt,'{' ); } strt = strchr( inln, '}' ); if( strt == NULL ) continue; strt++; end = rindex( strt, '=' ); if( end != NULL ) { *end= '\0'; slen = strlen( strt ); wstrg1 = strt; // // string to upper case // slen = strlen( wstrg1 ); for( i=0; i <= slen; i++ ) wstrg1[i] = toupper( wstrg1[i] ); // // remove all text between {} pair including delimiters // strt = strchr( wstrg1,'{' ); if( strt != NULL ) { end = index( wstrg1,'}' ); if( end != NULL ) { char c[128]; *strt = '\0'; strcpy( c,wstrg1 ); end++; strcat( c,end ); strcpy( wstrg1,c ); } } strcpy( rxtstr_tbl[Nrxt],wstrg1 ); // // check for unique reaction string // if( Nrxt > 0 ) { int Nmatch = 0; for( i = 0; i < Nrxt; i++) if( !strcmp( wstrg1,rxtstr_tbl[i] ) ) Nmatch++; if( Nmatch > 0 ) { Nmatch--; strcat( wstrg1,"_" ); strncat( wstrg1,stradj+Nmatch,1 ); } } strcpy( rxtstr,wstrg1 ); strcpy( rxtsym,wstrg1 ); // // change + to _ // for( i=0; i < slen; i++ ) { if( ! strncmp( rxtsym+i, "+", 1 ) ) strncpy( rxtsym+i, "_", 1 ); } strcat( rxtsym,"_IRR" ); // // form output line // fprintf(fp_reg,"state real %s ikjf irr_diag_%s 1 - rh9 \"%s\" \"%s Integrated Reaction Rate\" \"molecules/cm^3/s\"\n",rxtsym,fname,rxtstr,rxtstr); Nrxt++; } } } fclose(fp_eqn); fclose(fp_reg); exit(0); }