PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/tools/gen_streams.c

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