Skip to content

Commit

Permalink
Refactoring of longitude, latitude, and altitude. Updated database sc…
Browse files Browse the repository at this point in the history
…hema.
  • Loading branch information
interkosmos committed Aug 4, 2024
1 parent 24acf62 commit 7038ad3
Show file tree
Hide file tree
Showing 19 changed files with 702 additions and 456 deletions.
65 changes: 40 additions & 25 deletions app/dmdbctl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ integer function db_update(db, app) result(rc)
if (dm_is_error(rc)) exit db_select

! Overwrite if not passed.
if (.not. app%mask(ATTR_NAME)) app%node%name = old_node%name
if (.not. app%mask(ATTR_META)) app%node%meta = old_node%meta
if (.not. app%mask(ATTR_X)) app%node%x = old_node%x
if (.not. app%mask(ATTR_Y)) app%node%y = old_node%y
if (.not. app%mask(ATTR_Z)) app%node%z = old_node%z
if (.not. app%mask(ATTR_LON)) app%node%longitude = old_node%longitude
if (.not. app%mask(ATTR_LAT)) app%node%latitude = old_node%latitude
if (.not. app%mask(ATTR_ALT)) app%node%altitude = old_node%altitude
if (.not. app%mask(ATTR_NAME)) app%node%name = old_node%name
if (.not. app%mask(ATTR_META)) app%node%meta = old_node%meta
if (.not. app%mask(ATTR_X)) app%node%x = old_node%x
if (.not. app%mask(ATTR_Y)) app%node%y = old_node%y
if (.not. app%mask(ATTR_Z)) app%node%z = old_node%z
if (.not. app%mask(ATTR_LON)) app%node%lon = old_node%lon
if (.not. app%mask(ATTR_LAT)) app%node%lat = old_node%lat
if (.not. app%mask(ATTR_ALT)) app%node%alt = old_node%alt

rc = dm_db_update(db, app%node)

Expand All @@ -336,6 +336,9 @@ integer function db_update(db, app) result(rc)
if (.not. app%mask(ATTR_X)) app%sensor%x = old_sensor%x
if (.not. app%mask(ATTR_Y)) app%sensor%y = old_sensor%y
if (.not. app%mask(ATTR_Z)) app%sensor%z = old_sensor%z
if (.not. app%mask(ATTR_LON)) app%sensor%lon = old_sensor%lon
if (.not. app%mask(ATTR_LAT)) app%sensor%lat = old_sensor%lat
if (.not. app%mask(ATTR_ALT)) app%sensor%alt = old_sensor%alt

if (len_trim(app%sensor%node_id) == 0) then
rc = E_INVALID
Expand Down Expand Up @@ -371,6 +374,9 @@ integer function db_update(db, app) result(rc)
if (.not. app%mask(ATTR_X)) app%target%x = old_target%x
if (.not. app%mask(ATTR_Y)) app%target%y = old_target%y
if (.not. app%mask(ATTR_Z)) app%target%z = old_target%z
if (.not. app%mask(ATTR_LON)) app%target%lon = old_target%lon
if (.not. app%mask(ATTR_LAT)) app%target%lat = old_target%lat
if (.not. app%mask(ATTR_ALT)) app%target%alt = old_target%alt

rc = dm_db_update(db, app%target)
end select db_select
Expand Down Expand Up @@ -413,9 +419,9 @@ integer function read_args(app) result(rc)
arg_type('x', short='X', type=ARG_TYPE_REAL), & ! -X, --x <x>
arg_type('y', short='Y', type=ARG_TYPE_REAL), & ! -Y, --y <y>
arg_type('z', short='Z', type=ARG_TYPE_REAL), & ! -Z, --z <z>
arg_type('longitude', short='G', type=ARG_TYPE_REAL), & ! -G, --longitude <lng>
arg_type('latitude', short='L', type=ARG_TYPE_REAL), & ! -L, --latitude <lat>
arg_type('altitude', short='A', type=ARG_TYPE_REAL), & ! -A, --altitude <alt>
arg_type('lon', short='G', type=ARG_TYPE_REAL), & ! -G, --lon <lng>
arg_type('lat', short='L', type=ARG_TYPE_REAL), & ! -L, --lat <lat>
arg_type('alt', short='A', type=ARG_TYPE_REAL), & ! -A, --alt <alt>
arg_type('verbose', short='V', type=ARG_TYPE_LOGICAL) & ! -V, --verbose
]

