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 /* SamT: bug fix: main returns int */
23 main( int argc
, char *argv
[], char *env
[] )
25 char fname_in
[NAMELEN
], dir
[NAMELEN
], fname_tmp
[NAMELEN
], command
[NAMELEN
] ;
26 char fname_wrk
[NAMELEN
] ;
27 FILE * fp_in
, *fp_tmp
;
36 mypid
= (int) getpid() ;
37 strcpy( thiscom
, argv
[0] ) ;
41 sw_io_deref_kludge
= 0 ;
42 sw_3dvar_iry_kludge
= 0 ;
43 sw_distrib_io_layer
= 1 ;
44 sw_limit_args
= 0 ; /* usually set -- except for GRAPS */
46 sw_all_x_staggered
= 0 ;
48 sw_all_y_staggered
= 0 ;
49 sw_fort_kludge
= 1 ; /* unconditionally true for v3 */
50 sw_dm_serial_in_only
= 0 ; /* input and bdy data set is distributed by node 0,
51 other data streams are written to file per process */
53 sw_unidir_shift_halo
= 0 ;
55 strcpy( fname_in
, "" ) ;
58 rlim
.rlim_cur
= RLIM_INFINITY
;
59 rlim
.rlim_max
= RLIM_INFINITY
;
60 setrlimit ( RLIMIT_STACK
, &rlim
) ;
66 if (*argv
[0] == '-') { /* an option */
67 if (!strncmp(*argv
,"-D",2)) {
73 if (!strcmp(*argv
,"-DDEREF_KLUDGE")) {
76 if (!strcmp(*argv
,"-DIO_DEREF_KLUDGE")) {
77 sw_io_deref_kludge
= 1 ;
79 if (!strcmp(*argv
,"-DLIMIT_ARGS")) {
82 if (!strcmp(*argv
,"-DMOVE_NESTS")) {
85 if (!strcmp(*argv
,"-DMOVE_NL_OUTSIDE_MODULE_CONFIGURE")) {
88 if (!strcmp(*argv
,"-DD3VAR_IRY_KLUDGE")) {
90 sw_3dvar_iry_kludge
= 1 ;
92 fprintf(stderr
,"WARNING: -DD3VAR_IRY_KLUDGE option obsolete (it is now disabled by default). Ignored.\n") ;
95 if (!strcmp(*argv
,"-DALL_X_STAGGERED")) {
96 sw_all_x_staggered
= 1 ;
98 if (!strcmp(*argv
,"-DALL_Y_STAGGERED")) {
99 sw_all_y_staggered
= 1 ;
101 if (!strcmp(*argv
,"-DDM_PARALLEL")) {
104 if (!strcmp(*argv
,"-DNEW_BDYS")) {
107 if (!strcmp(*argv
,"-DEM_CORE=1")) {
108 sw_unidir_shift_halo
= 1 ;
110 if (!strcmp(*argv
,"-DNEW_WITH_OLD_BDYS")) {
111 sw_new_with_old_bdys
= 1 ;
113 if (!strcmp(*argv
,"-DDISTRIB_IO_LAYER")) {
115 sw_distrib_io_layer
= 1 ;
117 fprintf(stderr
,"WARNING: -DDISTRIB_IO_LAYER option obsolete (it is now default). Ignored.\n") ;
120 if (!strcmp(*argv
,"-DDM_SERIAL_IN_ONLY")) {
121 sw_dm_serial_in_only
= 1 ;
123 if (!strncmp(*argv
,"-h",2)) {
124 fprintf(stderr
,"Usage: %s [-DDEREF_KLUDGE] [-DDM_PARALLEL] [-DDISTRIB_IO_LAYER] [-DDM_SERIAL_IN_ONLY] [-DD3VAR_IRY_KLUDGE] registryfile\n",thisprog
) ;
128 else /* consider it an input file */
130 strcpy( fname_in
, *argv
) ;
135 gen_io_boilerplate() ; /* 20091213 jm. Generate the io_boilerplate_temporary.inc file */
141 // possible IRR diagnostcis?
144 env_val
= getenv( "WRF_CHEM" );
145 if( env_val
!= NULL
&& !strncmp( env_val
, "1", 1 ) ) {
146 env_val
= getenv( "WRF_KPP" );
147 if( env_val
!= NULL
&& !strncmp( env_val
, "1", 1 ) ) do_irr_diag
= 1;
150 if( access( fname_in
,F_OK
) ) {
151 fprintf(stderr
,"Registry program %s does not exist. Ending.\n", fname_in
) ;
155 strcpy( dir
, fname_in
) ;
156 if ( ( e
= rindex ( dir
, '/' ) ) != NULL
) { *e
= '\0' ; } else { strcpy( dir
, "." ) ; }
157 sprintf( fname_wrk
,"%s/Registry_irr_diag",dir
) ;
159 // fprintf(stderr,"Registry tmp file = %s\n",fname_wrk);
160 sprintf(command
,"/bin/cp %s %s\n",fname_in
,fname_wrk
);
161 // fprintf(stderr,"Command = %s\n",command);
162 if( system( command
) ) {
163 fprintf(stderr
,"Could not copy %s to %s\n",fname_in
,fname_wrk
);
166 if (( fp_tmp
= fopen( fname_wrk
, "a" )) == NULL
)
168 fprintf(stderr
,"Registry program cannot open %s for appending. Ending.\n", fname_tmp
) ;
171 if( !access( "Registry/registry.irr_diag",F_OK
) ) {
172 sprintf(command
,"/bin/rm -f Registry/registry.irr_diag\n");
173 if( system( command
) ) {
174 fprintf(stderr
,"Could not remove Registry/registry.irr_diag\n");
181 retcod
= AppendReg( "mozcart",ndx
);
183 retcod
= AppendReg( "t1_mozcart",ndx
);
185 retcod
= AppendReg( "mozart_mosaic_4bin",ndx
);
187 retcod
= AppendReg( "mozart_mosaic_4bin_aq",ndx
);
190 fprintf(fp_tmp
,"\n");
191 fprintf(fp_tmp
,"include registry.irr_diag\n");
193 strcpy( fname_in
,fname_wrk
);
194 irr_diag_scalar_indices( "inc" );
195 // fprintf(stderr,"fname_in = %s\n",fname_in);
198 if ( !strcmp(fname_in
,"") ) fp_in
= stdin
;
200 if (( fp_in
= fopen( fname_in
, "r" )) == NULL
)
202 fprintf(stderr
,"Registry program cannot open %s for reading. Ending.\n", fname_in
) ;
206 sprintf( fname_tmp
, "Registry_tmp.%d",mypid
) ;
207 if (( fp_tmp
= fopen( fname_tmp
, "w" )) == NULL
)
209 fprintf(stderr
,"Registry program cannot open temporary %s for writing. Ending.\n", fname_tmp
) ;
214 strcpy( dir
, fname_in
) ;
215 if ( ( e
= rindex ( dir
, '/' ) ) != NULL
) { *e
= '\0' ; } else { strcpy( dir
, "." ) ; }
217 if ( pre_parse( dir
, fp_in
, fp_tmp
) ) {
218 fprintf(stderr
,"Problem with Registry File %s\n", fname_in
) ;
226 if (( fp_tmp
= fopen( fname_tmp
, "r" )) == NULL
)
228 fprintf(stderr
,"Registry program cannot open %s for reading. Ending.\n", fname_tmp
) ;
239 gen_state_struct( "inc" ) ;
240 gen_state_subtypes( "inc" ) ;
242 /* gen_alloc_count( "inc" ) ; */
243 gen_dealloc( "inc" ) ;
244 gen_scalar_indices( "inc" ) ;
245 gen_module_state_description( "frame" ) ;
246 gen_actual_args( "inc" ) ;
247 gen_actual_args_new( "inc" ) ;
248 gen_dummy_args( "inc" ) ;
249 gen_dummy_args_new( "inc" ) ;
250 gen_dummy_decls( "inc" ) ;
251 gen_dummy_decls_new( "inc" ) ;
252 gen_i1_decls( "inc" ) ;
253 gen_namelist_statements("inc") ;
254 gen_namelist_defines ( "inc", 0 ) ; /* without dimension statements */
255 gen_namelist_defines ( "inc", 1 ) ; /* with dimension statements */
256 gen_namelist_defaults ( "inc" ) ;
257 gen_namelist_script ( "inc" ) ;
258 gen_get_nl_config( "inc" ) ;
259 gen_config_assigns( "inc" ) ;
260 gen_config_reads( "inc" ) ;
261 gen_wrf_io( "inc" ) ;
262 gen_model_data_ord( "inc" ) ;
263 gen_nest_interp( "inc" ) ;
264 gen_nest_v_interp( "inc") ; /*KAL added this for vertical interpolation*/
265 gen_scalar_derefs( "inc" ) ;
268 /* this has to happen after gen_nest_interp, which adds halos to the AST */
269 gen_comms( "inc" ) ; /* this is either package supplied (by copying a */
270 /* gen_comms.c file into this directory) or a */
276 sprintf(command
,"del /F /Q %s\n",fname_wrk
);
279 sprintf(command
,"del /F /Q %s\n",fname_tmp
);
282 sprintf(command
,"/bin/rm -f %s\n",fname_wrk
);
285 sprintf(command
,"/bin/rm -f %s\n",fname_tmp
);
287 return system( command
) ;