gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
sysdep.f90
Go to the documentation of this file.
1!-----------------------------------------------------------------------
2! Copyright (c) 2000-2026 Gtool Development Group. All rights reserved.
3!-----------------------------------------------------------------------
4!>
5!> @author Youhei SASAKI, Eizi TOYODA, Yasuhiro MORIKAWA
6!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
7!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
8!> @en
9!> @brief Provides interface for system dependent procedures
10!> @details
11!> This module provides interfaces for system dependent procedures.
12!> In other words, there are interface declarations of functions and
13!> subroutines whose features are regarded as system dependent.
14!>
15!> Note that a procedure with one name may have several implementations.
16!>
17!> The sysdep module has no dependence to other modules.
18!>
19!> @section sysdep_procedures Procedures list
20!>
21!> | Procedure | Description |
22!> |-----------------|--------------------------------------|
23!> | AbortProgram | Abort program execution |
24!> | SysdepArgGet | Get command line argument |
25!> | SysdepArgCount | Get number of command line arguments |
26!> | SysdepEnvGet | Get environment variable |
27!>
28!> @enden
29!>
30!> @ja
31!> @brief システムに依存する手続きのインタフェースを提供します
32!> @details
33!> このモジュールはシステムに依存する手続きに関する
34!> インタフェースを提供します.
35!> 言い換えると, このモジュールではシステムに依存するサブルーチンと関数の
36!> インタフェース宣言がなされています.
37!>
38!> 従って, ある名前の手続きがあったとして, その手続きの実装は実際には
39!> 複数のファイルにおいて行われている可能性があるので気をつけてください.
40!>
41!> この sysdep モジュールは他のモジュールに依存しません.
42!>
43!> @section sysdep_procedures_ja 手続一覧
44!>
45!> | 手続名 | 説明 |
46!> |-----------------|--------------------------------------|
47!> | AbortProgram | プログラムを異常終了 |
48!> | SysdepArgGet | コマンドライン引数を取得 |
49!> | SysdepArgCount | コマンドライン引数の数を取得 |
50!> | SysdepEnvGet | 環境変数を取得 |
51!>
52!> @endja
53
54module sysdep
55 use, intrinsic :: iso_c_binding
56 implicit none
57 private
58 public :: abortprogram
59 public :: sysdepargget
60 public :: sysdepargcount
61 public :: sysdepenvget
62
63 interface
64 subroutine dc_f_abort() &
65 ! bind(C, name="dc_c_abort")
66 bind(C, name="abort")
67 import
68 end subroutine dc_f_abort
69 end interface
70
71contains
72
73 !> -------------------------------------------------------------------------
74 !> @en
75 !> @brief Abort program execution
76 !> @details
77 !> Aborts the program, optionally displaying an error message to stderr.
78 !> @param[in] message Optional error message to display before aborting
79 !> @enden
80 !>
81 !> @ja
82 !> @brief プログラムを異常終了させます
83 !> @details
84 !> プログラムを異常終了させます.
85 !> オプションでエラーメッセージを標準エラー出力に表示します.
86 !> @param[in] message 表示するエラーメッセージ (オプション)
87 !> @endja
88 !>
89 subroutine abortprogram(message)
90 use dc_types, only: stderr
91 implicit none
92 character(len=*), intent(in), optional :: message
93 continue
94 if (present(message)) write(stderr, *) trim(message)
95 call dc_f_abort()
96 end subroutine abortprogram
97
98 !> -------------------------------------------------------------------------
99 !> @en
100 !> @brief Get number of command line arguments
101 !> @details
102 !> Returns the number of command line arguments passed to the program.
103 !> @return Number of command line arguments
104 !> @enden
105 !>
106 !> @ja
107 !> @brief コマンドライン引数の数を取得します
108 !> @details
109 !> プログラムに渡されたコマンドライン引数の数を返します.
110 !> @return コマンドライン引数の数
111 !> @endja
112 !>
113 integer function sysdepargcount()
114 implicit none
115 sysdepargcount = command_argument_count()
116 end function sysdepargcount
117
118 !> -------------------------------------------------------------------------
119 !> @en
120 !> @brief Get command line argument
121 !> @details
122 !> Retrieves the command line argument at the specified index.
123 !> Negative indices count from the end (e.g., -1 is the last argument).
124 !> @param[in] index Index of the argument to retrieve
125 !> @param[out] val Value of the argument
126 !> @enden
127 !>
128 !> @ja
129 !> @brief コマンドライン引数を取得します
130 !> @details
131 !> 指定されたインデックスのコマンドライン引数を取得します.
132 !> 負のインデックスは末尾からカウントします (例: -1 は最後の引数).
133 !> @param[in] index 取得する引数のインデックス
134 !> @param[out] val 引数の値
135 !> @endja
136 !>
137 subroutine sysdepargget(index, val)
138 implicit none
139 integer, intent(in) :: index
140 character(len = *), intent(out) :: val
141 !
142 integer:: idx
143 integer:: argc
144 continue
145 argc = sysdepargcount()
146 if (index < 0) then
147 idx = argc + 1 + index
148 else
149 idx = index
150 endif
151 if (idx > argc) then
152 val = ''
153 else
154 call get_command_argument(index, val)
155 end if
156 end subroutine sysdepargget
157
158 !> -------------------------------------------------------------------------
159 !> @en
160 !> @brief Get environment variable
161 !> @details
162 !> Retrieves the value of the specified environment variable.
163 !> @param[in] env Name of the environment variable
164 !> @param[out] str Value of the environment variable
165 !> @enden
166 !>
167 !> @ja
168 !> @brief 環境変数を取得します
169 !> @details
170 !> 指定された環境変数の値を取得します.
171 !> @param[in] env 環境変数の名前
172 !> @param[out] str 環境変数の値
173 !> @endja
174 !>
175 subroutine sysdepenvget(env, str)
176 character(len = *), intent(in) :: env
177 character(len = *), intent(out) :: str
178 call get_environment_variable(trim(adjustl(env)), str)
179 end subroutine sysdepenvget
180
181end module sysdep
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public stderr
標準エラー出力の装置番号
Definition dc_types.f90:122
システムに依存する手続きのインタフェースを提供します
Definition sysdep.f90:54
subroutine, public abortprogram(message)
プログラムを異常終了させます
Definition sysdep.f90:90
subroutine, public sysdepenvget(env, str)
環境変数を取得します
Definition sysdep.f90:176
subroutine, public sysdepargget(index, val)
コマンドライン引数を取得します
Definition sysdep.f90:138
integer function, public sysdepargcount()
コマンドライン引数の数を取得します
Definition sysdep.f90:114