Expand Down Expand Up @@ -448,14 +454,14 @@ integer function read_args(app) result(rc)
case (TYPE_NODE)
! Get node attributes.
rc = dm_arg_get(args( 6), app%node%id)
rc = dm_arg_get(args( 7), app%node%name, passed=app%mask(ATTR_NAME))
rc = dm_arg_get(args( 8), app%node%meta, passed=app%mask(ATTR_META))
rc = dm_arg_get(args(13), app%node%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%node%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%node%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%node%longitude, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%node%latitude, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%node%altitude, passed=app%mask(ATTR_ALT))
rc = dm_arg_get(args( 7), app%node%name, passed=app%mask(ATTR_NAME))
rc = dm_arg_get(args( 8), app%node%meta, passed=app%mask(ATTR_META))
rc = dm_arg_get(args(13), app%node%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%node%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%node%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%node%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%node%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%node%alt, passed=app%mask(ATTR_ALT))

case (TYPE_SENSOR)
! Get sensor attributes.
Expand All @@ -468,6 +474,9 @@ integer function read_args(app) result(rc)
rc = dm_arg_get(args(13), app%sensor%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%sensor%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%sensor%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%sensor%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%sensor%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%sensor%alt, passed=app%mask(ATTR_ALT))

app%sensor%type = dm_sensor_type_from_name(sensor)

Expand All @@ -480,6 +489,9 @@ integer function read_args(app) result(rc)
rc = dm_arg_get(args(13), app%target%x, passed=app%mask(ATTR_X))
rc = dm_arg_get(args(14), app%target%y, passed=app%mask(ATTR_Y))
rc = dm_arg_get(args(15), app%target%z, passed=app%mask(ATTR_Z))
rc = dm_arg_get(args(16), app%target%lon, passed=app%mask(ATTR_LON))
rc = dm_arg_get(args(17), app%target%lat, passed=app%mask(ATTR_LAT))
rc = dm_arg_get(args(18), app%target%alt, passed=app%mask(ATTR_ALT))

case default
rc = E_INVALID
Expand Down Expand Up @@ -515,17 +527,19 @@ integer function read_args(app) result(rc)
.not. app%mask(ATTR_X) .and. .not. app%mask(ATTR_Y) .and. &
.not. app%mask(ATTR_Z) .and. .not. app%mask(ATTR_LON) .and. &
.not. app%mask(ATTR_LAT) .and. .not. app%mask(ATTR_ALT)) then
call dm_error_out(rc, 'command-line option --name, --meta, -x, -y, -z, ' // &
'--longitude, --latitude, or --altitude required')
call dm_error_out(rc, 'command-line option --name, --meta, --x, --y, --z, ' // &
'--lon, --lat, or --alt required')
return
end if

case (TYPE_TARGET)
if (.not. app%mask(ATTR_NAME) .and. .not. app%mask(ATTR_META) .and. &
.not. app%mask(ATTR_STATE) .and. .not. app%mask(ATTR_X) .and. &
.not. app%mask(ATTR_Y) .and. .not. app%mask(ATTR_Z)) then
call dm_error_out(rc, 'command-line option --name, --meta, --state, -x, -y, -z, ' // &
'--longitude, --latitude, or --altitude required')
.not. app%mask(ATTR_Y) .and. .not. app%mask(ATTR_Z) .and. &
.not. app%mask(ATTR_LON) .and. .not. app%mask(ATTR_LAT) .and. &
.not. app%mask(ATTR_ALT)) then
call dm_error_out(rc, 'command-line option --name, --meta, --state, --x, --y, --z, ' // &
'--lon, --lat, or --alt required')
return
end if

Expand All @@ -537,12 +551,13 @@ integer function read_args(app) result(rc)

if (.not. any(app%mask)) then
call dm_error_out(rc, 'command-line option --node, --type, --name, --sn, ' // &
'--meta, --easting, --northing, or --altitude required')
'--meta, --x, --y, --z, --lon, --lat, or --alt required')
return
end if
end select
end select

