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 use ext_adios2_support_routines
20 include 'wrf_status_codes.h'
21 integer ,intent(in) :: DataHandle
22 character*(*) ,intent(in) :: Element
23 character (DateStrLen),intent(in) :: DateStr
24 character*(*) ,intent(in) :: Var
28 integer ,intent(out) :: Status
29 type(wrf_data_handle) ,pointer :: DH
30 character (VarNameLen) :: VarName
31 character (40+len(Element)) :: Name
32 character (40+len(Element)) :: FName
34 TYPE_BUFFER ,allocatable :: Buffer(:)
42 type(adios2_variable) :: VarID
47 integer(kind=8) :: TimeIndex_int8
48 integer(kind=8),dimension(:),allocatable :: shape_dims
49 integer :: ndims_adios2
52 Status = WRF_WARN_ZERO_LENGTH_GET
54 'Warning ZERO LENGTH GET in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
55 call wrf_debug ( WARN , msg)
59 call DateCheck(DateStr,Status)
60 if(Status /= WRF_NO_ERR) then
62 'Warning DATE STRING ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
63 call wrf_debug ( WARN , msg)
66 call GetDH(DataHandle,DH,Status)
67 if(Status /= WRF_NO_ERR) then
69 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
70 call wrf_debug ( WARN , msg)
73 call GetName(Element, VarName, Name, Status)
74 if(Status /= WRF_NO_ERR) then
76 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
77 call wrf_debug ( WARN , msg)
80 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
81 Status = WRF_WARN_FILE_NOT_OPENED
83 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
84 call wrf_debug ( WARN , msg)
85 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
86 Status = WRF_WARN_DRYRUN_READ
88 'Warning DRYRUN READ in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
89 call wrf_debug ( WARN , msg)
90 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
91 Status = WRF_WARN_READ_WONLY_FILE
93 'Warning READ WONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
94 call wrf_debug ( WARN , msg)
95 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
96 call adios2_inquire_variable(VarID, DH%adios2IO, Name, stat)
97 call adios2_err(stat,Status)
98 if(Status /= WRF_NO_ERR) then
99 write(msg,*) 'adios2 error in ext_adios2_get_var_td ',__FILE__,', line', __LINE__
100 call wrf_debug ( WARN , TRIM(msg))
103 call adios2_variable_shape(shape_dims, ndims_adios2, VarID, stat)
104 call adios2_err(stat,Status)
105 if(Status /= WRF_NO_ERR) then
106 write(msg,*) 'adios2 error in ext_adios2_get_var_td ',__FILE__,', line', __LINE__
107 call wrf_debug ( WARN , TRIM(msg))
111 call GetTimeIndex('read',DataHandle,DateStr,TimeIndex,Status)
112 if(Status /= WRF_NO_ERR) then
114 'Warning in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
115 call wrf_debug ( WARN , msg)
118 TimeIndex_int8 = TimeIndex
119 call adios2_set_step_selection(VarID, TimeIndex_int8 -1_8, 1_8, stat)
120 call adios2_err(stat,Status)
121 if(Status /= WRF_NO_ERR) then
122 write(msg,*) 'adios2 error in ext_adios2_get_var_td ',__FILE__,', line', __LINE__
123 call wrf_debug ( WARN , TRIM(msg))
127 VStart(2) = TimeIndex
131 allocate(Buffer(VCount(1)), STAT=stat)
133 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
135 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
136 call wrf_debug ( FATAL , msg)
139 call adios2_get(DH%adios2Engine, VarID, Buffer, adios2_mode_sync, stat)
142 call adios2_get(DH%adios2Engine, VarID, Data, adios2_mode_sync, stat)
144 call adios2_err(stat,Status)
145 if(Status /= WRF_NO_ERR) then
146 write(msg,*) 'adios2 error in ext_adios2_get_var_td ',__FILE__,', line', __LINE__
147 call wrf_debug ( WARN , TRIM(msg))
152 deallocate(Buffer, STAT=stat)
154 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
156 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
157 call wrf_debug ( FATAL , msg)
160 if(Len1 > Count) then
162 Status = WRF_WARN_MORE_DATA_IN_FILE
169 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
171 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
172 call wrf_debug ( FATAL , msg)