libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
sufr_system Module Reference

System-related procedures. More...

Functions/Subroutines

subroutine quit_program (message)
 Print a message to StdOut and stop the execution of the current program.
 
subroutine quit_program_warning (message, status)
 Print a warning to StdOut and stop the execution of the current program.
 
subroutine quit_program_error (message, status)
 Print an error message to StdErr and stop the execution of the current program.
 
subroutine execute_command_line_verbose (command, wait, status, quit_on_error)
 Execute a shell command and print a message upon error. Optionally stop the execution of the current program in that case.
 
subroutine execute_command_line_quit_on_error (command, wait, status)
 Execute a shell command. Upon error, print a message and stop the execution of the current program.
 
character function, dimension(1024 *10) execute_command_line_and_return_str (command, wait, status)
 Execute a shell command and return the result as a string.
 
integer function execute_command_line_and_return_int (command, wait, status)
 Execute a shell command and return the result as an integer.
 
subroutine syntax_print (syntax, descr)
 Print a syntax message to StdErr.
 
subroutine syntax_quit (syntax, status, descr)
 Print a syntax message to StdErr and stop the execution of the current program.
 
subroutine file_open_error (filename, filetype, iostat, iomsg)
 Print a message to StdErr upon file open error.
 
subroutine file_open_error_quit (filename, filetype, iostat, iomsg)
 Print a message to StdErr on file open error, and stop the execution of the current program.
 
subroutine file_read_error (filename, line, procedure, iostat, iomsg)
 Print a message to StdErr on file read error.
 
subroutine file_read_error_quit (filename, line, status, procedure, iostat, iomsg)
 Print a message to StdErr on file read error, and stop the execution of the current program.
 
subroutine file_write_error (filename, line)
 Print a message to StdErr on file write error.
 
subroutine file_write_error_quit (filename, line, status)
 Print a message to StdErr on file write error, and stop the execution of the current program.
 
subroutine file_end_error (filename)
 Print a message to StdErr on reaching the end of a file while reading.
 
subroutine file_end_quit (filename, status)
 Print a message to StdErr on reaching the end of a file while reading, and stop the code.
 
subroutine file_read_end_error (filename, line, readstatus, stopcode, exitstatus, message)
 Print a message to StdErr on read error or reaching the end of a file while reading, and optionally stop the code.
 
subroutine warn (message, unit)
 Print a warning to StdOut or StErr.
 
subroutine error (message, unit)
 Print an error to StdOut or StErr.
 
subroutine system_time (year, month, day, hour, minute, second, tz)
 Get date and time from the system clock.
 
real(double) function timestamp ()
 Return the time stamp in seconds since 1970-01-01 00:00:00 UTC.
 
subroutine printprogressbar (frac, timestamp0)
 Print a text progress bar to the screen, optionally with estimated time left.
 
pure character function, dimension(8) tms (t)
 Print time as mm:ss.s string, input in hours.
 
subroutine print_runtimes (calltype, sp, dec)
 Print run times: wall time and CPU time.
 
subroutine print_cputime (sp, dec, unit)
 Print CPU time since the first execution of the program.
 
subroutine find_free_io_unit (unit)
 Find the first unused I/O unit larger than 100.
 
subroutine file_skip_header (unit, nlines)
 Skip the next (e.g. first) lines of a file.
 
pure subroutine swapint (int1, int2)
 Swap two integer variables.
 
pure subroutine swapreal (rl1, rl2)
 Swap two single-precision real variables.
 
pure subroutine swapdbl (dbl1, dbl2)
 Swap two double-precision real variables.
 
subroutine swapstr (str1, str2)
 Swap two strings.
 

Detailed Description

System-related procedures.

Function/Subroutine Documentation

◆ error()

subroutine sufr_system::error ( character, dimension(*), intent(in) message,
integer, intent(in), optional unit )

Print an error to StdOut or StErr.

Parameters
messageWarning message
unitOutput unit: 0-StdErr, 1-StdOut - (optional; default = 0)

