NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
basic Module Reference

This module will provide some basic convenience routines Description. More...

Data Types

type  timer
 Simple timer. Holds start-time, stop-time, and time-difference. More...
 

Functions/Subroutines

integer function, public is_inf (x)
 is_inf Checks if the argument is plus or minus infinite.
 
subroutine, public print_msg (msg, sub, errcode, unit)
 Print a message, and optionally stop the program.
 

Variables

real(dp), parameter, public zero = 0._dp
 Real cero.
 
real(dp), parameter, public small = epsilon(1._dp)
 Real small number.
 
complex(dp), parameter, public c_z0 = (0._dp, 0._dp)
 Complex cero.
 
complex(dp), parameter, public c_r1 = (1._dp, 0._dp)
 Complex unit.
 
complex(dp), parameter, public c_i1 = (0._dp, 1._dp)
 Complex imaginary unit.
 
real(dp), parameter, public nf_minf = -huge(1._dp)
 Minus infinite.
 
real(dp), parameter, public nf_inf = huge(1._dp)
 Positive infinite.
 
real(dp), parameter, public m_pi = 3.14159265358979323846264338328_dp
 $ \pi $
 
real(dp), parameter, public m_dpi = 6.28318530717958647692528676656_dp
 2*pi
 
real(dp), parameter, public m_pi_2 = 1.57079632679489661923132169164_dp
 pi/2
 
real(dp), parameter, public m_pi_4 = 0.78539816339744830966156608458_dp
 pi/4
 
real(dp), parameter, public m_sqrtpi = 1.77245385090551602729816748334_dp
 sqrt(pi)
 
real(dp), parameter, public m_2_sqrtpi = 1.12837916709551257389615890312_dp
 2/sqrt(pi)
 
real(dp), parameter, public m_1_pi = 0.31830988618379067153776752675_dp
 1/pi
 
real(dp), parameter, public m_2_pi = 0.63661977236758134307553505349_dp
 2/pi
 
real(dp), parameter, public m_lnpi = 1.14472988584940017414342735135_dp
 ln(pi)
 
real(dp), parameter, public m_ln2 = 0.693147180559945309417232121458176568_dp
 ln(2)
 
real(dp), parameter, public m_e = 2.71828182845904523536028747135_dp
 e
 
real(dp), parameter, public m_log2e = 1.442695040888963407359924681001892137_dp
 log_2 (e)
 
real(dp), parameter, public m_log10e = 0.43429448190325182765112891892_dp
 log_10 (e)
 
real(dp), parameter, public deg2rad = 0.017453292519943295_dp
 pi/180
 
real(dp), parameter, public rad2deg = 57.295779513082320876654618_dp
 180/pi
 

Detailed Description

This module will provide some basic convenience routines Description.

Eventually it will provide:

  • [X] types (real, double precision, infinite, etc)
  • [X] Basic error handling (defining output for warning and errors) To improve maybe look into https://docs.python.org/3/library/warnings.html
  • Some basic file handling (some os.path functionality) (Really needed?)
  • [X] Some sys functionality (stdin, stdout, stderr via iso_fortran_env)
  • [X] Timers, timestamp (a simple implementation)

For numerical work we need to use specific minimal precision which is machine-and-compiler-independent. The real type definitions emphatize this. The names are sp and dp are chosen only by tradition/historic reasons. We define types with at least 15 decimal places and exponent range of 307. (see for instance http://fortranwiki.org/fortran/show/Real+precision). We also could use c_double from module iso_c_binding (fortran 2003 and later)

Function/Subroutine Documentation

◆ is_inf()

integer function, public is_inf ( real(dp), intent(in) x)

is_inf Checks if the argument is plus or minus infinite.

Returns
Returns 0 if is finite, -1 if is minus-infinite and +1 if is plus-infinite
Parameters
[in]xVariable to test

References zero.

Referenced by timer::assignment().

Here is the caller graph for this function:

◆ print_msg()

subroutine, public print_msg ( character(len=*), intent(in) msg,
character(len=*), intent(in), optional sub,
integer, intent(in), optional errcode,
integer, intent(in), optional unit )

Print a message, and optionally stop the program.

If errcode > 0 stop the program

Examples of use:

call print_msg("Invalid argument!", errcode=1) ! will stop the program with error code 1.
call print_msg("Invalid argument","my_sub",1) ! will stop the program with error code 1.
call print_msg("Fishy values of argument","my_sub", errcode=3) ! will stop the program with error code 3.
call print_msg("Fishy values of argument", errcode=-3) ! will **NOT** stop the program. Show error code 3.
call print_msg("Fishy values of argument","my_sub", errcode=0) ! will **NOT** stop the program.
call print_msg("Fishy values of argument","my_sub", errcode=0, unit=13) ! will **NOT** stop the program.

The first three examples print the given message and stop the program. The next two will keep running after printing the message to stderr. The last will keep running after printing the message to a previously open file.

Parameters
[in]msgMessage to print on stderr
[in]subRoutine name. Default = None
[in]errcodeError code. Default = 0
[in]unitUnit to write. Default = stderr

Referenced by timer::assignment(), csplines::cspl_clean(), csplevder::cspl_interpdev(), csplevder::cspl_interpdev_tab(), csplines::csplder(), csplines::csplrep(), histograms::histogram(), polynomial::polyder(), polynomial::polyint(), save_array::save_array1d(), and save_array::save_array2d().

Here is the caller graph for this function: