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