PLplot  5.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
strutil.f90
Go to the documentation of this file.
1 ! Copyright (C) 2004-2014 Alan W. Irwin
2 !
3 ! This file is part of PLplot.
4 !
5 ! PLplot is free software; you can redistribute it and/or modify
6 ! it under the terms of the GNU Library General Public License as published
7 ! by the Free Software Foundation; either version 2 of the License, or
8 ! (at your option) any later version.
9 !
10 ! PLplot is distributed in the hope that it will be useful,
11 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ! GNU Library General Public License for more details.
14 !
15 ! You should have received a copy of the GNU Library General Public License
16 ! along with PLplot; if not, write to the Free Software
17 ! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
20  use plplot_types
21  implicit none
22 
23 contains
24 
25 !--------------------------------------------------------------------------
26 ! plstrf2c()
27 !
28 ! Converts Fortran string to C format
29 !--------------------------------------------------------------------------
30 
31 subroutine plstrf2c(string1, string2)
32  character(len=*) :: string1, string2
33 
34  integer(kind=plint) :: limit
35 
36  string2 = string1
37 ! limit = min(len(string2), len(string1))
38  limit = len_trim(string2)
39  string2(limit+1:limit+1) = char(0)
40 end subroutine plstrf2c
41 
42 !--------------------------------------------------------------------------
43 ! plstrf2c_esc()
44 !
45 ! Converts Fortran string to C format, substituting a line feed for \n
46 !--------------------------------------------------------------------------
47 
48 subroutine plstrf2c_esc(string1, string2)
49  character(len=*) :: string1, string2
50 
51  integer(kind=plint) :: limit
52  integer :: k
53 
54  string2 = string1
55 ! limit = min(len(string2), len(string1))
56  limit = len_trim(string2)
57  string2(limit+1:limit+1) = char(0)
58 
59  do
60  k = index( string2, '\n' )
61  if ( k > 0 ) then
62  string2 = string2(1:k-1) // char(10) // string2(k+2:)
63  else
64  exit
65  endif
66  enddo
67 end subroutine plstrf2c_esc
68 
69 
70 !--------------------------------------------------------------------------
71 ! plstrc2f()
72 !
73 ! Converts C string to Fortran conventions
74 !--------------------------------------------------------------------------
75 
76 subroutine plstrc2f(string1, string2)
77  use plplot_types
78  character(len=*) :: string1, string2
79 
80  integer(kind=plint) :: limit
81 
82  string2 = string1
83 
84  limit = index( string2, achar(0) )
85  if ( limit > 0 ) then
86  string2(limit:) = ' '
87  endif
88 
89 end subroutine plstrc2f
90 
91 end module plplot_strutils