sysdep.f90
Go to the documentation of this file.
1 ! -*- coding: utf-8; mode: f90 -*-
2 !== sysdep.f90 - module providing interface for system dependent procedures
3 !
4 ! Authors:: Youhei SASAKI, Eizi TOYODA, Yasuhiro MORIKAWA
5 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2017. All rights reserved.
6 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
7 !
8 ! This file provides sysdep
9 !
10 
11 module sysdep
12  !
13  != module providing interface for system dependent procedures
14  !
15  ! このモジュールはシステムに依存する手続きに関する
16  ! インタフェースを提供します。
17  ! 言い換えると、このモジュールではシステムに依存するサブルーチンと関数の
18  ! インタフェース宣言がなされています。
19  ! これらの手続きは対応する名前がついたファイル内において実装されています
20  ! (すなわち <tt>sysdep</tt> で始まる名前のファイル群において、です)。
21  !
22  ! 従って、ある名前の手続きがあったとして、その手続きの実装は実際には
23  ! 複数のファイルにおいて行われている可能性があるので気をつけてください。
24  !
25  ! この sysdep モジュールは他のモジュールに依存しません。
26  !
27  !
28  ! It provides interface for system dependent procedures.
29  ! In other words, there is interface declaration of a function and
30  ! subroutines whose feature is regarded as system dependent.
31  ! Implementation of these procedures are given in files with
32  ! corresponding name (i.e. that begins with <tt>sysdep</tt>-).
33  !
34  ! Note that a procedure with one name may have several implementations.
35  !
36  ! The sysdep has no dependence to other modules.
37  !
38  use, intrinsic :: iso_c_binding
39  implicit none
40  private
41  public :: abortprogram
42  public :: sysdepargget
43  public :: sysdepargcount
44  public :: sysdepenvget
45 
46  interface
47  subroutine dc_f_abort() &
48  ! bind(C, name="dc_c_abort")
49  bind(c, name="abort")
50  import
51  end subroutine dc_f_abort
52  end interface
53 
54 contains
55 
56  subroutine abortprogram(message)
57  use dc_types, only: stderr
58  implicit none
59  character(len=*), intent(in), optional :: message
60  continue
61  if (present(message)) write(stderr, *) trim(message)
62  call dc_f_abort()
63  end subroutine abortprogram
64 
65  integer function sysdepargcount()
66  implicit none
67  sysdepargcount = command_argument_count()
68  end function sysdepargcount
69 
70  subroutine sysdepargget(index, val)
71  implicit none
72  integer, intent(in) :: index
73  character(len = *), intent(out) :: val
74  !
75  integer:: idx
76  integer:: argc
77  continue
78  argc = sysdepargcount()
79  if (index < 0) then
80  idx = argc + 1 + index
81  else
82  idx = index
83  endif
84  if (idx > argc) then
85  val = ''
86  else
87  call get_command_argument(index, val)
88  end if
89  end subroutine sysdepargget
90 
91  subroutine sysdepenvget(env, str)
92  character(len = *), intent(in) :: env
93  character(len = *), intent(out) :: str
94  call get_environment_variable(trim(adjustl(env)), str)
95  end subroutine sysdepenvget
96 
97 end module sysdep
subroutine, public sysdepenvget(env, str)
Definition: sysdep.f90:92
subroutine, public abortprogram(message)
Definition: sysdep.f90:57
integer, parameter, public stderr
Unit number for Standard ERROR.
Definition: dc_types.f90:103
Provides kind type parameter values.
Definition: dc_types.f90:49
integer function, public sysdepargcount()
Definition: sysdep.f90:66
subroutine, public sysdepargget(index, val)
Definition: sysdep.f90:71