|
| 1 | +program main |
| 2 | + implicit none |
| 3 | + call example1() |
| 4 | + |
| 5 | +contains |
| 6 | + |
| 7 | + subroutine example1() |
| 8 | + ! use tecplot module |
| 9 | + use tecplot |
| 10 | + |
| 11 | + ! define a tecplot object |
| 12 | + type(tecplot_time_file) :: plt_file |
| 13 | + integer,allocatable :: locations(:) |
| 14 | + integer,allocatable :: type_list(:) |
| 15 | + integer,allocatable :: shared_list(:) |
| 16 | + integer,parameter :: num_of_variables = 6 |
| 17 | + integer :: nx,ny,nz,i,j,k,d |
| 18 | + character(len=50) :: filename='test.plt' |
| 19 | + real(kind=4),allocatable :: your_datas(:,:,:,:) |
| 20 | + real(kind=4) :: physics_time |
| 21 | + real :: xyz(3), ijk(3) |
| 22 | + |
| 23 | + ! set dimensions |
| 24 | + nx = 20 |
| 25 | + ny = 10 |
| 26 | + nz = 5 |
| 27 | + |
| 28 | + allocate(your_datas(nx,ny,nz,num_of_variables)) |
| 29 | + allocate(locations(num_of_variables)) |
| 30 | + allocate(type_list(num_of_variables)) |
| 31 | + allocate(shared_list(num_of_variables)) |
| 32 | + |
| 33 | + ! locations = 0 means data in node, 1 means data in cell(not supported yet) |
| 34 | + locations = 0 |
| 35 | + ! shared_list(i)=-1 means the i-th data is not shared in this zone. If shared_list(i)=m, |
| 36 | + ! it means the i-th data is shared with zone m in this file |
| 37 | + shared_list = -1 |
| 38 | + ! type_list(i) = 0 means the i-th data is of type float. (Other data type not supported yet.) |
| 39 | + type_list = 1 |
| 40 | + |
| 41 | + ! call init subroutine first |
| 42 | + ! nx, ny, nz means the dimension of the data |
| 43 | + ! 'x,y,z,u,v,w' is a string contains names of variables, must be divided by ',' |
| 44 | + call plt_file%init(filename,nx,ny,nz,'Tecplot File Title','x,y,z,u,v,w') |
| 45 | + |
| 46 | + ! for each zone, call the two subroutines |
| 47 | + ! physics_time can be any value, it will only be used when there are more than 1 zone in a file. |
| 48 | + call plt_file%write_zone_header('zone name', physics_time, 0, locations) |
| 49 | + |
| 50 | + ! your_datas(:,:,:,1:3) = x,y,z coordinates(Variable assignment is omitted in this example) |
| 51 | + ! your_datas(:,:,:,4:6) = u,v,w datas (Variable assignment is omitted in this example) |
| 52 | + ! ALL datas are stored in sequence like (((x(ix,iy,iz),ix=1,nx),iy=1,ny),iz=1,nz) |
| 53 | + ! set coordinate |
| 54 | + do d = 1, 3 |
| 55 | + do concurrent(i=1:nx, j=1:ny, k=1:nz) |
| 56 | + xyz = [i-1., j-1., k-1.] |
| 57 | + your_datas(i,j,k,d) = xyz(d) |
| 58 | + end do |
| 59 | + end do |
| 60 | + ! set value |
| 61 | + do d = 4, num_of_variables |
| 62 | + do concurrent(i=1:nx, j=1:ny, k=1:nz) |
| 63 | + ijk = [i, j, k] |
| 64 | + your_datas(i,j,k,d) = ijk(d-3) |
| 65 | + end do |
| 66 | + end do |
| 67 | + call plt_file%write_zone_data(type_list, shared_list, your_datas) |
| 68 | + |
| 69 | + ! before exit, you must call complete subroutine |
| 70 | + call plt_file%complete |
| 71 | + |
| 72 | + end subroutine example1 |
| 73 | + |
| 74 | +end program main |
0 commit comments