5 # define rindex(X,Y) strrchr(X,Y)
6 # define index(X,Y) strchr(X,Y)
9 # include <sys/resource.h>
15 #define DEFINE_GLOBALS
21 // Helper macro to actually do return checks
22 #define EXIT_ON_NONZERO( A ) { int result = A; if ( result != 0 ) { printf( "Error in %s, zero return expected, received %i\n", #A, result ); exit(result); } }
24 /* SamT: bug fix: main returns int */
26 main( int argc
, char *argv
[], char *env
[] )
28 char fname_in
[NAMELEN
], dir
[NAMELEN
], fname_tmp
[NAMELEN
], command
[NAMELEN
] ;
29 char fname_wrk
[NAMELEN
] ;
30 FILE * fp_in
, *fp_tmp
;
39 mypid
= (int) getpid() ;
40 strcpy( thiscom
, argv
[0] ) ;
44 sw_io_deref_kludge
= 0 ;
45 sw_3dvar_iry_kludge
= 0 ;
46 sw_distrib_io_layer
= 1 ;
47 sw_limit_args
= 0 ; /* usually set -- except for GRAPS */
49 sw_all_x_staggered
= 0 ;
51 sw_all_y_staggered
= 0 ;
52 sw_fort_kludge
= 1 ; /* unconditionally true for v3 */
53 sw_dm_serial_in_only
= 0 ; /* input and bdy data set is distributed by node 0,
54 other data streams are written to file per process */
56 sw_unidir_shift_halo
= 0 ;
58 strcpy( fname_in
, "" ) ;
61 rlim
.rlim_cur
= RLIM_INFINITY
;
62 rlim
.rlim_max
= RLIM_INFINITY
;
63 setrlimit ( RLIMIT_STACK
, &rlim
) ;
69 if (*argv
[0] == '-') { /* an option */
70 if (!strncmp(*argv
,"-D",2)) {
76 if (!strcmp(*argv
,"-DDEREF_KLUDGE")) {
79 if (!strcmp(*argv
,"-DIO_DEREF_KLUDGE")) {
80 sw_io_deref_kludge
= 1 ;
82 if (!strcmp(*argv
,"-DLIMIT_ARGS")) {
85 if (!strcmp(*argv
,"-DMOVE_NESTS")) {
88 if (!strcmp(*argv
,"-DMOVE_NL_OUTSIDE_MODULE_CONFIGURE")) {
91 if (!strcmp(*argv
,"-DD3VAR_IRY_KLUDGE")) {
93 sw_3dvar_iry_kludge
= 1 ;
95 fprintf(stderr
,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ;
98 if (!strcmp(*argv
,"-DALL_X_STAGGERED")) {
99 sw_all_x_staggered
= 1 ;
101 if (!strcmp(*argv
,"-DALL_Y_STAGGERED")) {
102 sw_all_y_staggered
= 1 ;
104 if (!strcmp(*argv
,"-DDM_PARALLEL")) {
107 if (!strcmp(*argv
,"-DNEW_BDYS")) {
110 if (!strcmp(*argv
,"-DEM_CORE=1")) {
111 sw_unidir_shift_halo
= 1 ;
113 if (!strcmp(*argv
,"-DNEW_WITH_OLD_BDYS")) {
114 sw_new_with_old_bdys
= 1 ;
116 if (!strcmp(*argv
,"-DDISTRIB_IO_LAYER")) {
118 sw_distrib_io_layer
= 1 ;
120 fprintf(stderr
,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ;
123 if (!strcmp(*argv
,"-DDM_SERIAL_IN_ONLY")) {
124 sw_dm_serial_in_only
= 1 ;
126 if (!strncmp(*argv
,"-h",2)) {
127 fprintf(stderr
,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog
) ;
131 else /* consider it an input file */
133 strcpy( fname_in
, *argv
) ;
138 EXIT_ON_NONZERO( gen_io_boilerplate() ); /* 20091213 jm. Generate the io_boilerplate_temporary.inc file */
140 EXIT_ON_NONZERO( init_parser() );
141 EXIT_ON_NONZERO( init_type_table() );
142 EXIT_ON_NONZERO( init_dim_table() );
144 // possible IRR diagnostcis?
147 env_val
= getenv( "WRF_CHEM" );
148 if( env_val
!= NULL
&& !strncmp( env_val
, "1", 1 ) ) {
149 env_val
= getenv( "WRF_KPP" );
150 if( env_val
!= NULL
&& !strncmp( env_val
, "1", 1 ) ) do_irr_diag
= 1;
153 if( access( fname_in
,F_OK
) ) {
154 fprintf(stderr
,"Registry program %s does not exist. Ending.\n", fname_in
) ;
158 strcpy( dir
, fname_in
) ;
159 if ( ( e
= rindex ( dir
, '/' ) ) != NULL
) { *e
= '\0' ; } else { strcpy( dir
, "." ) ; }
160 sprintf( fname_wrk
,"%s/Registry_irr_diag",dir
) ;
162 // fprintf(stderr,"Registry tmp file = %s\n",fname_wrk);
163 sprintf(command
,"/bin/cp %s %s\n",fname_in
,fname_wrk
);
164 // fprintf(stderr,"Command = %s\n",command);
165 if( system( command
) ) {
166 fprintf(stderr
,"Could not copy %s to %s\n",fname_in
,fname_wrk
);
169 if (( fp_tmp
= fopen( fname_wrk
, "a" )) == NULL
)
171 fprintf(stderr
,"Registry program cannot open %s for appending. Ending.\n", fname_tmp
) ;
174 if( !access( "Registry/registry.irr_diag",F_OK
) ) {
175 sprintf(command
,"/bin/rm -f Registry/registry.irr_diag\n");
176 if( system( command
) ) {
177 fprintf(stderr
,"Could not remove Registry/registry.irr_diag\n");
184 retcod
= AppendReg( "mozcart",ndx
);
186 retcod
= AppendReg( "t1_mozcart",ndx
);
188 retcod
= AppendReg( "mozart_mosaic_4bin",ndx
);
190 retcod
= AppendReg( "mozart_mosaic_4bin_aq",ndx
);
193 fprintf(fp_tmp
,"\n");
194 fprintf(fp_tmp
,"include registry.irr_diag\n");
196 strcpy( fname_in
,fname_wrk
);
197 irr_diag_scalar_indices( "inc" );
198 // fprintf(stderr,"fname_in = %s\n",fname_in);
201 if ( !strcmp(fname_in
,"") ) fp_in
= stdin
;
203 if (( fp_in
= fopen( fname_in
, "r" )) == NULL
)
205 fprintf(stderr
,"Registry program cannot open %s for reading. Ending.\n", fname_in
) ;
209 sprintf( fname_tmp
, "Registry_tmp.%d",mypid
) ;
210 if (( fp_tmp
= fopen( fname_tmp
, "w" )) == NULL
)
212 fprintf(stderr
,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp
) ;
217 strcpy( dir
, fname_in
) ;
218 if ( ( e
= rindex ( dir
, '/' ) ) != NULL
) { *e
= '\0' ; } else { strcpy( dir
, "." ) ; }
220 if ( pre_parse( dir
, fp_in
, fp_tmp
) ) {
221 fprintf(stderr
,"Problem with Registry File %s\n", fname_in
) ;
229 if (( fp_tmp
= fopen( fname_tmp
, "r" )) == NULL
)
231 fprintf(stderr
,"Registry program cannot open %s for reading. Ending.\n", fname_tmp
) ;
236 EXIT_ON_NONZERO( reg_parse(fp_tmp
) );
242 EXIT_ON_NONZERO( gen_state_struct( "inc" ) );
243 EXIT_ON_NONZERO( gen_state_subtypes( "inc" ) );
244 EXIT_ON_NONZERO( gen_alloc( "inc" ) );
245 /* gen_alloc_count( "inc" ) ; */
246 EXIT_ON_NONZERO( gen_dealloc( "inc" ) ) ;
247 EXIT_ON_NONZERO( gen_scalar_indices( "inc" ) ) ;
248 EXIT_ON_NONZERO( gen_module_state_description( "frame" ) ) ;
249 EXIT_ON_NONZERO( gen_actual_args( "inc" ) ) ;
250 EXIT_ON_NONZERO( gen_actual_args_new( "inc" ) ) ;
251 EXIT_ON_NONZERO( gen_dummy_args( "inc" ) ) ;
252 EXIT_ON_NONZERO( gen_dummy_args_new( "inc" ) ) ;
253 EXIT_ON_NONZERO( gen_dummy_decls( "inc" ) ) ;
254 EXIT_ON_NONZERO( gen_dummy_decls_new( "inc" ) ) ;
255 EXIT_ON_NONZERO( gen_i1_decls( "inc" ) ) ;
256 EXIT_ON_NONZERO( gen_namelist_statements("inc") ; )
257 EXIT_ON_NONZERO( gen_namelist_defines ( "inc", 0 ) ) ; /* without dimension statements */
258 EXIT_ON_NONZERO( gen_namelist_defines ( "inc", 1 ) ) ; /* with dimension statements */
259 EXIT_ON_NONZERO( gen_namelist_defaults ( "inc" ) ) ;
260 EXIT_ON_NONZERO( gen_namelist_script ( "inc" ) ) ;
261 EXIT_ON_NONZERO( gen_get_nl_config( "inc" ) ) ;
262 EXIT_ON_NONZERO( gen_config_assigns( "inc" ) ) ;
263 EXIT_ON_NONZERO( gen_config_reads( "inc" ) ) ;
264 EXIT_ON_NONZERO( gen_wrf_io( "inc" ) ) ;
265 EXIT_ON_NONZERO( gen_model_data_ord( "inc" ) ) ;
266 EXIT_ON_NONZERO( gen_nest_interp( "inc" ) ) ;
267 EXIT_ON_NONZERO( gen_nest_v_interp( "inc") ; ) /*KAL added this for vertical interpolation*/
268 EXIT_ON_NONZERO( gen_scalar_derefs( "inc" ) ) ;
269 EXIT_ON_NONZERO( gen_streams("inc") ; )
271 /* this has to happen after gen_nest_interp, which adds halos to the AST */
272 EXIT_ON_NONZERO( gen_comms( "inc" ) ); /* this is either package supplied (by copying a */
273 /* gen_comms.c file into this directory) or a */
279 sprintf(command
,"del /F /Q %s\n",fname_wrk
);
282 sprintf(command
,"del /F /Q %s\n",fname_tmp
);
285 sprintf(command
,"/bin/rm -f %s\n",fname_wrk
);
288 sprintf(command
,"/bin/rm -f %s\n",fname_tmp
);
290 return system( command
) ;