wrf svn trunk commit r4103
[wrffire.git] / wrfv2_fire / tools / registry.c
blobf03cab9c221aaff2146b544548fcefd086badfc8
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
15 #define DEFINE_GLOBALS
16 #include "protos.h"
17 #include "registry.h"
18 #include "data.h"
19 #include "sym.h"
21 void
22 main( int argc, char *argv[], char *env[] )
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
32 mypid = (int) getpid() ;
33 strcpy( thiscom, argv[0] ) ;
34 argv++ ;
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 ;
50 strcpy( fname_in , "" ) ;
52 #ifndef _WIN32
53 rlim.rlim_cur = RLIM_INFINITY ;
54 rlim.rlim_max = RLIM_INFINITY ;
55 setrlimit ( RLIMIT_STACK , &rlim ) ;
56 #endif
58 sym_forget() ;
59 thisprog = *argv ;
60 while (*argv) {
61 if (*argv[0] == '-') { /* an option */
62 if (!strncmp(*argv,"-D",2)) {
63 char * p ;
64 p = *argv ;
65 sym_add(p+2) ;
68 if (!strcmp(*argv,"-DDEREF_KLUDGE")) {
69 sw_deref_kludge = 1 ;
71 if (!strcmp(*argv,"-DIO_DEREF_KLUDGE")) {
72 sw_io_deref_kludge = 1 ;
74 if (!strcmp(*argv,"-DLIMIT_ARGS")) {
75 sw_limit_args = 1 ;
77 if (!strcmp(*argv,"-DMOVE_NESTS")) {
78 sw_move = 1 ;
80 if (!strcmp(*argv,"-DMOVE_NL_OUTSIDE_MODULE_CONFIGURE")) {
81 sw_fort_kludge = 1 ;
83 if (!strcmp(*argv,"-DD3VAR_IRY_KLUDGE")) {
84 #if 0
85 sw_3dvar_iry_kludge = 1 ;
86 #else
87 fprintf(stderr,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ;
88 #endif
90 if (!strcmp(*argv,"-DALL_X_STAGGERED")) {
91 sw_all_x_staggered = 1 ;
93 if (!strcmp(*argv,"-DALL_Y_STAGGERED")) {
94 sw_all_y_staggered = 1 ;
96 if (!strcmp(*argv,"-DDM_PARALLEL")) {
97 sw_dm_parallel = 1 ;
99 if (!strcmp(*argv,"-DNEW_BDYS")) {
100 sw_new_bdys = 1 ;
102 if (!strcmp(*argv,"-DNEW_WITH_OLD_BDYS")) {
103 sw_new_with_old_bdys = 1 ;
105 if (!strcmp(*argv,"-DDISTRIB_IO_LAYER")) {
106 #if 0
107 sw_distrib_io_layer = 1 ;
108 #else
109 fprintf(stderr,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ;
110 #endif
112 if (!strcmp(*argv,"-DDM_SERIAL_IN_ONLY")) {
113 sw_dm_serial_in_only = 1 ;
115 if (!strncmp(*argv,"-h",2)) {
116 fprintf(stderr,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog) ;
117 exit(1) ;
120 else /* consider it an input file */
122 strcpy( fname_in , *argv ) ;
124 argv++ ;
127 gen_io_boilerplate() ; /* 20091213 jm. Generate the io_boilerplate_temporary.inc file */
129 init_parser() ;
130 init_type_table() ;
131 init_dim_table() ;
133 if ( !strcmp(fname_in,"") ) fp_in = stdin ;
134 else
135 if (( fp_in = fopen( fname_in , "r" )) == NULL )
137 fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_in ) ;
138 exit(2) ;
141 sprintf( fname_tmp , "Registry_tmp.%d",mypid) ;
142 if (( fp_tmp = fopen( fname_tmp , "w" )) == NULL )
144 fprintf(stderr,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp ) ;
145 exit(2) ;
148 { char *e ;
149 strcpy( dir , fname_in ) ;
150 if ( ( e = rindex ( dir , '/' ) ) != NULL ) { *e = '\0' ; } else { strcpy( dir, "." ) ; }
152 if ( pre_parse( dir, fp_in, fp_tmp ) ) {
153 fprintf(stderr,"Problem with Registry File %s\n", fname_in ) ;
154 goto cleanup ;
156 sym_forget() ;
158 fclose(fp_in) ;
159 fclose(fp_tmp) ;
161 if (( fp_tmp = fopen( fname_tmp , "r" )) == NULL )
163 fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_tmp ) ;
164 goto cleanup ;
168 reg_parse(fp_tmp) ;
170 fclose(fp_tmp) ;
172 check_dimspecs() ;
174 gen_state_struct( "inc" ) ;
175 gen_state_subtypes( "inc" ) ;
176 gen_alloc( "inc" ) ;
177 /* gen_alloc_count( "inc" ) ; */
178 gen_dealloc( "inc" ) ;
179 gen_scalar_indices( "inc" ) ;
180 gen_module_state_description( "frame" ) ;
181 gen_actual_args( "inc" ) ;
182 gen_actual_args_new( "inc" ) ;
183 gen_dummy_args( "inc" ) ;
184 gen_dummy_args_new( "inc" ) ;
185 gen_dummy_decls( "inc" ) ;
186 gen_dummy_decls_new( "inc" ) ;
187 gen_i1_decls( "inc" ) ;
188 gen_namelist_statements("inc") ;
189 gen_namelist_defines ( "inc", 0 ) ; /* without dimension statements */
190 gen_namelist_defines ( "inc", 1 ) ; /* with dimension statements */
191 gen_namelist_defaults ( "inc" ) ;
192 gen_namelist_script ( "inc" ) ;
193 gen_get_nl_config( "inc" ) ;
194 gen_config_assigns( "inc" ) ;
195 gen_config_reads( "inc" ) ;
196 gen_wrf_io( "inc" ) ;
197 gen_model_data_ord( "inc" ) ;
198 gen_nest_interp( "inc" ) ;
199 gen_scalar_derefs( "inc" ) ;
200 gen_streams("inc") ;
202 /* this has to happen after gen_nest_interp, which adds halos to the AST */
203 gen_comms( "inc" ) ; /* this is either package supplied (by copying a */
204 /* gen_comms.c file into this directory) or a */
205 /* stubs routine. */
207 cleanup:
208 #ifdef _WIN32
209 sprintf(command,"del /F /Q %s\n",fname_tmp );
210 #else
211 sprintf(command,"/bin/rm -f %s\n",fname_tmp );
212 #endif
213 system( command ) ;