Skip to content

Commit c89af5d

Browse files
authored
Merge pull request #4 from tammasloughran/master
Added lplot for 3d line plots
2 parents c25b6ea + f23a126 commit c89af5d

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

ogpf.f90

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ module ogpf
292292
generic, public :: loglog => loglogv, loglogm
293293

294294
procedure, pass, public :: surf => splot ! 3D surface plot
295+
procedure, pass, public :: lplot => lplot3d ! 3D line plot
295296
procedure, pass, public :: contour => cplot ! contour plot
296297

297298
procedure, pass, public :: fplot => function_plot
@@ -1285,6 +1286,100 @@ subroutine cplot(this, x, y, z, lspec, palette)
12851286
!: End of cplot
12861287
end subroutine cplot
12871288

1289+
subroutine lplot3d(this, x, y, z, lspec, palette)
1290+
!..............................................................................
1291+
! lplot3d create a line plot in 3d
1292+
! datablock is used instead of gnuplot inline file "-"
1293+
!..............................................................................
1294+
1295+
class(gpf):: this
1296+
! Input vector
1297+
real(wp), intent(in) :: x(:)
1298+
real(wp), intent(in), optional :: y(:)
1299+
real(wp), intent(in), optional :: z(:)
1300+
character(len=*), intent(in), optional :: lspec
1301+
character(len=*), intent(in), optional :: palette
1302+
1303+
! Local variables
1304+
!----------------------------------------------------------------------
1305+
integer:: ncx
1306+
integer:: nrx
1307+
integer:: i
1308+
integer:: j
1309+
logical:: xyz_data
1310+
character(len=80):: pltstring
1311+
character(len=*), parameter :: datablock = '$xyz'
1312+
1313+
pltstring=''
1314+
! Check the input data
1315+
nrx=size(x)
1316+
if (present(y) .and. present(z)) then
1317+
xyz_data=.true.
1318+
elseif (present(y)) then
1319+
print*, "gpf error: Z matrix was not sent to 3D plot routine"
1320+
return
1321+
else
1322+
xyz_data=.false.
1323+
end if
1324+
1325+
! set default line style for 3D plot, can be overwritten
1326+
this%txtdatastyle = 'lines'
1327+
! create the script file for writing gnuplot commands and data
1328+
call create_outputfile(this)
1329+
1330+
! Write titles and other annotations
1331+
call processcmd(this)
1332+
1333+
! Write xy data into file
1334+
write ( this%file_unit, '(a)' ) '#data x y z'
1335+
! Rev 0.20
1336+
! write the $xyz datablocks
1337+
write( this%file_unit, '(a)' ) datablock // ' << EOD'
1338+
if (xyz_data) then
1339+
do i=1, nrx
1340+
write ( this%file_unit, * ) x(i), y(i), z(i)
1341+
enddo
1342+
write( this%file_unit, '(a)' ) !put an empty line
1343+
write ( this%file_unit, '(a)' ) 'EOD' !end of datablock
1344+
else !only Z has been sent (i.e. single matrix data)
1345+
do i=1, nrx
1346+
write ( this%file_unit, * ) i, x(i)
1347+
enddo
1348+
write( this%file_unit, '(a)' ) !put an empty line
1349+
write ( this%file_unit, '(a)' ) 'EOD' !end of datablock
1350+
end if
1351+
1352+
1353+
!write the color palette into gnuplot script file
1354+
if (present(palette)) then
1355+
write ( this%file_unit, '(a)' ) color_palettes(palette)
1356+
write ( this%file_unit, '(a)' ) 'set pm3d' ! a conflict with lspec
1357+
end if
1358+
1359+
1360+
if ( present(lspec) ) then
1361+
if (hastitle(lspec)) then
1362+
pltstring='splot ' // datablock // ' ' // trim(lspec) // 'with lines'
1363+
else
1364+
pltstring='splot ' // datablock // ' notitle '//trim(lspec) // 'with lines'
1365+
end if
1366+
else
1367+
pltstring='splot ' // datablock // ' notitle with lines'
1368+
end if
1369+
1370+
write ( this%file_unit, '(a)' ) trim(pltstring)
1371+
1372+
1373+
!> Rev 0.2: animation
1374+
! if there is no animation finalize
1375+
if (.not. (this%hasanimation)) then
1376+
call finalize_plot(this)
1377+
else
1378+
write(this%file_unit, '(a, I2)') 'pause ', this%pause_seconds
1379+
end if
1380+
1381+
!: End of lplot3d
1382+
end subroutine lplot3d
12881383

12891384
subroutine function_plot(this, func,xrange,np)
12901385
!..............................................................................

0 commit comments

Comments
 (0)