Skip to content

Commit

Permalink
Merge branch 'release/2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
szaghi committed Dec 23, 2016
2 parents 0030e8d + 59b8248 commit c7ccc18
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 20 deletions.
31 changes: 15 additions & 16 deletions src/lib/vtk_fortran_vtk_file_xml_writer_abstract.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ module vtk_fortran_vtk_file_xml_writer_abstract
!-----------------------------------------------------------------------------------------------------------------------------------
type, abstract :: xml_writer_abstract
!< VTK file abstract XML writer.
type(string) :: format_ch !< Output format, string code.
type(string) :: topology !< Mesh topology.
integer(I4P) :: indent=0_I4P !< Indent count.
integer(I8P) :: ioffset=0_I8P !< Offset count.
integer(I4P) :: xml=0_I4P !< XML Logical unit.
integer(I4P) :: vtm_block(1:2)=[0_I4P, 0_I4P] !< Block indexes.
integer(I4P) :: error=0_I4P !< IO Error status.
type(xml_tag) :: tag !< XML tags handler.
type(string) :: format_ch !< Output format, string code.
type(string) :: topology !< Mesh topology.
integer(I4P) :: indent=0_I4P !< Indent count.
integer(I8P) :: ioffset=0_I8P !< Offset count.
integer(I4P) :: xml=0_I4P !< XML Logical unit.
integer(I4P) :: vtm_block(1:2)=[-1_I4P, -1_I4P] !< Block indexes.
integer(I4P) :: error=0_I4P !< IO Error status.
type(xml_tag) :: tag !< XML tags handler.
contains
! public methods (some deferred)
procedure, pass(self) :: close_xml_file !< Close xml file.
Expand Down Expand Up @@ -784,9 +784,9 @@ subroutine write_header_tag(self)
!---------------------------------------------------------------------------------------------------------------------------------
buffer = '<?xml version="1.0"?>'//end_rec
if (endian==endianL) then
buffer = buffer//'<VTKFile type="'//self%topology//'" version="0.1" byte_order="LittleEndian">'
buffer = buffer//'<VTKFile type="'//self%topology//'" version="1.0" byte_order="LittleEndian">'
else
buffer = buffer//'<VTKFile type="'//self%topology//'" version="0.1" byte_order="BigEndian">'
buffer = buffer//'<VTKFile type="'//self%topology//'" version="1.0" byte_order="BigEndian">'
endif
write(unit=self%xml, iostat=self%error)buffer//end_rec
self%indent = 2
Expand Down Expand Up @@ -1548,22 +1548,21 @@ function write_parallel_open_block(self, name) result(error)
!---------------------------------------------------------------------------------------------------------------------------------
self%vtm_block = self%vtm_block + 1
if (present(name)) then
buffer = 'index="'//trim(str((self%vtm_block(1)+self%vtm_block(2)),.true.))//'" name="'//trim(adjustl(name))//'"'
buffer = 'index="'//trim(str((self%vtm_block(1) + self%vtm_block(2)),.true.))//'" name="'//trim(adjustl(name))//'"'
else
buffer = 'index="'//trim(str((self%vtm_block(1)+self%vtm_block(2)),.true.))//'"'
buffer = 'index="'//trim(str((self%vtm_block(1) + self%vtm_block(2)),.true.))//'"'
endif
call self%write_start_tag(name='Block', attributes=buffer%chars())
error = self%error
!---------------------------------------------------------------------------------------------------------------------------------
endfunction write_parallel_open_block