Definition at line 670 of file system.f90.

References sufr_constants::program_name.

Referenced by execute_command_line_verbose(), sufr_statistics::mean_weight(), sufr_statistics::prob_range(), sufr_text::replace_string_in_textfile(), sufr_statistics::stdev(), and sufr_statistics::stdev_weight().

◆ execute_command_line_and_return_int()

integer function sufr_system::execute_command_line_and_return_int ( character, dimension(*), intent(in) command,
logical, intent(in), optional wait,
integer, intent(in), optional status )

Execute a shell command and return the result as an integer.

Parameters
commandCommand line to execute
waitExecute command synchronously (in the foreground) if true, asynchronously (in the background) if false (optional; default=true)
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen (optional; default=1)
Return values
Integercontaining the result. If more data were returned by the command, only the first is parsed.

Definition at line 254 of file system.f90.

References execute_command_line_and_return_int(), execute_command_line_and_return_str(), and quit_program_error().

Referenced by execute_command_line_and_return_int().

Here is the call graph for this function:

◆ execute_command_line_and_return_str()

character function, dimension(1024*10) sufr_system::execute_command_line_and_return_str ( character, dimension(*), intent(in) command,
logical, intent(in), optional wait,
integer, intent(in), optional status )

Execute a shell command and return the result as a string.

Parameters
commandCommand line to execute
waitExecute command synchronously (in the foreground) if true, asynchronously (in the background) if false (optional; default=true)
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen (optional; default=1)
Return values
Stringcontaining the result. Multiple lines are separated by newline code. The size is 10kb, and an error occurs when one attempts to stuff more into it.

Definition at line 182 of file system.f90.

References sufr_kinds::double, execute_command_line_and_return_str(), execute_command_line_verbose(), file_open_error_quit(), file_read_error_quit(), find_free_io_unit(), sufr_random_numbers::get_ran_seed(), sufr_constants::homedir, sufr_constants::newline, and sufr_random_numbers::ran_unif().

Referenced by execute_command_line_and_return_int(), and execute_command_line_and_return_str().

Here is the call graph for this function:

◆ execute_command_line_quit_on_error()

subroutine sufr_system::execute_command_line_quit_on_error ( character, dimension(*), intent(in) command,
logical, intent(in), optional wait,
integer, intent(in), optional status )

Execute a shell command. Upon error, print a message and stop the execution of the current program.

Parameters
commandCommand line to execute
waitExecute command synchronously (in the foreground) if true, asynchronously (in the background) if false (optional; default=true)
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen (optional; default=1)

Definition at line 153 of file system.f90.

References execute_command_line_verbose().

Here is the call graph for this function:

◆ execute_command_line_verbose()

subroutine sufr_system::execute_command_line_verbose ( character, dimension(*), intent(in) command,
logical, intent(in), optional wait,
integer, intent(in), optional status,
logical, intent(in), optional quit_on_error )

Execute a shell command and print a message upon error. Optionally stop the execution of the current program in that case.

Parameters
commandCommand line to execute
waitExecute command synchronously (in the foreground) if true, asynchronously (in the background) if false (optional; default=true)
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen (optional; default=1)
quit_on_errorQuit the program upon error (optional; defaults to false)

Definition at line 104 of file system.f90.

References error(), and quit_program_error().

Referenced by execute_command_line_and_return_str(), and execute_command_line_quit_on_error().

Here is the call graph for this function:

◆ file_end_error()

subroutine sufr_system::file_end_error ( character, dimension(*), intent(in) filename)

Print a message to StdErr on reaching the end of a file while reading.

Parameters
filenameFilename

Definition at line 552 of file system.f90.

References sufr_constants::program_name.

Referenced by file_read_end_error().

◆ file_end_quit()

subroutine sufr_system::file_end_quit ( character, dimension(*), intent(in) filename,
integer, intent(in) status )

Print a message to StdErr on reaching the end of a file while reading, and stop the code.

