Skip to content

Commit 149b4c9

Browse files
committed
bug fix & upload examples
1 parent 776bf07 commit 149b4c9

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FC=gfortran
2+
3+
obj = string.o tecplot.o examples.o
4+
5+
.SUFFIXES: .o .f90
6+
7+
%.o: %.f90
8+
$(FC) -c $(FFLAGS) $<
9+
10+
all: $(obj)
11+
$(FC) $^
12+
13+
clean:
14+
rm -rf *.o *.mod a.out *~ *.plt
15+

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ character(len=50) :: filename='test.plt'
1818
real(kind=4),allocatable :: your_datas(:,:,:,:)
1919
real(kind=4) :: physics_time
2020
21-
allocate(your_datas(nx,ny,nz,num_of_variables)
21+
allocate(your_datas(nx,ny,nz,num_of_variables))
2222
allocate(locations(num_of_variables))
2323
allocate(type_list(num_of_variables))
2424
allocate(shared_list(num_of_variables))
@@ -47,6 +47,13 @@ call plt_file%write_zone_data(type_list, shared_list, your_datas)
4747
! before exit, you must call complete subroutine
4848
call plt_file%complete
4949
```
50+
51+
To test the code with the above example, just type the following two lines of command in terminal and check out the result `test.plt` with tecplot or paraview:
52+
```
53+
$ make
54+
$ ./a.out
55+
```
56+
5057
# Notice
5158
1. Only float data format is supported now.
5259
2. All subroutiens must be called in sequences.

examples.f90

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

tecplot.f90

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ subroutine plt_init_sb(this, fname, nnx, nny, nnz, title, variables)
5656
this%max_K = nnz
5757
call RANDOM_NUMBER(rand_num)
5858
this%fid = int(rand_num*1000+10)
59-
open(unit=this%fid, file=fname, status='replace', form='binary')
59+
open(unit=this%fid, file=fname, status='replace', form='unformatted', access='stream')
6060
!open scratch files
6161
call RANDOM_NUMBER(rand_num)
6262
this%sfid = int(rand_num*1000+10)
63-
open(unit=this%sfid, status='scratch', form='binary')
63+
open(unit=this%sfid, status='scratch', form='unformatted', access='stream')
6464
call this%write_header(nnx,nny,nnz,title,variables)
6565
this%isInitialized = .true.
6666
this%n_zone_header = 0
@@ -323,4 +323,4 @@ subroutine plt_write_zone_data_sb(this, type_list, shared_list, time_data)
323323
this%n_zone_data = this%n_zone_data + 1
324324
end subroutine plt_write_zone_data_sb
325325

326-
end module tecplot
326+
end module tecplot

0 commit comments

Comments
 (0)