forked from wrf-model/WRF
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodule_io.F
4502 lines (4194 loc) · 185 KB
/
module_io.F
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!WRF:DRIVER_LAYER:IO
!
#define DEBUG_LVL 500
MODULE module_io
!<DESCRIPTION>
!<PRE>
! WRF-specific package-independent interface to package-dependent WRF-specific
! I/O packages.
!
! These routines have the same names as those specified in the WRF I/O API
! except that:
! - Routines defined in this file and called by users of this module have
! the "wrf_" prefix.
! - Routines defined in the I/O packages and called from routines in this
! file have the "ext_" prefix.
! - Routines called from routines in this file to initiate communication
! with I/O quilt servers have the "wrf_quilt_" prefix.
!
! See http://www.mmm.ucar.edu/wrf/WG2/software_2.0/IOAPI.doc for the latest
! version of the WRF I/O API. This document includes detailed descriptions
! of subroutines and their arguments that are not duplicated in this file.
!
! We wish to be able to link to different packages depending on whether
! the I/O is restart, initial, history, or boundary.
!</PRE>
!</DESCRIPTION>
USE module_configure
LOGICAL :: is_inited = .FALSE.
INTEGER, PARAMETER, PRIVATE :: MAX_WRF_IO_HANDLE = 1000
INTEGER :: wrf_io_handles(MAX_WRF_IO_HANDLE)
INTEGER :: how_opened(MAX_WRF_IO_HANDLE)
LOGICAL :: for_output(MAX_WRF_IO_HANDLE), first_operation(MAX_WRF_IO_HANDLE)
INTEGER :: filtno = 0
LOGICAL, PRIVATE :: bdy_dist_flag = .TRUE. ! false is old style undecomposed boundary data structs,
! true is new style decomposed boundary data structs
! are_bdys_distributed, bdys_are_distributed and
! bdys_not_distributed routines access this flag
CHARACTER*256 extradims
!<DESCRIPTION>
!<PRE>
!
! include the file generated from md_calls.m4 using the m4 preprocessor
! note that this file also includes the CONTAINS declaration for the module
!
!</PRE>
!</DESCRIPTION>
#include "md_calls.inc"
!--- registry-generated routine that gets the io format being used for a dataset
INTEGER FUNCTION io_form_for_dataset ( DataSet )
IMPLICIT NONE
CHARACTER*(*), INTENT(IN) :: DataSet
INTEGER :: io_form
#include "io_form_for_dataset.inc"
io_form_for_dataset = io_form
RETURN
END FUNCTION io_form_for_dataset
INTEGER FUNCTION io_form_for_stream ( stream )
USE module_streams
IMPLICIT NONE
INTEGER, INTENT(IN) :: stream
INTEGER :: io_form
#include "io_form_for_stream.inc"
io_form_for_stream = io_form
RETURN
END FUNCTION io_form_for_stream
!--- ioinit
SUBROUTINE wrf_ioinit( Status )
!<DESCRIPTION>
!<PRE>
! Initialize the WRF I/O system.
!</PRE>
!</DESCRIPTION>
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: Status
!Local
CHARACTER(len=80) :: SysDepInfo
INTEGER :: ierr(100), minerr, maxerr
!
Status = 0
ierr = 0
SysDepInfo = " "
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_ioinit' )
CALL init_io_handles ! defined below
#ifdef NETCDF
if ( model_config_rec%use_netcdf_classic ) SysDepInfo="use_netcdf_classic"
CALL ext_ncd_ioinit ( SysDepInfo, ierr( 1) )
SysDepInfo = " "
#endif
#ifdef INTIO
CALL ext_int_ioinit ( SysDepInfo, ierr( 2) )
#endif
#ifdef PHDF5
CALL ext_phdf5_ioinit( SysDepInfo, ierr( 3) )
#endif
#ifdef XXX
CALL ext_xxx_ioinit ( SysDepInfo, ierr( 5) )
#endif
#ifdef YYY
CALL ext_yyy_ioinit ( SysDepInfo, ierr( 6) )
#endif
#ifdef ZZZ
CALL ext_zzz_ioinit ( SysDepInfo, ierr( 7) )
#endif
#ifdef ESMFIO
CALL ext_esmf_ioinit ( SysDepInfo, ierr( 8) )
#endif
#ifdef GRIB1
CALL ext_gr1_ioinit ( SysDepInfo, ierr( 9) )
#endif
#ifdef GRIB2
CALL ext_gr2_ioinit ( SysDepInfo, ierr(10) )
#endif
#ifdef PNETCDF
CALL ext_pnc_ioinit ( SysDepInfo, ierr(11) )
#endif
#ifdef PIO
CALL ext_pio_ioinit ( SysDepInfo, ierr(12) )
#endif
#ifdef NETCDFPAR
CALL ext_ncdpar_ioinit( SysDepInfo, ierr(13) )
#endif
#ifdef ADIOS2
CALL ext_adios2_ioinit ( SysDepInfo, ierr(14) )
#endif
minerr = MINVAL(ierr)
maxerr = MAXVAL(ierr)
IF ( minerr < 0 ) THEN
Status = minerr
ELSE IF ( maxerr > 0 ) THEN
Status = maxerr
ELSE
Status = 0
ENDIF
END SUBROUTINE wrf_ioinit
!--- ioexit
SUBROUTINE wrf_ioexit( Status )
!<DESCRIPTION>
!<PRE>
! Shut down the WRF I/O system.
!</PRE>
!</DESCRIPTION>
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: Status
!Local
LOGICAL, EXTERNAL :: use_output_servers
INTEGER :: ierr(100), minerr, maxerr
!
Status = 0
ierr = 0
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_ioexit' )
#ifdef NETCDF
CALL ext_ncd_ioexit ( ierr( 1) )
#endif
#ifdef INTIO
CALL ext_int_ioexit ( ierr( 2) )
#endif
#ifdef PHDF5
CALL ext_phdf5_ioexit( ierr( 3) )
#endif
#ifdef XXX
CALL ext_xxx_ioexit ( ierr( 5) )
#endif
#ifdef YYY
CALL ext_yyy_ioexit ( ierr( 6) )
#endif
#ifdef ZZZ
CALL ext_zzz_ioexit ( ierr( 7) )
#endif
#ifdef ESMFIO
CALL ext_esmf_ioexit ( ierr( 8) )
#endif
#ifdef GRIB1
CALL ext_gr1_ioexit ( ierr( 9) )
#endif
#ifdef GRIB2
CALL ext_gr2_ioexit ( ierr(10) )
#endif
#ifdef PNETCDF
CALL ext_pnc_ioexit ( ierr(11) )
#endif
#ifdef PIO
CALL ext_pio_ioexit ( ierr(12) )
#endif
#ifdef NETCDFPAR
CALL ext_ncdpar_ioexit ( ierr(13) )
#endif
#ifdef ADIOS2
CALL ext_adios2_ioexit ( ierr(14) )
#endif
IF ( use_output_servers() ) THEN
CALL wrf_quilt_ioexit( ierr(11) )
ENDIF
minerr = MINVAL(ierr)
maxerr = MAXVAL(ierr)
IF ( minerr < 0 ) THEN
Status = minerr
ELSE IF ( maxerr > 0 ) THEN
Status = maxerr
ELSE
Status = 0
ENDIF
END SUBROUTINE wrf_ioexit
!--- open_for_write_begin
SUBROUTINE wrf_open_for_write_begin( FileName , grid, SysDepInfo, &
DataHandle , Status )
!<DESCRIPTION>
!<PRE>
! Begin data definition ("training") phase for writing to WRF dataset
! FileName.
!</PRE>
!</DESCRIPTION>
USE module_state_description
USE module_domain
#ifdef DM_PARALLEL
USE module_dm, ONLY : ntasks_x, mytask_x, local_communicator_x
#endif
IMPLICIT NONE
#include "wrf_io_flags.h"
CHARACTER*(*) :: FileName
type(domain) :: grid
CHARACTER*(*), INTENT(INOUT):: SysDepInfo
INTEGER , INTENT(OUT) :: DataHandle
INTEGER , INTENT(OUT) :: Status
!Local
CHARACTER*128 :: DataSet
INTEGER :: io_form
INTEGER :: Hndl
INTEGER, EXTERNAL :: use_package
LOGICAL, EXTERNAL :: wrf_dm_on_monitor, multi_files
LOGICAL, EXTERNAL :: use_output_servers_for
CHARACTER*512 :: LocFilename ! for appending the process ID if necessary
INTEGER :: myproc
CHARACTER*512 :: mess
CHARACTER (LEN=256) :: message
CHARACTER*1028 :: tstr, t1
INTEGER :: i,j
INTEGER :: Comm_compute , Comm_io
LOGICAL ncd_nofill
WRITE(mess,*) 'module_io.F: in wrf_open_for_write_begin, FileName = ',TRIM(FileName)
CALL wrf_debug( 100, mess )
Comm_compute = grid%communicator
Comm_io = grid%iocommunicator
CALL get_value_from_pairs ( "DATASET" , SysDepInfo , DataSet )
CALL nl_get_ncd_nofill( 1 , ncd_nofill )
io_form = io_form_for_dataset( DataSet )
Status = 0
Hndl = -1
IF ( .not. use_output_servers_for(io_form) ) THEN
SELECT CASE ( use_package(io_form) )
#ifdef NETCDF
CASE ( IO_NETCDF )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
IF ( ncd_nofill ) THEN
CALL ext_ncd_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo // ",NOFILL=.TRUE.", &
Hndl , Status )
ELSE
CALL ext_ncd_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
ENDIF
#endif
#ifdef NETCDFPAR
CASE ( IO_NETCDFPAR )
IF ( ncd_nofill ) THEN
CALL wrf_debug ( 100 , 'calling ext_ncdpar_open_for_write_begin 1' )
CALL ext_ncdpar_open_for_write_begin ( FileName , Comm_compute, Comm_io, SysDepInfo // ",NOFILL=.TRUE.", &
Hndl , Status )
WRITE ( message , '("after ext_ncdpar_open_for_write_begin 1: status = ",i8)') status
CALL wrf_debug ( 100 , message )
ELSE
CALL wrf_debug ( 100 , 'calling ext_ncdpar_open_for_write_begin 2' )
CALL ext_ncdpar_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
CALL wrf_debug ( 100 , 'after ext_ncdpar_open_for_write_begin 1' )
ENDIF
#endif
#ifdef ADIOS2
CASE (IO_ADIOS2 )
WRITE(tstr,"(A,',ADIOS ADIOS NTASKS_X=',i10,',MYTASK_X=',i10,',LOCAL_COMMUNICATOR_X=',i10)") &
TRIM(SysDepInfo),ntasks_x,mytask_x,local_communicator_x
j=1
t1 = " "
DO i=1,len(TRIM(tstr))
IF ( tstr(i:i) .NE. ' ' ) THEN
t1(j:j) = tstr(i:i)
j = j + 1
ENDIF
ENDDO
tstr = t1
CALL ext_adios2_open_for_write_begin( FileName, tstr, &
Dataset, Hndl, Status)
#endif
#ifdef PHDF5
CASE (IO_PHDF5 )
CALL ext_phdf5_open_for_write_begin( FileName, Comm_compute, Comm_io, SysDepInfo, &
Hndl, Status)
#endif
#ifdef PNETCDF
CASE (IO_PNETCDF )
WRITE(tstr,"(A,',NTASKS_X=',i10,',MYTASK_X=',i10,',LOCAL_COMMUNICATOR_X=',i10)") &
TRIM(SysDepInfo),ntasks_x,mytask_x,local_communicator_x
j=1
t1 = " "
DO i=1,len(TRIM(tstr))
IF ( tstr(i:i) .NE. ' ' ) THEN
t1(j:j) = tstr(i:i)
j = j + 1
ENDIF
ENDDO
tstr = t1
CALL ext_pnc_open_for_write_begin( FileName, Comm_compute, Comm_io, tstr, &
Hndl, Status)
#endif
#ifdef PIO
CASE ( IO_PIO )
WRITE(tstr,"(A,',NTASKS_X=',i10,',MYTASK_X=',i10,',LOCAL_COMMUNICATOR_X=',i10)") &
TRIM(SysDepInfo),ntasks_x,mytask_x,local_communicator_x
j=1
t1 = " "
DO i=1,len(TRIM(tstr))
IF ( tstr(i:i) .NE. ' ' ) THEN
t1(j:j) = tstr(i:i)
j = j + 1
ENDIF
ENDDO
tstr = t1
CALL ext_pio_open_for_write_begin( FileName, grid, tstr, Hndl, Status)
#endif
#ifdef XXX
CASE ( IO_XXX )
CALL ext_xxx_open_for_write_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef YYY
CASE ( IO_YYY )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_yyy_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
ENDIF
#endif
#ifdef ZZZ
CASE ( IO_ZZZ )
CALL ext_zzz_open_for_write_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef GRIB1
CASE ( IO_GRIB1 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr1_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
ENDIF
#endif
#ifdef GRIB2
CASE ( IO_GRIB2 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr2_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
ENDIF
#endif
#ifdef ESMFIO
CASE ( IO_ESMF )
CALL ext_esmf_open_for_write_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef INTIO
CASE ( IO_INTIO )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_int_open_for_write_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
ENDIF
#endif
CASE DEFAULT
IF ( io_form .NE. 0 ) THEN
WRITE(mess,*)'Tried to open ',FileName,' writing: no valid io_form (',io_form,')'
CALL wrf_debug(1, mess)
Status = WRF_FILE_NOT_OPENED
ENDIF
END SELECT
ELSE ! use_output_servers_for(io_form)
IF ( io_form .GT. 0 ) THEN
IF ( ncd_nofill ) THEN
CALL wrf_quilt_open_for_write_begin ( FileName , grid%id, Comm_compute, Comm_io, TRIM(SysDepInfo) // ",NOFILL=.TRUE.", &
Hndl , io_form, Status )
ELSE
CALL wrf_quilt_open_for_write_begin ( FileName , grid%id, Comm_compute, Comm_io, SysDepInfo, &
Hndl , io_form, Status )
ENDIF
ENDIF
ENDIF
CALL add_new_handle( Hndl, io_form, .TRUE., DataHandle )
END SUBROUTINE wrf_open_for_write_begin
!--- open_for_write_commit
SUBROUTINE wrf_open_for_write_commit( DataHandle , Status )
!<DESCRIPTION>
!<PRE>
! This routine switches an internal flag to enable output for the data set
! referenced by DataHandle. The call to wrf_open_for_write_commit() must be
! paired with a call to wrf_open_for_write_begin().
!</PRE>
!</DESCRIPTION>
USE module_state_description
IMPLICIT NONE
INTEGER , INTENT(IN ) :: DataHandle
INTEGER , INTENT(OUT) :: Status
CHARACTER (128) :: DataSet
INTEGER :: io_form
INTEGER :: Hndl
LOGICAL :: for_out
INTEGER, EXTERNAL :: use_package
LOGICAL, EXTERNAL :: wrf_dm_on_monitor, multi_files, use_output_servers_for
#include "wrf_io_flags.h"
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_open_for_write_commit' )
Status = 0
CALL get_handle ( Hndl, io_form , for_out, DataHandle )
CALL set_first_operation( DataHandle )
IF ( Hndl .GT. -1 ) THEN
IF ( multi_files( io_form ) .OR. .NOT. (for_out .AND. use_output_servers_for(io_form)) ) THEN
SELECT CASE ( use_package(io_form) )
#ifdef NETCDF
CASE ( IO_NETCDF )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
CALL ext_ncd_open_for_write_commit ( Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
#endif
#ifdef NETCDFPAR
CASE ( IO_NETCDFPAR )
CALL ext_ncdpar_open_for_write_commit ( Hndl , Status )
#endif
#ifdef ESMFIO
CASE ( IO_ESMF )
CALL ext_esmf_open_for_write_commit ( Hndl , Status )
#endif
#ifdef PHDF5
CASE ( IO_PHDF5 )
CALL ext_phdf5_open_for_write_commit ( Hndl , Status )
#endif
#ifdef PNETCDF
CASE ( IO_PNETCDF )
CALL ext_pnc_open_for_write_commit ( Hndl , Status )
#endif
#ifdef ADIOS2
CASE ( IO_ADIOS2 )
CALL ext_adios2_open_for_write_commit ( Hndl , Status )
#endif
#ifdef PIO
CASE ( IO_PIO )
CALL ext_pio_open_for_write_commit ( Hndl , Status )
#endif
#ifdef XXX
CASE ( IO_XXX )
CALL ext_xxx_open_for_write_commit ( Hndl , Status )
#endif
#ifdef YYY
CASE ( IO_YYY )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
CALL ext_yyy_open_for_write_commit ( Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
#endif
#ifdef ZZZ
CASE ( IO_ZZZ )
CALL ext_zzz_open_for_write_commit ( Hndl , Status )
#endif
#ifdef GRIB1
CASE ( IO_GRIB1 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
CALL ext_gr1_open_for_write_commit ( Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
#endif
#ifdef GRIB2
CASE ( IO_GRIB2 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
CALL ext_gr2_open_for_write_commit ( Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
#endif
#ifdef INTIO
CASE ( IO_INTIO )
CALL ext_int_open_for_write_commit ( Hndl , Status )
#endif
CASE DEFAULT
Status = 0
END SELECT
ELSE IF ( io_form .GT. 0 .AND. for_out .AND. use_output_servers_for(io_form) ) THEN
CALL wrf_quilt_open_for_write_commit ( Hndl , Status )
ELSE
Status = 0
ENDIF
ELSE
Status = 0
ENDIF
RETURN
END SUBROUTINE wrf_open_for_write_commit
!--- open_for_read_begin
SUBROUTINE wrf_open_for_read_begin( FileName , grid, SysDepInfo, &
DataHandle , Status )
!<DESCRIPTION>
!<PRE>
! Begin data definition ("training") phase for reading from WRF dataset
! FileName.
!</PRE>
!</DESCRIPTION>
USE module_state_description
USE module_domain
IMPLICIT NONE
#include "wrf_io_flags.h"
CHARACTER*(*) :: FileName
TYPE (domain) :: grid
CHARACTER*(*) :: SysDepInfo
INTEGER , INTENT(OUT) :: DataHandle
INTEGER , INTENT(OUT) :: Status
CHARACTER*128 :: DataSet
INTEGER :: io_form
INTEGER :: Hndl
LOGICAL :: also_for_out
INTEGER, EXTERNAL :: use_package
LOGICAL, EXTERNAL :: wrf_dm_on_monitor, multi_files, use_output_servers_for
CHARACTER*128 :: LocFilename ! for appending the process ID if necessary
INTEGER myproc
CHARACTER*128 :: mess, fhand
CHARACTER*1028 :: tstr
INTEGER :: Comm_compute , Comm_io
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_open_for_read_begin' )
Comm_compute = grid%communicator
Comm_io = grid%iocommunicator
CALL get_value_from_pairs ( "DATASET" , SysDepInfo , DataSet )
io_form = io_form_for_dataset( DataSet )
Status = 0
Hndl = -1
also_for_out = .FALSE.
! IF ( .NOT. use_output_servers_for(io_form) ) THEN
SELECT CASE ( use_package(io_form) )
#ifdef NETCDF
CASE ( IO_NETCDF )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_ncd_open_for_read_begin ( LocFilename , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef NETCDFPAR
CASE ( IO_NETCDFPAR )
CALL ext_ncdpar_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef PNETCDF
CASE ( IO_PNETCDF )
CALL ext_pnc_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef ADIOS2
CASE ( IO_ADIOS2 )
CALL ext_adios2_open_for_read_begin ( FileName , SysDepInfo, &
Hndl , Status )
#endif
#ifdef PIO
CASE ( IO_PIO )
CALL ext_pio_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef XXX
CASE ( IO_XXX )
CALL ext_xxx_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef YYY
CASE ( IO_YYY )
CALL ext_yyy_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef ZZZ
CASE ( IO_ZZZ )
CALL ext_zzz_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef ESMFIO
CASE ( IO_ESMF )
also_for_out = .TRUE.
CALL ext_esmf_open_for_read_begin ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef GRIB1
CASE ( IO_GRIB1 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr1_open_for_read_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef GRIB2
CASE ( IO_GRIB2 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr2_open_for_read_begin ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef INTIO
CASE ( IO_INTIO )
#endif
CASE DEFAULT
IF ( io_form .NE. 0 ) THEN
WRITE(mess,*)'Tried to open ',FileName,' reading: no valid io_form (',io_form,')'
CALL wrf_message(mess)
ENDIF
Status = WRF_FILE_NOT_OPENED
END SELECT
! ELSE
! Status = 0
! ENDIF
CALL add_new_handle( Hndl, io_form, also_for_out, DataHandle )
END SUBROUTINE wrf_open_for_read_begin
!--- open_for_read_commit
SUBROUTINE wrf_open_for_read_commit( DataHandle , Status )
!<DESCRIPTION>
!<PRE>
! End "training" phase for WRF dataset FileName. The call to
! wrf_open_for_read_commit() must be paired with a call to
! wrf_open_for_read_begin().
!</PRE>
!</DESCRIPTION>
USE module_state_description
IMPLICIT NONE
INTEGER , INTENT(IN ) :: DataHandle
INTEGER , INTENT(OUT) :: Status
CHARACTER (128) :: DataSet
INTEGER :: io_form
INTEGER :: Hndl
LOGICAL :: for_out
INTEGER, EXTERNAL :: use_package
LOGICAL, EXTERNAL :: wrf_dm_on_monitor, multi_files, use_output_servers_for
#include "wrf_io_flags.h"
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_open_for_read_commit' )
Status = 0
CALL get_handle ( Hndl, io_form , for_out, DataHandle )
CALL set_first_operation( DataHandle )
IF ( Hndl .GT. -1 ) THEN
IF ( .NOT. (for_out .AND. use_output_servers_for(io_form)) ) THEN
SELECT CASE ( use_package(io_form) )
#ifdef NETCDF
CASE ( IO_NETCDF )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
CALL ext_ncd_open_for_read_commit ( Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
#endif
#ifdef ESMFIO
CASE ( IO_ESMF )
CALL ext_esmf_open_for_read_commit ( Hndl , Status )
#endif
#ifdef NETCDFPAR
CASE ( IO_NETCDFPAR )
CALL ext_ncdpar_open_for_read_commit ( Hndl , Status )
#endif
#ifdef PNETCDF
CASE ( IO_PNETCDF )
CALL ext_pnc_open_for_read_commit ( Hndl , Status )
#endif
#ifdef ADIOS2
CASE ( IO_ADIOS2 )
CALL ext_adios2_open_for_read_commit ( Hndl , Status )
#endif
#ifdef PIO
CASE ( IO_PIO )
CALL ext_pio_open_for_read_commit ( Hndl , Status )
#endif
#ifdef XXX
CASE ( IO_XXX )
CALL ext_xxx_open_for_read_commit ( Hndl , Status )
#endif
#ifdef YYY
CASE ( IO_YYY )
CALL ext_yyy_open_for_read_commit ( Hndl , Status )
#endif
#ifdef ZZZ
CASE ( IO_ZZZ )
CALL ext_zzz_open_for_read_commit ( Hndl , Status )
#endif
#ifdef GRIB1
CASE ( IO_GRIB1 )
CALL ext_gr1_open_for_read_commit ( Hndl , Status )
#endif
#ifdef GRIB2
CASE ( IO_GRIB2 )
CALL ext_gr2_open_for_read_commit ( Hndl , Status )
#endif
#ifdef INTIO
CASE ( IO_INTIO )
#endif
CASE DEFAULT
Status = 0
END SELECT
ELSE
Status = 0
ENDIF
ELSE
Status = WRF_FILE_NOT_OPENED
ENDIF
RETURN
END SUBROUTINE wrf_open_for_read_commit
!--- open_for_read
SUBROUTINE wrf_open_for_read ( FileName , grid, SysDepInfo, &
DataHandle , Status )
!<DESCRIPTION>
!<PRE>
! Opens a WRF dataset for reading.
!</PRE>
!</DESCRIPTION>
USE module_state_description
USE module_domain
IMPLICIT NONE
CHARACTER*(*) :: FileName
TYPE (domain) :: grid
CHARACTER*(*) :: SysDepInfo
INTEGER , INTENT(OUT) :: DataHandle
INTEGER , INTENT(OUT) :: Status
CHARACTER (128) :: DataSet, LocFileName
INTEGER :: io_form, myproc
INTEGER :: Hndl
INTEGER, EXTERNAL :: use_package
LOGICAL, EXTERNAL :: wrf_dm_on_monitor, multi_files, use_output_servers_for
INTEGER :: Comm_compute, Comm_io
CALL wrf_debug( DEBUG_LVL, 'module_io.F: in wrf_open_for_read' )
Comm_compute = grid%communicator
Comm_io = grid%iocommunicator
CALL get_value_from_pairs ( "DATASET" , SysDepInfo , DataSet )
io_form = io_form_for_dataset( DataSet )
Hndl = -1
Status = 0
SELECT CASE ( use_package(io_form) )
#ifdef NETCDF
CASE ( IO_NETCDF )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_ncd_open_for_read ( LocFilename , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef NETCDFPAR
CASE ( IO_NETCDFPAR )
CALL ext_ncdpar_open_for_read ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef PNETCDF
CASE ( IO_PNETCDF )
CALL ext_pnc_open_for_read ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef ADIOS2
CASE ( IO_ADIOS2 )
CALL ext_adios2_open_for_read ( FileName , SysDepInfo, &
Hndl , Status )
#endif
#ifdef PIO
CASE ( IO_PIO )
CALL ext_pio_open_for_read ( FileName , grid, SysDepInfo, Hndl , Status )
#endif
#ifdef PHDF5
CASE ( IO_PHDF5 )
CALL ext_phdf5_open_for_read ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef XXX
CASE ( IO_XXX )
CALL ext_xxx_open_for_read ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef YYY
CASE ( IO_YYY )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_yyy_open_for_read ( LocFilename , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef ZZZ
CASE ( IO_ZZZ )
CALL ext_zzz_open_for_read ( FileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
#endif
#ifdef GRIB1
CASE ( IO_GRIB1 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr1_open_for_read ( LocFilename , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef GRIB2
CASE ( IO_GRIB2 )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_gr2_open_for_read ( LocFilename , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
#ifdef INTIO
CASE ( IO_INTIO )
IF ( multi_files(io_form) .OR. wrf_dm_on_monitor() ) THEN
IF ( multi_files(io_form) ) THEN
CALL wrf_get_myproc ( myproc )
CALL append_to_filename ( LocFilename , FileName , myproc, 4 )
ELSE
LocFilename = FileName
ENDIF
CALL ext_int_open_for_read ( LocFileName , Comm_compute, Comm_io, SysDepInfo, &
Hndl , Status )
ENDIF
IF ( .NOT. multi_files(io_form) ) THEN
CALL wrf_dm_bcast_bytes( Status, IWORDSIZE )
CALL wrf_dm_bcast_bytes( Hndl, IWORDSIZE )
ENDIF
#endif
CASE DEFAULT
Status = 0
END SELECT
CALL add_new_handle( Hndl, io_form, .FALSE., DataHandle )
RETURN
END SUBROUTINE wrf_open_for_read
!--- inquire_opened
SUBROUTINE wrf_inquire_opened ( DataHandle, FileName , FileStatus, Status )
!<DESCRIPTION>
!<PRE>
! Inquire if the dataset referenced by DataHandle is open.
!</PRE>
!</DESCRIPTION>