Skip to content

Commit

Permalink
Refactoring and reformatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Oct 16, 2024
1 parent 40077ed commit 48ffe3b
Show file tree
Hide file tree
Showing 57 changed files with 565 additions and 625 deletions.
8 changes: 4 additions & 4 deletions app/dmapi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ program dmapi
! Clean up.
call dm_cgi_router_destroy(router)
contains
! ******************************************************************
! **************************************************************************
! ENDPOINTS.
! ******************************************************************
! **************************************************************************
subroutine route_beat(env)
!! Accepts beat in Namelist format via HTTP POST. Returns beat of
!! a given node id in CSV, JSON or Namelist format to GET requests.
Expand Down Expand Up @@ -2037,9 +2037,9 @@ subroutine route_timeseries(env)
rc = dm_db_close(db)
end subroutine route_timeseries

! ******************************************************************
! **************************************************************************
! UTILITY ROUTINES.
! ******************************************************************
! **************************************************************************
function content_type(env, default)
!! Returns the content type first found in CGI environment variable
!! `HTTP_ACCEPT`, either CSV, JSON Lines, JSON, or NML (in this order).
Expand Down
478 changes: 238 additions & 240 deletions app/dmbot.f90

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions app/dmdbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,11 @@ integer function crud(app) result(rc)

! Perform database operation.
select case (app%operation)
case (OP_CREATE)
rc = db_create(db, app)
case (OP_READ)
rc = db_read(db, app)
case (OP_UPDATE)
rc = db_update(db, app)
case (OP_DELETE)
rc = db_delete(db, app)
case default
rc = E_INVALID
case (OP_CREATE); rc = db_create(db, app)
case (OP_READ); rc = db_read (db, app)
case (OP_UPDATE); rc = db_update(db, app)
case (OP_DELETE); rc = db_delete(db, app)
case default; rc = E_INVALID
end select

! Close database.
Expand Down
69 changes: 24 additions & 45 deletions app/dmexport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ integer function export(app) result(rc)

