xmlIntWrapFort.f90 5.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Wrapper routines for XML IO - Fortran side
!
!                                   GM'16
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 15
MODULE m_xmlIntWrapFort

16 17
USE m_juDFT

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
CONTAINS
SUBROUTINE xmlInitInterface()

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   INTEGER :: errorStatus

   interface
      function initializeXMLInterface() bind(C, name="initializeXMLInterface")
         use iso_c_binding
         INTEGER(c_int) initializeXMLInterface
      end function initializeXMLInterface
   end interface

   errorStatus = 0
   errorStatus = initializeXMLInterface()
37 38 39
   IF(errorStatus.NE.0) THEN
      CALL juDFT_error("Could not initialize XML interface.",calledby="xmlInitInterface")
   END IF
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

END SUBROUTINE xmlInitInterface

SUBROUTINE xmlParseSchema(schemaFilename)

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   CHARACTER(LEN=200,KIND=c_char), INTENT(IN) :: schemaFilename

   INTEGER :: errorStatus

   interface
      function parseXMLSchema(schemaFilename) bind(C, name="parseXMLSchema")
         use iso_c_binding
         INTEGER(c_int) parseXMLSchema
         character(kind=c_char) :: schemaFilename(*)
      end function parseXMLSchema
   end interface

   errorStatus = 0
   errorStatus = parseXMLSchema(schemaFilename)
64
   IF(errorStatus.NE.0) THEN
65
      CALL juDFT_error("XML Schema file not parsable: "//TRIM(ADJUSTL(schemaFilename)),calledby="xmlParseSchema")
66
   END IF
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

END SUBROUTINE xmlParseSchema

SUBROUTINE xmlParseDoc(docFilename)

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   CHARACTER(LEN=200,KIND=c_char), INTENT(IN) :: docFilename

   INTEGER :: errorStatus

   interface
      function parseXMLDocument(docFilename) bind(C, name="parseXMLDocument")
         use iso_c_binding
         INTEGER(c_int) parseXMLDocument
         character(kind=c_char) :: docFilename(*)
      end function parseXMLDocument
   end interface

   errorStatus = 0
   errorStatus = parseXMLDocument(docFilename)
91
   IF(errorStatus.NE.0) THEN
92
      CALL juDFT_error("XML document file not parsable: "//TRIM(ADJUSTL(docFilename)),calledby="xmlParseDoc")
93
   END IF
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

END SUBROUTINE xmlParseDoc

SUBROUTINE xmlValidateDoc()

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   INTEGER :: errorStatus

   interface
      function validateXMLDocument() bind(C, name="validateXMLDocument")
         use iso_c_binding
         INTEGER(c_int) validateXMLDocument
      end function validateXMLDocument
   end interface

   errorStatus = 0
   errorStatus = validateXMLDocument()
115
   IF(errorStatus.NE.0) THEN
116
      CALL juDFT_error("XML document cannot be validated against Schema.",calledby="xmlValidateDoc")
117
   END IF
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

END SUBROUTINE xmlValidateDoc

SUBROUTINE xmlInitXPath()

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   INTEGER :: errorStatus

   interface
      function initializeXPath() bind(C, name="initializeXPath")
         use iso_c_binding
         INTEGER(c_int) initializeXPath
      end function initializeXPath
   end interface

   errorStatus = 0
   errorStatus = initializeXPath()
139 140 141
   IF(errorStatus.NE.0) THEN
      CALL juDFT_error("Could not initialize XPath.",calledby="xmlInitXPath")
   END IF
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

END SUBROUTINE xmlInitXPath

FUNCTION xmlGetNumberOfNodes(xPath)

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   INTEGER :: xmlGetNumberOfNodes
   CHARACTER(LEN=*,KIND=c_char), INTENT(IN) :: xPath

   interface
      function getNumberOfXMLNodes(xPathExpression) bind(C, name="getNumberOfXMLNodes")
         use iso_c_binding
         INTEGER(c_int) getNumberOfXMLNodes
         character(kind=c_char) :: xPathExpression(*)
      end function getNumberOfXMLNodes
   end interface

   xmlGetNumberOfNodes = getNumberOfXMLNodes(TRIM(ADJUSTL(xPath))//C_NULL_CHAR)

END FUNCTION xmlGetNumberOfNodes

FUNCTION xmlGetAttributeValue(xPath)

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   CHARACTER(LEN=255) :: xmlGetAttributeValue

   CHARACTER(LEN=*, KIND=c_char), INTENT(IN) :: xPath

   CHARACTER (LEN=1, KIND=c_char), POINTER, DIMENSION (:) :: valueFromC => null()
   CHARACTER*255 :: value
   INTEGER :: length, errorStatus, i
   TYPE(c_ptr) :: c_string

   interface
      function getXMLAttributeValue(xPathExpression) bind(C, name="getXMLAttributeValue")
         use iso_c_binding
         CHARACTER(KIND=c_char) :: xPathExpression(*)
         TYPE(c_ptr) :: getXMLAttributeValue
      end function getXMLAttributeValue
   end interface

   c_string = getXMLAttributeValue(TRIM(ADJUSTL(xPath))//C_NULL_CHAR)

   CALL C_F_POINTER(c_string, valueFromC, [ 255 ])
   IF (.NOT.c_associated(c_string)) THEN
195 196 197
      WRITE(*,*) 'Error in trying to obtain attribute value from XPath:'
      WRITE(*,*) TRIM(ADJUSTL(xPath))
      CALL juDFT_error("Attribute value could not be obtained.",calledby="xmlGetAttributeValue")
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
   END IF
   DO i=1, 255
     value(i:i) = valueFromC(i)
   END DO
   length = LEN_TRIM(value(1:INDEX(value, CHAR(0))))

   xmlGetAttributeValue = value(1:length-1)

END FUNCTION xmlGetAttributeValue

SUBROUTINE xmlFreeResources()

   USE iso_c_binding
   USE m_types

   IMPLICIT NONE

   INTEGER :: errorStatus

   interface
      function freeXMLResources() bind(C, name="freeXMLResources")
         use iso_c_binding
         INTEGER freeXMLResources
      end function freeXMLResources
   end interface

   errorStatus = 0
   errorStatus = freeXMLResources()
226 227 228 229
   IF(errorStatus.NE.0) THEN
      CALL juDFT_error("Could not free XML resources.",calledby="xmlFreeResources")
      STOP 'Error!'
   END IF
230 231 232 233

END SUBROUTINE xmlFreeResources

END MODULE m_xmlIntWrapFort