@@ -12,9 +12,9 @@ module VTI
1212 private
1313
1414 public :: &
15- VTI_readDataset_int, &
1615 VTI_readDataset_real, &
17- VTI_readCellsSizeOrigin
16+ VTI_readDataset_int, &
17+ VTI_readGeometry
1818
1919contains
2020
@@ -109,7 +109,7 @@ subroutine VTI_readDataset_raw(base64Str,dataType,headerType,compressed, &
109109 getXMLValue(fileContent(startPos:endPos),' Name' ) == label ) then
110110
111111 if (getXMLValue(fileContent(startPos:endPos),' format' ) /= ' binary' ) &
112- call IO_error(error_ID = 844 , ext_msg = ' " ' // label// ' " not in binary format' )
112+ call IO_error(844_pI16 , label, ' not in binary format' , emph = [ 1 ] )
113113 dataType = getXMLValue(fileContent(startPos:endPos),' type' )
114114
115115 startPos = endPos + 2_pI64
@@ -129,24 +129,26 @@ subroutine VTI_readDataset_raw(base64Str,dataType,headerType,compressed, &
129129
130130 end do outer
131131
132- if (.not. allocated (base64Str)) call IO_error(error_ID = 844 , ext_msg = ' dataset " ' // label// ' " not found' )
132+ if (.not. allocated (base64Str)) call IO_error(844_pI16 , ' dataset' , label, ' not found' , emph = [ 2 ] )
133133
134134end subroutine VTI_readDataset_raw
135135
136136
137137!- -------------------------------------------------------------------------------------------------
138- ! > @brief Read cells, size, and origin of an VTK image data (*.vti) file.
138+ ! > @brief Read cells, size, and origin, and cell data labels of an VTK image data (*.vti) file.
139139! > @details https://vtk.org/Wiki/VTK_XML_Formats
140140!- -------------------------------------------------------------------------------------------------
141- subroutine VTI_readCellsSizeOrigin (cells ,geomSize ,origin , &
142- fileContent )
141+ subroutine VTI_readGeometry (cells ,geomSize ,origin , labels , &
142+ fileContent )
143143
144144 integer , dimension (3 ), intent (out ) :: &
145145 cells ! # of cells (across all processes!)
146146 real (pREAL), dimension (3 ), intent (out ) :: &
147147 geomSize, & ! size (across all processes!)
148148 origin ! origin (across all processes!)
149- character (len=* ), intent (in ) :: &
149+ character (len= pSTRLEN), allocatable , dimension (:), intent (out ) :: &
150+ labels ! cell data labels
151+ character (len=* ), intent (in ) :: &
150152 fileContent
151153
152154 character (len= :), allocatable :: headerType
@@ -161,7 +163,8 @@ subroutine VTI_readCellsSizeOrigin(cells,geomSize,origin, &
161163 inFile = .false.
162164 inImage = .false.
163165 startPos = 1_pI64
164- outer: do while (startPos < len (fileContent,kind= pI64))
166+
167+ do while (startPos < len (fileContent,kind= pI64))
165168 endPos = startPos + index (fileContent(startPos:),IO_EOL,kind= pI64) - 2_pI64
166169 if (endPos < startPos) endPos = len (fileContent,kind= pI64) ! end of file without new line
167170
@@ -170,26 +173,30 @@ subroutine VTI_readCellsSizeOrigin(cells,geomSize,origin, &
170173 inFile = .true.
171174 call checkFileFormat(fileContent(startPos:endPos))
172175 headerType = merge (' UInt64' ,' UInt32' ,getXMLValue(fileContent(startPos:endPos),' header_type' )==' UInt64' )
173- compressed = getXMLValue(fileContent(startPos:endPos),' compressor' ) == ' vtkZLibDataCompressor'
176+ compressed = getXMLValue(fileContent(startPos:endPos),' compressor' ) == ' vtkZLibDataCompressor'
174177 end if
175178 else
176179 if (.not. inImage) then
177180 if (index (fileContent(startPos:endPos),' <ImageData' ,kind= pI64) /= 0_pI64 ) then
178181 inImage = .true.
179182 call cellsSizeOrigin(cells,geomSize,origin,fileContent(startPos:endPos))
180- exit outer
183+ end if
184+ else
185+ if (index (fileContent(startPos:endPos),' <CellData' ,kind= pI64) /= 0_pI64 ) then
186+ call cell_labels(labels,fileContent(startPos:))
187+ exit
181188 end if
182189 end if
183190 end if
184191
185192 startPos = endPos + 2_pI64
186193
187- end do outer
194+ end do
188195
189- if (any (geomSize<= 0 )) call IO_error(error_ID = 844 , ext_msg = ' one or more grid.size <= 0' )
190- if (any (cells< 1 )) call IO_error(error_ID = 844 , ext_msg = ' one or more grid.cells < 1' )
196+ if (any (geomSize < = 0 )) call IO_error(844_pI16 , ' one or more grid.size <= 0' )
197+ if (any (cells < 1 )) call IO_error(844_pI16 , ' one or more grid.cells < 1' )
191198
192- end subroutine VTI_readCellsSizeOrigin
199+ end subroutine VTI_readGeometry
193200
194201
195202!- -------------------------------------------------------------------------------------------------
@@ -225,6 +232,39 @@ subroutine cellsSizeOrigin(c,s,o,header)
225232end subroutine cellsSizeOrigin
226233
227234
235+ !- -------------------------------------------------------------------------------------------------
236+ ! > @brief Get labels of all cell-based datasets.
237+ !- -------------------------------------------------------------------------------------------------
238+ subroutine cell_labels (labels ,file_content )
239+
240+ character (len= pSTRLEN), allocatable , dimension (:), intent (out ) :: labels ! < labels of cell data
241+ character (len=* ), intent (in ) :: file_content
242+
243+ character (len= pSTRLEN) :: label
244+ integer (pI64) :: startPos, endPos
245+
246+
247+ startPos = 1_pI64
248+ endPos = startPos + index (file_content(startPos:),IO_EOL,kind= pI64) - 2_pI64
249+
250+ allocate (labels(0 ))
251+
252+ do while (index (file_content(startPos:endPos),' </CellData>' ,kind= pI64) == 0_pI64 )
253+ if (index (file_content(startPos:endPos),' <DataArray' ,kind= pI64) /= 0_pI64 ) then
254+ label = getXMLValue(file_content(startPos:endPos),' Name' )
255+ if (any (labels == label)) then
256+ call IO_error(844_pI16 , ' repeated label' , trim (label), emph = [2 ])
257+ else
258+ labels = [labels, label]
259+ end if
260+ end if
261+ startPos = endPos + 2_pI64
262+ endPos = startPos + index (file_content(startPos:),IO_EOL,kind= pI64) - 2_pI64
263+ end do
264+
265+ end subroutine cell_labels
266+
267+
228268!- -------------------------------------------------------------------------------------------------
229269! > @brief Interpret Base64 string in vtk XML file as integer of default kind.
230270!- -------------------------------------------------------------------------------------------------
@@ -248,7 +288,7 @@ function as_Int(base64Str,headerType,compressed,dataType)
248288 case (' Float64' )
249289 as_Int = int (prec_bytesToC_DOUBLE (asBytes(base64Str,headerType,compressed)))
250290 case default
251- call IO_error(844 ,ext_msg = ' unknown data type: ' // trim (dataType))
291+ call IO_error(844_pI16 , ' unknown data type' , trim (dataType),emph = [ 2 ] )
252292 end select
253293
254294end function as_Int
@@ -277,7 +317,7 @@ function as_real(base64Str,headerType,compressed,dataType)
277317 case (' Float64' )
278318 as_real = real (prec_bytesToC_DOUBLE (asBytes(base64Str,headerType,compressed)),pREAL)
279319 case default
280- call IO_error(844 ,ext_msg = ' unknown data type: ' // trim (dataType))
320+ call IO_error(844_pI16 , ' unknown data type' , trim (dataType),emph = [ 2 ] )
281321 end select
282322
283323end function as_real
@@ -436,15 +476,15 @@ subroutine checkFileFormat(line)
436476
437477 val = getXMLValue(line,' type' )
438478 if (val /= ' ImageData' ) &
439- call IO_error(844 , ext_msg = ' type (" ' // val// ' ") is not "ImageData"' )
479+ call IO_error(844_pI16 , ' type' , val, ' is not "ImageData"' ,emph = [ 2 ] )
440480
441481 val = getXMLValue(line,' byte_order' )
442482 if (val /= ' LittleEndian' ) &
443- call IO_error(844 , ext_msg = ' byte_order (" ' // val// ' ") is not "LittleEndian"' )
483+ call IO_error(844_pI16 , ' byte_order' , val, ' is not "LittleEndian"' ,emph = [ 2 ] )
444484
445485 val = getXMLValue(line,' compressor' )
446486 if (val /= ' ' .and. val /= ' vtkZLibDataCompressor' ) &
447- call IO_error(844 , ext_msg = ' compressor (" ' // val// ' ") is not "vtkZLibDataCompressor"' )
487+ call IO_error(844_pI16 , ' compressor' , val, ' is not "vtkZLibDataCompressor"' ,emph = [ 2 ] )
448488
449489end subroutine checkFileFormat
450490
0 commit comments