1 !*----------------------------------------------------------------------------
4 !* Author: Michael Laufer
5 !* Toga Networks, a Huawei Company
6 !* michael.laufer@toganetworks.com
8 !* Computer Science Department, The Jerusalem College of Technology
10 !* Toga Networks, a Huawei Company
11 !* erick.fredj@toganetworks.com
13 !* Date: November 3, 2021
15 !*----------------------------------------------------------------------------
17 module wrf_data_adios2
19 integer , parameter :: FATAL = 0
20 integer , parameter :: WARN = 0
21 integer , parameter :: WrfDataHandleMax = 99
22 integer , parameter :: MaxDims = 2000 ! = NF_MAX_VARS
23 integer , parameter :: MaxVars = 3000
24 integer , parameter :: MaxTimes = 60000
25 integer , parameter :: DateStrLen = 19
26 integer , parameter :: VarNameLen = 31
27 integer , parameter :: NO_DIM = 0
28 integer , parameter :: NVarDims = 3 !down from 4, as time is dealt with as "steps" in ADIOS2
29 integer , parameter :: NMDVarDims = 2
30 character (8) , parameter :: NO_NAME = 'NULL'
31 character (DateStrLen) , parameter :: ZeroDate = '0000-00-00-00:00:00'
32 #include "wrf_io_flags.h"
33 character (256) :: msg
34 logical :: WrfIOnotInitialized = .true.
35 type(adios2_adios) :: adios
37 type :: wrf_data_handle
38 character (255) :: FileName
42 character (5) :: TimesName
44 integer :: CurrentTime !Only used for read
45 integer :: NumberTimes !Only used for read
46 character (DateStrLen), pointer :: Times(:)
47 type(adios2_variable) :: TimesVarID
48 integer , pointer :: DimLengths(:)
49 type(adios2_attribute), pointer :: DimIDs(:)
50 character (31) , pointer :: DimNames(:)
51 type(adios2_attribute) :: DimUnlimID
52 character (9) :: DimUnlimName
53 type(adios2_attribute), dimension(NVarDims) :: DimID
54 integer , dimension(NVarDims) :: Dimension
55 type(adios2_variable), pointer :: MDVarIDs(:)
56 integer , pointer :: MDVarDimLens(:)
57 character (80) , pointer :: MDVarNames(:)
58 type(adios2_variable) , pointer :: VarIDs(:)
59 integer , pointer :: VarDimLens(:,:)
60 character (VarNameLen), pointer :: VarNames(:)
61 integer :: CurrentVariable !Only used for read
63 ! first_operation is set to .TRUE. when a new handle is allocated
64 ! or when open-for-write or open-for-read are committed. It is set
65 ! to .FALSE. when the first field is read or written.
66 logical :: first_operation
67 type(adios2_io) :: adios2IO
68 type(adios2_engine) :: adios2Engine
69 type(adios2_operator) :: compress_operator
70 character(32) :: blosc_compressor
71 end type wrf_data_handle
72 type(wrf_data_handle),target :: WrfDataHandles(WrfDataHandleMax)
73 end module wrf_data_adios2
75 module ext_adios2_support_routines
82 subroutine allocHandle(DataHandle,DH,Status)
84 include 'wrf_status_codes.h'
85 integer ,intent(out) :: DataHandle
86 type(wrf_data_handle),pointer :: DH
87 integer ,intent(out) :: Status
91 do i=1,WrfDataHandleMax
92 if(WrfDataHandles(i)%Free) then
93 DH => WrfDataHandles(i)
95 allocate(DH%Times(MaxTimes), STAT=stat)
97 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
98 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
99 call wrf_debug ( FATAL , msg)
102 allocate(DH%DimLengths(MaxDims), STAT=stat)
104 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
105 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
106 call wrf_debug ( FATAL , msg)
109 allocate(DH%DimIDs(MaxDims), STAT=stat)
111 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
112 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
113 call wrf_debug ( FATAL , msg)
116 allocate(DH%DimNames(MaxDims), STAT=stat)
118 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
119 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
120 call wrf_debug ( FATAL , msg)
123 allocate(DH%MDVarIDs(MaxVars), STAT=stat)
125 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
126 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
127 call wrf_debug ( FATAL , msg)
130 allocate(DH%MDVarDimLens(MaxVars), STAT=stat)
132 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
133 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
134 call wrf_debug ( FATAL , msg)
137 allocate(DH%MDVarNames(MaxVars), STAT=stat)
139 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
140 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
141 call wrf_debug ( FATAL , msg)
144 allocate(DH%VarIDs(MaxVars), STAT=stat)
146 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
147 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
148 call wrf_debug ( FATAL , msg)
151 allocate(DH%VarDimLens(NVarDims,MaxVars), STAT=stat)
153 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
154 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
155 call wrf_debug ( FATAL , msg)
158 allocate(DH%VarNames(MaxVars), STAT=stat)
160 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
161 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
162 call wrf_debug ( FATAL , msg)
167 if(i==WrfDataHandleMax) then
168 Status = WRF_WARN_TOO_MANY_FILES
169 write(msg,*) 'Warning TOO MANY FILES in ',__FILE__,', line', __LINE__
170 call wrf_debug ( WARN , TRIM(msg))
171 write(msg,*) 'Did you call ext_adios2_ioinit?'
172 call wrf_debug ( WARN , TRIM(msg))
178 DH%first_operation = .TRUE.
180 end subroutine allocHandle
182 subroutine deallocHandle(DataHandle, Status)
184 include 'wrf_status_codes.h'
185 integer ,intent(in) :: DataHandle
186 integer ,intent(out) :: Status
187 type(wrf_data_handle),pointer :: DH
191 IF ( DataHandle .GE. 1 .AND. DataHandle .LE. WrfDataHandleMax ) THEN
192 if(.NOT. WrfDataHandles(DataHandle)%Free) then
193 DH => WrfDataHandles(DataHandle)
194 deallocate(DH%Times, STAT=stat)
196 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
197 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
198 call wrf_debug ( FATAL , msg)
201 deallocate(DH%DimLengths, STAT=stat)
203 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
204 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
205 call wrf_debug ( FATAL , msg)
208 deallocate(DH%DimIDs, STAT=stat)
210 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
211 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
212 call wrf_debug ( FATAL , msg)
215 deallocate(DH%DimNames, STAT=stat)
217 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
218 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
219 call wrf_debug ( FATAL , msg)
222 deallocate(DH%MDVarIDs, STAT=stat)
224 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
225 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
226 call wrf_debug ( FATAL , msg)
229 deallocate(DH%MDVarDimLens, STAT=stat)
231 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
232 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
233 call wrf_debug ( FATAL , msg)
236 deallocate(DH%MDVarNames, STAT=stat)
238 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
239 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
240 call wrf_debug ( FATAL , msg)
243 deallocate(DH%VarIDs, STAT=stat)
245 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
246 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
247 call wrf_debug ( FATAL , msg)
250 deallocate(DH%VarDimLens, STAT=stat)
252 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
253 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
254 call wrf_debug ( FATAL , msg)
257 deallocate(DH%VarNames, STAT=stat)
259 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
260 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
261 call wrf_debug ( FATAL , msg)
268 end subroutine deallocHandle
270 subroutine GetDH(DataHandle,DH,Status)
272 include 'wrf_status_codes.h'
273 integer ,intent(in) :: DataHandle
274 type(wrf_data_handle) ,pointer :: DH
275 integer ,intent(out) :: Status
277 if(DataHandle < 1 .or. DataHandle > WrfDataHandleMax) then
278 Status = WRF_WARN_BAD_DATA_HANDLE
281 DH => WrfDataHandles(DataHandle)
283 Status = WRF_WARN_BAD_DATA_HANDLE
290 subroutine DateCheck(Date,Status)
292 include 'wrf_status_codes.h'
293 character*(*) ,intent(in) :: Date
294 integer ,intent(out) :: Status
296 if(len(Date) /= DateStrLen) then
297 Status = WRF_WARN_DATESTR_BAD_LENGTH
302 end subroutine DateCheck
304 subroutine GetName(Element,Var,Name,Status)
306 include 'wrf_status_codes.h'
307 character*(*) ,intent(in) :: Element
308 character*(*) ,intent(in) :: Var
309 character*(*) ,intent(out) :: Name
310 integer ,intent(out) :: Status
311 character (VarNameLen) :: VarName
314 integer, parameter :: upper_to_lower =IACHAR('a')-IACHAR('A')
317 Name = 'MD___'//trim(Element)//VarName
320 if('A'<=c .and. c <='Z') Name(i:i)=achar(iachar(c)+upper_to_lower)
321 if(c=='-'.or.c==':') Name(i:i)='_'
325 end subroutine GetName
327 subroutine GetTimeIndex(IO,DataHandle,DateStr,TimeIndex,Status)
330 include 'wrf_status_codes.h'
331 character (*) ,intent(in) :: IO
332 integer ,intent(in) :: DataHandle
333 character*(*) ,intent(in) :: DateStr
334 integer ,intent(out) :: TimeIndex
335 integer ,intent(out) :: Status
336 type(wrf_data_handle) ,pointer :: DH
340 DH => WrfDataHandles(DataHandle)
341 call DateCheck(DateStr,Status)
342 if(Status /= WRF_NO_ERR) then
343 Status = WRF_WARN_DATESTR_ERROR
344 write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
345 call wrf_debug ( WARN , TRIM(msg))
348 if(IO == 'write') then
349 TimeIndex = DH%TimeIndex
350 if(TimeIndex <= 0) then
352 elseif(DateStr == DH%Times(TimeIndex)) then
356 TimeIndex = TimeIndex +1
357 if(TimeIndex > MaxTimes) then
358 Status = WRF_WARN_TIME_EOF
359 write(msg,*) 'Warning TIME EOF in ',__FILE__,', line', __LINE__
360 call wrf_debug ( WARN , TRIM(msg))
364 DH%TimeIndex = TimeIndex
365 DH%Times(TimeIndex) = DateStr
366 CALL adios2_put(DH%adios2Engine, DH%TimesVarID, DateStr, adios2_mode_sync, stat)
367 call adios2_err(stat,Status)
368 if(Status /= WRF_NO_ERR) then
369 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
370 call wrf_debug ( WARN , TRIM(msg))
375 if(DH%Times(i)==DateStr) then
381 Status = WRF_WARN_TIME_NF
382 write(msg,*) 'Warning TIME ',DateStr,' NOT FOUND in ',__FILE__,', line', __LINE__
383 call wrf_debug ( WARN , TRIM(msg))
389 end subroutine GetTimeIndex
391 subroutine GetDim(MemoryOrder,NDim,Status)
392 include 'wrf_status_codes.h'
393 character*(*) ,intent(in) :: MemoryOrder
394 integer ,intent(out) :: NDim
395 integer ,intent(out) :: Status
396 character*3 :: MemOrd
398 call LowerCase(MemoryOrder,MemOrd)
400 case ('xyz','xzy','yxz','yzx','zxy','zyx','xsz','xez','ysz','yez')
402 case ('xy','yx','xs','xe','ys','ye')
406 case ('0') ! NDim=0 for scalars. TBH: 20060502
409 print *, 'memory order = ',MemOrd,' ',MemoryOrder
410 Status = WRF_WARN_BAD_MEMORYORDER
415 end subroutine GetDim
417 subroutine GetIndices(NDim,Start,End,i1,i2,j1,j2,k1,k2)
418 integer ,intent(in) :: NDim
419 integer ,dimension(*),intent(in) :: Start,End
420 integer ,intent(out) :: i1,i2,j1,j2,k1,k2
428 if(NDim == 0) return ! NDim=0 for scalars. TBH: 20060502
438 end subroutine GetIndices
440 logical function ZeroLengthHorzDim(MemoryOrder,Vector,Status)
442 include 'wrf_status_codes.h'
443 character*(*) ,intent(in) :: MemoryOrder
444 integer,dimension(*) ,intent(in) :: Vector
445 integer ,intent(out) :: Status
447 integer,dimension(NVarDims) :: temp
448 character*3 :: MemOrd
451 call GetDim(MemoryOrder,NDim,Status)
452 temp(1:NDim) = Vector(1:NDim)
453 call LowerCase(MemoryOrder,MemOrd)
454 zero_length = .false.
456 case ('xsz','xez','ysz','yez','xs','xe','ys','ye','z','c')
459 continue ! NDim=0 for scalars. TBH: 20060502
461 zero_length = temp(1) .lt. 1 .or. temp(3) .lt. 1
462 case ('xy','yx','xyz','yxz')
463 zero_length = temp(1) .lt. 1 .or. temp(2) .lt. 1
465 zero_length = temp(2) .lt. 1 .or. temp(3) .lt. 1
467 Status = WRF_WARN_BAD_MEMORYORDER
468 ZeroLengthHorzDim = .true.
472 ZeroLengthHorzDim = zero_length
474 end function ZeroLengthHorzDim
476 subroutine ExtOrder(MemoryOrder,Vector,Status)
478 include 'wrf_status_codes.h'
479 character*(*) ,intent(in) :: MemoryOrder
480 integer,dimension(*) ,intent(inout) :: Vector
481 integer ,intent(out) :: Status
483 integer,dimension(NVarDims) :: temp
484 character*3 :: MemOrd
486 call GetDim(MemoryOrder,NDim,Status)
487 temp(1:NDim) = Vector(1:NDim)
488 call LowerCase(MemoryOrder,MemOrd)
490 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c')
493 continue ! NDim=0 for scalars. TBH: 20060502
515 Status = WRF_WARN_BAD_MEMORYORDER
520 end subroutine ExtOrder
522 subroutine ExtOrderStr(MemoryOrder,Vector,ROVector,Status)
524 include 'wrf_status_codes.h'
525 character*(*) ,intent(in) :: MemoryOrder
526 character*(*),dimension(*) ,intent(in) :: Vector
527 character(80),dimension(NVarDims),intent(out) :: ROVector
528 integer ,intent(out) :: Status
530 character*3 :: MemOrd
532 call GetDim(MemoryOrder,NDim,Status)
533 ROVector(1:NDim) = Vector(1:NDim)
534 call LowerCase(MemoryOrder,MemOrd)
536 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c')
539 continue ! NDim=0 for scalars. TBH: 20060502
541 ROVector(2) = Vector(3)
542 ROVector(3) = Vector(2)
544 ROVector(1) = Vector(2)
545 ROVector(2) = Vector(1)
547 ROVector(1) = Vector(3)
548 ROVector(2) = Vector(1)
549 ROVector(3) = Vector(2)
551 ROVector(1) = Vector(2)
552 ROVector(2) = Vector(3)
553 ROVector(3) = Vector(1)
555 ROVector(1) = Vector(3)
556 ROVector(3) = Vector(1)
558 ROVector(1) = Vector(2)
559 ROVector(2) = Vector(1)
561 Status = WRF_WARN_BAD_MEMORYORDER
566 end subroutine ExtOrderStr
569 subroutine LowerCase(MemoryOrder,MemOrd)
570 character*(*) ,intent(in) :: MemoryOrder
571 character*(*) ,intent(out) :: MemOrd
573 integer ,parameter :: upper_to_lower =IACHAR('a')-IACHAR('A')
578 MemOrd(1:N) = MemoryOrder(1:N)
581 if('A'<=c .and. c <='Z') MemOrd(i:i)=achar(iachar(c)+upper_to_lower)
584 end subroutine LowerCase
586 subroutine UpperCase(MemoryOrder,MemOrd)
587 character*(*) ,intent(in) :: MemoryOrder
588 character*(*) ,intent(out) :: MemOrd
590 integer ,parameter :: lower_to_upper =IACHAR('A')-IACHAR('a')
595 MemOrd(1:N) = MemoryOrder(1:N)
598 if('a'<=c .and. c <='z') MemOrd(i:i)=achar(iachar(c)+lower_to_upper)
601 end subroutine UpperCase
603 subroutine adios2_err(err,Status)
606 include 'wrf_status_codes.h'
607 integer ,intent(in) :: err
608 integer ,intent(out) :: Status
609 character(len=80) :: errmsg
612 if( err == adios2_error_none )then
615 write(msg,*) 'adios2 error code: ',err
616 call wrf_debug ( WARN , TRIM(msg))
617 Status = WRF_WARN_ADIOS2
620 end subroutine adios2_err
622 subroutine FieldIO(IO,DataHandle,DateStr,Starts,Length,MemoryOrder &
623 ,FieldType,VarID,XField,Status)
626 include 'wrf_status_codes.h'
627 character (*) ,intent(in) :: IO
628 integer ,intent(in) :: DataHandle
629 character*(*) ,intent(in) :: DateStr
630 integer,dimension(NVarDims),intent(in) :: Starts
631 integer,dimension(NVarDims),intent(in) :: Length
632 character*(*) ,intent(in) :: MemoryOrder
633 integer ,intent(in) :: FieldType
634 type(adios2_variable) ,intent(in) :: VarID
635 integer,dimension(*) ,intent(inout) :: XField
636 integer ,intent(out) :: Status
639 integer(kind=8),dimension(NVarDims) :: VStart
640 integer(kind=8),dimension(NVarDims) :: VCount
641 integer(kind=8) :: TimeIndex_int8
644 call GetTimeIndex(IO,DataHandle,DateStr,TimeIndex,Status)
645 if(Status /= WRF_NO_ERR) then
646 write(msg,*) 'Warning in ',__FILE__,', line', __LINE__
647 call wrf_debug ( WARN , TRIM(msg))
648 write(msg,*) ' Bad time index for DateStr = ',DateStr
649 call wrf_debug ( WARN , TRIM(msg))
652 if(IO == 'write') then
653 TimeIndex_int8 = TimeIndex
654 call adios2_set_step_selection(VarID, TimeIndex_int8 -1_8, 1_8, stat)
655 call adios2_err(stat,Status)
656 if(Status /= WRF_NO_ERR) then
657 write(msg,*) 'adios2 error in FieldIO ',__FILE__,', line', __LINE__
658 call wrf_debug ( WARN , TRIM(msg))
662 call GetDim(MemoryOrder,NDim,Status)
665 VStart(1:NDim) = Starts(1:NDim)
666 VCount(1:NDim) = Length(1:NDim)
667 select case (FieldType)
669 call ext_adios2_RealFieldIO (IO, DataHandle,VarID,VStart,VCount,XField,Status)
671 call ext_adios2_DoubleFieldIO (IO,DataHandle,VarID,VStart,VCount,XField,Status)
673 call ext_adios2_IntFieldIO (IO,DataHandle,VarID,VStart,VCount,XField,Status)
675 call ext_adios2_LogicalFieldIO (IO,DataHandle,VarID,VStart,VCount,XField,Status)
676 if(Status /= WRF_NO_ERR) return
678 !for wrf_complex, double_complex
679 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
680 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
681 call wrf_debug ( WARN , TRIM(msg))
685 end subroutine FieldIO
687 subroutine Transpose(IO,MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
688 ,XField,x1,x2,y1,y2,z1,z2 &
690 character*(*) ,intent(in) :: IO
691 character*(*) ,intent(in) :: MemoryOrder
692 integer ,intent(in) :: l1,l2,m1,m2,n1,n2
693 integer ,intent(in) :: di
694 integer ,intent(in) :: x1,x2,y1,y2,z1,z2
695 integer ,intent(in) :: i1,i2,j1,j2,k1,k2
696 integer ,intent(inout) :: Field(di,l1:l2,m1:m2,n1:n2)
697 integer ,intent(inout) :: XField(di,(i2-i1+1)*(j2-j1+1)*(k2-k1+1))
698 character*3 :: MemOrd
700 integer ,parameter :: MaxUpperCase=IACHAR('Z')
701 integer :: i,j,k,ix,jx,kx
703 call LowerCase(MemoryOrder,MemOrd)
705 ! Cannot use following define due to gfortran cpp traditional mode concatenation limitations
706 !#define XDEX(A,B,C) A-A ## 1+1+(A ## 2-A ## 1+1)*((B-B ## 1)+(C-C ## 1)*(B ## 2-B ## 1+1))
707 ! define(`XDEX',($1-``$1''1+1+(``$1''2-``$1''1+1)*(($2-``$2''1)+($3-``$3''1)*(``$2''2-``$2''1+1))))
710 #define DFIELD XField(1:di,XDEX(i,k,j))
711 #include "transpose.code"
712 case ('xyz','xsz','xez','ysz','yez','xy','xs','xe','ys','ye','z','c','0')
714 #define DFIELD XField(1:di,XDEX(i,j,k))
715 #include "transpose.code"
718 #define DFIELD XField(1:di,XDEX(j,i,k))
719 #include "transpose.code"
722 #define DFIELD XField(1:di,XDEX(k,i,j))
723 #include "transpose.code"
726 #define DFIELD XField(1:di,XDEX(j,k,i))
727 #include "transpose.code"
730 #define DFIELD XField(1:di,XDEX(k,j,i))
731 #include "transpose.code"
734 #define DFIELD XField(1:di,XDEX(j,i,k))
735 #include "transpose.code"
738 end subroutine Transpose
740 subroutine reorder (MemoryOrder,MemO)
741 character*(*) ,intent(in) :: MemoryOrder
742 character*3 ,intent(out) :: MemO
743 character*3 :: MemOrd
744 integer :: N,i,i1,i2,i3
747 N = len_trim(MemoryOrder)
749 call lowercase(MemoryOrder,MemOrd)
750 ! never invert the boundary codes
751 select case ( MemOrd )
752 case ( 'xsz','xez','ysz','yez' )
760 if(ichar(MemOrd(i:i)) < ichar(MemOrd(i1:i1))) I1 = i
761 if(ichar(MemOrd(i:i)) > ichar(MemOrd(i3:i3))) I3 = i
768 MemO(1:1) = MemoryOrder(i1:i1)
769 MemO(2:2) = MemoryOrder(i2:i2)
770 if(N == 3) MemO(3:3) = MemoryOrder(i3:i3)
771 if(MemOrd(i1:i1) == 's' .or. MemOrd(i1:i1) == 'e') then
772 MemO(1:N-1) = MemO(2:N)
773 MemO(N:N ) = MemoryOrder(i1:i1)
776 end subroutine reorder
778 ! Returns .TRUE. iff it is OK to write time-independent domain metadata to the
779 ! file referenced by DataHandle. If DataHandle is invalid, .FALSE. is
781 LOGICAL FUNCTION adios2_ok_to_put_dom_ti( DataHandle )
783 include 'wrf_status_codes.h'
784 INTEGER, INTENT(IN) :: DataHandle
785 CHARACTER*80 :: fname
788 LOGICAL :: dryrun, first_output, retval
789 call ext_adios2_inquire_filename( DataHandle, fname, filestate, Status )
790 IF ( Status /= WRF_NO_ERR ) THEN
791 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
793 call wrf_debug ( WARN , TRIM(msg) )
796 dryrun = ( filestate .EQ. WRF_FILE_OPENED_NOT_COMMITTED )
797 first_output = adios2_is_first_operation( DataHandle )
798 ! retval = .NOT. dryrun .AND. first_output
801 adios2_ok_to_put_dom_ti = retval
803 END FUNCTION adios2_ok_to_put_dom_ti
805 ! Returns .TRUE. iff it is OK to read time-independent domain metadata from the
806 ! file referenced by DataHandle. If DataHandle is invalid, .FALSE. is
808 LOGICAL FUNCTION adios2_ok_to_get_dom_ti( DataHandle )
810 include 'wrf_status_codes.h'
811 INTEGER, INTENT(IN) :: DataHandle
812 CHARACTER*80 :: fname
815 LOGICAL :: dryrun, retval
816 call ext_adios2_inquire_filename( DataHandle, fname, filestate, Status )
817 IF ( Status /= WRF_NO_ERR ) THEN
818 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
820 call wrf_debug ( WARN , TRIM(msg) )
823 dryrun = ( filestate .EQ. WRF_FILE_OPENED_NOT_COMMITTED )
824 retval = .NOT. dryrun
826 adios2_ok_to_get_dom_ti = retval
828 END FUNCTION adios2_ok_to_get_dom_ti
830 ! Returns .TRUE. iff nothing has been read from or written to the file
831 ! referenced by DataHandle. If DataHandle is invalid, .FALSE. is returned.
832 LOGICAL FUNCTION adios2_is_first_operation( DataHandle )
834 INCLUDE 'wrf_status_codes.h'
835 INTEGER, INTENT(IN) :: DataHandle
836 TYPE(wrf_data_handle) ,POINTER :: DH
839 CALL GetDH( DataHandle, DH, Status )
840 IF ( Status /= WRF_NO_ERR ) THEN
841 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__, &
843 call wrf_debug ( WARN , TRIM(msg) )
846 retval = DH%first_operation
848 adios2_is_first_operation = retval
850 END FUNCTION adios2_is_first_operation
852 end module ext_adios2_support_routines
854 subroutine ext_adios2_open_for_read(DatasetName, SysDepInfo, DataHandle, Status)
856 use ext_adios2_support_routines
859 include 'wrf_status_codes.h'
860 character *(*), INTENT(IN) :: DatasetName
861 character *(*), INTENT(IN) :: SysDepInfo
862 integer , INTENT(OUT) :: DataHandle
863 integer , INTENT(OUT) :: Status
865 DataHandle = 0 ! dummy setting to quiet warning message
866 CALL ext_adios2_open_for_read_begin( DatasetName, SysDepInfo, DataHandle, Status )
867 IF ( Status .EQ. WRF_NO_ERR ) THEN
868 CALL ext_adios2_open_for_read_commit( DataHandle, Status )
871 end subroutine ext_adios2_open_for_read
873 !ends training phase; switches internal flag to enable input
874 !must be paired with call to ext_adios2_open_for_read_begin
875 subroutine ext_adios2_open_for_read_commit(DataHandle, Status)
877 use ext_adios2_support_routines
880 include 'wrf_status_codes.h'
881 integer, intent(in) :: DataHandle
882 integer, intent(out) :: Status
884 type(wrf_data_handle) ,pointer :: DH
886 if(WrfIOnotInitialized) then
887 Status = WRF_IO_NOT_INITIALIZED
888 write(msg,*) 'ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
889 call wrf_debug ( FATAL , msg)
892 call GetDH(DataHandle,DH,Status)
893 if(Status /= WRF_NO_ERR) then
894 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
895 call wrf_debug ( WARN , TRIM(msg))
898 DH%FileStatus = WRF_FILE_OPENED_FOR_READ
899 DH%first_operation = .TRUE.
902 end subroutine ext_adios2_open_for_read_commit
904 subroutine ext_adios2_open_for_read_begin( FileName, SysDepInfo, DataHandle, Status)
906 use ext_adios2_support_routines
909 include 'wrf_status_codes.h'
910 character*(*) ,intent(IN) :: FileName
911 character*(*) ,intent(in) :: SysDepInfo
912 integer ,intent(out) :: DataHandle
913 integer ,intent(out) :: Status
914 type(wrf_data_handle) ,pointer :: DH
917 type(adios2_variable) :: VarIDTime
918 type(adios2_variable) :: VarID
921 integer :: TotalNumVars
924 integer(kind=8) :: timestep
925 integer(kind=8) :: nsteps
926 character(len=4096), dimension(:), allocatable :: varnamelist
927 type(adios2_namestruct) :: namestruct
928 character(len=256) :: Name
930 if(WrfIOnotInitialized) then
931 Status = WRF_IO_NOT_INITIALIZED
932 write(msg,*) 'ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
933 call wrf_debug ( FATAL , msg)
936 call allocHandle(DataHandle,DH,Status)
937 if(Status /= WRF_NO_ERR) then
938 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
939 call wrf_debug ( WARN , TRIM(msg))
942 call adios2_declare_io(DH%adios2IO, adios, FileName, stat)
943 call adios2_err(stat,Status)
944 if(Status /= WRF_NO_ERR) then
945 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
946 call wrf_debug ( WARN , TRIM(msg))
949 call adios2_open(DH%adios2Engine, DH%adios2IO, FileName, adios2_mode_read, stat)
950 call adios2_err(stat,Status)
951 if(Status /= WRF_NO_ERR) then
952 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
953 call wrf_debug ( WARN , TRIM(msg))
956 call adios2_inquire_variable(VarIDTime, DH%adios2IO, DH%TimesName, stat)
957 call adios2_err(stat,Status)
958 if(Status /= WRF_NO_ERR) then
959 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
960 call wrf_debug ( WARN , TRIM(msg))
963 call adios2_steps(nsteps, DH%adios2Engine, stat)
964 call adios2_err(stat,Status)
965 if(Status /= WRF_NO_ERR) then
966 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
967 call wrf_debug ( WARN , TRIM(msg))
970 if(nsteps > MaxTimes) then
971 Status = WRF_ERR_FATAL_TOO_MANY_TIMES
972 write(msg,*) 'Fatal TOO MANY TIME VALUES in ',__FILE__,', line', __LINE__
973 call wrf_debug ( FATAL , TRIM(msg))
976 ! Read in times from different time steps
978 call adios2_set_step_selection(VarIDTime, timestep - 1, 1_8, stat)
979 call adios2_err(stat,Status)
980 if(Status /= WRF_NO_ERR) then
981 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
982 call wrf_debug ( WARN , TRIM(msg))
985 call adios2_get(DH%adios2Engine, VarIDTime, DH%Times(timestep), adios2_mode_sync, stat)
986 call adios2_err(stat,Status)
987 if(Status /= WRF_NO_ERR) then
988 write(msg,*) 'adios2 error in ext_adios2_open_for_read_begin ',__FILE__,', line', __LINE__
989 call wrf_debug ( WARN , TRIM(msg))
994 call adios2_available_variables(DH%adios2IO, namestruct, stat)
995 call adios2_err(stat,Status)
996 if(Status /= WRF_NO_ERR) then
997 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
998 call wrf_debug ( WARN , TRIM(msg))
1001 allocate(varnamelist(namestruct%count))
1002 call adios2_retrieve_names(namestruct, varnamelist, stat)
1003 call adios2_err(stat,Status)
1004 if(Status /= WRF_NO_ERR) then
1005 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1006 call wrf_debug ( WARN , TRIM(msg))
1009 TotalNumVars = namestruct%count
1012 Name = varnamelist(i)
1013 call adios2_inquire_variable(VarID, DH%adios2IO, Name, stat)
1014 call adios2_err(stat,Status)
1015 if(Status /= WRF_NO_ERR) then
1016 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1017 call wrf_debug ( WARN , TRIM(msg))
1019 elseif(Name(1:5) /= 'md___' .and. Name /= DH%TimesName) then
1020 NumVars = NumVars + 1
1021 DH%VarNames(NumVars) = Name
1022 DH%VarIDs(NumVars) = VarID
1025 deallocate(varnamelist)
1026 DH%NumVars = NumVars
1027 DH%NumberTimes = nsteps
1028 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1029 DH%FileName = FileName
1030 DH%CurrentVariable = 0
1032 DH%TimesVarID = VarIDTime
1035 end subroutine ext_adios2_open_for_read_begin
1037 subroutine ext_adios2_open_for_update( FileName, SysDepInfo, DataHandle, Status)
1039 use ext_adios2_support_routines
1042 include 'wrf_status_codes.h'
1043 character*(*) ,intent(IN) :: FileName
1044 character*(*) ,intent(in) :: SysDepInfo
1045 integer ,intent(out) :: DataHandle
1046 integer ,intent(out) :: Status
1047 type(wrf_data_handle) ,pointer :: DH
1050 type(adios2_variable) :: VarIDTime
1051 type(adios2_variable) :: VarID
1052 integer :: StoredDim
1053 integer :: DimIDs(2)
1054 integer :: TotalNumVars
1057 integer(kind=8) :: timestep
1058 integer(kind=8) :: nsteps
1059 character(len=4096), dimension(:), allocatable :: varnamelist
1060 type(adios2_namestruct) :: namestruct
1061 character(len=256) :: Name
1063 if(WrfIOnotInitialized) then
1064 Status = WRF_IO_NOT_INITIALIZED
1065 write(msg,*) 'ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
1066 call wrf_debug ( FATAL , msg)
1069 call allocHandle(DataHandle,DH,Status)
1070 if(Status /= WRF_NO_ERR) then
1071 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
1072 call wrf_debug ( WARN , TRIM(msg))
1075 call adios2_declare_io(DH%adios2IO, adios, FileName, stat)
1076 call adios2_err(stat,Status)
1077 if(Status /= WRF_NO_ERR) then
1078 write(msg,*) 'adios2 error in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1079 call wrf_debug ( WARN , TRIM(msg))
1082 call adios2_open(DH%adios2Engine, DH%adios2IO, FileName, adios2_mode_read, stat)
1083 call adios2_err(stat,Status)
1084 if(Status /= WRF_NO_ERR) then
1085 write(msg,*) 'adios2 error (',stat,') from adios2_open in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1086 call wrf_debug ( WARN , TRIM(msg))
1089 call adios2_inquire_variable(VarIDTime, DH%adios2IO, DH%TimesName, stat)
1090 call adios2_err(stat,Status)
1091 if(Status /= WRF_NO_ERR) then
1092 write(msg,*) 'adios2 error in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1093 call wrf_debug ( WARN , TRIM(msg))
1096 call adios2_steps(nsteps, DH%adios2Engine, stat)
1097 call adios2_err(stat,Status)
1098 if(Status /= WRF_NO_ERR) then
1099 write(msg,*) 'adios2 error in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1100 call wrf_debug ( WARN , TRIM(msg))
1103 if(nsteps > MaxTimes) then
1104 Status = WRF_ERR_FATAL_TOO_MANY_TIMES
1105 write(msg,*) 'Fatal TOO MANY TIME VALUES in ',__FILE__,', line', __LINE__
1106 call wrf_debug ( FATAL , TRIM(msg))
1109 ! Read in times from different time steps
1110 do timestep=1,nsteps
1111 call adios2_set_step_selection(VarIDTime, timestep-1, 1_8, stat)
1112 call adios2_err(stat,Status)
1113 if(Status /= WRF_NO_ERR) then
1114 write(msg,*) 'adios2 error in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1115 call wrf_debug ( WARN , TRIM(msg))
1118 call adios2_get(DH%adios2Engine, VarIDTime, DH%Times(timestep), adios2_mode_sync, stat)
1119 call adios2_err(stat,Status)
1120 if(Status /= WRF_NO_ERR) then
1121 write(msg,*) 'adios2 error in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1122 call wrf_debug ( WARN , TRIM(msg))
1126 ! Get variable names
1127 call adios2_available_variables(DH%adios2IO, namestruct, stat)
1128 call adios2_err(stat,Status)
1129 if(Status /= WRF_NO_ERR) then
1130 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1131 call wrf_debug ( WARN , TRIM(msg))
1134 allocate(varnamelist(namestruct%count))
1135 call adios2_retrieve_names(namestruct, varnamelist, stat)
1136 call adios2_err(stat,Status)
1137 if(Status /= WRF_NO_ERR) then
1138 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1139 call wrf_debug ( WARN , TRIM(msg))
1142 TotalNumVars = namestruct%count
1145 Name = varnamelist(i)
1146 call adios2_inquire_variable(VarID, DH%adios2IO, Name, stat)
1147 call adios2_err(stat,Status)
1148 if(Status /= WRF_NO_ERR) then
1149 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1150 call wrf_debug ( WARN , TRIM(msg))
1152 elseif(Name(1:5) /= 'md___' .and. Name /= DH%TimesName) then
1153 NumVars = NumVars + 1
1154 DH%VarNames(NumVars) = Name
1155 DH%VarIDs(NumVars) = VarID
1158 deallocate(varnamelist)
1159 DH%NumVars = NumVars
1160 DH%NumberTimes = nsteps
1161 DH%FileStatus = WRF_FILE_OPENED_FOR_UPDATE
1162 DH%FileName = FileName
1163 DH%CurrentVariable = 0
1165 DH%TimesVarID = VarIDTime
1168 call adios2_close(DH%adios2Engine, stat)
1169 call adios2_err(stat,Status)
1170 if(Status /= WRF_NO_ERR) then
1171 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
1172 call wrf_debug ( WARN , TRIM(msg))
1175 call adios2_open(DH%adios2Engine, DH%adios2IO, FileName, adios2_mode_append, stat)
1176 call adios2_err(stat,Status)
1177 if(Status /= WRF_NO_ERR) then
1178 write(msg,*) 'adios2 error (',stat,') from adios2_open in ext_adios2_open_for_update ',__FILE__,', line', __LINE__
1179 call wrf_debug ( WARN , TRIM(msg))
1183 end subroutine ext_adios2_open_for_update
1185 SUBROUTINE ext_adios2_open_for_write_begin(FileName,SysDepInfo,Iotype,DataHandle,Status)
1187 use ext_adios2_support_routines
1190 include 'wrf_status_codes.h'
1191 character*(*) ,intent(in) :: FileName
1192 character*(*) ,intent(in) :: SysDepInfo
1193 character*(*) ,intent(in) :: Iotype
1194 integer ,intent(out) :: DataHandle
1195 integer ,intent(out) :: Status
1196 type(wrf_data_handle),pointer :: DH
1199 character (7) :: Buffer
1202 type(adios2_variable) :: var
1203 type(adios2_attribute) :: attribute
1204 type(adios2_attribute) :: timeAttribute
1205 logical :: compression_enabled
1206 character*32 :: compressor
1207 character(80),dimension(2) :: DimNamesOut
1208 logical :: in_config
1209 integer :: numaggregators
1210 character(256) :: s_numaggregators
1212 if(WrfIOnotInitialized) then
1213 Status = WRF_IO_NOT_INITIALIZED
1214 write(msg,*) 'ext_adios2_open_for_write_begin: ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
1215 call wrf_debug ( FATAL , msg)
1218 call allocHandle(DataHandle,DH,Status)
1219 if(Status /= WRF_NO_ERR) then
1220 write(msg,*) 'Fatal ALLOCATION ERROR in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1221 call wrf_debug ( FATAL , TRIM(msg))
1226 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1227 DH%FileName = FileName
1229 if(DH%first_operation) then
1230 call adios2_declare_io(DH%adios2IO, adios, DH%FileName, stat)
1231 call adios2_err(stat,Status)
1232 if(Status /= WRF_NO_ERR) then
1233 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1234 call wrf_debug ( WARN , TRIM(msg))
1237 DH%first_operation = .false.
1239 DH%VarNames (1:MaxVars) = NO_NAME
1240 DH%MDVarNames(1:MaxVars) = NO_NAME
1242 write(Buffer,FMT="('DIM',i4.4)") i
1243 DH%DimNames (i) = Buffer
1244 DH%DimLengths(i) = NO_DIM
1246 DH%DimNames(1) = 'DateStrLen'
1247 call adios2_define_attribute(DH%DimIDs(1), DH%adios2IO, '_DIM_DateStrLen', &
1249 call adios2_err(stat,Status)
1250 if(Status /= WRF_NO_ERR) then
1251 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1252 call wrf_debug ( WARN , TRIM(msg))
1255 !define "Times" variable and dimension attribute
1256 call adios2_define_variable(DH%TimesVarID, DH%adios2IO, DH%TimesName, adios2_type_character, stat)
1257 call adios2_err(stat,Status)
1258 if(Status /= WRF_NO_ERR) then
1259 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1260 call wrf_debug ( WARN , TRIM(msg))
1263 DimNamesOut(1) = 'DateStrLen'
1264 DimNamesOut(2) = 'Time'
1265 call adios2_define_attribute(timeAttribute,DH%adios2IO, 'Dims', DimNamesOut, 2, DH%TimesVarID%name, '/', stat)
1266 call adios2_err(stat,Status)
1267 if(Status /= WRF_NO_ERR) then
1268 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1269 call wrf_debug ( WARN , TRIM(msg))
1273 CALL nl_get_adios2_compression_enable(1, compression_enabled)
1274 if (compression_enabled) then
1275 if (DH%compress_operator%name .ne. 'Compressor') then
1276 CALL nl_get_adios2_blosc_compressor(1, compressor)
1277 DH%blosc_compressor = compressor
1278 call adios2_define_operator(DH%compress_operator, adios, 'Compressor', 'blosc', stat)
1279 call adios2_err(stat,Status)
1280 if(Status /= WRF_NO_ERR) then
1281 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1282 call wrf_debug ( WARN , TRIM(msg))
1287 !ADIOS2 number of aggregators (AKA substreams, subfiles). Overrules setting in adios2.xml.
1288 !numaggregators = 0 will set a single aggregator per node.
1289 CALL nl_get_adios2_numaggregators(1, numaggregators)
1290 write(s_numaggregators,*) numaggregators
1291 call adios2_set_parameter(DH%adios2IO, 'NumAggregators', s_numaggregators, stat)
1292 call adios2_err(stat,Status)
1293 if(Status /= WRF_NO_ERR) then
1294 write(msg,*) 'adios2 error in ext_adios2_open_for_write_begin ',__FILE__,', line', __LINE__
1295 call wrf_debug ( WARN , TRIM(msg))
1299 DH%DimLengths(1) = DateStrLen
1301 end subroutine ext_adios2_open_for_write_begin
1304 !opens a file for writing or coupler datastream for sending messages.
1305 !no training phase for this version of the open stmt.
1306 subroutine ext_adios2_open_for_write (DatasetName, SysDepInfo, DataHandle, Status)
1308 use ext_adios2_support_routines
1310 include 'wrf_status_codes.h'
1311 character *(*), intent(in) :: DatasetName
1312 character *(*), intent(in) :: SysDepInfo
1313 integer , intent(out) :: DataHandle
1314 integer , intent(out) :: Status
1316 Status=WRF_WARN_NOOP
1317 DataHandle = 0 ! dummy setting to quiet warning message
1319 end subroutine ext_adios2_open_for_write
1321 SUBROUTINE ext_adios2_start_io_timestep(DataHandle, Status)
1323 use ext_adios2_support_routines
1326 include 'wrf_status_codes.h'
1327 integer ,intent(in) :: DataHandle
1328 integer ,intent(out) :: Status
1329 type(wrf_data_handle),pointer :: DH
1332 call GetDH(DataHandle,DH,Status)
1333 if(Status /= WRF_NO_ERR) then
1334 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_start_io_timestep ',__FILE__,', line', __LINE__
1335 call wrf_debug ( WARN , TRIM(msg))
1338 if (DH%adios2Engine%valid .eqv. .true.) then
1339 call adios2_begin_step(DH%adios2Engine, stat)
1340 call adios2_err(stat,Status)
1341 if(Status /= WRF_NO_ERR) then
1342 write(msg,*) 'adios2 error (',stat,') from adios2_begin_step in ext_adios2_start_io_timestep ',__FILE__,', line', __LINE__
1343 call wrf_debug ( WARN , TRIM(msg))
1348 end SUBROUTINE ext_adios2_start_io_timestep
1350 SUBROUTINE ext_adios2_end_io_timestep(DataHandle, Status)
1352 use ext_adios2_support_routines
1355 include 'wrf_status_codes.h'
1356 integer ,intent(in) :: DataHandle
1357 integer ,intent(out) :: Status
1358 type(wrf_data_handle),pointer :: DH
1361 call GetDH(DataHandle,DH,Status)
1362 if(Status /= WRF_NO_ERR) then
1363 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_end_io_timestep ',__FILE__,', line', __LINE__
1364 call wrf_debug ( WARN , TRIM(msg))
1367 if (DH%adios2Engine%valid .eqv. .true.) then
1368 call adios2_end_step(DH%adios2Engine, stat)
1369 call adios2_err(stat,Status)
1370 if(Status /= WRF_NO_ERR) then
1371 write(msg,*) 'adios2 error (',stat,') from adios2_end_step in ext_adios2_end_io_timestep ',__FILE__,', line', __LINE__
1372 call wrf_debug ( WARN , TRIM(msg))
1377 end SUBROUTINE ext_adios2_end_io_timestep
1379 SUBROUTINE ext_adios2_open_for_write_commit(DataHandle, Status)
1381 use ext_adios2_support_routines
1384 include 'wrf_status_codes.h'
1385 integer ,intent(in) :: DataHandle
1386 integer ,intent(out) :: Status
1387 type(wrf_data_handle),pointer :: DH
1391 if(WrfIOnotInitialized) then
1392 Status = WRF_IO_NOT_INITIALIZED
1393 write(msg,*) 'ext_adios2_open_for_write_commit: ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
1394 call wrf_debug ( FATAL , msg)
1397 call GetDH(DataHandle,DH,Status)
1398 if(Status /= WRF_NO_ERR) then
1399 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_open_for_write_commit ',__FILE__,', line', __LINE__
1400 call wrf_debug ( WARN , TRIM(msg))
1403 call adios2_open(DH%adios2Engine, DH%adios2IO, DH%FileName, adios2_mode_write, stat)
1404 call adios2_err(stat,Status)
1405 if(Status /= WRF_NO_ERR) then
1406 write(msg,*) 'adios2 error (',stat,') from adios2_open in ext_adios2_open_for_write_commit ',__FILE__,', line', __LINE__
1407 call wrf_debug ( WARN , TRIM(msg))
1410 DH%FileStatus = WRF_FILE_OPENED_FOR_WRITE
1411 DH%first_operation = .TRUE.
1413 end subroutine ext_adios2_open_for_write_commit
1415 subroutine ext_adios2_ioclose(DataHandle, Status)
1417 use ext_adios2_support_routines
1420 include 'wrf_status_codes.h'
1421 integer ,intent(in) :: DataHandle
1422 integer ,intent(out) :: Status
1423 type(wrf_data_handle),pointer :: DH
1426 call GetDH(DataHandle,DH,Status)
1427 if(Status /= WRF_NO_ERR) then
1428 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_ioclose ',__FILE__,', line', __LINE__
1429 call wrf_debug ( WARN , TRIM(msg))
1432 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1433 Status = WRF_WARN_FILE_NOT_OPENED
1434 write(msg,*) 'Warning FILE NOT OPENED in ext_adios2_ioclose ',__FILE__,', line', __LINE__
1435 call wrf_debug ( WARN , TRIM(msg))
1436 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1437 Status = WRF_WARN_DRYRUN_CLOSE
1438 write(msg,*) 'Warning TRY TO CLOSE DRYRUN in ext_adios2_ioclose ',__FILE__,', line', __LINE__
1439 call wrf_debug ( WARN , TRIM(msg))
1440 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1442 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1444 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
1447 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1448 write(msg,*) 'Fatal error BAD FILE STATUS in ext_adios2_ioclose ',__FILE__,', line', __LINE__
1449 call wrf_debug ( FATAL , TRIM(msg))
1452 call adios2_close(DH%adios2Engine, stat)
1453 call adios2_err(stat,Status)
1454 if(Status /= WRF_NO_ERR) then
1455 write(msg,*) 'adios2 error in ext_adios2_ioclose ',__FILE__,', line', __LINE__
1456 call wrf_debug ( WARN , TRIM(msg))
1459 CALL deallocHandle( DataHandle, Status )
1462 end subroutine ext_adios2_ioclose
1464 subroutine ext_adios2_iosync( DataHandle, Status)
1466 use ext_adios2_support_routines
1468 include 'wrf_status_codes.h'
1469 integer ,intent(in) :: DataHandle
1470 integer ,intent(out) :: Status
1471 type(wrf_data_handle),pointer :: DH
1474 call GetDH(DataHandle,DH,Status)
1475 if(Status /= WRF_NO_ERR) then
1476 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_iosync ',__FILE__,', line', __LINE__
1477 call wrf_debug ( WARN , TRIM(msg))
1480 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1481 Status = WRF_WARN_FILE_NOT_OPENED
1482 write(msg,*) 'Warning FILE NOT OPENED in ext_adios2_iosync ',__FILE__,', line', __LINE__
1483 call wrf_debug ( WARN , TRIM(msg))
1484 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1485 Status = WRF_WARN_FILE_NOT_COMMITTED
1486 write(msg,*) 'Warning FILE NOT COMMITTED in ext_adios2_iosync ',__FILE__,', line', __LINE__
1487 call wrf_debug ( WARN , TRIM(msg))
1488 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1490 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1493 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1494 write(msg,*) 'Fatal error BAD FILE STATUS in ext_adios2_iosync ',__FILE__,', line', __LINE__
1495 call wrf_debug ( FATAL , TRIM(msg))
1499 end subroutine ext_adios2_iosync
1501 subroutine ext_adios2_redef( DataHandle, Status)
1503 use ext_adios2_support_routines
1505 include 'wrf_status_codes.h'
1506 integer ,intent(in) :: DataHandle
1507 integer ,intent(out) :: Status
1508 type(wrf_data_handle),pointer :: DH
1511 call GetDH(DataHandle,DH,Status)
1512 if(Status /= WRF_NO_ERR) then
1513 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
1514 call wrf_debug ( WARN , TRIM(msg))
1517 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1518 Status = WRF_WARN_FILE_NOT_OPENED
1519 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
1520 call wrf_debug ( WARN , TRIM(msg))
1521 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1522 Status = WRF_WARN_FILE_NOT_COMMITTED
1523 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
1524 call wrf_debug ( WARN , TRIM(msg))
1525 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1527 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1528 Status = WRF_WARN_FILE_OPEN_FOR_READ
1529 write(msg,*) 'Warning FILE OPEN FOR READ in ',__FILE__,', line', __LINE__
1530 call wrf_debug ( WARN , TRIM(msg))
1532 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1533 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
1534 call wrf_debug ( FATAL , TRIM(msg))
1537 DH%FileStatus = WRF_FILE_OPENED_NOT_COMMITTED
1539 end subroutine ext_adios2_redef
1541 subroutine ext_adios2_enddef( DataHandle, Status)
1543 use ext_adios2_support_routines
1545 include 'wrf_status_codes.h'
1546 integer ,intent(in) :: DataHandle
1547 integer ,intent(out) :: Status
1548 type(wrf_data_handle),pointer :: DH
1551 call GetDH(DataHandle,DH,Status)
1552 if(Status /= WRF_NO_ERR) then
1553 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
1554 call wrf_debug ( WARN , TRIM(msg))
1557 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
1558 Status = WRF_WARN_FILE_NOT_OPENED
1559 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
1560 call wrf_debug ( WARN , TRIM(msg))
1561 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
1562 Status = WRF_WARN_FILE_NOT_COMMITTED
1563 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
1564 call wrf_debug ( WARN , TRIM(msg))
1565 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
1567 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
1568 Status = WRF_WARN_FILE_OPEN_FOR_READ
1569 write(msg,*) 'Warning FILE OPEN FOR READ in ',__FILE__,', line', __LINE__
1570 call wrf_debug ( WARN , TRIM(msg))
1572 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
1573 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
1574 call wrf_debug ( FATAL , TRIM(msg))
1577 DH%FileStatus = WRF_FILE_OPENED_FOR_WRITE
1579 end subroutine ext_adios2_enddef
1581 subroutine ext_adios2_ioinit(SysDepInfo, Status)
1583 use ext_adios2_support_routines
1586 include 'wrf_status_codes.h'
1588 CHARACTER*(*), INTENT(IN) :: SysDepInfo
1589 integer :: stat, rank, ierror
1590 INTEGER ,INTENT(INOUT) :: Status
1591 logical :: file_exists=.FALSE.
1593 WrfIOnotInitialized = .false.
1594 WrfDataHandles(1:WrfDataHandleMax)%Free = .true.
1595 WrfDataHandles(1:WrfDataHandleMax)%TimesName = 'Times'
1596 WrfDataHandles(1:WrfDataHandleMax)%DimUnlimName = 'Time'
1597 WrfDataHandles(1:WrfDataHandleMax)%FileStatus = WRF_FILE_NOT_OPENED
1599 !look for adios2 xml runtime configuration
1600 INQUIRE(FILE="adios2.xml", EXIST=file_exists)
1601 if(file_exists) then
1602 call adios2_init(adios, 'adios2.xml', MPI_COMM_WORLD, stat)
1604 call adios2_init(adios, MPI_COMM_WORLD, stat)
1606 call adios2_err(stat,Status)
1607 if(Status /= WRF_NO_ERR) then
1608 write(msg,*) 'adios2 error in ext_adios2_ioinit ',__FILE__,', line', __LINE__
1609 call wrf_debug ( WARN , TRIM(msg))
1613 end subroutine ext_adios2_ioinit
1616 subroutine ext_adios2_inquiry (Inquiry, Result, Status)
1619 include 'wrf_status_codes.h'
1620 character *(*), INTENT(IN) :: Inquiry
1621 character *(*), INTENT(OUT) :: Result
1622 integer ,INTENT(INOUT) :: Status
1624 SELECT CASE (Inquiry)
1625 CASE ("RANDOM_WRITE","RANDOM_READ","SEQUENTIAL_WRITE","SEQUENTIAL_READ")
1627 CASE ("OPEN_READ","OPEN_COMMIT_WRITE")
1629 CASE ("OPEN_WRITE","OPEN_COMMIT_READ","PARALLEL_IO")
1631 CASE ("SELF_DESCRIBING","SUPPORT_METADATA","SUPPORT_3D_FIELDS")
1636 Result = 'No Result for that inquiry!'
1640 end subroutine ext_adios2_inquiry
1643 subroutine ext_adios2_ioexit(Status)
1645 use ext_adios2_support_routines
1648 include 'wrf_status_codes.h'
1649 integer , INTENT(INOUT) :: Status
1651 type(wrf_data_handle),pointer :: DH
1655 if(WrfIOnotInitialized) then
1656 Status = WRF_IO_NOT_INITIALIZED
1657 write(msg,*) 'ext_adios2_ioinit was not called ',__FILE__,', line', __LINE__
1658 call wrf_debug ( FATAL , msg)
1661 do i=1,WrfDataHandleMax
1662 CALL deallocHandle( i , stat )
1664 call adios2_finalize(adios, stat)
1665 call adios2_err(stat,Status)
1666 if(Status /= WRF_NO_ERR) then
1667 write(msg,*) 'adios2 error in ext_adios2_ioexit ',__FILE__,', line', __LINE__
1668 call wrf_debug ( WARN , TRIM(msg))
1672 end subroutine ext_adios2_ioexit
1674 subroutine ext_adios2_get_dom_ti_real(DataHandle,Element,Data,Count,OutCount,Status)
1675 #define ROUTINE_TYPE 'REAL'
1676 #define TYPE_DATA real,intent(out) :: Data(*)
1677 #define TYPE_COUNT integer,intent(in) :: Count
1678 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1679 #define TYPE_BUFFER real,allocatable :: Buffer(:)
1680 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1681 #include "ext_adios2_get_dom_ti.code"
1683 end subroutine ext_adios2_get_dom_ti_real
1685 subroutine ext_adios2_get_dom_ti_integer(DataHandle,Element,Data,Count,OutCount,Status)
1690 #define ROUTINE_TYPE 'INTEGER'
1691 #define TYPE_DATA integer,intent(out) :: Data(*)
1692 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
1693 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1694 #include "ext_adios2_get_dom_ti.code"
1696 end subroutine ext_adios2_get_dom_ti_integer
1698 subroutine ext_adios2_get_dom_ti_double(DataHandle,Element,Data,Count,OutCount,Status)
1703 #define ROUTINE_TYPE 'DOUBLE'
1704 #define TYPE_DATA real*8,intent(out) :: Data(*)
1705 #define TYPE_BUFFER real*8,allocatable :: Buffer(:)
1706 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))
1707 #include "ext_adios2_get_dom_ti.code"
1709 end subroutine ext_adios2_get_dom_ti_double
1711 subroutine ext_adios2_get_dom_ti_logical(DataHandle,Element,Data,Count,OutCount,Status)
1716 #define ROUTINE_TYPE 'LOGICAL'
1717 #define TYPE_DATA logical,intent(out) :: Data(*)
1718 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
1719 #define COPY Data(1:min(Len,Count)) = Buffer(1:min(Len,Count))==1
1720 #include "ext_adios2_get_dom_ti.code"
1722 end subroutine ext_adios2_get_dom_ti_logical
1724 subroutine ext_adios2_get_dom_ti_char(DataHandle,Element,Data,Status)
1728 #undef TYPE_OUTCOUNT
1730 #define ROUTINE_TYPE 'CHAR'
1731 #define TYPE_DATA character*(*),intent(out) :: Data
1733 #define TYPE_OUTCOUNT
1736 #include "ext_adios2_get_dom_ti.code"
1739 end subroutine ext_adios2_get_dom_ti_char
1741 subroutine ext_adios2_put_dom_ti_real(DataHandle,Element,Data,Count,Status)
1746 #define ROUTINE_TYPE 'REAL'
1747 #define TYPE_DATA real ,intent(in) :: Data(Count)
1748 #define TYPE_COUNT integer,intent(in) :: Count
1749 #include "ext_adios2_put_dom_ti.code"
1750 end subroutine ext_adios2_put_dom_ti_real
1752 subroutine ext_adios2_put_dom_ti_integer(DataHandle,Element,Data,Count,Status)
1757 #define ROUTINE_TYPE 'INTEGER'
1758 #define TYPE_DATA integer,intent(in) :: Data(Count)
1759 #define TYPE_COUNT integer,intent(in) :: Count
1760 #include "ext_adios2_put_dom_ti.code"
1761 end subroutine ext_adios2_put_dom_ti_integer
1763 subroutine ext_adios2_put_dom_ti_double(DataHandle,Element,Data,Count,Status)
1768 #define ROUTINE_TYPE 'DOUBLE'
1769 #define TYPE_DATA real*8 ,intent(in) :: Data(:)
1770 #define TYPE_COUNT integer,intent(in) :: Count
1771 #include "ext_adios2_put_dom_ti.code"
1772 end subroutine ext_adios2_put_dom_ti_double
1774 subroutine ext_adios2_put_dom_ti_logical(DataHandle,Element,Data,Count,Status)
1778 #define ROUTINE_TYPE 'LOGICAL'
1779 #define TYPE_DATA logical,intent(in) :: Data(Count)
1780 #define TYPE_COUNT integer,intent(in) :: Count
1782 #include "ext_adios2_put_dom_ti.code"
1783 end subroutine ext_adios2_put_dom_ti_logical
1785 subroutine ext_adios2_put_dom_ti_char(DataHandle,Element,Data,Status)
1790 #define ROUTINE_TYPE 'CHAR'
1793 #define TYPE_DATA character*(*), intent(in) :: Data
1794 #include "ext_adios2_put_dom_ti.code"
1796 end subroutine ext_adios2_put_dom_ti_char
1798 subroutine ext_adios2_put_var_ti_real(DataHandle,Element,Var,Data,Count,Status)
1803 #define ROUTINE_TYPE 'REAL'
1804 #define TYPE_DATA real ,intent(in) :: Data(Count)
1805 #define TYPE_COUNT integer ,intent(in) :: Count
1806 #include "ext_adios2_put_var_ti.code"
1807 end subroutine ext_adios2_put_var_ti_real
1809 subroutine ext_adios2_put_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,Status)
1816 #define ROUTINE_TYPE 'REAL'
1817 #define TYPE_DATA real ,intent(in) :: Data(Count)
1818 #define TYPE_COUNT integer ,intent(in) :: Count
1819 #define ADIOS2TYPE adios2_type_real
1820 #define LENGTH Count
1821 #include "ext_adios2_put_var_td.code"
1822 end subroutine ext_adios2_put_var_td_real
1824 subroutine ext_adios2_put_var_ti_double(DataHandle,Element,Var,Data,Count,Status)
1829 #define ROUTINE_TYPE 'DOUBLE'
1830 #define TYPE_DATA real*8 ,intent(in) :: Data(Count)
1831 #define TYPE_COUNT integer ,intent(in) :: Count
1832 #include "ext_adios2_put_var_ti.code"
1833 end subroutine ext_adios2_put_var_ti_double
1835 subroutine ext_adios2_put_var_td_double(DataHandle,Element,DateStr,Var,Data,Count,Status)
1842 #define ROUTINE_TYPE 'DOUBLE'
1843 #define TYPE_DATA real*8,intent(in) :: Data(Count)
1844 #define TYPE_COUNT integer ,intent(in) :: Count
1845 #define ADIOS2TYPE adios2_type_dp
1846 #define LENGTH Count
1847 #include "ext_adios2_put_var_td.code"
1848 end subroutine ext_adios2_put_var_td_double
1850 subroutine ext_adios2_put_var_ti_integer(DataHandle,Element,Var,Data,Count,Status)
1855 #define ROUTINE_TYPE 'INTEGER'
1856 #define TYPE_DATA integer ,intent(in) :: Data(Count)
1857 #define TYPE_COUNT integer ,intent(in) :: Count
1858 #include "ext_adios2_put_var_ti.code"
1859 end subroutine ext_adios2_put_var_ti_integer
1861 subroutine ext_adios2_put_var_td_integer(DataHandle,Element,DateStr,Var,Data,Count,Status)
1868 #define ROUTINE_TYPE 'INTEGER'
1869 #define TYPE_DATA integer ,intent(in) :: Data(Count)
1870 #define TYPE_COUNT integer ,intent(in) :: Count
1871 #define ADIOS2TYPE adios2_type_integer4
1872 #define LENGTH Count
1873 #include "ext_adios2_put_var_td.code"
1874 end subroutine ext_adios2_put_var_td_integer
1876 subroutine ext_adios2_put_var_ti_logical(DataHandle,Element,Var,Data,Count,Status)
1880 #define ROUTINE_TYPE 'LOGICAL'
1881 #define TYPE_DATA logical ,intent(in) :: Data(Count)
1882 #define TYPE_COUNT integer ,intent(in) :: Count
1884 #include "ext_adios2_put_var_ti.code"
1885 end subroutine ext_adios2_put_var_ti_logical
1887 subroutine ext_adios2_put_var_td_logical(DataHandle,Element,DateStr,Var,Data,Count,Status)
1893 #define ROUTINE_TYPE 'LOGICAL'
1894 #define TYPE_DATA logical ,intent(in) :: Data(Count)
1895 #define TYPE_COUNT integer ,intent(in) :: Count
1896 #define ADIOS2TYPE adios2_type_integer4
1898 #define LENGTH Count
1899 #include "ext_adios2_put_var_td.code"
1900 end subroutine ext_adios2_put_var_td_logical
1902 subroutine ext_adios2_put_var_ti_char(DataHandle,Element,Var,Data,Status)
1907 #define ROUTINE_TYPE 'CHAR'
1908 #define TYPE_DATA character*(*) ,intent(in) :: Data(1)
1911 #include "ext_adios2_put_var_ti.code"
1913 end subroutine ext_adios2_put_var_ti_char
1915 subroutine ext_adios2_put_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
1922 #define ROUTINE_TYPE 'CHAR'
1923 #define TYPE_DATA character*(*) ,intent(in) :: Data
1925 #define ADIOS2TYPE adios2_type_string
1926 #define LENGTH len(Data)
1927 #include "ext_adios2_put_var_td.code"
1928 end subroutine ext_adios2_put_var_td_char
1930 subroutine ext_adios2_get_var_ti_real(DataHandle,Element,Var,Data,Count,OutCount,Status)
1935 #undef TYPE_OUTCOUNT
1937 #define ROUTINE_TYPE 'REAL'
1938 #define TYPE_DATA real ,intent(out) :: Data(Count)
1939 #define TYPE_BUFFER real ,allocatable :: Buffer(:)
1940 #define TYPE_COUNT integer,intent(in) :: Count
1941 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1942 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
1943 #include "ext_adios2_get_var_ti.code"
1945 end subroutine ext_adios2_get_var_ti_real
1947 subroutine ext_adios2_get_var_td_real(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
1952 #undef TYPE_OUTCOUNT
1955 #define ROUTINE_TYPE 'REAL'
1956 #define TYPE_DATA real ,intent(out) :: Data(Count)
1957 #define TYPE_BUFFER real
1958 #define TYPE_COUNT integer,intent(in) :: Count
1959 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1960 #define LENGTH min(Count,Len1)
1961 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
1962 #include "ext_adios2_get_var_td.code"
1964 end subroutine ext_adios2_get_var_td_real
1966 subroutine ext_adios2_get_var_ti_double(DataHandle,Element,Var,Data,Count,OutCount,Status)
1971 #undef TYPE_OUTCOUNT
1973 #define ROUTINE_TYPE 'DOUBLE'
1974 #define TYPE_DATA real*8 ,intent(out) :: Data(Count)
1975 #define TYPE_BUFFER real*8 ,allocatable :: Buffer(:)
1976 #define TYPE_COUNT integer,intent(in) :: Count
1977 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1978 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
1979 #include "ext_adios2_get_var_ti.code"
1981 end subroutine ext_adios2_get_var_ti_double
1983 subroutine ext_adios2_get_var_td_double(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
1988 #undef TYPE_OUTCOUNT
1991 #define ROUTINE_TYPE 'DOUBLE'
1992 #define TYPE_DATA real*8 ,intent(out) :: Data(Count)
1993 #define TYPE_BUFFER real*8
1994 #define TYPE_COUNT integer,intent(in) :: Count
1995 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
1996 #define LENGTH min(Count,Len1)
1997 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
1998 #include "ext_adios2_get_var_td.code"
2000 end subroutine ext_adios2_get_var_td_double
2002 subroutine ext_adios2_get_var_ti_integer(DataHandle,Element,Var,Data,Count,OutCount,Status)
2007 #undef TYPE_OUTCOUNT
2009 #define ROUTINE_TYPE 'INTEGER'
2010 #define TYPE_DATA integer,intent(out) :: Data(Count)
2011 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
2012 #define TYPE_COUNT integer,intent(in) :: Count
2013 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2014 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))
2015 #include "ext_adios2_get_var_ti.code"
2017 end subroutine ext_adios2_get_var_ti_integer
2019 subroutine ext_adios2_get_var_td_integer(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
2024 #undef TYPE_OUTCOUNT
2027 #define ROUTINE_TYPE 'INTEGER'
2028 #define TYPE_DATA integer,intent(out) :: Data(Count)
2029 #define TYPE_BUFFER integer
2030 #define TYPE_COUNT integer,intent(in) :: Count
2031 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2032 #define LENGTH min(Count,Len1)
2033 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))
2034 #include "ext_adios2_get_var_td.code"
2036 end subroutine ext_adios2_get_var_td_integer
2038 subroutine ext_adios2_get_var_ti_logical(DataHandle,Element,Var,Data,Count,OutCount,Status)
2043 #undef TYPE_OUTCOUNT
2045 #define ROUTINE_TYPE 'LOGICAL'
2046 #define TYPE_DATA logical,intent(out) :: Data(Count)
2047 #define TYPE_BUFFER integer,allocatable :: Buffer(:)
2048 #define TYPE_COUNT integer,intent(in) :: Count
2049 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2050 #define COPY Data(1:min(XLen,Count)) = Buffer(1:min(XLen,Count))==1
2051 #include "ext_adios2_get_var_ti.code"
2053 end subroutine ext_adios2_get_var_ti_logical
2055 subroutine ext_adios2_get_var_td_logical(DataHandle,Element,DateStr,Var,Data,Count,OutCount,Status)
2060 #undef TYPE_OUTCOUNT
2063 #define ROUTINE_TYPE 'LOGICAL'
2064 #define TYPE_DATA logical,intent(out) :: Data(Count)
2065 #define TYPE_BUFFER integer
2066 #define TYPE_COUNT integer,intent(in) :: Count
2067 #define TYPE_OUTCOUNT integer,intent(out) :: OutCount
2068 #define LENGTH min(Count,Len1)
2069 #define COPY Data(1:min(Len1,Count)) = Buffer(1:min(Len1,Count))==1
2070 #include "ext_adios2_get_var_td.code"
2072 end subroutine ext_adios2_get_var_td_logical
2074 subroutine ext_adios2_get_var_ti_char(DataHandle,Element,Var,Data,Status)
2079 #undef TYPE_OUTCOUNT
2081 #define ROUTINE_TYPE 'CHAR'
2082 #define TYPE_DATA character*(*) ,intent(out) :: Data
2084 #define TYPE_COUNT integer :: Count = 1
2085 #define TYPE_OUTCOUNT
2088 #include "ext_adios2_get_var_ti.code"
2091 end subroutine ext_adios2_get_var_ti_char
2093 subroutine ext_adios2_get_var_td_char(DataHandle,Element,DateStr,Var,Data,Status)
2098 #undef TYPE_OUTCOUNT
2100 #define ROUTINE_TYPE 'CHAR'
2101 #define TYPE_DATA character*(*) ,intent(out) :: Data
2102 #define TYPE_BUFFER character (80)
2103 #define TYPE_COUNT integer :: Count = 1
2104 #define TYPE_OUTCOUNT
2107 #include "ext_adios2_get_var_td.code"
2110 end subroutine ext_adios2_get_var_td_char
2112 subroutine ext_adios2_put_dom_td_real(DataHandle,Element,DateStr,Data,Count,Status)
2113 integer ,intent(in) :: DataHandle
2114 character*(*) ,intent(in) :: Element
2115 character*(*) ,intent(in) :: DateStr
2116 real ,intent(in) :: Data(*)
2117 integer ,intent(in) :: Count
2118 integer ,intent(out) :: Status
2120 call ext_adios2_put_var_td_real(DataHandle,Element,DateStr, &
2121 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2123 end subroutine ext_adios2_put_dom_td_real
2125 subroutine ext_adios2_put_dom_td_integer(DataHandle,Element,DateStr,Data,Count,Status)
2126 integer ,intent(in) :: DataHandle
2127 character*(*) ,intent(in) :: Element
2128 character*(*) ,intent(in) :: DateStr
2129 integer ,intent(in) :: Data(*)
2130 integer ,intent(in) :: Count
2131 integer ,intent(out) :: Status
2133 call ext_adios2_put_var_td_integer(DataHandle,Element,DateStr, &
2134 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2136 end subroutine ext_adios2_put_dom_td_integer
2138 subroutine ext_adios2_put_dom_td_double(DataHandle,Element,DateStr,Data,Count,Status)
2139 integer ,intent(in) :: DataHandle
2140 character*(*) ,intent(in) :: Element
2141 character*(*) ,intent(in) :: DateStr
2142 real*8 ,intent(in) :: Data(*)
2143 integer ,intent(in) :: Count
2144 integer ,intent(out) :: Status
2146 call ext_adios2_put_var_td_double(DataHandle,Element,DateStr, &
2147 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2149 end subroutine ext_adios2_put_dom_td_double
2151 subroutine ext_adios2_put_dom_td_logical(DataHandle,Element,DateStr,Data,Count,Status)
2152 integer ,intent(in) :: DataHandle
2153 character*(*) ,intent(in) :: Element
2154 character*(*) ,intent(in) :: DateStr
2155 logical ,intent(in) :: Data(*)
2156 integer ,intent(in) :: Count
2157 integer ,intent(out) :: Status
2159 call ext_adios2_put_var_td_logical(DataHandle,Element,DateStr, &
2160 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,Status)
2162 end subroutine ext_adios2_put_dom_td_logical
2164 subroutine ext_adios2_put_dom_td_char(DataHandle,Element,DateStr,Data,Status)
2165 integer ,intent(in) :: DataHandle
2166 character*(*) ,intent(in) :: Element
2167 character*(*) ,intent(in) :: DateStr
2168 character*(*) ,intent(in) :: Data
2169 integer ,intent(out) :: Status
2171 call ext_adios2_put_var_td_char(DataHandle,Element,DateStr, &
2172 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Status)
2174 end subroutine ext_adios2_put_dom_td_char
2176 subroutine ext_adios2_get_dom_td_real(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2177 integer ,intent(in) :: DataHandle
2178 character*(*) ,intent(in) :: Element
2179 character*(*) ,intent(in) :: DateStr
2180 real ,intent(out) :: Data(*)
2181 integer ,intent(in) :: Count
2182 integer ,intent(out) :: OutCount
2183 integer ,intent(out) :: Status
2185 call ext_adios2_get_var_td_real(DataHandle,Element,DateStr, &
2186 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2188 end subroutine ext_adios2_get_dom_td_real
2190 subroutine ext_adios2_get_dom_td_integer(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2191 integer ,intent(in) :: DataHandle
2192 character*(*) ,intent(in) :: Element
2193 character*(*) ,intent(in) :: DateStr
2194 integer ,intent(out) :: Data(*)
2195 integer ,intent(in) :: Count
2196 integer ,intent(out) :: OutCount
2197 integer ,intent(out) :: Status
2199 call ext_adios2_get_var_td_integer(DataHandle,Element,DateStr, &
2200 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2202 end subroutine ext_adios2_get_dom_td_integer
2204 subroutine ext_adios2_get_dom_td_double(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2205 integer ,intent(in) :: DataHandle
2206 character*(*) ,intent(in) :: Element
2207 character*(*) ,intent(in) :: DateStr
2208 real*8 ,intent(out) :: Data(*)
2209 integer ,intent(in) :: Count
2210 integer ,intent(out) :: OutCount
2211 integer ,intent(out) :: Status
2213 call ext_adios2_get_var_td_double(DataHandle,Element,DateStr, &
2214 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2216 end subroutine ext_adios2_get_dom_td_double
2218 subroutine ext_adios2_get_dom_td_logical(DataHandle,Element,DateStr,Data,Count,OutCount,Status)
2219 integer ,intent(in) :: DataHandle
2220 character*(*) ,intent(in) :: Element
2221 character*(*) ,intent(in) :: DateStr
2222 logical ,intent(out) :: Data(*)
2223 integer ,intent(in) :: Count
2224 integer ,intent(out) :: OutCount
2225 integer ,intent(out) :: Status
2227 call ext_adios2_get_var_td_logical(DataHandle,Element,DateStr, &
2228 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Count,OutCount,Status)
2230 end subroutine ext_adios2_get_dom_td_logical
2232 subroutine ext_adios2_get_dom_td_char(DataHandle,Element,DateStr,Data,Status)
2233 integer ,intent(in) :: DataHandle
2234 character*(*) ,intent(in) :: Element
2235 character*(*) ,intent(in) :: DateStr
2236 character*(*) ,intent(out) :: Data
2237 integer ,intent(out) :: Status
2239 call ext_adios2_get_var_td_char(DataHandle,Element,DateStr, &
2240 'E_X_T_D_O_M_A_I_N_M_E_T_A_DATA_' ,Data,Status)
2242 end subroutine ext_adios2_get_dom_td_char
2245 subroutine ext_adios2_write_field(DataHandle,DateStr,Var,Field,FieldType, &
2246 DomainDesc, MemoryOrdIn, Stagger, DimNames, &
2247 DomainStart,DomainEnd,MemoryStart,MemoryEnd,PatchStart,PatchEnd,Status)
2249 use ext_adios2_support_routines
2252 include 'wrf_status_codes.h'
2253 integer ,intent(in) :: DataHandle
2254 character*(*) ,intent(in) :: DateStr
2255 character*(*) ,intent(in) :: Var
2256 integer ,intent(inout) :: Field(*)
2257 integer ,intent(in) :: FieldType
2258 integer ,intent(in) :: DomainDesc
2259 character*(*) ,intent(in) :: MemoryOrdIn
2260 character*(*) ,intent(in) :: Stagger ! Dummy for now
2261 character*(*) ,dimension(*) ,intent(in) :: DimNames
2262 integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
2263 integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
2264 integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
2265 integer ,intent(out) :: Status
2266 character (3) :: MemoryOrder
2267 type(wrf_data_handle) ,pointer :: DH
2269 character (VarNameLen) :: VarName
2270 character (3) :: MemO
2271 character (3) :: UCMemO
2272 type(adios2_variable) :: VarID
2273 type(adios2_attribute) :: AttributeID
2274 integer ,dimension(NVarDims) :: Length_global, Length_native
2275 integer ,dimension(NVarDims) :: Length
2276 integer, dimension(NVarDims) :: VDimIDs
2277 character(80),dimension(NVarDims) :: RODimNames
2278 integer ,dimension(NVarDims) :: StoredStart
2279 integer(kind=8) ,dimension(NVarDims) :: zero
2280 integer(kind=8) ,dimension(NVarDims) :: shape_dims
2281 integer ,dimension(:,:,:,:),allocatable :: XField
2285 integer :: i1,i2,j1,j2,k1,k2
2286 integer :: x1,x2,y1,y2,z1,z2
2287 integer :: p1,p2,q1,q2,r1,r2
2288 integer :: l1,l2,m1,m2,n1,n2
2291 character (80) :: NullName
2293 ! Local, possibly adjusted, copies of MemoryStart and MemoryEnd
2294 integer ,dimension(NVarDims) :: lMemoryStart, lMemoryEnd
2295 character(80),dimension(NVarDims+1) :: DimNamesOut
2296 integer :: operation_id
2298 MemoryOrder = trim(adjustl(MemoryOrdIn))
2300 call GetDim(MemoryOrder,NDim,Status)
2301 if(Status /= WRF_NO_ERR) then
2302 write(msg,*) 'Warning BAD MEMORY ORDER |',MemoryOrder,'| in ',__FILE__,', line', __LINE__
2303 call wrf_debug ( WARN , TRIM(msg))
2306 call DateCheck(DateStr,Status)
2307 if(Status /= WRF_NO_ERR) then
2308 write(msg,*) 'Warning DATE STRING ERROR |',DateStr,'| in ',__FILE__,', line', __LINE__
2309 call wrf_debug ( WARN , TRIM(msg))
2313 call GetDH(DataHandle,DH,Status)
2314 if(Status /= WRF_NO_ERR) then
2315 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2316 call wrf_debug ( WARN , TRIM(msg))
2319 write(msg,*)'ext_adios2_write_field: called for ',TRIM(Var)
2320 CALL wrf_debug( 100, msg )
2323 Length(1:NDim) = PatchEnd(1:NDim)-PatchStart(1:NDim)+1
2324 Length_native(1:NDim) = Length(1:NDim)
2325 Length_global(1:NDim) = DomainEnd(1:NDim)-DomainStart(1:NDim)+1
2327 call ExtOrder(MemoryOrder,Length,Status)
2328 call ExtOrder(MemoryOrder,Length_global,Status)
2329 call ExtOrderStr(MemoryOrder,DimNames,RODimNames,Status)
2331 lMemoryStart(1:NDim) = MemoryStart(1:NDim)
2332 lMemoryEnd(1:NDim) = MemoryEnd(1:NDim)
2333 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2334 Status = WRF_WARN_FILE_NOT_OPENED
2335 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2336 call wrf_debug ( WARN , TRIM(msg))
2337 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2338 Status = WRF_WARN_WRITE_RONLY_FILE
2339 write(msg,*) 'Warning WRITE READ ONLY FILE in ',__FILE__,', line', __LINE__
2340 call wrf_debug ( WARN , TRIM(msg))
2341 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2343 if(DH%VarNames(NVar) == VarName ) then
2344 Status = WRF_WARN_2DRYRUNS_1VARIABLE
2345 write(msg,*) 'Warning 2 DRYRUNS 1 VARIABLE (',TRIM(VarName),') in ',__FILE__,', line', __LINE__
2346 call wrf_debug ( WARN , TRIM(msg))
2348 elseif(DH%VarNames(NVar) == NO_NAME) then
2349 DH%VarNames(NVar) = VarName
2352 elseif(NVar == MaxVars) then
2353 Status = WRF_WARN_TOO_MANY_VARIABLES
2354 write(msg,*) 'Warning TOO MANY VARIABLES in ',__FILE__,', line', __LINE__
2355 call wrf_debug ( WARN , TRIM(msg))
2360 if(RODimNames(j) == NullName .or. RODimNames(j) == '') then
2362 if(DH%DimLengths(i) == Length_global(j)) then
2364 elseif(DH%DimLengths(i) == NO_DIM) then
2365 call adios2_define_attribute(DH%DimIDs(i), DH%adios2IO, '_DIM_'//DH%DimNames(i), &
2366 Length_global(j), stat)
2367 call adios2_err(stat,Status)
2368 if(Status /= WRF_NO_ERR) then
2369 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
2370 call wrf_debug ( WARN , TRIM(msg))
2373 DH%DimLengths(i) = Length_global(j)
2375 elseif(i == MaxDims) then
2376 Status = WRF_WARN_TOO_MANY_DIMS
2377 write(msg,*) 'Warning TOO MANY DIMENSIONS (',i,') in (',TRIM(VarName),') ',__FILE__,', line', __LINE__
2378 call wrf_debug ( WARN , TRIM(msg))
2382 else !look for input name and check if already defined
2385 if (DH%DimNames(i) == RODimNames(j)) then
2386 if (DH%DimLengths(i) == Length_global(j)) then
2390 Status = WRF_WARN_DIMNAME_REDEFINED
2391 write(msg,*) 'Warning DIM ',i,', NAME ',TRIM(DH%DimNames(i)),' REDEFINED by var ', &
2392 TRIM(Var),' ',DH%DimLengths(i),Length_global(j) ,' in ', __FILE__ ,' line', __LINE__
2393 call wrf_debug ( WARN , TRIM(msg))
2400 if (DH%DimLengths(i) == NO_DIM) then
2401 DH%DimNames(i) = RODimNames(j)
2402 call adios2_define_attribute(DH%DimIDs(i), DH%adios2IO, '_DIM_'//DH%DimNames(i), &
2403 Length_global(j), stat)
2404 call adios2_err(stat,Status)
2405 if(Status /= WRF_NO_ERR) then
2406 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
2407 call wrf_debug ( WARN , TRIM(msg))
2410 DH%DimLengths(i) = Length_global(j)
2412 elseif(i == MaxDims) then
2413 Status = WRF_WARN_TOO_MANY_DIMS
2414 write(msg,*) 'Warning TOO MANY DIMENSIONS in ',__FILE__,', line', __LINE__
2415 call wrf_debug ( WARN , TRIM(msg))
2422 DH%VarDimLens(j,NVar) = Length_global(j)
2424 select case (FieldType)
2426 XType = adios2_type_real
2428 Xtype = adios2_type_dp
2430 XType = adios2_type_integer4
2432 XType = adios2_type_integer4
2434 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
2435 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
2436 call wrf_debug ( WARN , TRIM(msg))
2440 shape_dims(:) = Length_global(:)
2443 call adios2_define_variable(VarID, DH%adios2IO, VarName, XType, &
2444 1, shape_dims, zero, zero, &
2445 adios2_variable_dims, stat)
2447 call adios2_define_variable(VarID, DH%adios2IO, VarName, XType, &
2448 NDim, shape_dims, zero, zero, &
2449 adios2_variable_dims, stat)
2451 call adios2_err(stat,Status)
2452 if(Status /= WRF_NO_ERR) then
2453 write(msg,*) 'ext_adios2_write_field: adios2 error for ',TRIM(VarName),' in ',__FILE__,', line', __LINE__
2454 call wrf_debug ( WARN , TRIM(msg))
2457 if (DH%compress_operator%valid .eqv. .true.) then
2458 if (DH%blosc_compressor == 'blosclz') then
2459 call adios2_add_operation(operation_id, VarID, DH%compress_operator, 'compressor', 'blosclz', stat)
2460 elseif (DH%blosc_compressor == 'zlib') then
2461 call adios2_add_operation(operation_id, VarID, DH%compress_operator, 'compressor', 'zlib', stat)
2462 elseif (DH%blosc_compressor == 'lz4') then
2463 call adios2_add_operation(operation_id, VarID, DH%compress_operator, 'compressor', 'lz4', stat)
2464 elseif (DH%blosc_compressor == 'lz4hc') then
2465 call adios2_add_operation(operation_id, VarID, DH%compress_operator, 'compressor', 'lz4hc', stat)
2466 elseif (DH%blosc_compressor == 'zstd') then
2467 call adios2_add_operation(operation_id, VarID, DH%compress_operator, 'compressor', 'zstd', stat)
2469 call adios2_err(stat,Status)
2470 if(Status /= WRF_NO_ERR) then
2471 write(msg,*) 'ext_adios2_write_field: adios2 error for ',TRIM(VarName),' in ',__FILE__,', line', __LINE__
2472 call wrf_debug ( WARN , TRIM(msg))
2476 DH%VarIDs(NVar) = VarID
2477 ! add attribute of dimension names (for reconstructing NetCDF file with converter)
2479 DimNamesOut(j) = DH%DimNames(VDimIDs(j))
2481 DimNamesOut(NDim+1) = DH%DimUnlimName
2482 call adios2_define_attribute(AttributeID,DH%adios2IO, 'Dims', &
2483 DimNamesOut, NDim+1, VarID%name, '/', stat)
2484 call adios2_err(stat,Status)
2485 if(Status /= WRF_NO_ERR) then
2486 write(msg,*) 'ext_adios2_write_field: adios2 error in ',__FILE__,', line', __LINE__
2487 call wrf_debug ( WARN , TRIM(msg))
2490 call adios2_define_attribute(AttributeID,DH%adios2IO, 'FieldType', &
2491 FieldType, VarID%name, stat)
2492 call adios2_err(stat,Status)
2493 if(Status /= WRF_NO_ERR) then
2494 write(msg,*) 'ext_adios2_write_field: adios2 error in ',__FILE__,', line', __LINE__
2495 call wrf_debug ( WARN , TRIM(msg))
2498 call reorder(MemoryOrder,MemO)
2499 call uppercase(MemO,UCMemO)
2500 call adios2_define_attribute(AttributeID, DH%adios2IO, 'MemoryOrder', &
2501 UCMemO, VarID%name, stat)
2502 call adios2_err(stat,Status)
2503 if(Status /= WRF_NO_ERR) then
2504 write(msg,*) 'ext_adios2_write_field: adios2 error in ',__FILE__,', line', __LINE__
2505 call wrf_debug ( WARN , TRIM(msg))
2508 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
2509 do NVar=1,DH%NumVars
2510 if(DH%VarNames(NVar) == VarName) then
2512 elseif(NVar == DH%NumVars) then
2513 Status = WRF_WARN_VAR_NF
2514 write(msg,*) 'Warning VARIABLE NOT FOUND in ',__FILE__,', line', __LINE__
2515 call wrf_debug ( WARN , TRIM(msg))
2519 VarID = DH%VarIDs(NVar)
2521 if(Length_global(j) /= DH%VarDimLens(j,NVar) .AND. DH%FileStatus /= WRF_FILE_OPENED_FOR_UPDATE ) then
2522 Status = WRF_WARN_WRTLEN_NE_DRRUNLEN
2523 write(msg,*) 'Warning LENGTH != DRY RUN LENGTH for |', &
2524 VarName,'| dim ',j,' in ',__FILE__,', line', __LINE__
2525 call wrf_debug ( WARN , TRIM(msg))
2526 write(msg,*) ' LENGTH ',Length_global(j),' DRY RUN LENGTH ',DH%VarDimLens(j,NVar)
2527 call wrf_debug ( WARN , TRIM(msg))
2529 !jm 061024 elseif(PatchStart(j) < MemoryStart(j)) then
2530 !jm elseif(DomainStart(j) < MemoryStart(j)) then
2531 elseif(PatchStart(j) < lMemoryStart(j)) then
2532 Status = WRF_WARN_DIMENSION_ERROR
2533 write(msg,*) 'Warning DIMENSION ERROR for |',VarName, &
2534 '| in ',__FILE__,', line', __LINE__
2535 call wrf_debug ( WARN , TRIM(msg))
2540 call GetIndices(NDim,lMemoryStart,lMemoryEnd,l1,l2,m1,m2,n1,n2)
2541 call GetIndices(NDim,StoredStart,Length ,x1,x2,y1,y2,z1,z2)
2542 call GetIndices(NDim,StoredStart,Length_native ,p1,p2,q1,q2,r1,r2)
2543 call GetIndices(NDim,PatchStart, PatchEnd ,i1,i2,j1,j2,k1,k2)
2545 if(FieldType == WRF_DOUBLE) di=2
2546 allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
2548 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
2549 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
2550 call wrf_debug ( FATAL , TRIM(msg))
2554 WRITE(msg,*) 'ARPDBG: MemoryStart = ',lMemoryStart(1:NDim)
2555 CALL wrf_message(msg)
2556 WRITE(msg,*) 'ARPDBG: lMemoryEnd = ',lMemoryEnd(1:NDim)
2557 CALL wrf_message(msg)
2558 WRITE(msg,*) 'ARPDBG: Length = ',Length(1:NDim)
2559 CALL wrf_message(msg)
2561 call Transpose('write',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
2562 ,XField,x1,x2,y1,y2,z1,z2 &
2563 ,i1,i2,j1,j2,k1,k2 )
2564 StoredStart(1:NDim) = PatchStart(1:NDim)
2565 call ExtOrder(MemoryOrder,StoredStart,Status)
2566 call FieldIO('write',DataHandle,DateStr,StoredStart,Length,MemoryOrder, &
2567 FieldType,VarID,XField,Status)
2568 if(Status /= WRF_NO_ERR) then
2569 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2570 call wrf_debug ( WARN , TRIM(msg))
2573 deallocate(XField, STAT=stat)
2575 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
2576 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
2577 call wrf_debug ( FATAL , TRIM(msg))
2581 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2582 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2583 call wrf_debug ( FATAL , TRIM(msg))
2585 DH%first_operation = .FALSE.
2587 end subroutine ext_adios2_write_field
2589 subroutine ext_adios2_read_field(DataHandle,DateStr,Var,Field,FieldType, &
2590 DomainDesc, MemoryOrdIn, Stagger, DimNames, &
2591 DomainStart,DomainEnd,MemoryStart,MemoryEnd,PatchStart,PatchEnd,Status)
2593 use ext_adios2_support_routines
2596 include 'wrf_status_codes.h'
2597 integer ,intent(in) :: DataHandle
2598 character*(*) ,intent(in) :: DateStr
2599 character*(*) ,intent(in) :: Var
2600 integer ,intent(out) :: Field(*)
2601 integer ,intent(in) :: FieldType
2602 integer ,intent(in) :: DomainDesc
2603 character*(*) ,intent(in) :: MemoryOrdIn
2604 character*(*) ,intent(in) :: Stagger ! Dummy for now
2605 character*(*) , dimension (*) ,intent(in) :: DimNames
2606 integer ,dimension(*) ,intent(in) :: DomainStart, DomainEnd
2607 integer ,dimension(*) ,intent(in) :: MemoryStart, MemoryEnd
2608 integer ,dimension(*) ,intent(in) :: PatchStart, PatchEnd
2609 integer ,intent(out) :: Status
2610 character (3) :: MemoryOrder
2611 type(wrf_data_handle) ,pointer :: DH
2613 character (VarNameLen) :: VarName
2614 type(adios2_variable) :: VarID
2615 integer ,dimension(NVarDims) :: VCount
2616 integer ,dimension(NVarDims) :: VStart
2617 integer ,dimension(NVarDims) :: Length
2618 integer ,dimension(NVarDims) :: VDimIDs
2619 integer ,dimension(NVarDims) :: MemS
2620 integer ,dimension(NVarDims) :: MemE
2621 integer ,dimension(NVarDims) :: StoredStart
2622 integer ,dimension(NVarDims) :: StoredLen
2623 integer ,dimension(:,:,:,:) ,allocatable :: XField
2626 integer :: i1,i2,j1,j2,k1,k2
2627 integer :: x1,x2,y1,y2,z1,z2
2628 integer :: l1,l2,m1,m2,n1,n2
2629 character (VarNameLen) :: Name
2631 integer :: StoredDim
2636 type(adios2_attribute) :: attribute
2638 MemoryOrder = trim(adjustl(MemoryOrdIn))
2639 call GetDim(MemoryOrder,NDim,Status)
2640 if(Status /= WRF_NO_ERR) then
2641 write(msg,*) 'Warning BAD MEMORY ORDER |',TRIM(MemoryOrder),'| for |', &
2642 TRIM(Var),'| in ext_adios2_read_field ',__FILE__,', line', __LINE__
2643 call wrf_debug ( WARN , TRIM(msg))
2646 call DateCheck(DateStr,Status)
2647 if(Status /= WRF_NO_ERR) then
2648 write(msg,*) 'Warning DATE STRING ERROR |',TRIM(DateStr),'| for |',TRIM(Var), &
2649 '| in ext_adios2_read_field ',__FILE__,', line', __LINE__
2650 call wrf_debug ( WARN , TRIM(msg))
2654 call GetDH(DataHandle,DH,Status)
2655 if(Status /= WRF_NO_ERR) then
2656 write(msg,*) 'Warning Status = ',Status,' in ext_adios2_read_field ',__FILE__,', line', __LINE__
2657 call wrf_debug ( WARN , TRIM(msg))
2660 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2661 Status = WRF_WARN_FILE_NOT_OPENED
2662 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2663 call wrf_debug ( WARN , TRIM(msg))
2664 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2665 ! jm it is okay to have a dry run read. means read is called between ofrb and ofrc. Just return.
2666 ! Status = WRF_WARN_DRYRUN_READ
2667 ! write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2668 ! call wrf_debug ( WARN , TRIM(msg))
2671 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2672 Status = WRF_WARN_READ_WONLY_FILE
2673 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2674 call wrf_debug ( WARN , TRIM(msg))
2675 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE ) then
2676 Length(1:NDim) = PatchEnd(1:NDim)-PatchStart(1:NDim)+1
2677 StoredStart(1:NDim) = PatchStart(1:NDim)
2678 call ExtOrder(MemoryOrder,Length,Status)
2679 call adios2_inquire_variable(VarID, DH%adios2IO, VarName, stat)
2680 call adios2_err(stat,Status)
2681 if(Status /= WRF_NO_ERR) then
2682 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__,' Varname ',Varname
2683 call wrf_debug ( WARN , TRIM(msg))
2686 call adios2_inquire_variable_attribute(attribute, DH%adios2IO, 'FieldType', VarName, '/', stat)
2687 call adios2_err(stat,Status)
2688 if(Status /= WRF_NO_ERR) then
2689 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
2690 call wrf_debug ( WARN , TRIM(msg))
2693 call adios2_attribute_data(FType, attribute, stat)
2694 if(Status /= WRF_NO_ERR) then
2695 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
2696 call wrf_debug ( WARN , TRIM(msg))
2699 ! allow coercion between double and single prec real
2700 !jm if(FieldType /= Ftype) then
2701 if( (FieldType == WRF_REAL .OR. FieldType == WRF_DOUBLE) ) then
2702 if ( .NOT. (Ftype == WRF_REAL .OR. Ftype == WRF_DOUBLE )) then
2703 Status = WRF_WARN_TYPE_MISMATCH
2704 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
2705 call wrf_debug ( WARN , TRIM(msg))
2708 else if(FieldType /= Ftype) then
2709 Status = WRF_WARN_TYPE_MISMATCH
2710 write(msg,*) 'Warning TYPE MISMATCH in ',__FILE__,', line', __LINE__
2711 call wrf_debug ( WARN , TRIM(msg))
2714 StoredDim = VarID%ndims
2716 select case (FieldType)
2718 ! allow coercion between double and single prec real
2719 if(.NOT. (XType == adios2_type_real .OR. XType == adios2_type_dp ) ) then
2720 Status = WRF_WARN_TYPE_MISMATCH
2721 write(msg,*) 'Warning REAL TYPE MISMATCH in ',__FILE__,', line', __LINE__
2724 ! allow coercion between double and single prec real
2725 if(.NOT. (XType == adios2_type_real .OR. XType == adios2_type_dp) ) then
2726 Status = WRF_WARN_TYPE_MISMATCH
2727 write(msg,*) 'Warning DOUBLE TYPE MISMATCH in ',__FILE__,', line', __LINE__
2730 if(XType /= adios2_type_integer4) then
2731 Status = WRF_WARN_TYPE_MISMATCH
2732 write(msg,*) 'Warning INTEGER TYPE MISMATCH in ',__FILE__,', line', __LINE__
2735 if(XType /= adios2_type_integer4) then
2736 Status = WRF_WARN_TYPE_MISMATCH
2737 write(msg,*) 'Warning LOGICAL TYPE MISMATCH in ',__FILE__,', line', __LINE__
2740 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
2741 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
2743 if(Status /= WRF_NO_ERR) then
2744 call wrf_debug ( WARN , TRIM(msg))
2748 call GetIndices(NDim,MemoryStart,MemoryEnd,l1,l2,m1,m2,n1,n2)
2749 call GetIndices(NDim,StoredStart,Length,x1,x2,y1,y2,z1,z2)
2750 !jm call GetIndices(NDim,DomainStart,DomainEnd,i1,i2,j1,j2,k1,k2)
2751 call GetIndices(NDim,PatchStart,PatchEnd,i1,i2,j1,j2,k1,k2)
2753 StoredStart(1:NDim) = PatchStart(1:NDim)
2754 call ExtOrder(MemoryOrder,StoredStart,Status)
2757 if(FieldType == WRF_DOUBLE) di=2
2758 allocate(XField(di,x1:x2,y1:y2,z1:z2), STAT=stat)
2760 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
2761 write(msg,*) 'Fatal ALLOCATION ERROR in ',__FILE__,', line', __LINE__
2762 call wrf_debug ( FATAL , msg)
2765 call FieldIO('read',DataHandle,DateStr,StoredStart,Length,MemoryOrder, &
2766 FieldType,VarID,XField,Status)
2767 if(Status /= WRF_NO_ERR) then
2768 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2769 call wrf_debug ( WARN , TRIM(msg))
2772 call Transpose('read',MemoryOrder,di, Field,l1,l2,m1,m2,n1,n2 &
2773 ,XField,x1,x2,y1,y2,z1,z2 &
2774 ,i1,i2,j1,j2,k1,k2 )
2775 deallocate(XField, STAT=stat)
2777 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
2778 write(msg,*) 'Fatal DEALLOCATION ERROR in ',__FILE__,', line', __LINE__
2779 call wrf_debug ( FATAL , msg)
2783 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2784 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2785 call wrf_debug ( FATAL , msg)
2787 DH%first_operation = .FALSE.
2789 end subroutine ext_adios2_read_field
2791 subroutine ext_adios2_inquire_opened( DataHandle, FileName , FileStatus, Status )
2793 use ext_adios2_support_routines
2795 include 'wrf_status_codes.h'
2796 integer ,intent(in) :: DataHandle
2797 character*(*) ,intent(in) :: FileName
2798 integer ,intent(out) :: FileStatus
2799 integer ,intent(out) :: Status
2800 type(wrf_data_handle) ,pointer :: DH
2802 call GetDH(DataHandle,DH,Status)
2803 if(Status /= WRF_NO_ERR) then
2804 FileStatus = WRF_FILE_NOT_OPENED
2807 if(FileName /= DH%FileName) then
2808 FileStatus = WRF_FILE_NOT_OPENED
2810 FileStatus = DH%FileStatus
2814 end subroutine ext_adios2_inquire_opened
2816 subroutine ext_adios2_inquire_filename( Datahandle, FileName, FileStatus, Status )
2818 use ext_adios2_support_routines
2820 include 'wrf_status_codes.h'
2821 integer ,intent(in) :: DataHandle
2822 character*(*) ,intent(out) :: FileName
2823 integer ,intent(out) :: FileStatus
2824 integer ,intent(out) :: Status
2825 type(wrf_data_handle) ,pointer :: DH
2827 FileStatus = WRF_FILE_NOT_OPENED
2828 call GetDH(DataHandle,DH,Status)
2829 if(Status /= WRF_NO_ERR) then
2830 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2831 call wrf_debug ( WARN , TRIM(msg))
2834 FileName = DH%FileName
2835 FileStatus = DH%FileStatus
2838 end subroutine ext_adios2_inquire_filename
2840 subroutine ext_adios2_set_time(DataHandle, DateStr, Status)
2842 use ext_adios2_support_routines
2844 include 'wrf_status_codes.h'
2845 integer ,intent(in) :: DataHandle
2846 character*(*) ,intent(in) :: DateStr
2847 integer ,intent(out) :: Status
2848 type(wrf_data_handle) ,pointer :: DH
2851 call DateCheck(DateStr,Status)
2852 if(Status /= WRF_NO_ERR) then
2853 write(msg,*) 'Warning DATE STRING ERROR in ',__FILE__,', line', __LINE__
2854 call wrf_debug ( WARN , TRIM(msg))
2857 call GetDH(DataHandle,DH,Status)
2858 if(Status /= WRF_NO_ERR) then
2859 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2860 call wrf_debug ( WARN , TRIM(msg))
2863 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2864 Status = WRF_WARN_FILE_NOT_OPENED
2865 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2866 call wrf_debug ( WARN , TRIM(msg))
2867 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2868 Status = WRF_WARN_FILE_NOT_COMMITTED
2869 write(msg,*) 'Warning FILE NOT COMMITTED in ',__FILE__,', line', __LINE__
2870 call wrf_debug ( WARN , TRIM(msg))
2871 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2872 Status = WRF_WARN_READ_WONLY_FILE
2873 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2874 call wrf_debug ( WARN , TRIM(msg))
2875 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2877 if(DH%Times(i)==DateStr) then
2881 if(i==MaxTimes) then
2882 Status = WRF_WARN_TIME_NF
2886 DH%CurrentVariable = 0
2889 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2890 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2891 call wrf_debug ( FATAL , msg)
2894 end subroutine ext_adios2_set_time
2896 subroutine ext_adios2_get_next_time(DataHandle, DateStr, Status)
2898 use ext_adios2_support_routines
2900 include 'wrf_status_codes.h'
2901 integer ,intent(in) :: DataHandle
2902 character*(*) ,intent(out) :: DateStr
2903 integer ,intent(out) :: Status
2904 type(wrf_data_handle) ,pointer :: DH
2906 call GetDH(DataHandle,DH,Status)
2907 if(Status /= WRF_NO_ERR) then
2908 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2909 call wrf_debug ( WARN , TRIM(msg))
2912 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2913 Status = WRF_WARN_FILE_NOT_OPENED
2914 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2915 call wrf_debug ( WARN , TRIM(msg))
2916 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2917 Status = WRF_WARN_DRYRUN_READ
2918 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2919 call wrf_debug ( WARN , TRIM(msg))
2920 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2921 Status = WRF_WARN_READ_WONLY_FILE
2922 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2923 call wrf_debug ( WARN , TRIM(msg))
2924 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE ) then
2925 if(DH%CurrentTime >= DH%NumberTimes) then
2926 write(msg,*) 'Warning ext_adios2_get_next_time: DH%CurrentTime >= DH%NumberTimes ',DH%CurrentTime,DH%NumberTimes
2927 call wrf_debug ( WARN , TRIM(msg))
2928 Status = WRF_WARN_TIME_EOF
2931 DH%CurrentTime = DH%CurrentTime + 1
2932 DateStr = DH%Times(DH%CurrentTime)
2933 DH%CurrentVariable = 0
2936 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2937 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2938 call wrf_debug ( FATAL , msg)
2941 end subroutine ext_adios2_get_next_time
2943 subroutine ext_adios2_get_previous_time(DataHandle, DateStr, Status)
2945 use ext_adios2_support_routines
2947 include 'wrf_status_codes.h'
2948 integer ,intent(in) :: DataHandle
2949 character*(*) ,intent(out) :: DateStr
2950 integer ,intent(out) :: Status
2951 type(wrf_data_handle) ,pointer :: DH
2953 call GetDH(DataHandle,DH,Status)
2954 if(Status /= WRF_NO_ERR) then
2955 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
2956 call wrf_debug ( WARN , TRIM(msg))
2959 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
2960 Status = WRF_WARN_FILE_NOT_OPENED
2961 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
2962 call wrf_debug ( WARN , TRIM(msg))
2963 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
2964 Status = WRF_WARN_DRYRUN_READ
2965 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
2966 call wrf_debug ( WARN , TRIM(msg))
2967 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
2968 Status = WRF_WARN_READ_WONLY_FILE
2969 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
2970 call wrf_debug ( WARN , TRIM(msg))
2971 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
2972 if(DH%CurrentTime.GT.0) then
2973 DH%CurrentTime = DH%CurrentTime -1
2975 DateStr = DH%Times(DH%CurrentTime)
2976 DH%CurrentVariable = 0
2979 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
2980 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
2981 call wrf_debug ( FATAL , msg)
2984 end subroutine ext_adios2_get_previous_time
2986 subroutine ext_adios2_get_next_var(DataHandle, VarName, Status)
2988 use ext_adios2_support_routines
2990 include 'wrf_status_codes.h'
2991 integer ,intent(in) :: DataHandle
2992 character*(*) ,intent(out) :: VarName
2993 integer ,intent(out) :: Status
2994 type(wrf_data_handle) ,pointer :: DH
2996 character (80) :: Name
2998 call GetDH(DataHandle,DH,Status)
2999 if(Status /= WRF_NO_ERR) then
3000 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
3001 call wrf_debug ( WARN , TRIM(msg))
3004 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
3005 Status = WRF_WARN_FILE_NOT_OPENED
3006 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
3007 call wrf_debug ( WARN , TRIM(msg))
3008 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
3009 Status = WRF_WARN_DRYRUN_READ
3010 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
3011 call wrf_debug ( WARN , TRIM(msg))
3012 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
3013 Status = WRF_WARN_READ_WONLY_FILE
3014 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
3015 call wrf_debug ( WARN , TRIM(msg))
3016 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
3017 DH%CurrentVariable = DH%CurrentVariable +1
3018 if(DH%CurrentVariable > DH%NumVars) then
3019 Status = WRF_WARN_VAR_EOF
3022 VarName = DH%VarNames(DH%CurrentVariable)
3025 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
3026 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
3027 call wrf_debug ( FATAL , msg)
3030 end subroutine ext_adios2_get_next_var
3032 subroutine ext_adios2_end_of_frame(DataHandle, Status)
3034 use ext_adios2_support_routines
3036 include 'wrf_status_codes.h'
3037 integer ,intent(in) :: DataHandle
3038 integer ,intent(out) :: Status
3039 type(wrf_data_handle) ,pointer :: DH
3041 call GetDH(DataHandle,DH,Status)
3043 end subroutine ext_adios2_end_of_frame
3045 subroutine ext_adios2_get_var_info(DataHandle,Name,NDim,MemoryOrder,Stagger,DomainStart,DomainEnd,WrfType,Status)
3047 use ext_adios2_support_routines
3050 include 'wrf_status_codes.h'
3051 integer ,intent(in) :: DataHandle
3052 character*(*) ,intent(in) :: Name
3053 integer ,intent(out) :: NDim
3054 character*(*) ,intent(out) :: MemoryOrder
3055 character*(*) :: Stagger ! Dummy for now
3056 integer ,dimension(*) ,intent(out) :: DomainStart, DomainEnd
3057 integer ,intent(out) :: WrfType
3058 integer ,intent(out) :: Status
3059 type(wrf_data_handle) ,pointer :: DH
3060 type(adios2_variable) :: VarID
3061 integer ,dimension(NVarDims) :: VDimIDs
3065 type(adios2_attribute) :: attribute
3066 integer(kind=8), dimension(:), allocatable :: shape_dims
3067 integer :: ndims_adios2
3069 call GetDH(DataHandle,DH,Status)
3070 if(Status /= WRF_NO_ERR) then
3071 write(msg,*) 'Warning Status = ',Status,' in ',__FILE__,', line', __LINE__
3072 call wrf_debug ( WARN , TRIM(msg))
3075 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
3076 Status = WRF_WARN_FILE_NOT_OPENED
3077 write(msg,*) 'Warning FILE NOT OPENED in ',__FILE__,', line', __LINE__
3078 call wrf_debug ( WARN , TRIM(msg))
3080 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
3081 Status = WRF_WARN_DRYRUN_READ
3082 write(msg,*) 'Warning DRYRUN READ in ',__FILE__,', line', __LINE__
3083 call wrf_debug ( WARN , TRIM(msg))
3085 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
3086 Status = WRF_WARN_READ_WONLY_FILE
3087 write(msg,*) 'Warning READ WRITE ONLY FILE in ',__FILE__,', line', __LINE__
3088 call wrf_debug ( WARN , TRIM(msg))
3090 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ .OR. DH%FileStatus == WRF_FILE_OPENED_FOR_UPDATE) then
3091 call adios2_inquire_variable(VarID, DH%adios2IO, Name, stat)
3092 call adios2_err(stat,Status)
3093 if(Status /= WRF_NO_ERR) then
3094 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3095 call wrf_debug ( WARN , TRIM(msg))
3099 call adios2_inquire_variable_attribute(attribute, DH%adios2IO, 'FieldType', Name, '/', stat)
3100 call adios2_err(stat,Status)
3101 if(Status /= WRF_NO_ERR) then
3102 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3103 call wrf_debug ( WARN , TRIM(msg))
3106 call adios2_attribute_data(WrfType, attribute, stat)
3107 call adios2_err(stat,Status)
3108 if(Status /= WRF_NO_ERR) then
3109 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3110 call wrf_debug ( WARN , TRIM(msg))
3114 case (adios2_type_character)
3115 Status = WRF_WARN_BAD_DATA_TYPE
3116 write(msg,*) 'Warning CHAR IS BAD DATA TYPE in ',__FILE__,', line', __LINE__
3117 call wrf_debug ( WARN , TRIM(msg))
3119 case (adios2_type_integer4)
3120 if(WrfType /= WRF_INTEGER .and. WrfType /= WRF_LOGICAL) then
3121 Status = WRF_WARN_BAD_DATA_TYPE
3122 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3123 call wrf_debug ( WARN , TRIM(msg))
3126 case (adios2_type_real)
3127 if(WrfType /= WRF_REAL) then
3128 Status = WRF_WARN_BAD_DATA_TYPE
3129 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3130 call wrf_debug ( WARN , TRIM(msg))
3133 case (adios2_type_dp)
3134 if(WrfType /= WRF_DOUBLE) then
3135 Status = WRF_WARN_BAD_DATA_TYPE
3136 write(msg,*) 'Warning BAD DATA TYPE in ',__FILE__,', line', __LINE__
3137 call wrf_debug ( WARN , TRIM(msg))
3141 Status = WRF_WARN_DATA_TYPE_NOT_FOUND
3142 write(msg,*) 'Warning DATA TYPE NOT FOUND in ',__FILE__,', line', __LINE__
3143 call wrf_debug ( WARN , TRIM(msg))
3146 call adios2_inquire_variable_attribute(attribute, DH%adios2IO, 'MemoryOrder', Name, '/', stat)
3147 call adios2_err(stat,Status)
3148 if(Status /= WRF_NO_ERR) then
3149 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3150 call wrf_debug ( WARN , TRIM(msg))
3153 call adios2_attribute_data(MemoryOrder, attribute, stat)
3154 call adios2_err(stat,Status)
3155 if(Status /= WRF_NO_ERR) then
3156 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3157 call wrf_debug ( WARN , TRIM(msg))
3160 call GetDim(MemoryOrder,NDim,Status)
3161 if(Status /= WRF_NO_ERR) then
3162 write(msg,*) 'Warning BAD MEMORY ORDER ',TRIM(MemoryOrder),' in ',__FILE__,', line', __LINE__
3163 call wrf_debug ( WARN , TRIM(msg))
3166 call adios2_variable_shape(shape_dims, ndims_adios2, VarID, stat)
3167 call adios2_err(stat,Status)
3168 if(Status /= WRF_NO_ERR) then
3169 write(msg,*) 'adios2 error in ',__FILE__,', line', __LINE__
3170 call wrf_debug ( WARN , TRIM(msg))
3173 DomainEnd(1:NDim) = shape_dims(1:NDim)
3175 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
3176 write(msg,*) 'Fatal error BAD FILE STATUS in ',__FILE__,', line', __LINE__
3177 call wrf_debug ( FATAL , msg)
3180 end subroutine ext_adios2_get_var_info