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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
!***********************************************************************
! plplot_double.f90
!
! Copyright (C) 2005-2016 Arjen Markus
! Copyright (C) 2006-2016 Alan W. Irwin
!
! This file is part of PLplot.
!
! PLplot is free software; you can redistribute it and/or modify
! it under the terms of the GNU Library General Public License as published
! by the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! PLplot is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU Library General Public License for more details.
!
! You should have received a copy of the GNU Library General Public License
! along with PLplot; if not, write to the Free Software
! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
!
!
!***********************************************************************
module plplot_double
use iso_c_binding, only: c_ptr, c_char, c_null_char, c_null_ptr, c_loc, c_funptr, c_null_funptr, c_funloc, c_associated
use iso_fortran_env, only: error_unit
use plplot_types, only: private_plflt, private_plint, private_plbool, private_double, PLcGrid, PLfGrid
use plplot_private_exposed
use plplot_private_utilities, only: character_array_to_c
implicit none
integer, parameter :: wp = private_double
private :: c_ptr, c_char, c_null_char, c_null_ptr, c_loc, c_funptr, c_null_funptr, c_funloc
private :: error_unit
private :: private_plflt, private_plint, private_plbool, private_double, PLcGrid, PLfGrid
private :: character_array_to_c
private :: wp
! Private interfaces for wp-precision callbacks
private :: plmapformf2c, pllabelerf2c, pllabelerf2c_data, pltransformf2c, pltransformf2c_data
! Normally interface blocks describing the C routines that are
! called by this Fortran binding are embedded as part of module
! procedures, but when more than one module procedure uses such
! interface blocks there is a requirement (enforced at least by
! the nagfor compiler) that those interface blocks be consistent.
! We could comply with that requirement by embedding such multiply
! used interface blocks as part of module procedures using
! duplicated code, but that is inefficient (in terms of the number
! of lines of code to be compiled) and implies a maintenance issue
! (to keep that code duplicated whenever there are changes on the
! C side). To deal with those two potential issues we collect
! here in alphabetical order all interface blocks describing C
! routines that are called directly by more than one module
! procedure.
interface
subroutine interface_plslabelfunc( proc, data ) bind(c, name = 'c_plslabelfunc' )
import :: c_funptr, c_ptr
type(c_funptr), value, intent(in) :: proc
type(c_ptr), value, intent(in) :: data
end subroutine interface_plslabelfunc
end interface
private :: interface_plslabelfunc
interface
subroutine interface_plstransform( proc, data ) bind(c, name = 'c_plstransform' )
import :: c_funptr, c_ptr
type(c_funptr), value, intent(in) :: proc
type(c_ptr), value, intent(in) :: data
end subroutine interface_plstransform
end interface
private :: interface_plstransform
! Routines that have floating-point attributes that nevertheless
! cannot be disambiguated so we only provide them for the
! double-precision case (rather than using a separate naming
! convention for these routines or some other complexity for users
! to distinguish the double- and single-precision cases).
interface plrandd
! Only provide double-precison version because of
! disambiguation problems with the corresponding
! single-precision versions.
module procedure plrandd_impl
end interface plrandd
private :: plrandd_impl
interface plslabelfunc
! Only provide double-precison versions because of
! disambiguation problems with the corresponding
! single-precision versions.
module procedure plslabelfunc_impl_data
module procedure plslabelfunc_impl
module procedure plslabelfunc_impl_null
end interface plslabelfunc
private :: plslabelfunc_impl_data
private :: plslabelfunc_impl
private :: plslabelfunc_impl_null
interface plstransform
! Only provide double-precison versions because of
! disambiguation problems with the corresponding
! single-precision versions.
module procedure plstransform_impl_data
module procedure plstransform_impl
module procedure plstransform_impl_null
end interface plstransform
private :: plstransform_impl_data
private :: plstransform_impl
private :: plstransform_impl_null
! Routines that have floating-point attributes that can
! be disambiguated.
include 'included_plplot_real_interfaces.f90'
! Routines that have floating-point attributes that nevertheless
! cannot be disambiguated so we only provide them for the
! double-precision case (rather than using a separate naming
! convention for these routines or some other complexity for users
! to distinguish the double- and single-precision cases).
! Return type is not part of the disambiguation so we provide
! one explicit double-precision version rather than both types.
function plrandd_impl()
real(kind=wp) :: plrandd_impl !function type
interface
function interface_plrandd() bind(c,name='c_plrandd')
import :: private_plflt
implicit none
real(kind=private_plflt) :: interface_plrandd !function type
end function interface_plrandd
end interface
plrandd_impl = real(interface_plrandd(), kind=wp)
end function plrandd_impl
! Only provide double-precison version because of disambiguation
! problems with the corresponding single-precision version.
subroutine plslabelfunc_impl_data( proc, data )
procedure(pllabeler_proc_data) :: proc
type(c_ptr), value, intent(in) :: data
pllabeler_data => proc
call interface_plslabelfunc( c_funloc(pllabelerf2c_data), data )
end subroutine plslabelfunc_impl_data
! Only provide double-precison version because of disambiguation
! problems with the corresponding single-precision version.
subroutine plslabelfunc_impl( proc )
procedure(pllabeler_proc) :: proc
pllabeler => proc
call interface_plslabelfunc( c_funloc(pllabelerf2c), c_null_ptr )
end subroutine plslabelfunc_impl
subroutine plslabelfunc_impl_null
call interface_plslabelfunc( c_null_funptr, c_null_ptr )
end subroutine plslabelfunc_impl_null
! Only provide double-precison version because of disambiguation
! problems with the corresponding single-precision version.
subroutine plstransform_impl_data( proc, data )
procedure(pltransform_proc_data) :: proc
type(c_ptr), value, intent(in) :: data
pltransform_data => proc
call interface_plstransform( c_funloc(pltransformf2c_data), data )
end subroutine plstransform_impl_data
! Only provide double-precison version because of disambiguation
! problems with the corresponding single-precision version.
subroutine plstransform_impl( proc )
procedure(pltransform_proc) :: proc
pltransform => proc
call interface_plstransform( c_funloc(pltransformf2c), c_null_ptr )
end subroutine plstransform_impl
subroutine plstransform_impl_null
call interface_plstransform( c_null_funptr, c_null_ptr )
end subroutine plstransform_impl_null
! plflt-precision callback routines that are called from C and which wrap a call to wp-precision Fortran routines.
subroutine plmapformf2c( n, x, y ) bind(c, name = 'plplot_double_private_plmapformf2c')
integer(kind=private_plint), value, intent(in) :: n
real(kind=private_plflt), dimension(n), intent(inout) :: x, y
real(kind=wp), dimension(:), allocatable :: x_inout, y_inout
allocate(x_inout(n), y_inout(n))
x_inout = real(x, kind=wp)
y_inout = real(y, kind=wp)
call plmapform( x_inout, y_inout )
x = real(x_inout, kind=private_plflt)
y = real(y_inout, kind=private_plflt)
end subroutine plmapformf2c
subroutine pllabelerf2c( axis, value, label, length, data ) bind(c, name = 'plplot_double_private_pllabelerf2c')
integer(kind=private_plint), value, intent(in) :: axis, length
real(kind=private_plflt), value, intent(in) :: value
character(len=1), dimension(*), intent(out) :: label
type(c_ptr), value, intent(in) :: data
character(len=:), allocatable :: label_out
integer :: trimmed_length
if ( c_associated(data) ) then
write(*,*) 'PLPlot: error in pllabelerf2c - data argument should be NULL'
stop
endif
allocate(character(length) :: label_out)
call pllabeler( int(axis), real(value,kind=wp), label_out )
trimmed_length = min(length,len_trim(label_out) + 1)
label(1:trimmed_length) = transfer(trim(label_out(1:length))//c_null_char, " ", trimmed_length)
deallocate(label_out)
end subroutine pllabelerf2c
subroutine pllabelerf2c_data( axis, value, label, length, data ) bind(c, name = 'plplot_double_private_pllabelerf2c_data')
integer(kind=private_plint), value, intent(in) :: axis, length
real(kind=private_plflt), value, intent(in) :: value
character(len=1), dimension(*), intent(out) :: label
type(c_ptr), value, intent(in) :: data
character(len=:), allocatable :: label_out
integer :: trimmed_length
allocate(character(length) :: label_out)
call pllabeler_data( int(axis), real(value,kind=wp), label_out, data )
trimmed_length = min(length,len_trim(label_out) + 1)
label(1:trimmed_length) = transfer(trim(label_out(1:length))//c_null_char, " ", trimmed_length)
deallocate(label_out)
end subroutine pllabelerf2c_data
subroutine pltransformf2c( x, y, tx, ty, data ) bind(c, name = 'plplot_double_private_pltransformf2c')
real(kind=private_plflt), value, intent(in) :: x, y
real(kind=private_plflt), intent(out) :: tx, ty
type(c_ptr), value, intent(in) :: data
real(kind=wp) :: tx_out, ty_out
if ( c_associated(data) ) then
write(*,*) 'PLPlot: error in pltransfrom2c - data argument should be NULL'
stop
endif
call pltransform( real(x,kind=wp), real(y,kind=wp), tx_out, ty_out )
tx = tx_out
ty = ty_out
end subroutine pltransformf2c
subroutine pltransformf2c_data( x, y, tx, ty, data ) bind(c, name = 'plplot_double_private_pltransformf2c_data')
real(kind=private_plflt), value, intent(in) :: x, y
real(kind=private_plflt), intent(out) :: tx, ty
type(c_ptr), value, intent(in) :: data
real(kind=wp) :: tx_out, ty_out
call pltransform_data( real(x,kind=wp), real(y,kind=wp), tx_out, ty_out, data )
tx = tx_out
ty = ty_out
end subroutine pltransformf2c_data
end module plplot_double
|