c==============================================================================
c=====  PROGRAMA DE SUBRUTINAS AUXILIARES PARA POSTPROCESO DE DATOS        ====
c==============================================================================
c
c AUTORES: I. Couceiro, J. París
c                                                                 
c        
c FECHA ULTIMA REVISION: 20231031
c
c Copyright: Este programa es propiedad de su autor.
c            No puede utilizarse con fines comerciales sin conocimiento
c            y autorizacion de su autor.
c            Puede utilizarse con fines educativos sin ninguna restriccion.
c
c
c===============================================================================
c===============================================================================
      subroutine genera_vtu(n,m,xlength,v)
      implicit real*8(a-h,o-z)
      implicit integer*4(i-n)
      dimension v(n,m)
      character*10 contador
      log_vtu=11
      open(unit=log_vtu,file='linea_de_influencia.vtu',status='unknown')
      dx=xlength/(n+1)
      
      write(log_vtu,'(a,a)')'<VTKFile type="UnstructuredGrid" ',
     .                      'version="0.1" byte_order="LittleEndian">'
      write(log_vtu,'(a)')'  <UnstructuredGrid>'
      write(log_vtu,'(a,i8,a,i8,a)')'    <Piece NumberOfPoints="',
     .                                  n+2,'" NumberOfCells="',n+1,'">'
      write(log_vtu,'(a)')'      <Points>'
      write(log_vtu,'(a,a,i1,a)')'        <DataArray type=',
     .            '"Float32" NumberOfComponents="',3,'" format="ascii">'
      do ipoin=0,n+1
        write(log_vtu,'(3e20.9)')ipoin*dx,0.0d+00,0.0d+00
      enddo
      write(log_vtu,'(a)')'        </DataArray>'
      write(log_vtu,'(a)')'      </Points>'
      write(log_vtu,'(a)')'      <Cells>'
      write(log_vtu,'(a)')
     .     '<DataArray type="Int32" Name="connectivity" format="ascii">'
      do ielem=1,n+1
        write(log_vtu,'(2i8)')ielem-1,ielem
      enddo
      write(log_vtu,'(a)')'        </DataArray>'
      write(log_vtu,'(a,a)')'<DataArray type="Int32" Name="offsets" ',
     .                        'format="ascii">'
      do ielem=1,n+1
        write(log_vtu,'(i8)')2*(ielem)
      enddo
      write(log_vtu,'(a)')'        </DataArray>'
      write(log_vtu,'(a,a)')'        <DataArray type="UInt8" ',
     .                        'Name="types" format="ascii">'
      do ielem=1,n+1
        write(log_vtu,'(i3)')3
      enddo
      write(log_vtu,'(a)')'        </DataArray>'
      write(log_vtu,'(a)')'      </Cells>'
      write(log_vtu,'(a)')'      <PointData>'
      do k=1,m
         contador='_'
         lon2=len(contador)
         do while(lon2.gt.2.and.contador(lon2:lon2).eq.' ')
          lon2=lon2-1
         enddo
         write(contador,'(A,I2.2)')contador(1:lon2),k
      write(log_vtu,'(5a)')' <DataArray type="Float32" ' ,
     .          'NumberOfComponents="3" ', 'Name="influencia',contador,
     .                ' " format="ascii">' 
      write(log_vtu,'(3e20.9)')0.0d+00,0.0d+00,0.0d+00  
      do ipoin=1,n
        write(log_vtu,'(3e20.9)')0.0d+00,0.0d+00,v(ipoin,k)
      enddo
      write(log_vtu,'(3e20.9)')0.0d+00,0.0d+00,0.0d+00
      write(log_vtu,'(a)')'        </DataArray>'
      enddo
      write(log_vtu,'(a)')'      </PointData>'
      write(log_vtu,'(a)')'        </Piece>'
      write(log_vtu,'(a)')'  </UnstructuredGrid>'
      write(log_vtu,'(a)')'</VTKFile>'
      close(log_vtu)
      return
      end
c===============================================================================
c===============================================================================