added README_changes.txt
[wrffire.git] / wrfv2_fire / chem / KPP / util / wkc / registry_kpp.c
blob1ad117b37ee21962275a427d99b4aeb33a2579dd
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <sys/resource.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <strings.h>
9 #define DEFINE_GLOBALS
10 #include "protos.h"
11 #include "protos_kpp.h"
12 #include "registry.h"
13 #include "data.h"
14 #include "sym.h"
16 main( int argc, char *argv[], char *env[] )
18 char fname_in[NAMELEN], dir[NAMELEN], fname_tmp[NAMELEN], command[NAMELEN] ;
19 FILE * fp_in, *fp_tmp ;
20 char * thisprog ;
21 int mypid ;
22 struct rlimit rlim ;
24 mypid = (int) getpid() ;
25 strcpy( thiscom, argv[0] ) ;
26 argv++ ;
28 sw_deref_kludge = 0 ;
29 sw_io_deref_kludge = 0 ;
30 sw_3dvar_iry_kludge = 0 ;
31 sw_distrib_io_layer = 1 ;
32 sw_limit_args = 0 ; /* usually set -- except for GRAPS */
33 sw_dm_parallel = 0 ;
34 sw_all_x_staggered = 0 ;
35 sw_move = 0 ;
36 sw_all_y_staggered = 0 ;
37 sw_ifort_kludge = 0 ;
38 sw_dm_serial_in_only = 0 ; /* input and bdy data set is distributed by node 0,
39 other data streams are written to file per process */
41 strcpy( fname_in , "" ) ;
43 rlim.rlim_cur = RLIM_INFINITY ;
44 rlim.rlim_max = RLIM_INFINITY ;
46 setrlimit ( RLIMIT_STACK , &rlim ) ;
48 sym_forget() ;
49 thisprog = *argv ;
50 while (*argv) {
51 if (*argv[0] == '-') { /* an option */
52 if (!strncmp(*argv,"-D",2)) {
53 char * p ;
54 p = *argv ;
55 sym_add(p+2) ;
58 if (!strcmp(*argv,"-DDEREF_KLUDGE")) {
59 sw_deref_kludge = 1 ;
61 if (!strcmp(*argv,"-DIO_DEREF_KLUDGE")) {
62 sw_io_deref_kludge = 1 ;
64 if (!strcmp(*argv,"-DLIMIT_ARGS")) {
65 sw_limit_args = 1 ;
67 if (!strcmp(*argv,"-DMOVE_NESTS")) {
68 sw_move = 1 ;
70 if (!strcmp(*argv,"-DIFORT_KLUDGE")) {
71 sw_ifort_kludge = 1 ;
73 if (!strcmp(*argv,"-DD3VAR_IRY_KLUDGE")) {
74 #if 0
75 sw_3dvar_iry_kludge = 1 ;
76 #else
77 fprintf(stderr,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ;
78 #endif
80 if (!strcmp(*argv,"-DALL_X_STAGGERED")) {
81 sw_all_x_staggered = 1 ;
83 if (!strcmp(*argv,"-DALL_Y_STAGGERED")) {
84 sw_all_y_staggered = 1 ;
86 if (!strcmp(*argv,"-DDM_PARALLEL")) {
87 sw_dm_parallel = 1 ;
89 if (!strcmp(*argv,"-DDISTRIB_IO_LAYER")) {
90 #if 0
91 sw_distrib_io_layer = 1 ;
92 #else
93 fprintf(stderr,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ;
94 #endif
96 if (!strcmp(*argv,"-DDM_SERIAL_IN_ONLY")) {
97 sw_dm_serial_in_only = 1 ;
99 if (!strncmp(*argv,"-h",2)) {
100 fprintf(stderr,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog) ;
101 exit(1) ;
104 else /* consider it an input file */
106 strcpy( fname_in , *argv ) ;
108 argv++ ;
111 init_parser() ;
112 init_type_table() ;
113 init_dim_table() ;
114 init_core_table() ;
116 if ( !strcmp(fname_in,"") ) fp_in = stdin ;
117 else
118 if (( fp_in = fopen( fname_in , "r" )) == NULL )
120 fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_in ) ;
121 exit(2) ;
124 sprintf( fname_tmp , "Registry_tmp.%d",mypid) ;
125 if (( fp_tmp = fopen( fname_tmp , "w" )) == NULL )
127 fprintf(stderr,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp ) ;
128 exit(2) ;
131 { char *e ;
132 strcpy( dir , fname_in ) ;
133 if ( ( e = rindex ( dir , '/' ) ) != NULL ) { *e = '\0' ; } else { strcpy( dir, "." ) ; }
136 if ( pre_parse( dir, fp_in, fp_tmp ) ) {
137 fprintf(stderr,"Problem with Registry File %s\n", fname_in ) ;
138 goto cleanup ;
140 sym_forget() ;
142 fclose(fp_in) ;
143 fclose(fp_tmp) ;
145 if (( fp_tmp = fopen( fname_tmp , "r" )) == NULL )
147 fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_tmp ) ;
148 goto cleanup ;
151 reg_parse(fp_tmp) ;
153 fclose(fp_tmp) ;
155 check_dimspecs() ;
158 gen_kpp("inc", "chem/KPP/mechanisms");
161 cleanup:
162 sprintf(command,"/bin/rm -f %s\n",fname_tmp );
163 system( command ) ;