function write_parallel_close_block(self, name) result(error)
function write_parallel_close_block(self) result(error)
!---------------------------------------------------------------------------------------------------------------------------------
!< Close a block container.
!---------------------------------------------------------------------------------------------------------------------------------
class(xml_writer_abstract), intent(inout) :: self !< Writer.
character(*), intent(in), optional :: name !< Block name.
integer(I4P) :: error !< Error status.
class(xml_writer_abstract), intent(inout) :: self !< Writer.
integer(I4P) :: error !< Error status.
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
Expand Down
70 changes: 68 additions & 2 deletions src/lib/vtk_fortran_vtm_file.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ module vtk_fortran_vtm_file
!< VTM file class.
class(xml_writer_abstract), allocatable, public :: xml_writer !< XML writer.
contains
procedure, pass(self) :: initialize !< Initialize file.
procedure, pass(self) :: finalize !< Finalize file.
! public methods
procedure, pass(self) :: initialize !< Initialize file.
procedure, pass(self) :: finalize !< Finalize file.
generic :: write_block => &
write_block_array, &
write_block_string !< Write one block dataset.
! private methods
procedure, pass(self), private :: write_block_array !< Write one block dataset (array input).
procedure, pass(self), private :: write_block_string !< Write one block dataset (string input).
endtype vtm_file
!-----------------------------------------------------------------------------------------------------------------------------------
contains
! public methods
function initialize(self, filename) result(error)
!---------------------------------------------------------------------------------------------------------------------------------
!< Initialize file (writer).
Expand Down Expand Up @@ -56,4 +64,62 @@ function finalize(self) result(error)
if (allocated(self%xml_writer)) error = self%xml_writer%finalize()
!---------------------------------------------------------------------------------------------------------------------------------
endfunction finalize

! private methods
function write_block_array(self, filenames, names, name) result(error)
!---------------------------------------------------------------------------------------------------------------------------------
!< Write one block dataset (array input).
!<
!<#### Example of usage: 3 files blocks
!<```fortran
!< error = vtm%write_block(filenames=['file_1.vts', 'file_2.vts', 'file_3.vtu'], name='my_block')
!<```
!<
!<#### Example of usage: 3 files blocks with custom name
!<```fortran
!< error = vtm%write_block(filenames=['file_1.vts', 'file_2.vts', 'file_3.vtu'], &
!< names=['block-bar', 'block-foo', 'block-baz'], name='my_block')
!<```
!---------------------------------------------------------------------------------------------------------------------------------
class(vtm_file), intent(inout) :: self !< VTM file.
character(*), intent(in) :: filenames(1:) !< File names of VTK files grouped into current block.
character(*), intent(in), optional :: names(1:) !< Auxiliary names attributed to each files.
character(*), intent(in), optional :: name !< Block name
integer(I4P) :: error !< Error status.
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
error = self%xml_writer%write_parallel_open_block(name=name)
error = self%xml_writer%write_parallel_block_files(filenames=filenames, names=names)
error = self%xml_writer%write_parallel_close_block()
!---------------------------------------------------------------------------------------------------------------------------------
endfunction write_block_array