Parameters
filenameFilename
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen

Definition at line 570 of file system.f90.

References sufr_constants::program_name.

Referenced by file_read_end_error().

◆ file_open_error()

subroutine sufr_system::file_open_error ( character, dimension(*), intent(in) filename,
integer, intent(in) filetype,
integer, intent(in), optional iostat,
character, dimension(*), intent(in), optional iomsg )

Print a message to StdErr upon file open error.

Parameters
filenameFilename
filetypeFile type: 0: (0)utput, 1: (1)nput
ioStatIO status (optional)
ioMsgIO status message (optional; default = none)

Definition at line 345 of file system.f90.

References sufr_constants::program_name.

Referenced by file_open_error_quit().

◆ file_open_error_quit()

subroutine sufr_system::file_open_error_quit ( character, dimension(*), intent(in) filename,
integer, intent(in) filetype,
integer, intent(in), optional iostat,
character, dimension(*), intent(in), optional iomsg )

Print a message to StdErr on file open error, and stop the execution of the current program.

Parameters
filenameFilename
filetypeFile type: 0: (0)utput, 1: (1)nput
ioStatIO status (optional): 0-ok, otherwise not ok. The latter makes the stop command appear on screen
ioMsgIO status message (optional; default = none)

Definition at line 388 of file system.f90.

References file_open_error().

Referenced by execute_command_line_and_return_str().

Here is the call graph for this function:

◆ file_read_end_error()

subroutine sufr_system::file_read_end_error ( character, dimension(*), intent(in) filename,
integer, intent(in) line,
integer, intent(in) readstatus,
integer, intent(in) stopcode,
integer, intent(in) exitstatus,
character, dimension(*), intent(in), optional message )

Print a message to StdErr on read error or reaching the end of a file while reading, and optionally stop the code.

Parameters
filenameFilename
lineLine number where read error occurred - 0: no line
readstatusRead status provided by iostat
stopcodeStop the execution of the code: 0-no, 1-yes
exitstatusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen
messageCustom message (optional; default = none)

Definition at line 601 of file system.f90.

References file_end_error(), file_end_quit(), file_read_error(), and file_read_error_quit().

Here is the call graph for this function:

◆ file_read_error()

subroutine sufr_system::file_read_error ( character, dimension(*), intent(in) filename,
integer, intent(in) line,
character, dimension(*), intent(in), optional procedure,
integer, intent(in), optional iostat,
character, dimension(*), intent(in), optional iomsg )

Print a message to StdErr on file read error.

Parameters
filenameFilename
lineLine number where read error occurred - 0: no line
procedureName of the procedure this subroutine is called from (without "()" - optional; default = none)
ioStatIO status code (optional)
ioMsgIO status message (optional; default = none)

Definition at line 424 of file system.f90.

References sufr_constants::program_name.

Referenced by file_read_end_error(), and file_read_error_quit().

◆ file_read_error_quit()

subroutine sufr_system::file_read_error_quit ( character, dimension(*), intent(in) filename,
integer, intent(in) line,
integer, intent(in) status,
character, dimension(*), intent(in), optional procedure,
integer, intent(in), optional iostat,
character, dimension(*), intent(in), optional iomsg )

Print a message to StdErr on file read error, and stop the execution of the current program.

Parameters
filenameFilename
lineLine number where read error occurred - 0: no line
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen
procedureName of the procedure this subroutine is called from (without "()"; optional; default = none)
ioStatIO status code (optional)
ioMsgIO status message (optional; default = none)

Definition at line 462 of file system.f90.

References file_read_error().

Referenced by execute_command_line_and_return_str(), and file_read_end_error().

Here is the call graph for this function:

◆ file_skip_header()

subroutine sufr_system::file_skip_header ( integer, intent(in) unit,
integer, intent(in) nlines )

Skip the next (e.g. first) lines of a file.

Parameters
unitFile unit
nLinesNumber of lines to skip

Definition at line 971 of file system.f90.

