Message System (message)¶
Module: utils_message
Overview¶
Provides SPEX messaging system for terminal output, warnings, error messages, and logging. Supports both interactive and API modes.
Key Features¶
Standardized message output
Error tracking and counting
Warning and informational messages
Log file support
API mode for Python interface
Types¶
message
Main message handling object:
Component |
Type |
Description |
|---|---|---|
|
integer |
Total number of errors detected |
|
integer |
Logical unit for terminal output |
|
integer |
Logical unit for error output |
|
logical |
.true. for Python API mode |
|
type(files) |
File handler for save operations |
|
type(files) |
File handler for log output |
Global Instance
A global message object is available:
type(message) :: mesg ! Global message handler
API Reference¶
Methods¶
spout
- mesg%spout(string)
Write standard output message
- Parameters:
string – Message text (character(*), input)
- Returns:
None
Writes to terminal and log file if active.
sper
- mesg%sper(string)
Write error message and increment error counter
- Parameters:
string – Error message text (character(*), input)
- Returns:
None
Prefixes message with “Error: “ and increments
errtot.
spwng
- mesg%spwng(string)
Write warning message
- Parameters:
string – Warning message text (character(*), input)
- Returns:
None
Prefixes message with “Warning: “.
spexstop
- mesg%spexstop()
Terminate SPEX execution
- Returns:
None
Stops program execution gracefully.
lushow
- mesg%lushow(lu)
Show logical unit information
- Parameters:
lu – Logical unit to display (integer, input)
- Returns:
None
Displays information about specified logical unit.
Usage Examples¶
Basic Message Usage
use utils_message
type(message) :: mesg
! Standard output
call mesg%spout('Processing started...')
! Warning message
call mesg%spwng('Low signal-to-noise ratio detected')
! Error message
call mesg%sper('Invalid parameter value')
write(*,*) 'Total errors:', mesg%errtot
Error Handling Pattern
use utils_message
type(message) :: mesg
integer :: status
! Operation with error checking
call some_operation(status)
if (status /= 0) then
call mesg%sper('Operation failed with error code: ' // status)
call mesg%spexstop() ! Terminate on critical error
endif
Logging to File
use utils_message
type(message) :: mesg
! Enable log file
call mesg%out%open('processing', 'log', 1, 2, status)
if (status == 0) then
call mesg%spout('Log file opened')
! Messages now go to both terminal and log
call mesg%spout('Processing data...')
call mesg%spwng('Background subtraction applied')
! Close log when done
call mesg%out%close(status)
endif
API Mode for Python
use utils_message
type(message) :: mesg
! Enable API mode (suppresses some terminal output)
mesg%apimode = .true.
! Messages handled differently in API mode
call mesg%spout('API mode activated')
call mesg%spwng('Running in batch mode')
Error Counting
use utils_message
type(message) :: mesg
integer :: i, n_operations
! Reset error counter
mesg%errtot = 0
! Perform multiple operations
n_operations = 10
do i = 1, n_operations
if (operation_failed(i)) then
call mesg%sper('Operation ' // i // ' failed')
endif
enddo
! Report final error count
if (mesg%errtot > 0) then
call mesg%spwng('Completed with errors: ' // mesg%errtot)
else
call mesg%spout('All operations completed successfully')
endif
Notes¶
Message Types
Method |
Prefix |
Typical Usage |
|---|---|---|
|
None |
Informational messages |
|
“Error: “ |
Error conditions |
|
“Warning: “ |
Non-critical issues |
Error Handling
errtotcounter tracks total errorsUse for validation and quality control
Reset counter as needed for different operations
Performance
Minimal overhead for message operations
Buffered output for efficiency
Suitable for frequent messaging
Best Practices
Use appropriate message type for each situation
Check error counter for critical operations
Enable logging for important processes
Use API mode for batch processing
Provide clear, actionable error messages
See Also¶
System Interface (sys) - System information
Temporary File Management (scratch) - Temporary file management