! Validation passed.
rc = E_NONE
end function read_args
end program dmdbctl
76 changes: 53 additions & 23 deletions app/dmweb.f90
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ subroutine route_map(env)
character(len=*), parameter :: JS_DMPACK = APP_JS_PATH // '/dmpack.js' !! DMPACK JS.
character(len=*), parameter :: JS_LEAFLET = APP_JS_PATH // '/leaflet.js' !! Leaflet JS.
character(len=*), parameter :: STYLE = APP_CSS_PATH // '/leaflet.min.css' !! Additional CSS file.
character(len=*), parameter :: INLINE = '#map { height: 600px; }' !! Inline CSS.
character(len=*), parameter :: INLINE = '#map { height: 600px; }' // CR_LF !! Inline CSS.
character(len=*), parameter :: MAP_ID = 'map' !! HTML element id of map.
character(len=*), parameter :: TITLE = 'Map' !! Page title.

Expand All @@ -734,7 +734,7 @@ subroutine route_map(env)
! GET REQUEST.
! ------------------------------------------------------------------
if (len_trim(tile_url) == 0) then
call html_error('No tile map URL provided.', error=E_NOT_FOUND)
call html_error('No tile map URL provided in environment variable DM_TILE_URL.', error=E_EMPTY)
return
end if

Expand All @@ -754,17 +754,19 @@ subroutine route_map(env)
lon = 0.0_r8
lat = 0.0_r8

! Select view point.
if (size(nodes) > 0) then
lon = nodes(1)%longitude
lat = nodes(1)%latitude
lon = nodes(1)%lon
lat = nodes(1)%lat
else if (size(sensors) > 0) then
lon = sensors(1)%x
lat = sensors(1)%y
lon = sensors(1)%lon
lat = sensors(1)%lat
else if (size(targets) > 0) then
lon = targets(1)%x
lat = targets(1)%y
lon = targets(1)%lon
lat = targets(1)%lat
end if

! Use default coordinates for view point.
if (dm_equals(lon, 0.0_r8) .and. dm_equals(lat, 0.0_r8)) then
lon = APP_MAP_LON
lat = APP_MAP_LAT
Expand Down Expand Up @@ -931,13 +933,13 @@ subroutine route_nodes(env)
end if

! Optional parameters.
rc = dm_cgi_get(param, 'meta', node%meta)
rc = dm_cgi_get(param, 'x', node%x)
rc = dm_cgi_get(param, 'y', node%y)
rc = dm_cgi_get(param, 'z', node%z)
rc = dm_cgi_get(param, 'longitude', node%longitude)
rc = dm_cgi_get(param, 'latitude', node%latitude)
rc = dm_cgi_get(param, 'altitude', node%altitude)
rc = dm_cgi_get(param, 'meta', node%meta)
rc = dm_cgi_get(param, 'x', node%x)
rc = dm_cgi_get(param, 'y', node%y)
rc = dm_cgi_get(param, 'z', node%z)
rc = dm_cgi_get(param, 'lon', node%lon)
rc = dm_cgi_get(param, 'lat', node%lat)
rc = dm_cgi_get(param, 'alt', node%alt)

! Validate node data.
if (.not. dm_node_valid(node)) then
Expand Down Expand Up @@ -1508,6 +1510,9 @@ subroutine route_sensors(env)
rc = dm_cgi_get(param, 'x', sensor%x)
rc = dm_cgi_get(param, 'y', sensor%y)
rc = dm_cgi_get(param, 'z', sensor%z)
rc = dm_cgi_get(param, 'lon', sensor%lon)
rc = dm_cgi_get(param, 'lat', sensor%lat)
rc = dm_cgi_get(param, 'alt', sensor%alt)

! Validate sensor data.
if (.not. dm_sensor_valid(sensor)) then
Expand Down Expand Up @@ -1818,6 +1823,9 @@ subroutine route_targets(env)
rc = dm_cgi_get(param, 'x', target%x)
rc = dm_cgi_get(param, 'y', target%y)
rc = dm_cgi_get(param, 'z', target%z)
rc = dm_cgi_get(param, 'lon', target%lon)
rc = dm_cgi_get(param, 'lat', target%lat)
rc = dm_cgi_get(param, 'alt', target%alt)

