Supplementary routines - vmagnin/gtk-fortran GitHub Wiki
gtk-fortran High Level API
Supplementary material
This module contains some supplementary material useful for writing GTK programs in Fortran. The functions are not listed in the gtk-fortran-index.csv file, either because they are not (currenty) extracted by the automatic tools, or because they are just convenient functions added here.
module gtk_sup
Currently it contains:
- GTYPE: Definitions of the integer length and the values for each type.
- GtkTreeIter: Type definition, and its clear procedure.
- GValue: Pseudo type definition, and its clear procedure.
- GtkTextIter: Type definition.
- GError: Type definition.
- Interfaces for string conversions.
- Boolean conversion routines.
- Miscellaneous functions.
Gtype
The various Gtype definitions from the gtype.h file.
Iterators and Gvalues
These structures are always allocated in the calling program, rather than being declared as pointers and leaving GTK to allocate them.
- GtkTreeIter, Iterator for TreeView widgets
- GtkTextIter, Iterator for TextView widgets
- GValue, A value container.
GError
GError is a transparent structure that returns error information.
clear_gtktreeiter
subroutine clear_gtktreeiter(iter)
type(gtktreeiter), intent(inout) :: iter
Clear a tree iterator
Argument | Type | Required? | Description |
---|---|---|---|
ITER | gtktreeiter | required | The iterator to clear |
clear_gvalue
subroutine clear_gvalue(gval)
type(gvalue), intent(inout) :: gval
Clear a GValue
Argument | Type | Required? | Description |
---|---|---|---|
GVAL | gvalue | required | The GValue to clear. |
c_f_string_copy_alloc
subroutine c_f_string_copy_alloc(the_ptr, f_string)
type(c_ptr), intent(in) :: the_ptr
character(:), intent(out), allocatable :: f_string
character(kind=c_char), pointer :: f_array(:)
integer :: i
Create a default character deferred length allocatable copy of the value of a C string. This function should be preferred to c_f_string_copy() when using a Fortran>=2008 compiler. An advantage is that the trim() function will generally not be needed.
Argument | Type | Required? | Description |
---|---|---|---|
THE_PTR | string | required | The C string to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
c_f_string_copy
subroutine c_f_string_copy(the_ptr, f_string, status)
type(c_ptr), intent(in) :: the_ptr
character(*), intent(out) :: f_string
integer, intent(out), optional :: status
character(kind=c_char), pointer :: f_array(:)
integer :: i
Create a default character fixed length copy of the value of a C string.
Argument | Type | Required? | Description |
---|---|---|---|
THE_PTR | string | required | The C string to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
STATUS | integer | optional | Is set to -1 if the Fortran string is too short. |
If the Fortran string is too short, the C string is truncated.
c_f_string_chars
subroutine c_f_string_chars(c_string, f_string)
character(len=1, kind=C_char), intent(in) :: c_string(*)
character(len=*), intent(out) :: f_string
integer :: i
Copy a C string, passed as a char-array reference, to a Fortran string. String routine from C_interface_module by Joseph M. Krahn: http://fortranwiki.org/fortran/show/c_interface_module
Argument | Type | Required? | Description |
---|---|---|---|
C_STRING | chars array | required | The C chars array to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
c_f_string_ptr
subroutine c_f_string_ptr(c_string, f_string)
type(C_ptr), intent(in) :: c_string
character(len=*), intent(out) :: f_string
character(len=1, kind=C_char), dimension(:), pointer :: p_chars
integer :: i
Copy a C string, passed by pointer, to a Fortran string. If the C pointer is NULL, the Fortran string is blanked. c_string must be NUL terminated, or at least as long as f_string. If c_string is longer, it is truncated. Otherwise, f_string is blank-padded at the end.
Argument | Type | Required? | Description |
---|---|---|---|
C_STRING | string | required | The C string to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
convert_c_string_scalar
subroutine convert_c_string_scalar(textptr, f_string, status)
character(kind=c_char), dimension(:), intent(in) :: textptr
character(len=*), intent(out) :: f_string
integer(c_int), intent(out), optional :: status
Convert a null-terminated C-string to a Fortran string
Argument | Type | Required? | Description |
---|---|---|---|
TEXTPTR | string | required | The C string to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
STATUS | integer | optional | Is set to -1 if the Fortran string is too short. |
Usually called via the convert_c_string generic interface.
convert_c_string_array
subroutine convert_c_string_array(textptr, f_string, status)
character(kind=c_char), dimension(:), intent(in) :: textptr
character(len=*), intent(out), dimension(:), allocatable :: f_string
integer, intent(out), optional :: status
Convert a null-terminated LF-separated C-string into a Fortran string array
Argument | Type | Required? | Description |
---|---|---|---|
TEXTPTR | string | required | The C string to be converted. |
F_STRING | f_string() | required | A Fortran string array. |
STATUS | integer | optional | Is set to -1 if the Fortran string is too short for any line. |
Usually called via the convert_c_string generic interface.
convert_c_string_scalar_cptr
subroutine convert_c_string_scalar_cptr(ctext, f_string, status)
type(c_ptr), intent(in) :: ctext
character(len=*), intent(out) :: f_string
integer, intent(out), optional :: status
Convert a null-terminated C-string to a Fortran string
Argument | Type | Required? | Description |
---|---|---|---|
CTEXT | c_ptr | required | A C poiner to string to be converted. |
F_STRING | f_string | required | A Scalar Fortran string. |
STATUS | integer | optional | Is set to -1 if the Fortran string is too short. |
Usually called via the convert_c_string generic interface.
convert_c_string_array_cptr
subroutine convert_c_string_array_cptr(ctext, f_string, status)
type(c_ptr), intent(in) :: ctext
character(len=*), intent(out), dimension(:), allocatable :: f_string
integer, intent(out), optional :: status
Convert a null-terminated LF-separated C-string into a Fortran string array
Argument | Type | Required? | Description |
---|---|---|---|
CTEXT | c_ptr | required | A C poiner to string to be converted. |
F_STRING | f_string() | required | A Fortran string. array |
STATUS | integer | optional | Is set to -1 if the Fortran string is too short for any of the lines. |
Usually called via the convert_c_string generic interface.
convert_f_string_a
subroutine convert_f_string_a(f_string, textptr, length)
character(len=*), intent(in), dimension(:) :: f_string
character(kind=c_char), dimension(:), intent(out), allocatable :: textptr
integer(c_int), intent(out), optional :: length
Convert a Fortran string array into a null-terminated, LF_separated C-string
Argument | Type | Required? | Description |
---|---|---|---|
F_STRING | f_string | required | The Fortran string to convert |
TEXTPR | string | required | A C type string, (allocatable). |
LENGTH | c_int | optional | The length of the generated C string. |
convert_f_string_s
subroutine convert_f_string_s(f_string, textptr, length)
character(len=*), intent(in) :: f_string
character(kind=c_char), dimension(:), intent(out), allocatable :: textptr
integer(c_int), intent(out), optional :: length
Convert a Fortran string into a null-terminated C-string
Argument | Type | Required? | Description |
---|---|---|---|
F_STRING | f_string | required | The Fortran string to convert |
TEXTPR | string | required | A C type string, (allocatable). |
LENGTH | c_int | optional | The length of the generated C string. |
c_f_logical
function c_f_logical(cbool)
logical :: c_f_logical
integer(c_int), intent(in) :: cbool
Convert a gboolean to a Fortran logical
Argument | Type | Required? | Description |
---|---|---|---|
CBOOL | boolean | required | The Gboolean to convert. |
f_c_logical4
function f_c_logical4(flog)
integer(c_int) :: f_c_logical4
logical, intent(in) :: flog
Convert a Fortran default logical to a gboolean
Argument | Type | Required? | Description |
---|---|---|---|
FLOG | logical | required | The Fortran logical to convert. |
Usually accessed via the generic f_c_logical interface
f_c_logical1
function f_c_logical1(flog)
integer(c_int) :: f_c_logical1
logical(1), intent(in) :: flog
Convert a Fortran 1-byte logical to a gboolean
Argument | Type | Required? | Description |
---|---|---|---|
FLOG | logical*1 | required | The Fortran logical to convert. |
Usually accessed via the generic f_c_logical interface
is_UNIX_OS
function is_UNIX_OS()
use g, only: g_get_current_dir
logical :: is_UNIX_OS
character(:), allocatable :: path
Returns .true. if the OS is of the UNIX type. On a Windows system, it will return .false. because an absolute path can not begin by a slash.
fdate
function fdate()
character(29) :: fdate
character(8) :: date
character(10) :: time
character(5) :: zone
Returns date, time and timezone in a string without spaces, for example: 2022-05-06T15:58:43.790+02:00