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 !*----------------------------------------------------------------------------
18 use ext_adios2_support_routines
21 include 'wrf_status_codes.h'
22 integer ,intent(in) :: DataHandle
23 character*(*) ,intent(in) :: Element
24 character*(*) ,intent(in) :: Var
28 integer ,intent(out) :: Status
29 type(wrf_data_handle) ,pointer :: DH
32 character (VarNameLen) :: VarName
36 type(adios2_attribute) :: AttributeID
39 Status = WRF_WARN_ZERO_LENGTH_GET
41 'Warning ZERO LENGTH GET in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
42 call wrf_debug ( WARN , msg)
46 call GetDH(DataHandle,DH,Status)
47 if(Status /= WRF_NO_ERR) then
49 'Warning Status = ',Status,' in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
50 call wrf_debug ( WARN , msg)
53 if(DH%FileStatus == WRF_FILE_NOT_OPENED) then
54 Status = WRF_WARN_FILE_NOT_OPENED
56 'Warning FILE NOT OPENED in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
57 call wrf_debug ( WARN , msg)
58 elseif(DH%FileStatus == WRF_FILE_OPENED_NOT_COMMITTED) then
59 Status = WRF_WARN_DRYRUN_READ
61 'Warning DRYRUN READ in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
62 call wrf_debug ( WARN , msg)
63 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_WRITE) then
64 Status = WRF_WARN_READ_WONLY_FILE
66 'Warning READ WONLY FILE in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
67 call wrf_debug ( WARN , msg)
68 elseif(DH%FileStatus == WRF_FILE_OPENED_FOR_READ) then
70 if(DH%VarNames(NVar) == VarName) then
72 elseif(NVar == DH%NumVars) then
73 Status = WRF_WARN_VAR_NF
75 'Warning VARIABLE NOT FOUND in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
76 call wrf_debug ( WARN , msg)
80 call adios2_inquire_variable_attribute(AttributeID, DH%adios2IO, trim(Element), VarName, '/', stat )
81 call adios2_err(stat,Status)
82 if(Status /= WRF_NO_ERR) then
83 write(msg,*) 'adios2 error in ext_adios2_get_var_ti',__FILE__,', line', __LINE__
84 call wrf_debug ( WARN , TRIM(msg))
87 XLen = AttributeID%length
89 allocate(Buffer(XLen), STAT=stat)
91 Status = WRF_ERR_FATAL_ALLOCATION_ERROR
93 'Fatal ALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
94 call wrf_debug ( FATAL , msg)
97 call adios2_attribute_data(Buffer, AttributeID, stat)
100 call adios2_attribute_data(Data, AttributeID, stat)
102 call adios2_err(stat,Status)
103 if(Status /= WRF_NO_ERR) then
104 write(msg,*) 'adios2 error in ext_adios2_get_var_ti',__FILE__,', line', __LINE__
105 call wrf_debug ( WARN , TRIM(msg))
110 deallocate(Buffer, STAT=stat)
112 Status = WRF_ERR_FATAL_DEALLOCATION_ERR
114 'Fatal DEALLOCATION ERROR in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
115 call wrf_debug ( FATAL , msg)
118 if(XLen > Count) then
120 Status = WRF_WARN_MORE_DATA_IN_FILE
127 Status = WRF_ERR_FATAL_BAD_FILE_STATUS
129 'Fatal error BAD FILE STATUS in ',__FILE__,' ',ROUTINE_TYPE,', line', __LINE__
130 call wrf_debug ( FATAL , msg)