-
Notifications
You must be signed in to change notification settings - Fork 1
/
gnuplot_example.f90
executable file
·62 lines (59 loc) · 2.01 KB
/
gnuplot_example.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
program gnuplotexample
use, intrinsic :: iso_fortran_env, only : &
& stdin=>input_unit, &
& stdout=>output_unit, &
& stderr=>error_unit
use m_process ,only: process_open_write, process_writeline
use m_process ,only: streampointer, process_close
implicit none
integer :: i, j
integer,parameter :: n = 300
real :: x(n) , y(n)
type(streampointer) :: fp
call plotit('start')
do j = 1 , 3000 , 1
do i = 1 , n ! set x() values as whole numbers 1 to n
x(i) = i
y(i) = sin(x(i)/25.0+j/40.0)
enddo
call plotit() ! plot the values in <x,y>
enddo
call plotit('end')
contains
subroutine plotit(step)
character(len=*),intent(in),optional :: step
character(len=10) :: step_local
character(len=80) :: line
character(len=*),parameter :: g='(*(g0,1x))'
integer :: ierr
integer :: i
if(present(step))then
select case(step)
case('start')
call process_open_write('gnuplot --persist',fp,ierr)
write(stdout,*)'WRITETEST: process is opened with status ',ierr
call process_writeline( [character(len=80) :: &
'set terminal X11',&
'set nokey',&
'set title " example of gnuplot data and command file generation"'],&
fp,ierr)
case('stop')
call process_close(fp,ierr)
write(*,*)'WRITETEST: process closed with status ',ierr
end select
else
call process_writeline( '$set1 <<eod' ,fp,ierr)
ierr=0
do i = 1 , n
write (line,g)' ', x(i) , y(i) !x! write the x,y array as coordinates to be plotted.
call process_writeline(trim(line),fp,ierr)
if(ierr.lt.0)then
write(*,*)'WRITETEST: ierr is ',ierr
exit
endif
enddo
call process_writeline('eod',fp,ierr)
call process_writeline('plot $set1 with lines lw 4',fp,ierr)
endif
end subroutine plotit
end program gnuplotexample