! Validate target data.
if (.not. dm_target_valid(target)) then
Expand Down Expand Up @@ -2029,14 +2037,14 @@ function html_form_nodes(disabled) result(html)
pattern='[\+\-\.0-9]+', placeholder='Enter Z or elevation (optional)') // &
H_DIV_END // & ! end column 2
H_DIV_COL // & ! column 3
dm_html_label('Longitude', for='longitude') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='longitude', name='longitude', &
dm_html_label('Longitude', for='lon') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lon', name='lon', &
pattern='[\+\-\.0-9]+', placeholder='Enter longitude (optional)') // &
dm_html_label('Latitude', for='latitude') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='latitude', name='latitude', &
dm_html_label('Latitude', for='lat') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lat', name='lat', &
pattern='[\+\-\.0-9]+', placeholder='Enter latitude (optional)') // &
dm_html_label('Altitude', for='altitude') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='altitude', name='altitude', &
dm_html_label('Altitude', for='alt') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='alt', name='alt', &
pattern='[\+\-\.0-9]+', placeholder='Enter altitude (optional)') // &
H_DIV_END // & ! end column 3
H_DIV_END // & ! end row 1
Expand Down Expand Up @@ -2321,8 +2329,19 @@ function html_form_sensors(nodes, disabled) result(html)
pattern='[\+\-\.0-9]+', placeholder='Enter Y or northing (optional)') // &
dm_html_label('Z', for='z') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='z', name='z', &
pattern='[\+\-\.0-9]+', placeholder='Enter Z or altitude (optional)') // &
pattern='[\+\-\.0-9]+', placeholder='Enter Z or alt (optional)') // &
H_DIV_END // & ! end column 3
H_DIV_COL // & ! column 4
dm_html_label('Longitude', for='lon') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lon', name='lon', &
pattern='[\+\-\.0-9]+', placeholder='Enter longitude (optional)') // &
dm_html_label('Latitude', for='lat') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lat', name='lat', &
pattern='[\+\-\.0-9]+', placeholder='Enter latitude (optional)') // &
dm_html_label('Altitude', for='alt') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='alt', name='alt', &
pattern='[\+\-\.0-9]+', placeholder='Enter altitude (optional)') // &
H_DIV_END // & ! end column 4
H_DIV_END // & ! end row 1
dm_html_input(HTML_INPUT_TYPE_SUBMIT, disabled=disabled_, name='submit', value='Submit') // &
H_FIELDSET_END // H_FORM_END // H_DETAILS_END
Expand Down Expand Up @@ -2378,8 +2397,19 @@ function html_form_targets(disabled) result(html)
pattern='[\+\-\.0-9]+', placeholder='Enter Y or northing (optional)') // &
dm_html_label('Z', for='z') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='z', name='z', &
pattern='[\+\-\.0-9]+', placeholder='Enter Z or altitude (optional)') // &
pattern='[\+\-\.0-9]+', placeholder='Enter Z or alt (optional)') // &
H_DIV_END // & ! end column 2
H_DIV_COL // & ! column 3
dm_html_label('Longitude', for='lon') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lon', name='lon', &
pattern='[\+\-\.0-9]+', placeholder='Enter longitude (optional)') // &
dm_html_label('Latitude', for='lat') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='lat', name='lat', &
pattern='[\+\-\.0-9]+', placeholder='Enter latitude (optional)') // &
dm_html_label('Altitude', for='alt') // &
dm_html_input(HTML_INPUT_TYPE_TEXT, disabled=disabled_, id='alt', name='alt', &
pattern='[\+\-\.0-9]+', placeholder='Enter altitude (optional)') // &
H_DIV_END // & ! end column 3
H_DIV_END // & ! end row 1
dm_html_input(HTML_INPUT_TYPE_SUBMIT, disabled=disabled_, name='submit', value='Submit') // &
H_FIELDSET_END // H_FORM_END // H_DETAILS_END
Expand Down
Loading

0 comments on commit 7038ad3

Please sign in to comment.