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 
40   strcpy( fname_in , "" ) ;
41 
42   rlim.rlim_cur = RLIM_INFINITY ;
43   rlim.rlim_max = RLIM_INFINITY ;
44 
45   setrlimit ( RLIMIT_STACK , &rlim ) ;
46 
47   sym_forget() ;
48   thisprog = *argv ;
49   while (*argv) {
50     if (*argv[0] == '-') {  /* an option */
51       if (!strncmp(*argv,"-D",2)) {
52         char * p ;
53         p = *argv ;
54         sym_add(p+2) ;
55       }
56    
57       if (!strcmp(*argv,"-DDEREF_KLUDGE")) {
58         sw_deref_kludge = 1 ;
59       }
60       if (!strcmp(*argv,"-DIO_DEREF_KLUDGE")) {
61         sw_io_deref_kludge = 1 ;
62       }
63       if (!strcmp(*argv,"-DLIMIT_ARGS")) {
64         sw_limit_args = 1 ;
65       }
66       if (!strcmp(*argv,"-DMOVE_NESTS")) {
67         sw_move = 1 ;
68       }
69       if (!strcmp(*argv,"-DIFORT_KLUDGE")) {
70         sw_ifort_kludge = 1 ;
71       }
72       if (!strcmp(*argv,"-DD3VAR_IRY_KLUDGE")) {
73 #if 0
74         sw_3dvar_iry_kludge = 1 ;
75 #else
76         fprintf(stderr,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ;
77 #endif
78       }
79       if (!strcmp(*argv,"-DALL_X_STAGGERED")) {
80         sw_all_x_staggered = 1 ;
81       }
82       if (!strcmp(*argv,"-DALL_Y_STAGGERED")) {
83         sw_all_y_staggered = 1 ;
84       }
85       if (!strcmp(*argv,"-DDM_PARALLEL")) {
86         sw_dm_parallel = 1 ;
87       }
88       if (!strcmp(*argv,"-DDISTRIB_IO_LAYER")) {
89 #if 0
90         sw_distrib_io_layer = 1 ;
91 #else
92         fprintf(stderr,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ;
93 #endif
94       }
95       if (!strcmp(*argv,"-DDM_SERIAL_IN_ONLY")) {
96         sw_dm_serial_in_only = 1 ;
97       }
98       if (!strncmp(*argv,"-h",2)) {
99         fprintf(stderr,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog) ;
100         exit(1) ;
101       }
102     }
103     else  /* consider it an input file */
104     {
105       strcpy( fname_in , *argv ) ;
106     }
107     argv++ ;
108   }
109 
110   init_parser() ;
111   init_type_table() ;
112   init_dim_table() ;
113   init_core_table() ;
114 
115   if ( !strcmp(fname_in,"") ) fp_in = stdin ;
116   else
117     if (( fp_in = fopen( fname_in , "r" )) == NULL )
118     {
119       fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_in ) ;
120       exit(2) ;
121     }
122   
123   sprintf( fname_tmp , "Registry_tmp.%d",mypid) ;
124   if (( fp_tmp = fopen( fname_tmp  , "w" )) == NULL )
125   {
126     fprintf(stderr,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp ) ;
127     exit(2) ;
128   }
129 
130   { char *e ;
131     strcpy( dir , fname_in ) ;
132     if ( ( e = rindex ( dir , '/' ) ) != NULL ) { *e = '\0' ; } else { strcpy( dir, "." ) ; } 
133   }
134 
135   if ( pre_parse( dir, fp_in, fp_tmp ) ) {
136     fprintf(stderr,"Problem with Registry File %s\n", fname_in ) ;
137     goto cleanup ;
138   }
139   sym_forget() ;
140 
141   fclose(fp_in) ;
142   fclose(fp_tmp) ;
143 
144   if (( fp_tmp = fopen( fname_tmp , "r" )) == NULL )
145   {
146     fprintf(stderr,"Registry program cannot open %s for reading. Ending.\n", fname_tmp ) ;
147     goto cleanup ;
148   }
149 
150   reg_parse(fp_tmp) ;
151 
152   fclose(fp_tmp) ;
153 
154   check_dimspecs() ;
155 
156   gen_state_struct( "inc" ) ;
157   gen_state_subtypes( "inc" ) ;
158   gen_alloc( "inc" ) ;
159   gen_dealloc( "inc" ) ;
160   gen_scalar_indices( "inc" ) ;
161   gen_module_state_description( "frame" ) ;
162   gen_actual_args( "inc" ) ;
163   gen_actual_args_new( "inc" ) ;
164   gen_dummy_args( "inc" ) ;
165   gen_dummy_args_new( "inc" ) ;
166   gen_dummy_decls( "inc" ) ;
167   gen_dummy_decls_new( "inc" ) ;
168   gen_i1_decls( "inc" ) ;
169   gen_namelist_statements("inc") ;
170   gen_namelist_defines ( "inc", 0 ) ;  /* without dimension statements  */
171   gen_namelist_defines ( "inc", 1 ) ;  /* with dimension statements     */
172   gen_namelist_defaults ( "inc" ) ;
173   gen_namelist_script ( "inc" ) ;
174   gen_get_nl_config( "inc" ) ;
175   gen_config_assigns( "inc" ) ;
176   gen_config_reads( "inc" ) ;
177   gen_wrf_io( "inc" ) ;
178   gen_model_data_ord( "inc" ) ;
179   gen_nest_interp( "inc" ) ;
180   gen_scalar_derefs( "inc" ) ;
181 
182 #if 1
183   system( "touch inc/em_nest_feedbackup_smooth.inc" ) ;
184   system( "touch inc/em_nest_feedbackup_unpack.inc" ) ;
185 #endif
186 
187 
188 /* this has to happen after gen_nest_interp, which adds halos to the AST */
189   gen_comms( "inc" ) ;    /* this is either package supplied (by copying a */
190                           /* gen_comms.c file into this directory) or a    */
191                           /* stubs routine.                                */
192 
193 cleanup:
194   sprintf(command,"/bin/rm -f %s\n",fname_tmp );
195   system( command ) ;
196 
197 }
198