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