Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / tools / gen_streams.c
blobad5251ff4d381985728191b3c5f631bd7cdf1900
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #ifndef _WIN32
5 # include <strings.h>
6 #endif
8 #include "protos.h"
9 #include "registry.h"
10 #include "data.h"
11 #include "sym.h"
13 int gen_streams( char * dirname )
15 FILE * fp ;
16 char fname[NAMELEN] ;
17 char * fn ;
18 if ( dirname == NULL ) return(1) ;
20 fn = "module_io_domain_defs.inc" ;
21 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
22 else { sprintf(fname,"%s",fn) ; }
23 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
24 print_warning(fp,fname) ;
25 gen_io_domain_defs( fp ) ;
26 close_the_file( fp ) ;
28 fn = "set_timekeeping_defs.inc" ;
29 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
30 else { sprintf(fname,"%s",fn) ; }
31 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
32 print_warning(fp,fname) ;
33 gen_set_timekeeping_defs( fp ) ;
34 close_the_file( fp ) ;
36 fn = "set_timekeeping_alarms.inc" ;
37 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
38 else { sprintf(fname,"%s",fn) ; }
39 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
40 print_warning(fp,fname) ;
41 gen_set_timekeeping_alarms( fp ) ;
42 close_the_file( fp ) ;
44 fn = "io_form_for_dataset.inc" ;
45 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
46 else { sprintf(fname,"%s",fn) ; }
47 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
48 print_warning(fp,fname) ;
49 gen_io_form_for_dataset( fp ) ;
50 close_the_file( fp ) ;
52 fn = "io_form_for_stream.inc" ;
53 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
54 else { sprintf(fname,"%s",fn) ; }
55 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
56 print_warning(fp,fname) ;
57 gen_io_form_for_stream( fp ) ;
58 close_the_file( fp ) ;
60 fn = "switches_and_alarms.inc" ;
61 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
62 else { sprintf(fname,"%s",fn) ; }
63 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
64 print_warning(fp,fname) ;
65 gen_switches_and_alarms( fp ) ;
66 close_the_file( fp ) ;
68 fn = "check_auxstream_alarms.inc" ;
69 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
70 else { sprintf(fname,"%s",fn) ; }
71 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
72 print_warning(fp,fname) ;
73 gen_check_auxstream_alarms( fp ) ;
74 close_the_file( fp ) ;
76 fn = "fine_stream_input.inc" ;
77 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
78 else { sprintf(fname,"%s",fn) ; }
79 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
80 print_warning(fp,fname) ;
81 gen_fine_stream_input( fp ) ;
82 close_the_file( fp ) ;
84 fn = "med_auxinput_in.inc" ;
85 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
86 else { sprintf(fname,"%s",fn) ; }
87 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
88 print_warning(fp,fname) ;
89 gen_med_auxinput_in( fp ) ;
90 close_the_file( fp ) ;
92 fn = "med_hist_out_opens.inc" ;
93 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
94 else { sprintf(fname,"%s",fn) ; }
95 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
96 print_warning(fp,fname) ;
97 gen_med_hist_out_opens( fp ) ;
98 close_the_file( fp ) ;
100 fn = "med_hist_out_closes.inc" ;
101 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
102 else { sprintf(fname,"%s",fn) ; }
103 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
104 print_warning(fp,fname) ;
105 gen_med_hist_out_closes( fp ) ;
106 close_the_file( fp ) ;
108 fn = "med_auxinput_in_closes.inc" ;
109 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
110 else { sprintf(fname,"%s",fn) ; }
111 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
112 print_warning(fp,fname) ;
113 gen_med_auxinput_in_closes( fp ) ;
114 close_the_file( fp ) ;
116 fn = "med_last_solve_io.inc" ;
117 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
118 else { sprintf(fname,"%s",fn) ; }
119 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
120 print_warning(fp,fname) ;
121 gen_med_last_solve_io( fp ) ;
122 close_the_file( fp ) ;
124 fn = "med_open_esmf_calls.inc" ;
125 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
126 else { sprintf(fname,"%s",fn) ; }
127 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
128 print_warning(fp,fname) ;
129 gen_med_open_esmf_calls( fp ) ;
130 close_the_file( fp ) ;
132 fn = "med_find_esmf_coupling.inc" ;
133 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
134 else { sprintf(fname,"%s",fn) ; }
135 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
136 print_warning(fp,fname) ;
137 gen_med_find_esmf_coupling( fp ) ;
138 close_the_file( fp ) ;
140 fn = "shutdown_closes.inc" ;
141 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
142 else { sprintf(fname,"%s",fn) ; }
143 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
144 print_warning(fp,fname) ;
145 gen_shutdown_closes( fp ) ;
146 close_the_file( fp ) ;
148 return(0) ;
152 gen_io_domain_defs ( FILE * fp )
154 char * dir , * aux , *streamtype , streamno[5] ;
155 int i, j ;
157 for ( j = 0 ; j < 2 ; j++ ) {
158 if ( j == 0 ) dir = "output" ;
159 else dir = "input" ;
160 for ( i = 0 ; i < 2*MAX_HISTORY ; i++ )
162 if ( i % MAX_HISTORY == 0 ) { aux = "" ; streamno[0] = '\0' ; }
163 else { aux="aux" ; sprintf(streamno,"%d",i%MAX_HISTORY) ; }
164 if ( i < MAX_HISTORY ) { streamtype = "input" ; }
165 else { streamtype = ( i%MAX_HISTORY == 0 )?"history":"hist" ; }
167 fprintf(fp,"SUBROUTINE %s_%s%s%s ( fid , grid , config_flags , ierr )\n",dir,aux,streamtype,streamno) ;
168 fprintf(fp," IMPLICIT NONE\n") ;
169 fprintf(fp," TYPE(domain) :: grid\n") ;
170 fprintf(fp," TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags\n") ;
171 fprintf(fp," INTEGER, INTENT(IN) :: fid\n") ;
172 fprintf(fp," INTEGER, INTENT(INOUT) :: ierr\n") ;
173 fprintf(fp," IF ( config_flags%%io_form_%s%s%s .GT. 0 ) THEN\n", aux,streamtype,streamno) ;
174 fprintf(fp," CALL %s_wrf( fid, grid, config_flags, %s%s%s_only, ierr ) ;\n",dir,aux,streamtype,streamno) ;
175 fprintf(fp," ENDIF\n") ;
176 fprintf(fp," RETURN\n") ;
177 fprintf(fp,"END SUBROUTINE %s_%s%s%s\n",dir,aux,streamtype,streamno) ;
180 return 0; /* SamT: bug fix: return a value */
184 gen_set_timekeeping_defs ( FILE *fp )
186 char * aux , *streamtype , streamno[5] ;
187 int i ;
188 for ( i = 0 ; i < 2*MAX_HISTORY ; i++ )
190 if ( i % MAX_HISTORY == 0 ) { aux = "" ; streamno[0] = '\0' ; }
191 else { aux="aux" ; sprintf(streamno,"%d",i%MAX_HISTORY) ; }
192 if ( i < MAX_HISTORY ) { streamtype = "input" ; }
193 else { streamtype = ( i%MAX_HISTORY == 0 )?"history":"hist" ; }
195 fprintf(fp," INTEGER :: %s%s%s_interval , &\n",aux,streamtype,streamno) ;
196 fprintf(fp," %s%s%s_interval_d, &\n",aux,streamtype,streamno) ;
197 fprintf(fp," %s%s%s_interval_h, &\n",aux,streamtype,streamno) ;
198 fprintf(fp," %s%s%s_interval_m, &\n",aux,streamtype,streamno) ;
199 fprintf(fp," %s%s%s_interval_s \n",aux,streamtype,streamno) ;
200 fprintf(fp," INTEGER :: %s%s%s_begin , &\n",aux,streamtype,streamno) ;
201 fprintf(fp," %s%s%s_begin_y, &\n",aux,streamtype,streamno) ;
202 fprintf(fp," %s%s%s_begin_d, &\n",aux,streamtype,streamno) ;
203 fprintf(fp," %s%s%s_begin_h, &\n",aux,streamtype,streamno) ;
204 fprintf(fp," %s%s%s_begin_m, &\n",aux,streamtype,streamno) ;
205 fprintf(fp," %s%s%s_begin_s \n",aux,streamtype,streamno) ;
206 fprintf(fp," INTEGER :: %s%s%s_end , &\n",aux,streamtype,streamno) ;
207 fprintf(fp," %s%s%s_end_y, &\n",aux,streamtype,streamno) ;
208 fprintf(fp," %s%s%s_end_d, &\n",aux,streamtype,streamno) ;
209 fprintf(fp," %s%s%s_end_h, &\n",aux,streamtype,streamno) ;
210 fprintf(fp," %s%s%s_end_m, &\n",aux,streamtype,streamno) ;
211 fprintf(fp," %s%s%s_end_s \n",aux,streamtype,streamno) ;
213 return 0; /* SamT: bug fix: return a value */
217 gen_set_timekeeping_alarms ( FILE * fp )
219 char * dir , * aux , *streamtype , streamno[5] ;
220 int i, j ;
222 for ( i = 0 ; i < 2*MAX_HISTORY ; i++ )
224 if ( i % MAX_HISTORY == 0 ) { aux = "" ; streamno[0] = '\0' ; }
225 else { aux="aux" ; sprintf(streamno,"%d",i%MAX_HISTORY) ; }
226 if ( i < MAX_HISTORY ) { streamtype = "input" ; }
227 else { streamtype = ( i%MAX_HISTORY == 0 )?"history":"hist" ; }
228 if ( i == 0 ) continue ; /* skip just input */
230 fprintf(fp,"! %s%s%s INTERVAL\n",aux,streamtype,streamno) ;
231 fprintf(fp," CALL nl_get_%s%s%s_interval( grid%%id, %s%s%s_interval ) ! same as minutes\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
232 fprintf(fp," CALL nl_get_%s%s%s_interval_d( grid%%id, %s%s%s_interval_d )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
233 fprintf(fp," CALL nl_get_%s%s%s_interval_h( grid%%id, %s%s%s_interval_h )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
234 fprintf(fp," CALL nl_get_%s%s%s_interval_m( grid%%id, %s%s%s_interval_m )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
235 fprintf(fp," CALL nl_get_%s%s%s_interval_s( grid%%id, %s%s%s_interval_s )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
236 fprintf(fp," IF ( %s%s%s_interval_m .EQ. 0 ) %s%s%s_interval_m = %s%s%s_interval\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
237 fprintf(fp," IF ( MAX( %s%s%s_interval_d, &\n",aux,streamtype,streamno) ;
238 fprintf(fp," %s%s%s_interval_h, %s%s%s_interval_m , %s%s%s_interval_s ) .GT. 0 ) THEN\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
239 fprintf(fp," CALL WRFU_TimeIntervalSet( interval, D=%s%s%s_interval_d, &\n",aux,streamtype,streamno) ;
240 fprintf(fp," H=%s%s%s_interval_h, M=%s%s%s_interval_m, S=%s%s%s_interval_s, rc=rc )\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
241 fprintf(fp," CALL wrf_check_error( WRFU_SUCCESS, rc, &\n") ;
242 fprintf(fp," 'WRFU_TimeIntervalSet(%s%s%s_interval) FAILED', &\n",aux,streamtype,streamno) ;
243 fprintf(fp," __FILE__ , &\n") ;
244 fprintf(fp," __LINE__ )\n") ;
245 fprintf(fp," ELSE\n") ;
246 #if 0
247 fprintf(fp," interval = run_length + padding_interval\n") ;
248 #else
249 fprintf(fp," interval = padding_interval\n") ;
250 #endif
251 fprintf(fp," ENDIF\n") ;
252 fprintf(fp," CALL nl_get_%s%s%s_begin ( grid%%id, %s%s%s_begin )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
253 fprintf(fp," CALL nl_get_%s%s%s_begin_y( grid%%id, %s%s%s_begin_y )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
254 fprintf(fp," CALL nl_get_%s%s%s_begin_d( grid%%id, %s%s%s_begin_d )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
255 fprintf(fp," CALL nl_get_%s%s%s_begin_h( grid%%id, %s%s%s_begin_h )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
256 fprintf(fp," CALL nl_get_%s%s%s_begin_m( grid%%id, %s%s%s_begin_m )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
257 fprintf(fp," CALL nl_get_%s%s%s_begin_s( grid%%id, %s%s%s_begin_s )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
258 fprintf(fp," IF ( %s%s%s_begin_m .EQ. 0 ) %s%s%s_begin_m = %s%s%s_begin\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
259 fprintf(fp," IF ( MAX( %s%s%s_begin_y, %s%s%s_begin_d, &\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
260 fprintf(fp," %s%s%s_begin_h, %s%s%s_begin_m , %s%s%s_begin_s ) .GT. 0 ) THEN\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
261 fprintf(fp," CALL WRFU_TimeIntervalSet( begin_time , D=%s%s%s_begin_d, &\n",aux,streamtype,streamno) ;
262 fprintf(fp," H=%s%s%s_begin_h, M=%s%s%s_begin_m, S=%s%s%s_begin_s, rc=rc )\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
263 fprintf(fp," CALL wrf_check_error( WRFU_SUCCESS, rc, &\n") ;
264 fprintf(fp," 'WRFU_TimeIntervalSet(%s%s%s_begin) FAILED', &\n",aux,streamtype,streamno) ;
265 fprintf(fp," __FILE__ , &\n") ;
266 fprintf(fp," __LINE__ )\n") ;
267 fprintf(fp," ELSE\n") ;
268 fprintf(fp," begin_time = zero_time\n") ;
269 fprintf(fp," ENDIF\n") ;
270 fprintf(fp," CALL nl_get_%s%s%s_end( grid%%id, %s%s%s_end )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
271 fprintf(fp," CALL nl_get_%s%s%s_end_y( grid%%id, %s%s%s_end_y )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
272 fprintf(fp," CALL nl_get_%s%s%s_end_d( grid%%id, %s%s%s_end_d )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
273 fprintf(fp," CALL nl_get_%s%s%s_end_h( grid%%id, %s%s%s_end_h )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
274 fprintf(fp," CALL nl_get_%s%s%s_end_m( grid%%id, %s%s%s_end_m )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
275 fprintf(fp," CALL nl_get_%s%s%s_end_s( grid%%id, %s%s%s_end_s )\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
276 fprintf(fp," IF ( %s%s%s_end_m .EQ. 0 ) %s%s%s_end_m = %s%s%s_end\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
277 fprintf(fp," IF ( MAX( %s%s%s_end_y, %s%s%s_end_d, &\n",aux,streamtype,streamno,aux,streamtype,streamno) ;
278 fprintf(fp," %s%s%s_end_h, %s%s%s_end_m , %s%s%s_end_s ) .GT. 0 ) THEN\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
279 fprintf(fp," CALL WRFU_TimeIntervalSet( end_time , D=%s%s%s_end_d, &\n",aux,streamtype,streamno) ;
280 fprintf(fp," H=%s%s%s_end_h, M=%s%s%s_end_m, S=%s%s%s_end_s, rc=rc )\n",aux,streamtype,streamno,aux,streamtype,streamno,aux,streamtype,streamno) ;
281 fprintf(fp," CALL wrf_check_error( WRFU_SUCCESS, rc, &\n") ;
282 fprintf(fp," 'WRFU_TimeIntervalSet(%s%s%s_end) FAILED', &\n",aux,streamtype,streamno) ;
283 fprintf(fp," __FILE__ , &\n") ;
284 fprintf(fp," __LINE__ )\n") ;
285 fprintf(fp," ELSE\n") ;
286 fprintf(fp," end_time = run_length + padding_interval\n") ;
287 fprintf(fp," ENDIF\n") ;
288 fprintf(fp," CALL domain_alarm_create( grid, %s%s%s_ALARM, interval, begin_time, end_time )\n",aux,streamtype,streamno) ;
289 #if 0
290 fprintf(fp," IF ( interval .NE. run_length + padding_interval .AND. begin_time .EQ. zero_time ) THEN\n") ;
291 #else
292 fprintf(fp," IF ( interval .NE. padding_interval .AND. begin_time .EQ. zero_time ) THEN\n") ;
293 #endif
294 fprintf(fp," CALL WRFU_AlarmRingerOn( grid%%alarms( %s%s%s_ALARM ), rc=rc )\n",aux,streamtype,streamno) ;
295 fprintf(fp," CALL wrf_check_error( WRFU_SUCCESS, rc, &\n") ;
296 fprintf(fp," 'WRFU_AlarmRingerOn(%s%s%s_ALARM) FAILED', &\n",aux,streamtype,streamno) ;
297 fprintf(fp," __FILE__ , &\n") ;
298 fprintf(fp," __LINE__ )\n") ;
299 fprintf(fp," ENDIF\n") ;
301 return 0; /* SamT: bug fix: return a value */
305 gen_io_form_for_dataset ( FILE *fp )
307 char * aux , *streamtype , streamno[5] ;
308 int i ;
310 fprintf(fp," IF ( DataSet .eq. 'RESTART' ) THEN\n") ;
311 fprintf(fp," CALL nl_get_io_form_restart( 1, io_form )\n") ;
312 fprintf(fp," ELSE IF ( DataSet .eq. 'INPUT' ) THEN\n") ;
313 fprintf(fp," CALL nl_get_io_form_input( 1, io_form )\n") ;
314 fprintf(fp," ELSE IF ( DataSet .eq. 'HISTORY' ) THEN\n") ;
315 fprintf(fp," CALL nl_get_io_form_history( 1, io_form )\n") ;
316 fprintf(fp," ELSE IF ( DataSet .eq. 'BOUNDARY' ) THEN\n") ;
317 fprintf(fp," CALL nl_get_io_form_boundary( 1, io_form )\n") ;
318 for ( i = 1 ; i < MAX_HISTORY ; i++ )
320 sprintf(streamno,"%d",i) ;
321 fprintf(fp," ELSE IF ( DataSet .eq. 'AUXINPUT%s' ) THEN\n", streamno) ;
322 fprintf(fp," CALL nl_get_io_form_auxinput%s( 1, io_form )\n", streamno) ;
323 fprintf(fp," ELSE IF ( DataSet .eq. 'AUXHIST%s' ) THEN\n", streamno) ;
324 fprintf(fp," CALL nl_get_io_form_auxhist%s( 1, io_form )\n", streamno) ;
326 fprintf(fp," ELSE ! default if nothing is set in SysDepInfo; use history\n") ;
327 fprintf(fp," CALL nl_get_io_form_history( 1, io_form )\n") ;
328 fprintf(fp," ENDIF\n") ;
329 return 0; /* SamT: bug fix: return a value */
333 gen_io_form_for_stream ( FILE *fp )
335 char * aux , *streamtype , streamno[5] ;
336 int i ;
338 fprintf(fp," IF ( stream .eq. restart_only ) THEN\n") ;
339 fprintf(fp," CALL nl_get_io_form_restart( 1, io_form )\n") ;
340 fprintf(fp," ELSE IF ( stream .eq. input_only ) THEN\n") ;
341 fprintf(fp," CALL nl_get_io_form_input( 1, io_form )\n") ;
342 fprintf(fp," ELSE IF ( stream .eq. history_only ) THEN\n") ;
343 fprintf(fp," CALL nl_get_io_form_history( 1, io_form )\n") ;
344 fprintf(fp," ELSE IF ( stream .eq. boundary_only ) THEN\n") ;
345 fprintf(fp," CALL nl_get_io_form_boundary( 1, io_form )\n") ;
346 for ( i = 1 ; i < MAX_HISTORY ; i++ )
348 sprintf(streamno,"%d",i) ;
349 fprintf(fp," ELSE IF ( stream .eq. auxinput%s_only ) THEN\n", streamno) ;
350 fprintf(fp," CALL nl_get_io_form_auxinput%s( 1, io_form )\n", streamno) ;
351 fprintf(fp," ELSE IF ( stream .eq. auxhist%s_only ) THEN\n", streamno) ;
352 fprintf(fp," CALL nl_get_io_form_auxhist%s( 1, io_form )\n", streamno) ;
354 fprintf(fp," ELSE ! if no match then do the old service representative schtick\n") ;
355 fprintf(fp," CALL wrf_error_fatal('internal error: please contact wrfhelp@ucar.edu: io_form_for_stream.inc -- invalid stream number')\n") ;
356 fprintf(fp," ENDIF\n") ;
357 return 0; /* SamT: bug fix: return a value */
361 gen_switches_and_alarms ( FILE *fp )
363 char * aux , *streamtype , streamno[5] ;
364 int i ;
366 fprintf(fp,"INTEGER, PARAMETER :: history_only = 1\n") ;
367 fprintf(fp,"INTEGER, PARAMETER :: HISTORY_ALARM = history_only\n") ;
368 fprintf(fp,"INTEGER, PARAMETER :: input_only = %d\n",MAX_HISTORY+1) ;
369 fprintf(fp,"INTEGER, PARAMETER :: INPUT_ALARM = input_only ! not used\n") ;
370 for ( i = 1 ; i < MAX_HISTORY ; i++ )
372 fprintf(fp,"INTEGER, PARAMETER :: auxhist%d_only = %d\n",i,i+1) ;
373 fprintf(fp,"INTEGER, PARAMETER :: AUXHIST%d_ALARM = %d\n",i,i+1) ;
374 fprintf(fp,"INTEGER, PARAMETER :: auxinput%d_only = %d\n",i,MAX_HISTORY+i+1) ;
375 fprintf(fp,"INTEGER, PARAMETER :: AUXINPUT%d_ALARM = %d\n",i,MAX_HISTORY+i+1) ;
377 return 0; /* SamT: bug fix: return a value */
381 gen_check_auxstream_alarms ( FILE *fp )
383 char * aux , *streamtype , streamno[5] ;
384 int i ;
386 fprintf(fp,"! - AUX HISTORY OUTPUT\n") ;
387 for ( i = 1 ; i < MAX_HISTORY ; i++ )
389 fprintf(fp,"#ifndef DISABLE_ALARM_AUXHIST%d\n",i) ;
390 fprintf(fp," IF( WRFU_AlarmIsRinging( grid%%alarms( AUXHIST%d_ALARM ), rc=rc ) ) THEN\n",i) ;
391 fprintf(fp," CALL med_hist_out ( grid , %d, config_flags )\n",i) ;
392 fprintf(fp," CALL WRFU_AlarmRingerOff( grid%%alarms( AUXHIST%d_ALARM ), rc=rc )\n",i) ;
393 fprintf(fp," ENDIF\n") ;
394 fprintf(fp,"#endif\n") ;
396 fprintf(fp,"! - AUX INPUT INPUT\n") ;
397 for ( i = 1 ; i < MAX_HISTORY ; i++ )
399 fprintf(fp,"#ifndef DISABLE_ALARM_AUXINPUT%d\n",i) ;
400 fprintf(fp," IF( WRFU_AlarmIsRinging( grid%%alarms( AUXINPUT%d_ALARM ), rc=rc ) ) THEN\n",i) ;
401 fprintf(fp," CALL med_auxinput%d_in ( grid , config_flags )\n",i) ;
402 fprintf(fp," WRITE ( message , FMT='(A,A,A,i3)' ) 'Input data processed for ' , &\n") ;
403 fprintf(fp," TRIM(config_flags%%auxinput%d_inname) , ' for domain ',grid%%id\n",i) ;
404 fprintf(fp," CALL wrf_debug ( 0 , message )\n") ;
405 fprintf(fp," CALL WRFU_AlarmRingerOff( grid%%alarms( AUXINPUT%d_ALARM ), rc=rc )\n",i) ;
406 fprintf(fp," ENDIF\n") ;
407 fprintf(fp,"#endif\n") ;
409 return 0; /* SamT: bug fix: return a value */
413 gen_fine_stream_input ( FILE *fp )
415 char * aux , *streamtype , streamno[5] ;
416 int i ;
417 fprintf(fp,"IF ( ( grid%%id .EQ. 1 ) .OR. ( config_flags%%fine_input_stream .EQ. 0 ) ) THEN\n") ;
418 fprintf(fp," CALL wrf_debug ( 0 , 'med_initialdata_input: calling input_input' )\n") ;
419 fprintf(fp," CALL input_input ( fid , grid , config_flags , ierr )\n") ;
420 fprintf(fp," CALL wrf_debug ( 100 , 'med_initialdata_input: back from input_input' )\n") ;
421 for ( i = 1 ; i < MAX_HISTORY ; i++ )
423 fprintf(fp,"ELSE IF ( config_flags%%fine_input_stream .EQ. %d ) THEN\n",i) ;
424 fprintf(fp," CALL wrf_debug ( 0 , 'med_initialdata_input: calling input_auxinput%d' )\n",i) ;
425 fprintf(fp," CALL input_auxinput%d ( fid , grid , config_flags , ierr )\n",i) ;
426 fprintf(fp," CALL wrf_debug ( 100 , 'med_initialdata_input: back from input_auxinput%d' )\n",i) ;
428 fprintf(fp,"ELSE\n") ;
429 fprintf(fp," WRITE( message , '(\"med_initialdata_input: bad fine_input_stream = \",I4)') config_flags%%fine_input_stream\n") ;
430 fprintf(fp," CALL WRF_ERROR_FATAL ( message )\n") ;
431 fprintf(fp,"END IF\n") ;
432 return 0; /* SamT: bug fix: return a value */
436 gen_med_auxinput_in ( FILE *fp )
438 char * aux , *streamtype , streamno[5] ;
439 int i ;
440 for ( i = 1 ; i < MAX_HISTORY ; i++ )
442 fprintf(fp," CASE ( AUXINPUT%d_ALARM )\n",i) ;
443 fprintf(fp," CALL open_aux_u( grid, config_flags, stream, AUXINPUT%d_ALARM, &\n",i) ;
444 fprintf(fp," config_flags%%auxinput%d_inname, grid%%auxinput%d_oid, &\n",i,i) ;
445 fprintf(fp," input_auxinput%d, ierr )\n",i) ;
446 fprintf(fp," CALL input_auxinput%d ( grid%%auxinput%d_oid, grid , config_flags , ierr )\n",i,i) ;
448 return 0; /* SamT: bug fix: return a value */
452 gen_med_hist_out_opens ( FILE *fp )
454 char * aux , *streamtype , streamno[5] ;
455 int i ;
456 for ( i = 1 ; i < MAX_HISTORY ; i++ )
458 fprintf(fp," CASE ( AUXHIST%d_ALARM )\n",i) ;
459 fprintf(fp," CALL open_hist_w( grid, config_flags, stream, AUXHIST%d_ALARM, &\n",i) ;
460 fprintf(fp," config_flags%%auxhist%d_outname, grid%%auxhist%d_oid, &\n",i,i) ;
461 fprintf(fp," output_auxhist%d, fname, n2, ierr )\n",i) ;
462 fprintf(fp," CALL output_auxhist%d ( grid%%auxhist%d_oid, grid , config_flags , ierr )\n",i,i) ;
464 return 0; /* SamT: bug fix: return a value */
468 gen_med_hist_out_closes ( FILE *fp )
470 char * aux , *streamtype , streamno[5] ;
471 int i ;
472 for ( i = 1 ; i < MAX_HISTORY ; i++ )
474 fprintf(fp," CASE ( AUXHIST%d_ALARM )\n",i) ;
475 fprintf(fp," IF ( grid%%nframes(stream) >= config_flags%%frames_per_auxhist%d ) THEN\n",i) ;
476 fprintf(fp," CALL close_dataset ( grid%%auxhist%d_oid , config_flags , n2 )\n",i) ;
477 fprintf(fp," grid%%auxhist%d_oid = 0\n",i) ;
478 fprintf(fp," grid%%nframes(stream) = 0\n") ;
479 fprintf(fp," ENDIF\n") ;
481 return 0; /* SamT: bug fix: return a value */
485 gen_med_auxinput_in_closes ( FILE *fp )
487 char * aux , *streamtype , streamno[5] ;
488 int i ;
489 for ( i = 1 ; i < MAX_HISTORY ; i++ ) /* the number of history is the same as the number of input and MAX_INPUT collides with system definitions */
491 fprintf(fp," CASE ( AUXINPUT%d_ALARM )\n",i) ;
492 fprintf(fp," IF ( grid%%nframes(stream) >= config_flags%%frames_per_auxinput%d ) THEN\n",i) ;
493 fprintf(fp," CALL close_dataset ( grid%%auxinput%d_oid , config_flags , \"DATASET=AUXINPUT%d\" )\n",i,i) ;
494 fprintf(fp," grid%%auxinput%d_oid = 0\n",i) ;
495 fprintf(fp," grid%%nframes(stream) = 0\n") ;
496 fprintf(fp," ENDIF\n") ;
498 return 0; /* SamT: bug fix: return a value */
502 gen_med_last_solve_io ( FILE *fp )
504 char * aux , *streamtype , streamno[5] ;
505 int i ;
506 for ( i = 1 ; i < MAX_HISTORY ; i++ )
508 fprintf(fp," IF( WRFU_AlarmIsRinging( grid%%alarms( AUXHIST%d_ALARM ), rc=rc ) ) THEN\n",i) ;
509 #if ( WRFPLUS == 1 )
510 if ( i == 6 || i == 8 ) fprintf(fp," IF ( .NOT. grid%%trajectory_io ) THEN\n") ;
511 fprintf(fp," CALL med_hist_out ( grid , AUXHIST%d_ALARM , config_flags )\n",i) ;
512 if ( i == 6 || i == 8 ) fprintf(fp," ELSE\n") ;
513 if ( i == 6 || i == 8 ) fprintf(fp," CALL domain_clock_get ( grid, current_timestr=message )\n") ;
514 if ( i == 6 ) fprintf(fp," CALL save_xtraj ( message )\n") ;
515 if ( i == 8 ) fprintf(fp," IF ( config_flags%%dyn_opt .EQ. dyn_em_tl .and. .not. config_flags%%tl_standalone ) THEN\n") ;
516 if ( i == 8 ) fprintf(fp," CALL save_tl_pert ( message )\n") ;
517 if ( i == 8 ) fprintf(fp," ELSEIF ( config_flags%%dyn_opt .EQ. dyn_em_tl .and. config_flags%%tl_standalone ) THEN\n") ;
518 if ( i == 8 ) fprintf(fp," CALL med_hist_out ( grid , AUXHIST%d_ALARM , config_flags )\n",i) ;
519 if ( i == 8 ) fprintf(fp," ENDIF\n") ;
520 if ( i == 6 || i == 8 ) fprintf(fp," ENDIF\n") ;
521 #else
522 fprintf(fp," CALL med_hist_out ( grid , AUXHIST%d_ALARM , config_flags )\n",i) ;
523 #endif
524 fprintf(fp," ENDIF\n") ;
526 return 0; /* SamT: bug fix: return a value */
530 gen_shutdown_closes ( FILE *fp )
532 char * aux , *streamtype , streamno[5] ;
533 int i ;
534 for ( i = 1 ; i < MAX_HISTORY ; i++ )
536 fprintf(fp,"IF( grid%%auxhist%d_oid > 0 ) CALL close_dataset ( grid%%auxhist%d_oid, config_flags, 'DATASET=AUXHIST%d' )\n",i,i,i) ;
538 return 0; /* SamT: bug fix: return a value */
541 /* generate the calls that main/wrf_ESMFMod.F uses in wrf_state_populate() */
542 int
543 gen_med_open_esmf_calls ( FILE *fp )
545 int i ;
546 for ( i = 1 ; i < MAX_HISTORY ; i++ )
548 fprintf(fp,"CALL nl_get_io_form_auxinput%d( 1, io_form )\n",i) ;
549 fprintf(fp,"IF ( use_package( io_form ) == IO_ESMF ) THEN\n") ;
550 fprintf(fp," stream = first_auxinput + %d\n",i-1) ;
551 fprintf(fp," CALL open_aux_u( grid, config_flags, stream, AUXINPUT%d_ALARM, &\n",i) ;
552 fprintf(fp," config_flags%%auxinput%d_inname, grid%%auxinput%d_oid, &\n",i,i) ;
553 fprintf(fp," input_auxinput%d, ierr )\n",i) ;
554 fprintf(fp," IF ( ierr /= 0 ) RETURN\n") ;
555 fprintf(fp,"ENDIF\n") ;
558 for ( i = 1 ; i < MAX_HISTORY ; i++ )
560 fprintf(fp,"CALL nl_get_io_form_auxhist%d( 1, io_form )\n",i) ;
561 fprintf(fp,"IF ( use_package( io_form ) == IO_ESMF ) THEN\n") ;
562 fprintf(fp," stream = first_auxhist + %d\n",i-1) ;
563 fprintf(fp," CALL open_hist_w( grid, config_flags, stream, AUXHIST%d_ALARM, &\n",i) ;
564 fprintf(fp," config_flags%%auxhist%d_outname, grid%%auxhist%d_oid, &\n",i,i) ;
565 fprintf(fp," output_auxhist%d, fname, n2, ierr )\n",i) ;
566 fprintf(fp," IF ( ierr /= 0 ) RETURN\n") ;
567 fprintf(fp,"ENDIF\n") ;
569 return 0; /* SamT: bug fix: return a value */
572 /* generate the calls that main/wrf_ESMFMod.F uses in wrf_state_populate() */
573 int
574 gen_med_find_esmf_coupling ( FILE *fp )
576 int i ;
577 for ( i = 1 ; i < MAX_HISTORY ; i++ )
579 fprintf(fp,"IF ( .NOT. foundcoupling ) THEN\n") ;
580 fprintf(fp," CALL nl_get_io_form_auxinput%d( 1, io_form )\n",i) ;
581 fprintf(fp," IF ( use_package( io_form ) == IO_ESMF ) THEN\n") ;
582 fprintf(fp," CALL ESMF_AlarmGet( head_grid%%alarms( AUXINPUT%d_ALARM ), &\n",i) ;
583 fprintf(fp," RingInterval=couplingInterval, rc=rc )\n") ;
584 fprintf(fp," IF ( rc /= ESMF_SUCCESS ) THEN\n") ;
585 fprintf(fp," CALL wrf_error_fatal ( 'wrf_findCouplingInterval: ESMF_AlarmGet(AUXINPUT%d_ALARM) failed' )\n",i) ;
586 fprintf(fp," ENDIF\n") ;
587 fprintf(fp," foundcoupling = .TRUE.\n") ;
588 fprintf(fp," ENDIF\n") ;
589 fprintf(fp,"ENDIF\n") ;
590 fprintf(fp,"IF ( .NOT. foundcoupling ) THEN\n") ;
591 fprintf(fp," CALL nl_get_io_form_auxhist%d( 1, io_form )\n",i) ;
592 fprintf(fp," IF ( use_package( io_form ) == IO_ESMF ) THEN\n") ;
593 fprintf(fp," CALL ESMF_AlarmGet( head_grid%%alarms( AUXHIST%d_ALARM ), &\n",i) ;
594 fprintf(fp," RingInterval=couplingInterval, rc=rc )\n") ;
595 fprintf(fp," IF ( rc /= ESMF_SUCCESS ) THEN\n") ;
596 fprintf(fp," CALL wrf_error_fatal ( 'wrf_findCouplingInterval: ESMF_AlarmGet(AUXHIST%d_ALARM) failed' )\n",i) ;
597 fprintf(fp," ENDIF\n") ;
598 fprintf(fp," foundcoupling = .TRUE.\n") ;
599 fprintf(fp," ENDIF\n") ;
600 fprintf(fp,"ENDIF\n") ;
602 return 0; /* SamT: bug fix: return a value */
607 This one is special; it gets called before the registry actually runs and produces a file
608 that defines a lot of per-stream variables, mostly rconfig but also the oid state variables
609 for each stream. This file is then included by the registry.io_boilerplate file when the
610 registry actually runs. As with the other mods above, this allows a variable, compile-time
611 number of io streams. Note that this one is self contained and dirname is hard-coded.
614 gen_io_boilerplate ()
616 FILE * fp ;
617 char * dirname = "Registry" ;
618 char fname[NAMELEN] ;
619 char * fn ;
620 char * aux , *streamtype , streamno[5] ;
621 char * howset = "namelist,time_control" ;
622 char * maxd = "max_domains" ;
623 int i, j ;
625 fn = "io_boilerplate_temporary.inc" ;
626 if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
627 else { sprintf(fname,"%s",fn) ; }
628 if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
629 print_warning(fp,fname) ;
631 fprintf(fp,"rconfig logical override_restart_timers namelist,time_control 1 .false.\n") ;
632 for ( j = 0 ; j < 2 ; j++ ) { /* j=0 is hist, j=1 is input */
633 streamtype = (j==0)?"hist":"input" ;
634 for ( i = 1 ; i < MAX_HISTORY ; i++ )
636 fprintf(fp,"state integer aux%s%d_oid - - - - - \"\" \"\" \"\"\n",streamtype,i) ;
637 fprintf(fp,"rconfig character aux%s%d_inname %s %s \"aux%s%d_d<domain>_<date>\"\n",streamtype,i,howset,"1",streamtype,i) ;
638 fprintf(fp,"rconfig character aux%s%d_outname %s %s \"aux%s%d_d<domain>_<date>\"\n",streamtype,i,howset,"1",streamtype,i) ;
639 fprintf(fp,"rconfig integer aux%s%d_interval_y %s %s 0\n",streamtype,i,howset,maxd) ;
640 fprintf(fp,"rconfig integer aux%s%d_interval_d %s %s 0\n",streamtype,i,howset,maxd) ;
641 fprintf(fp,"rconfig integer aux%s%d_interval_h %s %s 0\n",streamtype,i,howset,maxd) ;
642 fprintf(fp,"rconfig integer aux%s%d_interval_m %s %s 0\n",streamtype,i,howset,maxd) ;
643 fprintf(fp,"rconfig integer aux%s%d_interval_s %s %s 0\n",streamtype,i,howset,maxd) ;
644 fprintf(fp,"rconfig integer aux%s%d_interval %s %s 0\n",streamtype,i,howset,maxd) ;
645 fprintf(fp,"rconfig integer aux%s%d_begin_y %s %s 0\n",streamtype,i,howset,maxd) ;
646 fprintf(fp,"rconfig integer aux%s%d_begin_d %s %s 0\n",streamtype,i,howset,maxd) ;
647 fprintf(fp,"rconfig integer aux%s%d_begin_h %s %s 0\n",streamtype,i,howset,maxd) ;
648 fprintf(fp,"rconfig integer aux%s%d_begin_m %s %s 0\n",streamtype,i,howset,maxd) ;
649 fprintf(fp,"rconfig integer aux%s%d_begin_s %s %s 0\n",streamtype,i,howset,maxd) ;
650 fprintf(fp,"rconfig integer aux%s%d_begin %s %s 0\n",streamtype,i,howset,maxd) ;
651 fprintf(fp,"rconfig integer aux%s%d_end_y %s %s 0\n",streamtype,i,howset,maxd) ;
652 fprintf(fp,"rconfig integer aux%s%d_end_d %s %s 0\n",streamtype,i,howset,maxd) ;
653 fprintf(fp,"rconfig integer aux%s%d_end_h %s %s 0\n",streamtype,i,howset,maxd) ;
654 fprintf(fp,"rconfig integer aux%s%d_end_m %s %s 0\n",streamtype,i,howset,maxd) ;
655 fprintf(fp,"rconfig integer aux%s%d_end_s %s %s 0\n",streamtype,i,howset,maxd) ;
656 fprintf(fp,"rconfig integer aux%s%d_end %s %s 0\n",streamtype,i,howset,maxd) ;
657 fprintf(fp,"rconfig integer io_form_aux%s%d %s %s 0\n",streamtype,i,howset,"1") ;
658 fprintf(fp,"rconfig integer frames_per_aux%s%d %s %s 999999\n",streamtype,i,howset,maxd) ;
662 close_the_file( fp ) ;
663 return 0; /* SamT: bug fix: return a value */