References sufr_dummy::dumstr.

◆ file_write_error()

subroutine sufr_system::file_write_error ( character, dimension(*), intent(in) filename,
integer, intent(in) line )

Print a message to StdErr on file write error.

Parameters
filenameFilename
lineLine number where write error occurred - 0: no line

Definition at line 497 of file system.f90.

References sufr_constants::program_name.

◆ file_write_error_quit()

subroutine sufr_system::file_write_error_quit ( character, dimension(*), intent(in) filename,
integer, intent(in) line,
integer, intent(in) status )

Print a message to StdErr on file write error, and stop the execution of the current program.

Parameters
filenameFilename
lineLine number where write error occurred - 0: no line
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen

Definition at line 522 of file system.f90.

References sufr_constants::program_name.

◆ find_free_io_unit()

subroutine sufr_system::find_free_io_unit ( integer, intent(out) unit)

Find the first unused I/O unit larger than 100.

Parameters
unitI/O unit; unit > 100 (output)

Definition at line 950 of file system.f90.

Referenced by execute_command_line_and_return_str(), sufr_pgplot::pgplot_settings(), and sufr_text::replace_string_in_textfile().

◆ print_cputime()

subroutine sufr_system::print_cputime ( integer, intent(in), optional sp,
integer, intent(in), optional dec,
integer, intent(in), optional unit )

Print CPU time since the first execution of the program.

Parameters
spNumber of leading spaces (optional; default = 0)
decNumber of decimals in the time (optional; default = 3)
unitOutput unit (0: stdErr, 6: stdOut; optional; default = 6)

Definition at line 901 of file system.f90.

References sufr_kinds::double.

◆ print_runtimes()

subroutine sufr_system::print_runtimes ( integer, intent(in), optional calltype,
integer, intent(in), optional sp,
integer, intent(in), optional dec )

Print run times: wall time and CPU time.

Parameters
calltypeType of call: 1-reset time; 2-print and reset time; 3-print time (optional; default = 1 on first call, else 3)
spNumber of leading spaces (optional; default = 0)
decNumber of decimals in the time (optional; default = 3)

Definition at line 830 of file system.f90.

References sufr_kinds::double, sufr_kinds::long, and warn().

Here is the call graph for this function:

◆ printprogressbar()

subroutine sufr_system::printprogressbar ( real(double), intent(in) frac,
real(double), intent(in), optional timestamp0 )

Print a text progress bar to the screen, optionally with estimated time left.

