The VTK_INI_XML function is used for initializing file. This function must be the first to be called.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | output_format | |||
character(len=*), | intent(in) | :: | filename | |||
character(len=*), | intent(in) | :: | mesh_topology | |||
integer(kind=I4P), | intent(in), | optional | :: | nx1 | ||
integer(kind=I4P), | intent(in), | optional | :: | nx2 | ||
integer(kind=I4P), | intent(in), | optional | :: | ny1 | ||
integer(kind=I4P), | intent(in), | optional | :: | ny2 | ||
integer(kind=I4P), | intent(in), | optional | :: | nz1 | ||
integer(kind=I4P), | intent(in), | optional | :: | nz2 |
function VTK_INI_XML(output_format,filename,mesh_topology,nx1,nx2,ny1,ny2,nz1,nz2) result(E_IO)
!---------------------------------------------------------------------------------------------------------------------------------
!!The VTK\_INI\_XML function is used for initializing file. This function must be the first to be called.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
implicit none
character(*), intent(IN):: output_format ! output format: ASCII or BINARY
character(*), intent(IN):: filename ! file name
character(*), intent(IN):: mesh_topology ! mesh topology
integer(I4P), intent(IN), optional:: nx1,nx2 ! initial and final nodes of x axis
integer(I4P), intent(IN), optional:: ny1,ny2 ! initial and final nodes of y axis
integer(I4P), intent(IN), optional:: nz1,nz2 ! initial and final nodes of z axis
integer(I4P):: E_IO ! Input/Output inquiring flag: $0$ if IO is done, $> 0$ if IO is not done
character(len=maxlen):: s_buffer ! buffer string
!!The VTK\_INI\_XML variables have the following meaning:
!!
!!\begin{description}
!!\item[{\color{RoyalBlue}output\_format}] indicates the \virgo{format} of output file. It can assume the following values:
!! \begin{enumerateABlu}
!! \item \emph{ascii} (it is case insensitive) $\rightarrow$ creating an ascii output file.
!! \item \emph{binary} (it is case insensitive) $\rightarrow$ creating a binary (big\_endian encoding) output file.
!! \end{enumerateABlu}
!! \item[{\color{RoyalBlue}filename}] contains the name (with its path) of the output file.
!! \item[{\color{RoyalBlue}topology}] indicates the topology of the mesh and can assume the following values:
!! \begin{enumerateABlu}
!! \item \emph{StructuredGrid}.
!! \item \emph{RectilinearGrid}.
!! \item \emph{UnstructuredGrid}.
!! \end{enumerateABlu}
!! \item[{\color{RoyalBlue}nx1,nx2}] contains the extent of X axis; $nx1$ is the initial node and $nx2$ is the final.
!! \item[{\color{RoyalBlue}ny1,ny2}] contains the extent of Y axis; $ny1$ is the initial node and $ny2$ is the final.
!! \item[{\color{RoyalBlue}nz1,nz2}] contains the extent of Z axis; $nz1$ is the initial node and $nz2$ is the final.
!! \item[{\color{RoyalBlue}E\_IO}] contains the inquiring integer flag for error handling.
!!\end{description}
!!
!!This function is quite more complex than the rispective legacy function; it needs more inputs: the XML standard needs more
!!informations to initialize the file.
!!
!!The following is an example of VTK\_INI\_XML calling:
!!
!!\begin{boxred}{VTK\_INI\_XML Calling}
!!\begin{verbatim}
!!...
!!...
!!E_IO = VTK_INI_XML('BINARY','XML_RECT_BINARY.vtr', &
!! 'RectilinearGrid', &
!! nx1=nx1,nx2=nx2, &
!! ny1=ny1,ny2=ny2, &
!! nz1=nz1,nz2=nz2)
!!...
!!\end{verbatim}
!!\end{boxred}
!!
!!\noindent Note that the file extension is necessary in the file name. The XML standard has different extensions for each
!!different topologies (i.e. \MaiuscolettoBS{.vtr} for rectilinear topology). See the VTK-standard file for more information.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
topology = trim(mesh_topology)
Unit_VTK=GetUnit()
select case(trim(Upper_Case(output_format)))
case('ASCII')
f_out = f_out_ascii
open(unit = Unit_VTK, &
file = trim(filename), &
form = 'FORMATTED', &
access = 'SEQUENTIAL', &
action = 'WRITE', &
iostat = E_IO)
! writing header of file
write(unit=Unit_VTK,fmt='(A)',iostat=E_IO)'<?xml version="1.0"?>'
write(unit=Unit_VTK,fmt='(A)',iostat=E_IO)'<VTKFile type="'//trim(topology)//'" version="0.1" byte_order="BigEndian">'
indent = 2
select case(trim(topology))
case('RectilinearGrid','StructuredGrid')
write(unit=Unit_VTK,fmt='(A,6'//FI4P//',A)',iostat=E_IO)repeat(' ',indent)// &
'<'// &
trim(topology)// &
' WholeExtent="', &
nx1,nx2,ny1,ny2,nz1,nz2, &
'">'
case('UnstructuredGrid')
write(unit=Unit_VTK,fmt='(A)',iostat=E_IO)repeat(' ',indent)//'<'//trim(topology)//'>'
endselect
indent = indent + 2
case('BINARY')
f_out = f_out_binary
open(unit = Unit_VTK, &
file = trim(filename), &
form = 'UNFORMATTED', &
access = 'STREAM', &
action = 'WRITE', &
convert = 'BIG_ENDIAN', &
iostat = E_IO)
! writing header of file
write(unit=Unit_VTK,iostat=E_IO)'<?xml version="1.0"?>'//end_rec
write(unit=Unit_VTK,iostat=E_IO)'<VTKFile type="'//trim(topology)//'" version="0.1" byte_order="BigEndian">'//end_rec
indent = 2
select case(trim(topology))
case('RectilinearGrid','StructuredGrid')
write(s_buffer,fmt='(A,6'//FI4P//',A)',iostat=E_IO)repeat(' ',indent)// &
'<'// &
trim(topology)// &
' WholeExtent="', &
nx1,nx2,ny1,ny2,nz1,nz2, &
'">'
case('UnstructuredGrid')
write(s_buffer,fmt='(A)',iostat=E_IO)repeat(' ',indent)//'<'//trim(topology)//'>'
endselect
write(unit=Unit_VTK,iostat=E_IO)trim(s_buffer)//end_rec
indent = indent + 2
Unit_VTK_Append=GetUnit()
! opening the SCRATCH file used for appending raw binary data
open(unit = Unit_VTK_Append, &
form = 'UNFORMATTED', &
access = 'STREAM', &
action = 'READWRITE', &
convert = 'BIG_ENDIAN', &
status = 'SCRATCH', &
iostat = E_IO)
ioffset = 0 ! initializing offset puntator
endselect
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction VTK_INI_XML