function write_block_string(self, filenames, names, name) result(error)
!---------------------------------------------------------------------------------------------------------------------------------
!< Write one block dataset (string input).
!<
!<#### Example of usage: 3 files blocks
!<```fortran
!< error = vtm%write_block(filenames='file_1.vts file_2.vts file_3.vtu', name='my_block')
!<```
!<
!<#### Example of usage: 3 files blocks with custom name
!<```fortran
!< error = vtm%write_block(filenames='file_1.vts file_2.vts file_3.vtu', names='block-bar block-foo block-baz', name='my_block')
!<```
!---------------------------------------------------------------------------------------------------------------------------------
class(vtm_file), intent(inout) :: self !< VTM file.
character(*), intent(in) :: filenames !< File names of VTK files grouped into current block.
character(*), intent(in), optional :: names !< Auxiliary names attributed to each files.
character(*), intent(in), optional :: name !< Block name
integer(I4P) :: error !< Error status.
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
error = self%xml_writer%write_parallel_open_block(name=name)
error = self%xml_writer%write_parallel_block_files(filenames=filenames, names=names)
error = self%xml_writer%write_parallel_close_block()
!---------------------------------------------------------------------------------------------------------------------------------
endfunction write_block_string
endmodule vtk_fortran_vtm_file
83 changes: 83 additions & 0 deletions src/tests/write_vtm.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
!< VTK_Fortran test.
program write_vtm
!-----------------------------------------------------------------------------------------------------------------------------------
!< VTK_Fortran test.
!-----------------------------------------------------------------------------------------------------------------------------------
use penf
use vtk_fortran, only : vtm_file, vtk_file
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
implicit none
type(vtk_file) :: a_vtk_file !< A VTK file.
type(vtm_file) :: a_vtm_file !< A VTM file.
integer(I4P), parameter :: nx1=0_I4P !< X lower bound extent.
integer(I4P), parameter :: nx2=9_I4P !< X upper bound extent.
integer(I4P), parameter :: ny1=0_I4P !< Y lower bound extent.
integer(I4P), parameter :: ny2=5_I4P !< Y upper bound extent.
integer(I4P), parameter :: nz1=0_I4P !< Z lower bound extent.
integer(I4P), parameter :: nz2=5_I4P !< Z upper bound extent.
integer(I4P), parameter :: nn=(nx2-nx1+1)*(ny2-ny1+1)*(nz2-nz1+1) !< Number of elements.
real(R8P) :: x(nx1:nx2,ny1:ny2,nz1:nz2) !< X coordinates.
real(R8P) :: y(nx1:nx2,ny1:ny2,nz1:nz2) !< Y coordinates.
real(R8P) :: z(nx1:nx2,ny1:ny2,nz1:nz2) !< Z coordinates.
real(R8P) :: v(nx1:nx2,ny1:ny2,nz1:nz2) !< Variable defined at coordinates.
character(15) :: filenames(4) !< File names.
character(1) :: names(4) !< Custom names.
integer(I4P) :: error !< Status error.
integer(I4P) :: i !< Counter.
integer(I4P) :: j !< Counter.
integer(I4P) :: k !< Counter.
integer(I4P) :: f !< Counter.
logical :: test_passed(1) !< List of passed tests.
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
filenames = ['XML_STRG-01.vts', 'XML_STRG-02.vts', 'XML_STRG-03.vts', 'XML_STRG-04.vts']
names = ['1', '2', '3', '4']
do k=nz1, nz2
do j=ny1, ny2
do i=nx1, nx2
x(i, j, k) = i*1._R8P
y(i, j, k) = j*1._R8P
z(i, j, k) = k*1._R8P
v(i, j, k) = real(i*j*k, R8P)
enddo
enddo
enddo

do f=1, size(filenames, dim=1)
x = x + nx2
v = v * 2._R8P
error = a_vtk_file%initialize(format='raw', filename=filenames(f), mesh_topology='StructuredGrid', &
nx1=nx1, nx2=nx2, ny1=ny1, ny2=ny2, nz1=nz1, nz2=nz2)
call write_data
error = a_vtk_file%finalize()
enddo

error = a_vtm_file%initialize(filename='XML_STRG.vtm')
error = a_vtm_file%write_block(filenames=filenames(4)//' '//filenames(1), names=names(4)//' '//names(1), name='first block')
error = a_vtm_file%write_block(filenames=[filenames(2), filenames(3)], names=[names(2), names(3)], name='second block')
error = a_vtm_file%finalize()

test_passed = .true. ! nothing to test yet

print "(A,L1)", new_line('a')//'Are all tests passed? ', all(test_passed)
stop
!-----------------------------------------------------------------------------------------------------------------------------------
contains
subroutine write_data
!---------------------------------------------------------------------------------------------------------------------------------
!< Write data.
!---------------------------------------------------------------------------------------------------------------------------------

!---------------------------------------------------------------------------------------------------------------------------------
error = a_vtk_file%xml_writer%write_piece(nx1=nx1, nx2=nx2, ny1=ny1, ny2=ny2, nz1=nz1, nz2=nz2)
error = a_vtk_file%xml_writer%write_geo(n=nn, x=x, y=y, z=z)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='open')
error = a_vtk_file%xml_writer%write_dataarray(data_name='float64_scalar', x=v, one_component=.true.)
error = a_vtk_file%xml_writer%write_dataarray(location='node', action='close')
error = a_vtk_file%xml_writer%write_piece()
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine write_data
endprogram write_vtm
2 changes: 1 addition & 1 deletion src/third_party/StringiFor

0 comments on commit c7ccc18

Please sign in to comment.