Parameters
fracFraction of the task completed
timestamp0Timestamp of start of task (optional; default = don't print time left)

Definition at line 762 of file system.f90.

References sufr_constants::cursorup, sufr_kinds::double, timestamp(), and tms().

Here is the call graph for this function:

◆ quit_program()

subroutine sufr_system::quit_program ( character, dimension(*), intent(in) message)

Print a message to StdOut and stop the execution of the current program.

Parameters
messageExit message

Definition at line 34 of file system.f90.

Referenced by sufr_command_line::split_short_cl_options().

◆ quit_program_error()

◆ quit_program_warning()

subroutine sufr_system::quit_program_warning ( character, dimension(*), intent(in) message,
integer, intent(in) status )

Print a warning to StdOut and stop the execution of the current program.

Parameters
messageExit message/warning
statusExit code: 0-ok, 1-not ok. This makes the stop command appear on screen

Definition at line 52 of file system.f90.

References sufr_constants::program_name.

◆ swapdbl()

pure subroutine sufr_system::swapdbl ( real(double), intent(inout) dbl1,
real(double), intent(inout) dbl2 )

Swap two double-precision real variables.

Parameters
dbl1Double 1
dbl2Double 2

Definition at line 1033 of file system.f90.

References sufr_kinds::double.

Referenced by sufr_fitting::nonlin_fit_example_myfunc().

◆ swapint()

pure subroutine sufr_system::swapint ( integer, intent(inout) int1,
integer, intent(inout) int2 )

Swap two integer variables.

Parameters
int1Integer 1
int2Integer 2

Definition at line 993 of file system.f90.

Referenced by sufr_numerics::gcd2().

◆ swapreal()

pure subroutine sufr_system::swapreal ( real, intent(inout) rl1,
real, intent(inout) rl2 )

Swap two single-precision real variables.

Parameters
rl1real 1
rl2real 2

Definition at line 1013 of file system.f90.

◆ swapstr()

subroutine sufr_system::swapstr ( character, dimension(*), intent(inout) str1,
character, dimension(*), intent(inout) str2 )

Swap two strings.

Parameters
str1String 1 (I/O)
str2String 2 (I/O)

Definition at line 1053 of file system.f90.

References warn().

Here is the call graph for this function:

◆ syntax_print()

subroutine sufr_system::syntax_print ( character, dimension(*), intent(in) syntax,
character, dimension(*), intent(in), optional descr )

Print a syntax message to StdErr.

Parameters
syntaxDescription of syntax
descrProgram description (optional; default = none)

Definition at line 288 of file system.f90.

References sufr_constants::program_name.

◆ syntax_quit()

subroutine sufr_system::syntax_quit ( character, dimension(*), intent(in) syntax,
integer, intent(in), optional status,
character, dimension(*), intent(in), optional descr )

Print a syntax message to StdErr and stop the execution of the current program.

Parameters
syntaxDescription of syntax
statusExit code: 0-ok, 1-not ok. The latter makes the stop command appear on screen (optional; default = 0)
descrProgram description (optional; default = none)

Definition at line 310 of file system.f90.

References sufr_constants::program_name.

◆ system_time()

subroutine sufr_system::system_time ( integer, intent(out) year,
integer, intent(out) month,
integer, intent(out) day,
integer, intent(out) hour,
integer, intent(out) minute,
real(double), intent(out) second,
real(double), intent(out), optional tz )

Get date and time from the system clock.

Parameters
yearCurrent year CE
monthCurrent month
dayCurrent day of month
hourCurrent hour of day
minuteCurrent minute of time
secondCurrent second of time
tzTime zone in hours (optional)

Definition at line 703 of file system.f90.

References sufr_kinds::double, and sufr_dummy::dumstr99.

◆ timestamp()

real(double) function sufr_system::timestamp

Return the time stamp in seconds since 1970-01-01 00:00:00 UTC.

Return values
timestampUnix timestamp: number of seconds since 1970-01-01 00:00:00 UTC, accuracy: 1ms

Definition at line 738 of file system.f90.

References sufr_kinds::double, sufr_dummy::dumstr99, timestamp(), and sufr_date_and_time::ymdhms2jd().

Referenced by printprogressbar(), and timestamp().

Here is the call graph for this function:

◆ tms()

pure character function, dimension(8) sufr_system::tms ( real(double), intent(in) t)

Print time as mm:ss.s string, input in hours.

Parameters
tTime (h)
Return values
tmsTime as mm:ss.s string
Note
use here to drop dependency to SUFR_time2string. Alternative: move printProgressBar elsewhere

Definition at line 801 of file system.f90.

References sufr_kinds::double, and tms().

Referenced by printprogressbar(), and tms().

Here is the call graph for this function:

◆ warn()

subroutine sufr_system::warn ( character, dimension(*), intent(in) message,
integer, intent(in), optional unit )

Print a warning to StdOut or StErr.

Parameters
messageWarning message
unitOutput unit: 0-StdErr, 1-StdOut (optional; default = 0)

Definition at line 645 of file system.f90.

References sufr_constants::program_name.

Referenced by sufr_statistics::correlation(), sufr_fitting::linear_fit_yerr(), sufr_interpolate::linear_interpolate_array(), sufr_statistics::mean(), sufr_fitting::nonlin_fit_example_myfunc(), print_runtimes(), sufr_statistics::prob_range(), swapstr(), sufr_text::utf16to8(), and sufr_optics::wavelength2rgb().