Fortran stdlib 介绍

阅读 Fortran-lang/stdlib 文档,总结基本功能及用法

Introduction

ISO 发布的 Fortran 标准 (https://wg5-fortran.org/) 没有标准库, Stdlib (https://github.com/fortran-lang/stdlib) Fortran 提供一个社区驱动并达成共识的事实上的 “标准” 库,称为 Fortran 标准库.

项目文档 (https://stdlib.fortran-lang.org/) [中文版 https://stdlib.fortran-lang.cn/] 由 FORD (https://github.com/Fortran-FOSS-Programmers/ford#readme) 生成.

Fortran stdlib 尚无稳定发形版本 (https://stdlib.fortran-lang.org/page/specs/index.html#releasedstable-features-modules)

Scope

The goal of the Fortran Standard Library:

  • Utilities 实用程序
    • container 容器
    • string 字符串
    • files 文件处理
    • OS / environment integration 操作环境
    • unit testing / assertion 单元测试
    • logging 日志
  • Algorithms 算法
    • searching and sorting 搜索和排序
    • merging 合并
  • Mathematics 数学
    • line algebra 线性代数
    • sparse matrice 稀疏矩阵
    • special function 特殊函数
    • fast Fourier transform 快速傅立叶变换
    • random numbers 随机数
    • statistics 统计
    • ordinary differential equations 常微分方程
    • numerical integration 数值积分
    • optimization 优化

Build

构建 Fortran 标准库需要

  • Fortran 2008 版本以上编译器,最好符合 Fortran 2018 (GCC / Intel Fortran)
  • CMake 3.14 版本以上 (或直接使用 Make)
  • CMake 后端,如 Make 或 Ninja (Windows)
  • FYPP 预处理器,用于元编程

通过 cmake -B build 命令配置构建环境

1
2
3
4
5
6
7
# compile optimization
export FFLAGS="-O3"
# -DCMAKE_MAXIMUM_RANK: maximum array rank 7
# -DCMAKE_INSTALL_PREFIX: install path $HOME/.local
# -DCMAKE_VERBOSE_MAKEFILE: show commands used to compile the code
# -DCMAKE_BUILD_TYPE: override any compiler flags specified via FFLAGS
cmake -B build -DCMAKE_MAXIMUM_RANK:String=7 -DCMAKE_INSTALL_PREFIX=$HOME/.local -DCMAKE_VERBOSE_MAKEFILE=On -DCMAKE_BUILD_TYPE=NoConfig

仅希望构建标准库可使用以下命令

1
2
3
4
5
6
7
8
# build stdlib
cmake --build build
# run the test suite and all example programs
cmake --build build --target test
# run only the test suite
ctest --test-dir build/test
# install the project
cmake --install build

安装文件夹如下

1
2
3
4
5
6
7
8
9
10
11
12
13
├── include
│   ├── fortran_stdlib
│   │   └── GNU-13.2.0
│   └── test-drive
│   └── GNU-13.2.0
├── lib
│   ├── cmake
│   │   ├── fortran_stdlib
│   │   └── test-drive
│   └── pkgconfig
└── share
└── licenses
└── test-drive

文件夹 include 中包含 modulesubmodule 文件,lib 包含编译成功的静态库文件

也可使用 fpm 构建,此处不进行测试

Intrinsic

Specifications

Experimental Features & Modules

Specs Description
ansi 终端颜色和样式转义序列
array 用于索引操作和数组处理的过程
ascii 用于处理 ASCII 字符的过程
constants 常量
bitsets 位集数据类型和过程
error 捕获和处理错误
hash 对整数向量或字符字符串进行哈希运算
hashmaps 哈希映射/表
io 输入/输出辅助和便利功能
kinds 种类参数
linalg 线性代数
linalg_state_type 线性代数状态和错误处理
logger 运行时日志系统
math 通用数学函数
optval 可选参数的回退值
quadrature 数值积分
random 概率分布随机数生成器
sorting 一维数组的排序
stats 描述性统计
stats_distributions 均匀 / 正态 / 指数概率分布
string_type 基本字符串支持
stringlist_type 一维字符串列表
strings 字符串处理和操作例程
version 版本信息

Compile

VSCode

在 settings.json 中添加安装路径

1
2
3
"fortran.linter.includePaths": [
"/home/user/.local/include/fortran_stdlib/GNU-13.2.0"
],
0%