Fortran For Fun之iso_fortran_env

iso_fortran_env 是fortran语言的一个内部模块,其中定义了一些与fortran运行环境相关的常数或数据类型。主要包含

内部数据类型

1
2
3
4
5
real32
real64
int32
int64
...

标准输入输出

1
2
3
input_unit
output_unit
error_unit

io状态

1
2
iostat_end
iostat_eor

存储单元大小

1
2
3
numeric_storage_size
character_storage_size
...

learn_iso_fortran_env

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
program learn_iso_fortran_env
use, intrinsic :: iso_fortran_env
implicit none
print*, 'character_kinds =', character_kinds
print*, 'integer_kinds =', integer_kinds
print*, 'real_kinds =', real_kinds
print*, 'int32 = ',int32
print*, 'int64 = ',int64
print*, 'real32 = ',real32
print*, 'real64 = ',real64
print*, 'input_unit = ',input_unit
print*, 'output_unit = ',output_unit
print*, 'error_unit = ',error_unit
print*, 'numeric_storage_size = ',numeric_storage_size
print*, 'character_storage_size = ',character_storage_size
print*, 'file_storage_size = ',file_storage_size
print*, 'iostat_end = ',iostat_end
print*, 'iostat_eor = ',iostat_eor
end program learn_iso_fortran_env

结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
character_kinds = 1 4
integer_kinds = 1 2 4 8 16
real_kinds = 4 8 10 16
int32 = 4
int64 = 8
real32 = 4
real64 = 8
input_unit = 5
output_unit = 6
error_unit = 0
numeric_storage_size = 32
character_storage_size = 8
file_storage_size = 8
iostat_end = -1
iostat_eor = -2

iso_fortran_env