xdmf_obj_Write Subroutine

private impure subroutine xdmf_obj_Write(this, filename)

Write the XDMF info to a file. This is a serial subroutine and should be called by only one rank.

Type Bound

xdmf_obj

Arguments

Type IntentOptional Attributes Name
class(xdmf_obj), intent(inout) :: this

XDMF object

character(len=*), intent(in) :: filename

Name of file to write


Calls

proc~~xdmf_obj_write~~CallsGraph proc~xdmf_obj_write xdmf_obj%xdmf_obj_Write proc~stringtool_obj_removeextension stringtool_obj%stringtool_obj_RemoveExtension proc~xdmf_obj_write->proc~stringtool_obj_removeextension

Source Code

    impure subroutine xdmf_obj_Write(this,filename)
      !> Write the XDMF info to a file.
      ! This is a serial subroutine and should be called by only one rank.
      implicit none
      class(xdmf_obj),  intent(inout) :: this                                  !! XDMF object
      character(len=*), intent(in)    :: filename                              !! Name of file to write
      ! Work variables
      type(stringtool_obj) :: stringtool
      integer :: fid
      integer :: ierr
      integer :: dir
      integer :: n

      this%filename = stringtool%RemoveExtension(filename)//XDMF_EXTENSION

      open(newunit=fid, file = this%filename , action ='WRITE', iostat = ierr)

      ! Write headers
      write(fid, fmt='(a)')  '<?xml version="1.0" ?>'
      write(fid, fmt='(a)')  '<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>'
      write(fid, fmt='(a)')  '<Xdmf Version="3.0">'
      write(fid, fmt='(a)')  ' <Domain>'
      ! Write grid info
      write(fid, fmt='(3a)') '   <Grid Name="',this%grid%name,'" GridType="Uniform" >'
      write(fid, fmt='(3a)') '     <Topology TopologyType="3DRectMesh" NumberOfElements="',this%grid%NumberOfElements,'" />'
      write(fid, fmt='(a)')  '     <Geometry GeometryType="VXVYVZ" >'
      do dir=1,3
        write(fid, fmt='(9a)') '       <DataItem Dimensions="', this%grid%axis(dir)%dimensions, &
                                      '" NumberType="',         this%grid%axis(dir)%type,       &
                                      '" Precision="',          this%grid%axis(dir)%precision,  &
                                      '" Format="',             this%grid%axis(dir)%format,     &
                                      '" >'
        write(fid, fmt='(2a)')  '         ',this%grid%axis(1)%path
        write(fid, fmt='(a)')  '       </DataItem>'
      end do
      write(fid, fmt='(a)')  '     </Geometry>'
      ! Write field attributes
      do n=1,this%fields_count
        write(fid, fmt='(7a)') '     <Attribute Name="',     this%fields(n)%name, &
                                    '" AttributeType="',     'Scalar',            &
                                    '" Center="',            'Cell',              &
                                    '" >'

        write(fid, fmt='(9a)') '       <DataItem Dimensions="', this%fields(n)%dimensions, &
                                      '" NumberType="',         this%fields(n)%type,       &
                                      '" Precision="',          this%fields(n)%precision,  &
                                      '" Format="',             this%fields(n)%format,     &
                                      '" >'
        write(fid, fmt='(2a)')  '         ',this%fields(n)%path
        write(fid, fmt='(a)')  '       </DataItem>'
        write(fid, fmt='(a)')  '     </Attribute>'
      end do
      ! Close environemnts
      write(fid, fmt='(a)')  '   </Grid>'
      write(fid, fmt='(a)')  ' </Domain>'
      write(fid, fmt='(a)')  '</Xdmf>'

      close(fid)

      return
    end subroutine xdmf_obj_Write