! Arrays to hold the records from database.
type(beat_type), allocatable :: beats(:)
type(dp_type), allocatable :: data_points(:)
type(dp_type), allocatable :: dps(:)
type(log_type), allocatable :: logs(:)
type(node_type), allocatable :: nodes(:)
type(observ_type), allocatable :: observs(:)
Expand Down Expand Up @@ -91,7 +91,7 @@ integer function export(app) result(rc)
case (TYPE_BEAT)
rc = dm_db_select_beats(db, beats)
case (TYPE_DP)
rc = dm_db_select_data_points(db, data_points, node_id=app%node_id, sensor_id=app%sensor_id, &
rc = dm_db_select_data_points(db, dps, node_id=app%node_id, sensor_id=app%sensor_id, &
target_id=app%target_id, response_name=app%response, &
from=app%from, to=app%to)
end select
Expand All @@ -114,61 +114,40 @@ integer function export(app) result(rc)
case (FORMAT_BLOCK)
rc = E_INVALID
if (app%type == TYPE_DP) then
rc = dm_block_write(data_points, unit)
rc = dm_block_write(dps, unit)
end if

case (FORMAT_CSV)
select case (app%type)
case (TYPE_NODE)
rc = dm_csv_write(nodes, unit, app%header, app%separator)
case (TYPE_SENSOR)
rc = dm_csv_write(sensors, unit, app%header, app%separator)
case (TYPE_TARGET)
rc = dm_csv_write(targets, unit, app%header, app%separator)
case (TYPE_OBSERV)
rc = dm_csv_write(observs, unit, app%header, app%separator)
case (TYPE_LOG)
rc = dm_csv_write(logs, unit, app%header, app%separator)
case (TYPE_BEAT)
rc = dm_csv_write(beats, unit, app%header, app%separator)
case (TYPE_DP)
rc = dm_csv_write(data_points, unit, app%header, app%separator)
case (TYPE_NODE); rc = dm_csv_write(nodes, unit, app%header, app%separator)
case (TYPE_SENSOR); rc = dm_csv_write(sensors, unit, app%header, app%separator)
case (TYPE_TARGET); rc = dm_csv_write(targets, unit, app%header, app%separator)
case (TYPE_OBSERV); rc = dm_csv_write(observs, unit, app%header, app%separator)
case (TYPE_LOG); rc = dm_csv_write(logs, unit, app%header, app%separator)
case (TYPE_BEAT); rc = dm_csv_write(beats, unit, app%header, app%separator)
case (TYPE_DP); rc = dm_csv_write(dps, unit, app%header, app%separator)
end select

case (FORMAT_JSON)
select case (app%type)
case (TYPE_NODE)
rc = dm_json_write(nodes, unit)
case (TYPE_SENSOR)
rc = dm_json_write(sensors, unit)
case (TYPE_TARGET)
rc = dm_json_write(targets, unit)
case (TYPE_OBSERV)
rc = dm_json_write(observs, unit)
case (TYPE_LOG)
rc = dm_json_write(logs, unit)
case (TYPE_BEAT)
rc = dm_json_write(beats, unit)
case (TYPE_DP)
rc = dm_json_write(data_points, unit)
case (TYPE_NODE); rc = dm_json_write(nodes, unit)
case (TYPE_SENSOR); rc = dm_json_write(sensors, unit)
case (TYPE_TARGET); rc = dm_json_write(targets, unit)
case (TYPE_OBSERV); rc = dm_json_write(observs, unit)
case (TYPE_LOG); rc = dm_json_write(logs, unit)
case (TYPE_BEAT); rc = dm_json_write(beats, unit)
case (TYPE_DP); rc = dm_json_write(dps, unit)
end select

case (FORMAT_JSONL)
select case (app%type)
case (TYPE_NODE)
rc = dm_jsonl_write(nodes, unit)
case (TYPE_SENSOR)
rc = dm_jsonl_write(sensors, unit)
case (TYPE_TARGET)
rc = dm_jsonl_write(targets, unit)
case (TYPE_OBSERV)
rc = dm_jsonl_write(observs, unit)
case (TYPE_LOG)
rc = dm_jsonl_write(logs, unit)
case (TYPE_BEAT)
rc = dm_jsonl_write(beats, unit)
case (TYPE_DP)
rc = dm_jsonl_write(data_points, unit)
case (TYPE_NODE); rc = dm_jsonl_write(nodes, unit)
case (TYPE_SENSOR); rc = dm_jsonl_write(sensors, unit)
case (TYPE_TARGET); rc = dm_jsonl_write(targets, unit)
case (TYPE_OBSERV); rc = dm_jsonl_write(observs, unit)
case (TYPE_LOG); rc = dm_jsonl_write(logs, unit)
case (TYPE_BEAT); rc = dm_jsonl_write(beats, unit)
case (TYPE_DP); rc = dm_jsonl_write(dps, unit)
end select
end select

Expand Down
4 changes: 2 additions & 2 deletions app/dmfeed.f90
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ integer function read_args(app) result(rc)
return
end if

if (.not. dm_log_is_valid(app%min_level)) then
if (.not. dm_log_level_is_valid(app%min_level)) then
call dm_error_out(rc, 'invalid minimum log level')
return
end if

if (.not. dm_log_is_valid(app%max_level)) then
if (.not. dm_log_level_is_valid(app%max_level)) then
call dm_error_out(rc, 'invalid maximum log level')
return
end if
Expand Down
3 changes: 1 addition & 2 deletions app/dmfs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ integer function write_observ(observ, unit, format) result(rc)
select case (format)
case (FORMAT_CSV)
! CSV format.
rc = dm_csv_write(observ, unit=unit, header=.false., &
separator=APP_CSV_SEPARATOR)
rc = dm_csv_write(observ, unit=unit, header=.false., separator=APP_CSV_SEPARATOR)
case (FORMAT_JSONL)
! JSON Lines format.
rc = dm_json_write(observ, unit=unit)
Expand Down
4 changes: 2 additions & 2 deletions app/dmgrc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ integer function read_args(app) result(rc)
return
end if

if (.not. dm_log_is_valid(app%level)) then
if (.not. dm_log_level_is_valid(app%level)) then
call dm_error_out(rc, 'invalid log level')
return
end if
Expand Down Expand Up @@ -172,7 +172,7 @@ integer function read_config(app) result(rc)
call dm_config_get(config, 'warning', app%levels(LL_WARNING )%codes)
call dm_config_get(config, 'error', app%levels(LL_ERROR )%codes)
call dm_config_get(config, 'critical', app%levels(LL_CRITICAL)%codes)
call dm_config_get(config, 'user', app%levels(LL_USER) %codes)
call dm_config_get(config, 'user', app%levels(LL_USER )%codes)

call dm_config_remove(config)
end if
Expand Down
7 changes: 3 additions & 4 deletions app/dminfo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program dminfo
character(len=*), parameter :: APP_NAME = 'dminfo'
integer, parameter :: APP_MAJOR = 0
integer, parameter :: APP_MINOR = 9
integer, parameter :: APP_PATCH = 2
integer, parameter :: APP_PATCH = 6

type :: app_type
!! Command-line arguments.
Expand All @@ -27,6 +27,7 @@ program dminfo
rc = read_args(app)
if (dm_is_error(rc)) call dm_stop(STOP_FAILURE)

! Print information.
rc = output_info(app)
if (dm_is_error(rc)) call dm_stop(STOP_FAILURE)
contains
Expand Down Expand Up @@ -54,7 +55,7 @@ integer function output_info(app) result(rc)
character(len=:), allocatable :: mode_name
integer :: app_id, mode, user_version
integer(kind=i8) :: n, sz
logical :: foreign_keys, has_db
logical :: has_db
type(db_type) :: db
type(uname_type) :: uname

Expand All @@ -75,11 +76,9 @@ integer function output_info(app) result(rc)
if (has_db) then
rc = dm_db_get_application_id(db, app_id)
rc = dm_db_get_user_version(db, user_version)
rc = dm_db_get_foreign_keys(db, foreign_keys)
rc = dm_db_get_journal_mode(db, mode, mode_name)

print '("db.application_id: ", z0)', app_id
print '("db.foreign_keys: ", l1)', foreign_keys
print '("db.journal_mode: ", a)', mode_name
print '("db.library: ", a)', dm_db_version(.true.)
print '("db.path: ", a)', trim(app%database)
Expand Down
2 changes: 1 addition & 1 deletion app/dmlogger.f90
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ integer function read_args(app) result(rc)
return
end if

if (.not. dm_log_is_valid(app%minlevel)) then
if (.not. dm_log_level_is_valid(app%minlevel)) then
call dm_error_out(rc, 'invalid log level')
return
end if
Expand Down
4 changes: 2 additions & 2 deletions app/dmreport.f90
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ integer function read_args(app) result(rc)

! Validate log settings.
if (.not. log%disabled) then
if (.not. dm_log_is_valid(log%min_level)) then
if (.not. dm_log_level_is_valid(log%min_level)) then
call dm_error_out(rc, 'invalid minimum log level')
return
end if

if (.not. dm_log_is_valid(log%max_level)) then
if (.not. dm_log_level_is_valid(log%max_level)) then
call dm_error_out(rc, 'invalid maximum log level')
return
end if
Expand Down
3 changes: 0 additions & 3 deletions app/dmuuid.f90
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ subroutine convert()
integer :: stat

do
uuid = ' '
read (*, '(a)', iostat=stat) uuid

if (is_iostat_end(rc)) exit
if (stat /= 0 .or. .not. dm_uuid4_is_valid(uuid)) uuid = UUID_DEFAULT

print '(a)', dm_uuid4_hyphenize(uuid)
end do
end subroutine convert
Expand Down
12 changes: 6 additions & 6 deletions app/dmweb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ program dmweb

call dm_cgi_router_destroy(router)
contains
! ******************************************************************
! **************************************************************************
! ENDPOINTS.
! ******************************************************************
! **************************************************************************
subroutine route_beat(env)
!! Beat page.
!!
Expand Down Expand Up @@ -1873,9 +1873,9 @@ subroutine route_targets(env)
rc = dm_db_close(db)
end subroutine route_targets

! ******************************************************************
! **************************************************************************
! HTML FORM GENERATORS.
! ******************************************************************
! **************************************************************************
function html_form_logs(nodes, sensors, targets, max_results, node_id, sensor_id, target_id, &
source, from, to, level, nresults) result(html)
!! Returns HTML form for log selection.
Expand Down Expand Up @@ -2423,9 +2423,9 @@ function html_form_targets(disabled) result(html)
H_FIELDSET_END // H_FORM_END // H_DETAILS_END
end function html_form_targets

! ******************************************************************
! **************************************************************************
! UTILITY PROCEDURES.
! ******************************************************************
! **************************************************************************
subroutine html_error(heading, error, status, title, extra)
!! Outputs error page (with header and footer).
character(len=*), intent(in), optional :: heading !! Page heading.
Expand Down
10 changes: 5 additions & 5 deletions src/dm_arg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ module dm_arg
private :: arg_get_real64
private :: arg_get_string
contains
! ******************************************************************
! **************************************************************************
! PUBLIC PROCEDURES.
! ******************************************************************
! **************************************************************************
logical function dm_arg_has(name, short) result(has)
!! Returns `.true.` if argument of given name is passed without value.
character(len=*), intent(in) :: name !! Name of command-line argument.
Expand Down Expand Up @@ -439,7 +439,7 @@ integer function dm_arg_validate(arg) result(rc)
! Log level.
if (arg%length == 0) return
level = dm_log_level_from_string(arg%value)
if (.not. dm_log_is_valid(level)) return
if (.not. dm_log_level_is_valid(level)) return
! Set argument value to numeric log level.
arg%value = dm_itoa(level)

Expand Down Expand Up @@ -484,9 +484,9 @@ subroutine dm_arg_help(args)
write (stdout, '(4x, "-v, --version", /)')
end subroutine dm_arg_help

! ******************************************************************
! **************************************************************************
! PRIVATE PROCEDURES.
! ******************************************************************
! **************************************************************************
subroutine arg_get_int32(arg, value, default, passed, error)
!! Returns argument value as 4-byte integer.
type(arg_type), intent(inout) :: arg !! Arg type.
Expand Down
8 changes: 4 additions & 4 deletions src/dm_atom.f90
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ module dm_atom
private :: atom_link
private :: atom_style_sheet
contains
! ******************************************************************
! **************************************************************************
! PUBLIC PROCEDURES.
! ******************************************************************
! **************************************************************************
subroutine dm_atom_from_logs(atom, logs, xml)
!! Returns log messages in Atom Syndication Format (RFC 4287).
!!
Expand Down Expand Up @@ -163,9 +163,9 @@ subroutine dm_atom_from_logs(atom, logs, xml)
xml = xml // A_FEED_END
end subroutine dm_atom_from_logs

! ******************************************************************
! **************************************************************************
! PRIVATE PROCEDURES.
! ******************************************************************
! **************************************************************************
pure function atom_link(href, rel, type) result(xml)
!! Returns an Atom link, for example:
!!
Expand Down
4 changes: 2 additions & 2 deletions src/dm_block.f90
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ module dm_block
private :: block_write_data_point
private :: block_write_data_points
contains
! ******************************************************************
! **************************************************************************
! PRIVATE PROCEDURES.
! ******************************************************************
! **************************************************************************
pure elemental character(len=BLOCK_LINE_LEN) &
function block_from_data_point(data_point) result(str)
!! Returns ASCII block representation of data point.
Expand Down
8 changes: 4 additions & 4 deletions src/dm_cgi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ module dm_cgi
private :: cgi_get_string
private :: cgi_param_loc
contains
! ******************************************************************
! **************************************************************************
! PUBLIC PROCEDURES.
! ******************************************************************
! **************************************************************************
logical function dm_cgi_auth_basic(env) result(auth)
!! Returns `.true.` if CGI environment variable `AUTH` is set to
!! `Basic`.
Expand Down Expand Up @@ -385,9 +385,9 @@ subroutine dm_cgi_query(env, param)
call dm_cgi_parse(env%query_string, param)
end subroutine dm_cgi_query

! ******************************************************************
! **************************************************************************
! PRIVATE PROCEDURES.
! ******************************************************************
! **************************************************************************
integer function cgi_get_int32(param, key, value, default, required) result(rc)
!! Returns (last) value associated with key in `param` as 32-bit integer.
!! The return code is set to `E_EMPTY` if the key does not exist and
Expand Down
Loading

0 comments on commit 48ffe3b

Please sign in to comment.