1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #ifdef _WIN32 |
---|
4 | # include <io.h> |
---|
5 | # define rindex(X,Y) strrchr(X,Y) |
---|
6 | # define index(X,Y) strchr(X,Y) |
---|
7 | #else |
---|
8 | # include <sys/time.h> |
---|
9 | # include <sys/resource.h> |
---|
10 | # include <unistd.h> |
---|
11 | # include <string.h> |
---|
12 | # include <strings.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | #define DEFINE_GLOBALS |
---|
16 | #include "protos.h" |
---|
17 | #include "registry.h" |
---|
18 | #include "data.h" |
---|
19 | #include "sym.h" |
---|
20 | |
---|
21 | void |
---|
22 | main( int argc, char *argv[], char *env[] ) |
---|
23 | { |
---|
24 | char fname_in[NAMELEN], dir[NAMELEN], fname_tmp[NAMELEN], command[NAMELEN] ; |
---|
25 | FILE * fp_in, *fp_tmp ; |
---|
26 | char * thisprog ; |
---|
27 | int mypid ; |
---|
28 | #ifndef _WIN32 |
---|
29 | struct rlimit rlim ; |
---|
30 | #endif |
---|
31 | |
---|
32 | mypid = (int) getpid() ; |
---|
33 | strcpy( thiscom, argv[0] ) ; |
---|
34 | argv++ ; |
---|
35 | |
---|
36 | sw_deref_kludge = 0 ; |
---|
37 | sw_io_deref_kludge = 0 ; |
---|
38 | sw_3dvar_iry_kludge = 0 ; |
---|
39 | sw_distrib_io_layer = 1 ; |
---|
40 | sw_limit_args = 0 ; /* usually set -- except for GRAPS */ |
---|
41 | sw_dm_parallel = 0 ; |
---|
42 | sw_all_x_staggered = 0 ; |
---|
43 | sw_move = 0 ; |
---|
44 | sw_all_y_staggered = 0 ; |
---|
45 | sw_fort_kludge = 1 ; /* unconditionally true for v3 */ |
---|
46 | sw_dm_serial_in_only = 0 ; /* input and bdy data set is distributed by node 0, |
---|
47 | other data streams are written to file per process */ |
---|
48 | sw_new_bdys = 0 ; |
---|
49 | sw_unidir_shift_halo = 0 ; |
---|
50 | |
---|
51 | strcpy( fname_in , "" ) ; |
---|
52 | |
---|
53 | #ifndef _WIN32 |
---|
54 | rlim.rlim_cur = RLIM_INFINITY ; |
---|
55 | rlim.rlim_max = RLIM_INFINITY ; |
---|
56 | setrlimit ( RLIMIT_STACK , &rlim ) ; |
---|
57 | #endif |
---|
58 | |
---|
59 | sym_forget() ; |
---|
60 | thisprog = *argv ; |
---|
61 | while (*argv) { |
---|
62 | if (*argv[0] == '-') { /* an option */ |
---|
63 | if (!strncmp(*argv,"-D",2)) { |
---|
64 | char * p ; |
---|
65 | p = *argv ; |
---|
66 | sym_add(p+2) ; |
---|
67 | } |
---|
68 | |
---|
69 | if (!strcmp(*argv,"-DDEREF_KLUDGE")) { |
---|
70 | sw_deref_kludge = 1 ; |
---|
71 | } |
---|
72 | if (!strcmp(*argv,"-DIO_DEREF_KLUDGE")) { |
---|
73 | sw_io_deref_kludge = 1 ; |
---|
74 | } |
---|
75 | if (!strcmp(*argv,"-DLIMIT_ARGS")) { |
---|
76 | sw_limit_args = 1 ; |
---|
77 | } |
---|
78 | if (!strcmp(*argv,"-DMOVE_NESTS")) { |
---|
79 | sw_move = 1 ; |
---|
80 | } |
---|
81 | if (!strcmp(*argv,"-DMOVE_NL_OUTSIDE_MODULE_CONFIGURE")) { |
---|
82 | sw_fort_kludge = 1 ; |
---|
83 | } |
---|
84 | if (!strcmp(*argv,"-DD3VAR_IRY_KLUDGE")) { |
---|
85 | #if 0 |
---|
86 | sw_3dvar_iry_kludge = 1 ; |
---|
87 | #else |
---|
88 | fprintf(stderr,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ; |
---|
89 | #endif |
---|
90 | } |
---|
91 | if (!strcmp(*argv,"-DALL_X_STAGGERED")) { |
---|
92 | sw_all_x_staggered = 1 ; |
---|
93 | } |
---|
94 | if (!strcmp(*argv,"-DALL_Y_STAGGERED")) { |
---|
95 | sw_all_y_staggered = 1 ; |
---|
96 | } |
---|
97 | if (!strcmp(*argv,"-DDM_PARALLEL")) { |
---|
98 | sw_dm_parallel = 1 ; |
---|
99 | } |
---|
100 | if (!strcmp(*argv,"-DNEW_BDYS")) { |
---|
101 | sw_new_bdys = 1 ; |
---|
102 | } |
---|
103 | if (!strcmp(*argv,"-DEM_CORE=1")) { |
---|
104 | sw_unidir_shift_halo = 1 ; |
---|
105 | } |
---|
106 | if (!strcmp(*argv,"-DNEW_WITH_OLD_BDYS")) { |
---|
107 | sw_new_with_old_bdys = 1 ; |
---|
108 | } |
---|
109 | if (!strcmp(*argv,"-DDISTRIB_IO_LAYER")) { |
---|
110 | #if 0 |
---|
111 | sw_distrib_io_layer = 1 ; |
---|
112 | #else |
---|
113 | fprintf(stderr,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ; |
---|
114 | #endif |
---|
115 | } |
---|
116 | if (!strcmp(*argv,"-DDM_SERIAL_IN_ONLY")) { |
---|
117 | sw_dm_serial_in_only = 1 ; |
---|
118 | } |
---|
119 | if (!strncmp(*argv,"-h",2)) { |
---|
120 | fprintf(stderr,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog) ; |
---|
121 | exit(1) ; |
---|
122 | } |
---|
123 | } |
---|
124 | else /* consider it an input file */ |
---|
125 | { |
---|
126 | strcpy( fname_in , *argv ) ; |
---|
127 | } |
---|
128 | argv++ ; |
---|
129 | } |
---|
130 | |
---|
131 | gen_io_boilerplate() ; /* 20091213 jm. Generate the io_boilerplate_temporary.inc file */ |
---|
132 | |
---|
133 | init_parser() ; |
---|
134 | init_type_table() ; |
---|
135 | init_dim_table() ; |
---|
136 | |
---|
137 | if ( !strcmp(fname_in,"") ) fp_in = stdin ; |
---|
138 | else |
---|
139 | if (( fp_in = fopen( fname_in , "r" )) == NULL ) |
---|
140 | { |
---|
141 | fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_in ) ; |
---|
142 | exit(2) ; |
---|
143 | } |
---|
144 | |
---|
145 | sprintf( fname_tmp , "Registry_tmp.%d",mypid) ; |
---|
146 | if (( fp_tmp = fopen( fname_tmp , "w" )) == NULL ) |
---|
147 | { |
---|
148 | fprintf(stderr,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp ) ; |
---|
149 | exit(2) ; |
---|
150 | } |
---|
151 | |
---|
152 | { char *e ; |
---|
153 | strcpy( dir , fname_in ) ; |
---|
154 | if ( ( e = rindex ( dir , '/' ) ) != NULL ) { *e = '\0' ; } else { strcpy( dir, "." ) ; } |
---|
155 | } |
---|
156 | if ( pre_parse( dir, fp_in, fp_tmp ) ) { |
---|
157 | fprintf(stderr,"Problem with Registry File %s\n", fname_in ) ; |
---|
158 | goto cleanup ; |
---|
159 | } |
---|
160 | sym_forget() ; |
---|
161 | |
---|
162 | fclose(fp_in) ; |
---|
163 | fclose(fp_tmp) ; |
---|
164 | |
---|
165 | if (( fp_tmp = fopen( fname_tmp , "r" )) == NULL ) |
---|
166 | { |
---|
167 | fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_tmp ) ; |
---|
168 | goto cleanup ; |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | reg_parse(fp_tmp) ; |
---|
173 | |
---|
174 | fclose(fp_tmp) ; |
---|
175 | |
---|
176 | check_dimspecs() ; |
---|
177 | |
---|
178 | gen_state_struct( "inc" ) ; |
---|
179 | gen_state_subtypes( "inc" ) ; |
---|
180 | gen_alloc( "inc" ) ; |
---|
181 | /* gen_alloc_count( "inc" ) ; */ |
---|
182 | gen_dealloc( "inc" ) ; |
---|
183 | gen_scalar_indices( "inc" ) ; |
---|
184 | gen_module_state_description( "frame" ) ; |
---|
185 | gen_actual_args( "inc" ) ; |
---|
186 | gen_actual_args_new( "inc" ) ; |
---|
187 | gen_dummy_args( "inc" ) ; |
---|
188 | gen_dummy_args_new( "inc" ) ; |
---|
189 | gen_dummy_decls( "inc" ) ; |
---|
190 | gen_dummy_decls_new( "inc" ) ; |
---|
191 | gen_i1_decls( "inc" ) ; |
---|
192 | gen_namelist_statements("inc") ; |
---|
193 | gen_namelist_defines ( "inc", 0 ) ; /* without dimension statements */ |
---|
194 | gen_namelist_defines ( "inc", 1 ) ; /* with dimension statements */ |
---|
195 | gen_namelist_defaults ( "inc" ) ; |
---|
196 | gen_namelist_script ( "inc" ) ; |
---|
197 | gen_get_nl_config( "inc" ) ; |
---|
198 | gen_config_assigns( "inc" ) ; |
---|
199 | gen_config_reads( "inc" ) ; |
---|
200 | gen_wrf_io( "inc" ) ; |
---|
201 | gen_model_data_ord( "inc" ) ; |
---|
202 | gen_nest_interp( "inc" ) ; |
---|
203 | gen_scalar_derefs( "inc" ) ; |
---|
204 | gen_streams("inc") ; |
---|
205 | |
---|
206 | /* this has to happen after gen_nest_interp, which adds halos to the AST */ |
---|
207 | gen_comms( "inc" ) ; /* this is either package supplied (by copying a */ |
---|
208 | /* gen_comms.c file into this directory) or a */ |
---|
209 | /* stubs routine. */ |
---|
210 | |
---|
211 | cleanup: |
---|
212 | #ifdef _WIN32 |
---|
213 | sprintf(command,"del /F /Q %s\n",fname_tmp ); |
---|
214 | #else |
---|
215 | sprintf(command,"/bin/rm -f %s\n",fname_tmp ); |
---|
216 | #endif |
---|
217 | system( command ) ; |
---|
218 | |
---|
219 | } |
---|
220 | |
---|