subroutine output_data(qunit,xO1,xO2,dxO1,dxO2,wO,nXO1,nXO2,nWO,datatype)
! change the format of data and write data
use mod_global_parameters
integer, intent(in) :: qunit,nXO1,nXO2,nWO
double precision, intent(in) :: dxO1(nxO1),dxO2(nxO2)
double precision, intent(in) :: xO1(nXO1),xO2(nxO2)
double precision, intent(inout) :: wO(nXO1,nXO2,nWO)
character(20), intent(in) :: datatype
integer :: nPiece,nP1,nP2,nC1,nC2,nWC
integer :: piece_nmax1,piece_nmax2,ix1,ix2,j,ipc,ixc1,ixc2
double precision, allocatable :: xC(:,:,:,:),wC(:,:,:,:),dxC(:,:,:,:)
! clean small values
do ix1=1,nxO1
do ix2=1,nxO2
do j=1,nWO
if (abs(wO(ix1,ix2,j))<smalldouble) wO(ix1,ix2,j)=zero
enddo
enddo
enddo
! how many cells in each grid
if (dat_resolution) then
if (datatype=='image_euv' .or. datatype=='image_sxr') then
if (LOS_phi==0 .and. LOS_theta==90) then
piece_nmax1=block_nx2
piece_nmax2=block_nx3
else if (LOS_phi==90 .and. LOS_theta==90) then
piece_nmax1=block_nx3
piece_nmax2=block_nx1
else
piece_nmax1=block_nx1
piece_nmax2=block_nx2
endif
else if (datatype=='spectrum_euv') then
piece_nmax1=16
if (direction_slit==1) then
piece_nmax2=block_nx1
else if (direction_slit==2) then
piece_nmax2=block_nx2
else
piece_nmax2=block_nx3
endif
endif
else
piece_nmax1=20
piece_nmax2=20
endif
LOOPN1: do j=piece_nmax1,1,-1
if(mod(nXO1,j)==0) then
nC1=j
exit LOOPN1
endif
enddo LOOPN1
LOOPN2: do j=piece_nmax2,1,-1
if(mod(nXO2,j)==0) then
nC2=j
exit LOOPN2
endif
enddo LOOPN2
! how many grids
nP1=nXO1/nC1
nP2=nXO2/nC2
nPiece=nP1*nP2
nWC=nWO
! output images
select case(convert_type)
case('EIvtuCCmpi','ESvtuCCmpi','SIvtuCCmpi','WIvtuCCmpi')
! put data into grids
allocate(xC(nPiece,nC1,nC2,2))
allocate(dxC(nPiece,nC1,nC2,2))
allocate(wC(nPiece,nC1,nC2,nWO))
do ipc=1,nPiece
do ixc1=1,nC1
do ixc2=1,nC2
ix1=mod(ipc-1,nP1)*nC1+ixc1
ix2=floor(1.0*(ipc-1)/nP1)*nC2+ixc2
xC(ipc,ixc1,ixc2,1)=xO1(ix1)
xC(ipc,ixc1,ixc2,2)=xO2(ix2)
dxC(ipc,ixc1,ixc2,1)=dxO1(ix1)
dxC(ipc,ixc1,ixc2,2)=dxO2(ix2)
do j=1,nWC
wC(ipc,ixc1,ixc2,j)=wO(ix1,ix2,j)
enddo
enddo
enddo
enddo
! write data into vtu file
call write_image_vtuCC(qunit,xC,wC,dxC,nPiece,nC1,nC2,nWC,datatype)
deallocate(xC,dxC,wC)
case('EIvtiCCmpi','ESvtiCCmpi','SIvtiCCmpi','WIvtiCCmpi')
if (sum(stretch_type(:))>0 .and. dat_resolution) then
call mpistop&
("Error in synthesize emission: vti is not supported for dat resolution")
else
call write_image_vtiCC(qunit,xO1,xO2,dxO1,dxO2,wO,nXO1,nXO2,nWO,&
nC1,nC2)
endif
case default
call mpistop("Error in synthesize emission: Unknown convert_type")
end select
end subroutine output_data