Skip to content

Commit 547f883

Browse files
committed
Merge branch 'release/1.1.8'
2 parents cb1fee2 + 4ecd43a commit 547f883

11 files changed

+184
-111
lines changed

fobos

+4-2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ cflags_heritage = True
118118
compiler = gnu
119119
cflags = $CSHARED_GNU $DEBUG_GNU
120120
lflags = $LSHARED $DEBUG_GNU
121+
preproc = -D_R16P -D_ASCII_SUPPORTED -D_UCS4_SUPPORTED
121122
mod_dir = ./mod/
122123
obj_dir = ./obj/
123124
src = ./src/
@@ -131,6 +132,7 @@ cflags_heritage = True
131132
compiler = gnu
132133
cflags = $CSTATIC_GNU $DEBUG_GNU
133134
lflags = $DEBUG_GNU
135+
preproc = -D_R16P -D_ASCII_SUPPORTED -D_UCS4_SUPPORTED
134136
mod_dir = ./mod/
135137
obj_dir = ./obj/
136138
src = ./src/
@@ -220,15 +222,15 @@ rule = tar --xform="s%^%PENF/%" -czf PENF.tar.gz *
220222
[rule-makecoverage]
221223
help = Perform coverage analysis
222224
rule_1 = FoBiS.py clean -mode tests-gnu-debug
223-
rule_2 = FoBiS.py build -mode tests-gnu-debug -coverage --preproc ' -Dr16p'
225+
rule_2 = FoBiS.py build -mode tests-gnu-debug -coverage
224226
rule_3 = ./scripts/run_tests.sh
225227
rule_4 = gcov -o exe/obj/ src/lib/*
226228
rule_5 = rm -f *.gcov
227229

228230
[rule-makecoverage-analysis]
229231
help = Perform coverage analysis and saving reports in markdown
230232
rule_1 = FoBiS.py clean -mode tests-gnu-debug
231-
rule_2 = FoBiS.py build -mode tests-gnu-debug -coverage --preproc ' -Dr16p'
233+
rule_2 = FoBiS.py build -mode tests-gnu-debug -coverage
232234
rule_3 = ./scripts/run_tests.sh
233235
rule_4 = gcov -o exe/obj/ src/lib/*
234236
rule_5 = FoBiS.py rule -gcov_analyzer wiki/ Coverage-Analysis -verbose

src/lib/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ SET(LIB_SRC ${LIB_SRC} PARENT_SCOPE)
1111
ADD_LIBRARY(${LIB} ${LIB_SRC})
1212

1313
SET_TARGET_PROPERTIES(${LIB} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} SOVERSION ${${PROJECT_NAME}_SOVERSION})
14-

src/lib/penf.F90

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ module penf
88
#else
99
use penf_b_size
1010
#endif
11-
use penf_stringify, only : str, strz, cton, bstr, bcton
11+
use penf_stringify, only : str_ascii, str_ucs4, str, strz, cton, bstr, bcton
1212

1313
implicit none
1414
private
1515
save
1616
! global parameters and variables
1717
public :: endianL, endianB, endian, is_initialized
18+
public :: ASCII, UCS4
1819
public :: R16P, FR16P, DR16P, MinR16P, MaxR16P, BIR16P, BYR16P, smallR16P, ZeroR16
1920
public :: R8P, FR8P, DR8P, MinR8P, MaxR8P, BIR8P, BYR8P, smallR8P, ZeroR8
2021
public :: R4P, FR4P, DR4P, MinR4P, MaxR4P, BIR4P, BYR4P, smallR4P, ZeroR4
@@ -29,6 +30,7 @@ module penf
2930
! bit/byte size functions
3031
public :: bit_size, byte_size
3132
! stringify facility
33+
public :: str_ascii, str_ucs4
3234
public :: str, strz, cton
3335
public :: bstr, bcton
3436
! miscellanea facility
@@ -114,14 +116,10 @@ subroutine penf_init()
114116
!< Initialize PENF's variables that are not initialized into the definition specification.
115117

116118
call check_endian
117-
BIR8P = bit_size(MaxR8P) ; BYR8P = BIR8P/8_I1P
118-
BIR4P = bit_size(MaxR4P) ; BYR4P = BIR4P/8_I1P
119-
BIR_P = bit_size(MaxR_P) ; BYR_P = BIR_P/8_I1P
120-
! #ifdef r16p
121-
BIR16P = bit_size(MaxR16P) ; BYR16P = BIR16P/8_I2P
122-
! #else
123-
! BIR16P = int(BIR8P, kind=I2P) ; BYR16P = BIR16P/8_I2P
124-
! #endif
119+
BIR8P = bit_size(MaxR8P) ; BYR8P = BIR8P/8_I1P
120+
BIR4P = bit_size(MaxR4P) ; BYR4P = BIR4P/8_I1P
121+
BIR_P = bit_size(MaxR_P) ; BYR_P = BIR_P/8_I1P
122+
BIR16P = bit_size(MaxR16P) ; BYR16P = BIR16P/8_I2P
125123
is_initialized = .true.
126124
endsubroutine penf_init
127125

src/lib/penf_b_size.F90

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module penf_b_size
1212
interface bit_size
1313
!< Overloading of the intrinsic *bit_size* function for computing the number of bits of (also) real and character variables.
1414
module procedure &
15-
#ifdef r16p
15+
#ifdef _R16P_SUPPORTED
1616
bit_size_R16P, &
1717
#endif
1818
bit_size_R8P, &
@@ -27,7 +27,7 @@ module penf_b_size
2727
byte_size_I4P, &
2828
byte_size_I2P, &
2929
byte_size_I1P, &
30-
#ifdef r16p
30+
#ifdef _R16P_SUPPORTED
3131
byte_size_R16p, &
3232
#endif
3333
byte_size_R8P, &

src/lib/penf_global_parameters_variables.F90

+27-17
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,43 @@ module penf_global_parameters_variables
1515
integer :: endian = endianL !< Bit ordering: Little endian (endianL), or Big endian (endianB).
1616

1717
! portable kind parameters
18-
#ifdef r16p
19-
integer, parameter :: R16P = selected_real_kind(33,4931) !< 33 digits, range \([10^{-4931}, 10^{+4931} - 1]\); 128 bits.
18+
#ifdef _ASCII_SUPPORTED
19+
integer, parameter :: ASCII = selected_char_kind('ascii') !< ASCII character set kind.
2020
#else
21-
integer, parameter :: R16P = selected_real_kind(15,307) !< Defined as R8P; 64 bits.
21+
integer, parameter :: ASCII = selected_char_kind('default') !< ASCII character set kind defined as default set.
2222
#endif
23-
integer, parameter :: R8P = selected_real_kind(15,307) !< 15 digits, range \([10^{-307} , 10^{+307} - 1]\); 64 bits.
24-
integer, parameter :: R4P = selected_real_kind(6,37) !< 6 digits, range \([10^{-37} , 10^{+37} - 1]\); 32 bits.
25-
#ifdef r16p
26-
integer, parameter :: R_P = R16P !< Default real precision.
23+
#ifdef _UCS4_SUPPORTED
24+
integer, parameter :: UCS4 = selected_char_kind('iso_10646') !< Unicode character set kind.
2725
#else
28-
integer, parameter :: R_P = R8P !< Default real precision.
26+
integer, parameter :: UCS4 = selected_char_kind('default') !< Unicode character set kind defined as default set.
2927
#endif
30-
integer, parameter :: I8P = selected_int_kind(18) !< Range \([-2^{63},+2^{63} - 1]\), 19 digits plus sign; 64 bits.
31-
integer, parameter :: I4P = selected_int_kind(9) !< Range \([-2^{31},+2^{31} - 1]\), 10 digits plus sign; 32 bits.
32-
integer, parameter :: I2P = selected_int_kind(4) !< Range \([-2^{15},+2^{15} - 1]\), 5 digits plus sign; 16 bits.
33-
integer, parameter :: I1P = selected_int_kind(2) !< Range \([-2^{7} ,+2^{7} - 1]\), 3 digits plus sign; 8 bits.
34-
integer, parameter :: I_P = I4P !< Default integer precision.
28+
#ifdef _R16P_SUPPORTED
29+
integer, parameter :: R16P = selected_real_kind(33,4931) !< 33 digits, range \([10^{-4931}, 10^{+4931} - 1]\); 128 bits.
30+
#else
31+
integer, parameter :: R16P = selected_real_kind(15,307) !< Defined as R8P; 64 bits.
32+
#endif
33+
integer, parameter :: R8P = selected_real_kind(15,307) !< 15 digits, range \([10^{-307} , 10^{+307} - 1]\); 64 bits.
34+
integer, parameter :: R4P = selected_real_kind(6,37) !< 6 digits, range \([10^{-37} , 10^{+37} - 1]\); 32 bits.
35+
#ifdef _R16P_SUPPORTED
36+
integer, parameter :: R_P = R16P !< Default real precision.
37+
#else
38+
integer, parameter :: R_P = R8P !< Default real precision.
39+
#endif
40+
integer, parameter :: I8P = selected_int_kind(18) !< Range \([-2^{63},+2^{63} - 1]\), 19 digits plus sign; 64 bits.
41+
integer, parameter :: I4P = selected_int_kind(9) !< Range \([-2^{31},+2^{31} - 1]\), 10 digits plus sign; 32 bits.
42+
integer, parameter :: I2P = selected_int_kind(4) !< Range \([-2^{15},+2^{15} - 1]\), 5 digits plus sign; 16 bits.
43+
integer, parameter :: I1P = selected_int_kind(2) !< Range \([-2^{7} ,+2^{7} - 1]\), 3 digits plus sign; 8 bits.
44+
integer, parameter :: I_P = I4P !< Default integer precision.
3545

3646
! format parameters
37-
#ifdef r16p
47+
#ifdef _R16P_SUPPORTED
3848
character(*), parameter :: FR16P = '(E42.33E4)' !< Output format for kind=R16P real.
3949
#else
4050
character(*), parameter :: FR16P = '(E23.15E3)' !< Output format for kind=R16P real.
4151
#endif
4252
character(*), parameter :: FR8P = '(E23.15E3)' !< Output format for kind=R8P real.
4353
character(*), parameter :: FR4P = '(E13.6E2)' !< Output format for kind=R4P real.
44-
#ifdef r16p
54+
#ifdef _R16P_SUPPORTED
4555
character(*), parameter :: FR_P = FR16P !< Output format for kind=R_P real.
4656
#else
4757
character(*), parameter :: FR_P = FR8P !< Output format for kind=R_P real.
@@ -58,14 +68,14 @@ module penf_global_parameters_variables
5868
character(*), parameter :: FI_PZP = FI4PZP !< Output format for kind=I_P integer with zero prefixing.
5969

6070
! length (number of digits) of formatted numbers
61-
#ifdef r16p
71+
#ifdef _R16P_SUPPORTED
6272
integer, parameter :: DR16P = 42 !< Number of digits of output format FR16P.
6373
#else
6474
integer, parameter :: DR16P = 23 !< Number of digits of output format FR16P.
6575
#endif
6676
integer, parameter :: DR8P = 23 !< Number of digits of output format FR8P.
6777
integer, parameter :: DR4P = 13 !< Number of digits of output format FR4P.
68-
#ifdef r16p
78+
#ifdef _R16P_SUPPORTED
6979
integer, parameter :: DR_P = DR16P !< Number of digits of output format FR_P.
7080
#else
7181
integer, parameter :: DR_P = DR8P !< Number of digits of output format FR_P.

src/lib/penf_stringify.F90

+76-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,36 @@ module penf_stringify
99
implicit none
1010
private
1111
save
12+
public :: str_ascii, str_ucs4
1213
public :: str, strz, cton
1314
public :: bstr, bcton
1415

16+
interface str_ascii
17+
!< Convert string of any kind to ASCII string.
18+
module procedure str_ascii_default
19+
#if defined _ASCII_SUPPORTED && defined _ASCII_NEQ_DEFAULT
20+
module procedure str_ascii_ascii
21+
#endif
22+
#ifdef _UCS4_SUPPORTED
23+
module procedure str_ascii_ucs4
24+
#endif
25+
endinterface
26+
27+
interface str_ucs4
28+
!< Convert string of any kind to UCS4 string.
29+
module procedure str_ucs4_default
30+
#if defined _ASCII_SUPPORTED && defined _ASCII_NEQ_DEFAULT
31+
module procedure str_ucs4_ascii
32+
#endif
33+
#ifdef _UCS4_SUPPORTED
34+
module procedure str_ucs4_ucs4
35+
#endif
36+
endinterface
37+
1538
interface str
1639
!< Convert number (real and integer) to string (number to string type casting).
1740
module procedure &
18-
#ifdef r16p
41+
#ifdef _R16P_SUPPORTED
1942
strf_R16P,str_R16P, &
2043
#endif
2144
strf_R8P ,str_R8P, &
@@ -25,7 +48,7 @@ module penf_stringify
2548
strf_I2P ,str_I2P, &
2649
strf_I1P ,str_I1P, &
2750
str_bol, &
28-
#ifdef r16p
51+
#ifdef _R16P_SUPPORTED
2952
str_a_R16P, &
3053
#endif
3154
str_a_R8P, &
@@ -44,7 +67,7 @@ module penf_stringify
4467
interface cton
4568
!< Convert string to number (real and integer, string to number type casting).
4669
module procedure &
47-
#ifdef r16p
70+
#ifdef _R16P_SUPPORTED
4871
ctor_R16P, &
4972
#endif
5073
ctor_R8P, &
@@ -58,7 +81,7 @@ module penf_stringify
5881
interface bstr
5982
!< Convert number (real and integer) to bit-string (number to bit-string type casting).
6083
module procedure &
61-
#ifdef r16p
84+
#ifdef _R16P_SUPPORTED
6285
bstr_R16P, &
6386
#endif
6487
bstr_R8P, &
@@ -72,7 +95,7 @@ module penf_stringify
7295
interface bcton
7396
!< Convert bit-string to number (real and integer, bit-string to number type casting).
7497
module procedure &
75-
#ifdef r16p
98+
#ifdef _R16P_SUPPORTED
7699
bctor_R16P, &
77100
#endif
78101
bctor_R8P, &
@@ -84,6 +107,54 @@ module penf_stringify
84107
endinterface
85108

86109
contains
110+
pure function str_ascii_default(input) result(output)
111+
!< Convert string of default kind to ASCII string.
112+
character(len=*), intent(in) :: input !< Input string of default kind.
113+
character(len=:, kind=ASCII), allocatable :: output !< Output string of ASCII kind.
114+
115+
output = input
116+
endfunction str_ascii_default
117+
118+
pure function str_ascii_ascii(input) result(output)
119+
!< Convert string of ASCII kind to ASCII string, just for convenience in sanitize strings.
120+
character(len=*, kind=ASCII), intent(in) :: input !< Input string of ASCII kind.
121+
character(len=:, kind=ASCII), allocatable :: output !< Output string of ASCII kind.
122+
123+
output = input
124+
endfunction str_ascii_ascii
125+
126+
pure function str_ascii_ucs4(input) result(output)
127+
!< Convert string of UCS4 kind to ASCII string.
128+
character(len=*, kind=UCS4), intent(in) :: input !< Input string of UCS4 kind.
129+
character(len=:, kind=ASCII), allocatable :: output !< Output string of ASCII kind.
130+
131+
output = input
132+
endfunction str_ascii_ucs4
133+
134+
pure function str_ucs4_default(input) result(output)
135+
!< Convert string of default kind to UCS4 string.
136+
character(len=*), intent(in) :: input !< Input string of default kind.
137+
character(len=:, kind=UCS4), allocatable :: output !< Output string of UCS4 kind.
138+
139+
output = input
140+
endfunction str_ucs4_default
141+
142+
pure function str_ucs4_ascii(input) result(output)
143+
!< Convert string of ASCII kind to UCS4 string.
144+
character(len=*, kind=ASCII), intent(in) :: input !< Input string of ASCII kind.
145+
character(len=:, kind=UCS4), allocatable :: output !< Output string of UCS4 kind.
146+
147+
output = input
148+
endfunction str_ucs4_ascii
149+
150+
pure function str_ucs4_ucs4(input) result(output)
151+
!< Convert string of UCS4 kind to UCS4 string, just for convenience in sanitize strings.
152+
character(len=*, kind=UCS4), intent(in) :: input !< Input string of UCS4 kind.
153+
character(len=:, kind=UCS4), allocatable :: output !< Output string of UCS4 kind.
154+
155+
output = input
156+
endfunction str_ucs4_ucs4
157+
87158
elemental function strf_R16P(fm, n) result(str)
88159
!< Convert real to string.
89160
character(*), intent(in) :: fm !< Format different from the standard for the kind.

src/tests/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,3 @@ FOREACH(TEST_SRC ${TESTS_SRC})
1515
TARGET_LINK_LIBRARIES(${EXE_NAME} ${LIB})
1616
ADD_TEST(${EXE_NAME}_TEST ${EXECUTABLE_OUTPUT_PATH}/${EXE_NAME})
1717
ENDFOREACH()
18-
19-
20-

src/tests/compact_real.f90

-32
This file was deleted.

src/tests/penf_test_all.F90

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
!< PENF's testing program.
2+
program penf_test_all
3+
!< PENF's testing program.
4+
!<
5+
!<### Usage
6+
!<```bash
7+
!< ./penf_test_all
8+
!<```
9+
use penf
10+
use, intrinsic :: iso_fortran_env, only : stdout=>output_unit
11+
12+
implicit none
13+
14+
call penf_init
15+
call penf_print(unit=stdout)
16+
print "(A)", ''
17+
print "(A)", 'Testing PENF tools'
18+
print "(A)", ASCII_'Casting string_default-to-string_ascii: '//str_ascii('I was DEFAULT kind')
19+
print "(A)", ASCII_'Casting string_ascii-to-string_ascii: '//str_ascii(ASCII_'I was ASCII kind')
20+
print "(A)", ASCII_'Casting string_ucs4-to-string_ascii: '//str_ascii(UCS4_'I was UCS4 kind')
21+
print "(A)", UCS4_'Casting string_default-to-string_ucs4: '//str_ucs4('I was DEFAULT kind')
22+
print "(A)", UCS4_'Casting string_ascii-to-string_ucs4: '//str_ucs4(ASCII_'I was ASCII kind')
23+
print "(A)", UCS4_'Casting string_ucs4-to-string_ucs4: '//str_ucs4(UCS4_'I was UCS4 kind')
24+
print "(A)", 'Casting real-to-string: '//str(n=1._R8P)
25+
print "(A)", 'Casting integer-to-string: '//str(n=11_I8P)
26+
print "(A,"//FR8P//")", 'Casting string-to-real: ', cton(str='2.2d0', knd=1._R8P)
27+
print "(A,"//FI4P//")", 'Casting integer-to-string: ', cton(str='43', knd=1_I4P)
28+
print "(A)", 'Casting integer-to-string with zero padding: '//trim(strz(nz_pad=3, n=34_I8P))
29+
#ifndef __GFORTRAN__
30+
print "(A)", 'Casting real-to-bit_string: '//bstr(n=1._R4P)
31+
#endif
32+
print "(A)", 'Casting integer-to-bit_string: '//bstr(n=1_I4P)
33+
#ifndef __GFORTRAN__
34+
print "(A,"//FR4P//")", 'Casting bit_string-to-real: ', bcton(bstr='00111111100000000000000000000000', knd=1._R4P)
35+
#endif
36+
print "(A,"//FI4P//")", 'Casting bit_string-to-integer: ', bcton(bstr='00000000000000000000000000000001', knd=1_I4P)
37+
print "(A)", 'Number of digit of 1023: '//str(n=digit(1023_I4P))
38+
write(stdout, "(A,L1)") new_line('a')//'Are all tests passed? ', .true.
39+
endprogram penf_test_all

0 commit comments

Comments
 (0)