stdio Module

STDIO : Standard Input/Output module written by Son, Sang-Kil in Mar. 2005 This module requires two intrinsic subroutines: getarg() and getenv()

Data type - Argument : for command-line & input file options

Functions(F) and subroutines(SR) - SR error_message( string ) : print error messages and stop

  • SR get_options( ARG ) : get options from command line
  • SR get_input( ARG ) : get options from input file and command line ex) foobar -N 30 or -N:30 or -N=30 or -N30 or +N 30 foobar -N 10-30 foobar file.in or -N 30 file.in
    • if no option, file.in will be taken as input file
  • SR parse_option( ARG, option_name, string or value )
  • SR show_input( ARG ) : show options from input file and command line

  • SR footnote() : print out CPU_time, current time, and hostname

  • SR check_time( counter ) : check elapsed time

  • F job_time() : return job time converted from counter with hostname . F job_time_integer( counter ) : integer value from check_time() . F job_time_real( CPU_time ) : real value from CPU_time()

  • F today() : return the date string of today

  • F hostname() : return the hostname


Interfaces

public interface job_time

returns job time

  • private function job_time_integer8(counter) result(string)

    return the time string converted from counter ex) counter=100000000 with integer(8) --> 100 sec --> 1 minute 40.00 seconds


    Arguments

    Type IntentOptional Attributes Name
    integer(kind=8), intent(in) :: counter

    Return Value character(len=60)

  • private function job_time_real(time) result(string)

    Arguments

    Type IntentOptional Attributes Name
    real, intent(in) :: time

    Return Value character(len=60)

public interface parse_option

  • private subroutine parse_option_string(arg, option_name, string)

    get one option value or string from ARG The first chracter of ARG%option(i) should be + or -. That's why it is taken by ARG%option(i)(2:).


    Arguments

    Type IntentOptional Attributes Name
    type(argument), intent(in) :: arg
    character(len=*), intent(in) :: option_name
    character(len=*), intent(out) :: string
  • private subroutine parse_option_real(arg, option_name, value, value2)

    Arguments

    Type IntentOptional Attributes Name
    type(argument), intent(in) :: arg
    character(len=*), intent(in) :: option_name
    real(kind=long), intent(out) :: value
    real(kind=long), intent(out), optional :: value2
  • private subroutine parse_option_integer(arg, option_name, value, value2)

    Arguments

    Type IntentOptional Attributes Name
    type(argument), intent(in) :: arg
    character(len=*), intent(in) :: option_name
    integer, intent(out) :: value
    integer, intent(out), optional :: value2
  • private subroutine parse_option_logical(arg, option_name, yes)

    Arguments

    Type IntentOptional Attributes Name
    type(argument), intent(in) :: arg
    character(len=*), intent(in) :: option_name
    logical, intent(inout) :: yes

interface

  • public function check_mem_current() result(mem) bind(c, name="getCurrentRSS"))

    returns current memory

    Arguments

    None

    Return Value integer(kind=c_size_t)

interface

  • public function check_mem_peak() result(mem) bind(c, name="getPeakRSS"))

    returns peak memory

    Arguments

    None

    Return Value integer(kind=c_size_t)


Derived Types

type, public ::  argument

general command line argument

Components

Type Visibility Attributes Name Initial
integer, public :: n
character(len=2048), public, dimension(:), allocatable :: option
character(len=2048), public, dimension(:), allocatable :: string
real(kind=long), public, dimension(:), allocatable :: value
real(kind=long), public, dimension(:), allocatable :: value2
logical, public, dimension(:), allocatable :: yes

Functions

public function parse_string_array(buffer, delim) result(array)

parses a string array

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: buffer
character(len=1), intent(in) :: delim

Return Value character(len=:), allocatable, (:)

public function parse_int_array(buffer, delim, rangedelim) result(array)

parses an integer array

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: buffer
character(len=1), intent(in) :: delim
character(len=1), intent(in), optional :: rangedelim

Return Value integer, allocatable, (:)

public function parse_real_array(buffer, delim) result(array)

parses a float array

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: buffer
character(len=1), intent(in) :: delim

Return Value real(kind=long), allocatable, (:)

public function timestamp(time) result(string)

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Return Value character(len=60)


Subroutines

public subroutine purge_arg(arg)

Arguments

Type IntentOptional Attributes Name
type(argument), intent(inout) :: arg

public subroutine error_message(s)

show error message and stop the program

Arguments

Type IntentOptional Attributes Name
character(len=*), optional :: s

public subroutine get_input(arg, filename2)

if filename2 is specified, override reading of command line options. instead only read from filename2

Read more…

Arguments

Type IntentOptional Attributes Name
type(argument), intent(out) :: arg
character(len=*), intent(in), optional :: filename2

public subroutine convert_to_lowercase(string)

convert string into lowercase

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: string

public subroutine convert_to_uppercase(string)

convert string into uppercase

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: string

public subroutine show_input(arg)

Read more…

Arguments

Type IntentOptional Attributes Name
type(argument), intent(in) :: arg

public subroutine check_time(c, t)

Use this procedure when you want a check point. But, for initilization, you must put this without counter at the very begining of your program. ex) check_time() ... check_time( c, t ) print *, job_time( c )

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=8), intent(out), optional :: c
real, intent(out), optional :: t

public subroutine checkpoint(time, counter)

checkpoint(): more convenient procedure than check_time() An array time(0:) is a table containing all checkpoint times - time(0) : reference time stamp - time(1) : elapsed time for the first checkpoint - time(2) : elapsed time for the second checkpoint - ... ex) call init_checkpoint( time ) : initialize a time array ... (do some calculations) ... call checkpoint( time ) : make a checkpoint with the time array

Read more…

Arguments

Type IntentOptional Attributes Name
real, intent(inout) :: time(0:)
integer, intent(in), optional :: counter

public subroutine init_checkpoint(time)

Arguments

Type IntentOptional Attributes Name
real, intent(inout) :: time(0:)

public subroutine init_time()

print out CPU_time, current time, and hostname With PGI compiler, CPU_time gives real time instead of CPU time. What can I do for it? Huh? USAGE) call init_time() ... call footnote()

Read more…

Arguments

None

public subroutine footnote(iout)

prints footnote

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: iout

public subroutine c_f_string(cstrptr, fstr)

converts a c_char pointer array cStrPtr to a fortran string fStr

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: cstrptr

c pointer to a char* array

character(len=*), intent(out) :: fstr

fortan string