subroutine tecplot(qunit)
! output for tecplot (ASCII format)
! not parallel, uses calc_grid to compute nwauxio variables
! allows renormalizing using convert factors
use mod_global_parameters
use mod_calculate_xw
integer, intent(in) :: qunit
integer:: igrid,iigrid,level,igonlevel,iw,idim,ix1,ix2,ix3
integer:: NumGridsOnLevel(1:nlevelshi)
integer :: nx1,nx2,nx3,nxC1,nxC2,nxC3,nodesonlevel,elemsonlevel,ixCmin1,&
ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,ixCCmin1,ixCCmin2,ixCCmin3,&
ixCCmax1,ixCCmax2,ixCCmax3
integer :: nodes, elems
double precision :: x_TEC(ndim), w_TEC(nw+nwauxio)
double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,&
ixMlo3-1:ixMhi3,ndim) :: xC_TMP
double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo3:ixMhi3,&
ndim) :: xCC_TMP
double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,&
ixMlo3-1:ixMhi3,ndim) :: xC
double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo3:ixMhi3,&
ndim) :: xCC
double precision, dimension(ixMlo1-1:ixMhi1,ixMlo2-1:ixMhi2,&
ixMlo3-1:ixMhi3,nw+nwauxio) :: wC_TMP
double precision, dimension(ixMlo1:ixMhi1,ixMlo2:ixMhi2,ixMlo3:ixMhi3,&
nw+nwauxio) :: wCC_TMP
double precision, dimension(0:nw+nwauxio) :: normconv
logical :: fileopen,first
character(len=80) :: filename
integer :: filenr
!!! possible length conflict
character(len=1024) :: tecplothead
character(len=name_len) :: wnamei(1:nw+nwauxio),&
xandwnamei(1:ndim+nw+nwauxio)
character(len=1024) :: outfilehead
if(npe>1)then
if(mype==0) PRINT *,'tecplot not parallel, use tecplotmpi'
call mpistop('npe>1, tecplot')
end if
if(nw/=count(w_write(1:nw)))then
if(mype==0) PRINT *,'tecplot does not use w_write=F'
call mpistop('w_write, tecplot')
end if
if(nocartesian)then
if(mype==0) PRINT *,'tecplot with nocartesian'
end if
inquire(qunit,opened=fileopen)
if(.not.fileopen) then
! generate filename
filenr=snapshotini
if (autoconvert) filenr=snapshotnext
write(filename,'(a,i4.4,a)') TRIM(base_filename),filenr,".plt"
open(qunit,file=filename,status='unknown')
end if
call getheadernames(wnamei,xandwnamei,outfilehead)
write(tecplothead,'(a)') "VARIABLES = "//TRIM(outfilehead)
write(qunit,'(a)') tecplothead(1:len_trim(tecplothead))
NumGridsOnLevel(1:nlevelshi)=0
do level=levmin,levmax
NumGridsOnLevel(level)=0
do iigrid=1,igridstail; igrid=igrids(iigrid);
if (node(plevel_,igrid)/=level) cycle
NumGridsOnLevel(level)=NumGridsOnLevel(level)+1
end do
end do
nx1=ixMhi1-ixMlo1+1;nx2=ixMhi2-ixMlo2+1;nx3=ixMhi3-ixMlo3+1;
nxC1=nx1+1;nxC2=nx2+1;nxC3=nx3+1;
do level=levmin,levmax
nodesonlevel=NumGridsOnLevel(level)*nxC1*nxC2*nxC3
elemsonlevel=NumGridsOnLevel(level)*nx1*nx2*nx3
! for all tecplot variants coded up here, we let the TECPLOT ZONES coincide
! with the AMR grid LEVEL. Other options would be
! let each grid define a zone: inefficient for TECPLOT internal workings
! hence not implemented
! let entire octree define 1 zone: no difference in interpolation
! properties across TECPLOT zones detected as yet, hence not done
select case(convert_type)
case('tecplot')
! in this option, we store the corner coordinates, as well as the corner
! values of all variables (obtained by averaging). This allows POINT packaging,
! and thus we can save full grid info by using one call to calc_grid
write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,a)") 'ZONE T="',level,'"',&
', N=',nodesonlevel,', E=',elemsonlevel, ', SOLUTIONTIME=',&
global_time*time_convert_factor,', DATAPACKING=POINT, ZONETYPE=',&
'FEBRICK'
do iigrid=1,igridstail; igrid=igrids(iigrid);
if (node(plevel_,igrid)/=level) cycle
block=>ps(igrid)
call calc_x(igrid,xC,xCC)
call calc_grid(qunit,igrid,xC,xCC,xC_TMP,xCC_TMP,wC_TMP,wCC_TMP,&
normconv,ixCmin1,ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,&
ixCCmin1,ixCCmin2,ixCCmin3,ixCCmax1,ixCCmax2,ixCCmax3,.true.)
do ix3=ixCmin3,ixCmax3
do ix2=ixCmin2,ixCmax2
do ix1=ixCmin1,ixCmax1
x_TEC(1:ndim)=xC_TMP(ix1,ix2,ix3,1:ndim)*normconv(0)
w_TEC(1:nw+nwauxio)=wC_TMP(ix1,ix2,ix3,&
1:nw+nwauxio)*normconv(1:nw+nwauxio)
write(qunit,fmt="(100(e14.6))") x_TEC, w_TEC
end do
end do
end do
end do
case('tecplotCC')
! in this option, we store the corner coordinates, and the cell center
! values of all variables. Due to this mix of corner/cell center, we must
! use BLOCK packaging, and thus we have enormous overhead by using
! calc_grid repeatedly to merely fill values of cell corner coordinates
! and cell center values per dimension, per variable
if(ndim+nw+nwauxio>99) call mpistop(&
"adjust format specification in writeout")
if(nw+nwauxio==1)then
! to make tecplot happy: avoid [ndim+1-ndim+1] in varlocation varset
! and just set [ndim+1]
write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,a)") 'ZONE T="',&
level,'"',', N=',nodesonlevel,', E=',elemsonlevel,&
', SOLUTIONTIME=',global_time*time_convert_factor,&
', DATAPACKING=BLOCK, VARLOCATION=([', ndim+1,&
']=CELLCENTERED), ZONETYPE=', 'FEBRICK'
else
if(ndim+nw+nwauxio<10) then
! difference only in length of integer format specification for ndim+nw+nwauxio
write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i1,a,a)") &
'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel,&
', SOLUTIONTIME=',global_time*time_convert_factor,&
', DATAPACKING=BLOCK, VARLOCATION=([', ndim+1,'-',&
ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', 'FEBRICK'
else
write(qunit,"(a,i7,a,a,i7,a,i7,a,f25.16,a,i1,a,i2,a,a)") &
'ZONE T="',level,'"',', N=',nodesonlevel,', E=',elemsonlevel,&
', SOLUTIONTIME=',global_time*time_convert_factor,&
', DATAPACKING=BLOCK, VARLOCATION=([', ndim+1,'-',&
ndim+nw+nwauxio,']=CELLCENTERED), ZONETYPE=', 'FEBRICK'
end if
end if
do idim=1,ndim
first=(idim==1)
do iigrid=1,igridstail; igrid=igrids(iigrid);
if (node(plevel_,igrid)/=level) cycle
block=>ps(igrid)
call calc_x(igrid,xC,xCC)
call calc_grid(qunit,igrid,xC,xCC,xC_TMP,xCC_TMP,wC_TMP,wCC_TMP,&
normconv,ixCmin1,ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,&
ixCCmin1,ixCCmin2,ixCCmin3,ixCCmax1,ixCCmax2,ixCCmax3,first)
write(qunit,fmt="(100(e14.6))") xC_TMP(ixCmin1:ixCmax1,&
ixCmin2:ixCmax2,ixCmin3:ixCmax3,idim)*normconv(0)
end do
end do
do iw=1,nw+nwauxio
do iigrid=1,igridstail; igrid=igrids(iigrid);
if (node(plevel_,igrid)/=level) cycle
block=>ps(igrid)
call calc_x(igrid,xC,xCC)
call calc_grid(qunit,igrid,xC,xCC,xC_TMP,xCC_TMP,wC_TMP,wCC_TMP,&
normconv,ixCmin1,ixCmin2,ixCmin3,ixCmax1,ixCmax2,ixCmax3,&
ixCCmin1,ixCCmin2,ixCCmin3,ixCCmax1,ixCCmax2,ixCCmax3,&
.true.)
write(qunit,fmt="(100(e14.6))") wCC_TMP(ixCCmin1:ixCCmax1,&
ixCCmin2:ixCCmax2,ixCCmin3:ixCCmax3,iw)*normconv(iw)
enddo
enddo
case default
call mpistop('no such tecplot type')
end select
igonlevel=0
do iigrid=1,igridstail; igrid=igrids(iigrid);
if (node(plevel_,igrid)/=level) cycle
block=>ps(igrid)
igonlevel=igonlevel+1
call save_conntec(qunit,igrid,igonlevel)
end do
end do
close(qunit)
end subroutine tecplot