@@ -10,7 +10,7 @@ program dmdbctl
1010 character (len=* ), parameter :: APP_NAME = ' dmdbctl'
1111 integer , parameter :: APP_MAJOR = 0
1212 integer , parameter :: APP_MINOR = 9
13- integer , parameter :: APP_PATCH = 4
13+ integer , parameter :: APP_PATCH = 5
1414
1515 ! Database operations (CRUD).
1616 integer , parameter :: OP_NONE = 0
@@ -386,44 +386,62 @@ end function db_update
386386
387387 integer function read_args (app ) result(rc)
388388 ! ! Reads command-line arguments.
389+ integer , parameter :: OPT_CREATE = 1
390+ integer , parameter :: OPT_READ = 2
391+ integer , parameter :: OPT_UPDATE = 3
392+ integer , parameter :: OPT_DELETE = 4
393+ integer , parameter :: OPT_DATABASE = 5
394+ integer , parameter :: OPT_ID = 6
395+ integer , parameter :: OPT_NAME = 7
396+ integer , parameter :: OPT_META = 8
397+ integer , parameter :: OPT_NODE = 9
398+ integer , parameter :: OPT_SN = 10
399+ integer , parameter :: OPT_TYPE = 11
400+ integer , parameter :: OPT_STATE = 12
401+ integer , parameter :: OPT_X = 13
402+ integer , parameter :: OPT_Y = 14
403+ integer , parameter :: OPT_Z = 15
404+ integer , parameter :: OPT_LON = 16
405+ integer , parameter :: OPT_LAT = 17
406+ integer , parameter :: OPT_ALT = 18
407+ integer , parameter :: OPT_VERBOSE = 19
408+
389409 type (app_type), intent (out ) :: app ! ! App settings.
390410
391411 character (len= SENSOR_TYPE_NAME_LEN) :: sensor ! Sensor type name.
392412 character (len= TYPE_NAME_LEN) :: type ! DMPACK derived type name.
393413
394414 integer :: i, n
395415 logical :: mask(OP_LAST) ! CRUD operation mask.
396- type (arg_type) :: args(19 )
416+ type (arg_type) :: args(OPT_VERBOSE )
397417
398418 ! Required and optional command-line arguments.
399- args = [ &
400- arg_type(' create' , short= ' C' , type= ARG_TYPE_STRING), & ! -C, --create <type>
401- arg_type(' read' , short= ' R' , type= ARG_TYPE_STRING), & ! -R, --read <type>
402- arg_type(' update' , short= ' U' , type= ARG_TYPE_STRING), & ! -U, --update <type>
403- arg_type(' delete' , short= ' D' , type= ARG_TYPE_STRING), & ! -D, --delete <type>
404- arg_type(' database' , short= ' d' , type= ARG_TYPE_DATABASE, required= .true. ), & ! -d, --database <path>
405- arg_type(' id' , short= ' I' , type= ARG_TYPE_ID, required= .true. ), & ! -I, --id <id>
406- arg_type(' name' , short= ' n' , type= ARG_TYPE_STRING, max_len= NODE_NAME_LEN), & ! -n, --name <string>
407- arg_type(' meta' , short= ' M' , type= ARG_TYPE_STRING, max_len= NODE_META_LEN), & ! -M, --meta <string>
408- arg_type(' node' , short= ' N' , type= ARG_TYPE_ID), & ! -N, --node <id>
409- arg_type(' sn' , short= ' Q' , type= ARG_TYPE_STRING, max_len= SENSOR_SN_LEN), & ! -Q, --sn <string>
410- arg_type(' type' , short= ' t' , type= ARG_TYPE_STRING, max_len= SENSOR_TYPE_NAME_LEN), & ! -t, --type <type>
411- arg_type(' state' , short= ' S' , type= ARG_TYPE_INTEGER), & ! -S, --state <state>
412- arg_type(' x' , short= ' X' , type= ARG_TYPE_REAL), & ! -X, --x <x>
413- arg_type(' y' , short= ' Y' , type= ARG_TYPE_REAL), & ! -Y, --y <y>
414- arg_type(' z' , short= ' Z' , type= ARG_TYPE_REAL), & ! -Z, --z <z>
415- arg_type(' lon' , short= ' G' , type= ARG_TYPE_REAL), & ! -G, --lon <lng>
416- arg_type(' lat' , short= ' L' , type= ARG_TYPE_REAL), & ! -L, --lat <lat>
417- arg_type(' alt' , short= ' A' , type= ARG_TYPE_REAL), & ! -A, --alt <alt>
418- arg_type(' verbose' , short= ' V' , type= ARG_TYPE_LOGICAL) & ! -V, --verbose
419- ]
419+ args(OPT_CREATE) = arg_type(' create' , short= ' C' , type= ARG_TYPE_STRING) ! -C, --create <type>
420+ args(OPT_READ) = arg_type(' read' , short= ' R' , type= ARG_TYPE_STRING) ! -R, --read <type>
421+ args(OPT_UPDATE) = arg_type(' update' , short= ' U' , type= ARG_TYPE_STRING) ! -U, --update <type>
422+ args(OPT_DELETE) = arg_type(' delete' , short= ' D' , type= ARG_TYPE_STRING) ! -D, --delete <type>
423+ args(OPT_DATABASE) = arg_type(' database' , short= ' d' , type= ARG_TYPE_DATABASE, required= .true. ) ! -d, --database <path>
424+ args(OPT_ID) = arg_type(' id' , short= ' I' , type= ARG_TYPE_ID, required= .true. ) ! -I, --id <id>
425+ args(OPT_NAME) = arg_type(' name' , short= ' n' , type= ARG_TYPE_STRING, max_len= NODE_NAME_LEN) ! -n, --name <string>
426+ args(OPT_META) = arg_type(' meta' , short= ' M' , type= ARG_TYPE_STRING, max_len= NODE_META_LEN) ! -M, --meta <string>
427+ args(OPT_NODE) = arg_type(' node' , short= ' N' , type= ARG_TYPE_ID) ! -N, --node <id>
428+ args(OPT_SN) = arg_type(' sn' , short= ' Q' , type= ARG_TYPE_STRING, max_len= SENSOR_SN_LEN) ! -Q, --sn <string>
429+ args(OPT_TYPE) = arg_type(' type' , short= ' t' , type= ARG_TYPE_STRING, max_len= SENSOR_TYPE_NAME_LEN) ! -t, --type <type>
430+ args(OPT_STATE) = arg_type(' state' , short= ' S' , type= ARG_TYPE_INTEGER) ! -S, --state <state>
431+ args(OPT_X) = arg_type(' x' , short= ' X' , type= ARG_TYPE_REAL) ! -X, --x <x>
432+ args(OPT_Y) = arg_type(' y' , short= ' Y' , type= ARG_TYPE_REAL) ! -Y, --y <y>
433+ args(OPT_Z) = arg_type(' z' , short= ' Z' , type= ARG_TYPE_REAL) ! -Z, --z <z>
434+ args(OPT_LON) = arg_type(' lon' , short= ' G' , type= ARG_TYPE_REAL) ! -G, --lon <lng>
435+ args(OPT_LAT) = arg_type(' lat' , short= ' L' , type= ARG_TYPE_REAL) ! -L, --lat <lat>
436+ args(OPT_ALT) = arg_type(' alt' , short= ' A' , type= ARG_TYPE_REAL) ! -A, --alt <alt>
437+ args(OPT_VERBOSE) = arg_type(' verbose' , short= ' V' , type= ARG_TYPE_LOGICAL) ! -V, --verbose
420438
421439 ! Read command-line arguments.
422440 rc = dm_arg_read(args, version_callback)
423441 if (dm_is_error(rc)) return
424442
425443 ! CRUD operation.
426- mask = [ (args(i)% passed, i = 1 , OP_LAST ) ]
444+ mask = [ (args(i)% passed, i = OPT_CREATE, OPT_DELETE ) ]
427445 n = count (mask)
428446
429447 rc = E_INVALID
@@ -435,64 +453,63 @@ integer function read_args(app) result(rc)
435453 return
436454 end if
437455
438- ! Get entity type (node, sensor, target).
439- app% operation = sum (merge ([1 , 2 , 3 , 4 ], 0 , mask))
456+ app% operation = sum (merge ([OP_CREATE, OP_READ, OP_UPDATE, OP_DELETE], 0 , mask))
440457 call dm_arg_get(args(app% operation), type)
441458 app% type = dm_type_from_name(type)
442459
443460 ! Get remaining command-line arguments.
444- call dm_arg_get(args(5 ), app% database)
461+ call dm_arg_get(args(OPT_DATABASE ), app% database)
445462
446463 select case (app% type)
447464 case (TYPE_NODE)
448465 ! Get node attributes.
449- call dm_arg_get(args( 6 ), app% node% id)
450- call dm_arg_get(args( 7 ), app% node% name, passed= app% mask(ATTR_NAME))
451- call dm_arg_get(args( 8 ), app% node% meta, passed= app% mask(ATTR_META))
452- call dm_arg_get(args(13 ), app% node% x, passed= app% mask(ATTR_X))
453- call dm_arg_get(args(14 ), app% node% y, passed= app% mask(ATTR_Y))
454- call dm_arg_get(args(15 ), app% node% z, passed= app% mask(ATTR_Z))
455- call dm_arg_get(args(16 ), app% node% lon, passed= app% mask(ATTR_LON))
456- call dm_arg_get(args(17 ), app% node% lat, passed= app% mask(ATTR_LAT))
457- call dm_arg_get(args(18 ), app% node% alt, passed= app% mask(ATTR_ALT))
466+ call dm_arg_get(args(OPT_ID), app% node% id)
467+ call dm_arg_get(args(OPT_NAME ), app% node% name, passed= app% mask(ATTR_NAME))
468+ call dm_arg_get(args(OPT_META ), app% node% meta, passed= app% mask(ATTR_META))
469+ call dm_arg_get(args(OPT_X), app% node% x, passed= app% mask(ATTR_X))
470+ call dm_arg_get(args(OPT_Y), app% node% y, passed= app% mask(ATTR_Y))
471+ call dm_arg_get(args(OPT_Z), app% node% z, passed= app% mask(ATTR_Z))
472+ call dm_arg_get(args(OPT_LON), app% node% lon, passed= app% mask(ATTR_LON))
473+ call dm_arg_get(args(OPT_LAT), app% node% lat, passed= app% mask(ATTR_LAT))
474+ call dm_arg_get(args(OPT_ALT), app% node% alt, passed= app% mask(ATTR_ALT))
458475
459476 case (TYPE_SENSOR)
460477 ! Get sensor attributes.
461- call dm_arg_get(args( 6 ), app% sensor% id)
462- call dm_arg_get(args( 7 ), app% sensor% name, passed= app% mask(ATTR_NAME))
463- call dm_arg_get(args( 8 ), app% sensor% meta, passed= app% mask(ATTR_META))
464- call dm_arg_get(args( 9 ), app% sensor% node_id, passed= app% mask(ATTR_NODE))
465- call dm_arg_get(args(10 ), app% sensor% sn, passed= app% mask(ATTR_SN))
466- call dm_arg_get(args(11 ), sensor, passed= app% mask(ATTR_TYPE), default= SENSOR_TYPE_NAMES(SENSOR_TYPE_NONE))
467- call dm_arg_get(args(13 ), app% sensor% x, passed= app% mask(ATTR_X))
468- call dm_arg_get(args(14 ), app% sensor% y, passed= app% mask(ATTR_Y))
469- call dm_arg_get(args(15 ), app% sensor% z, passed= app% mask(ATTR_Z))
470- call dm_arg_get(args(16 ), app% sensor% lon, passed= app% mask(ATTR_LON))
471- call dm_arg_get(args(17 ), app% sensor% lat, passed= app% mask(ATTR_LAT))
472- call dm_arg_get(args(18 ), app% sensor% alt, passed= app% mask(ATTR_ALT))
478+ call dm_arg_get(args(OPT_ID), app% sensor% id)
479+ call dm_arg_get(args(OPT_NAME ), app% sensor% name, passed= app% mask(ATTR_NAME))
480+ call dm_arg_get(args(OPT_META ), app% sensor% meta, passed= app% mask(ATTR_META))
481+ call dm_arg_get(args(OPT_NODE ), app% sensor% node_id, passed= app% mask(ATTR_NODE))
482+ call dm_arg_get(args(OPT_SN), app% sensor% sn, passed= app% mask(ATTR_SN))
483+ call dm_arg_get(args(OPT_TYPE ), sensor, passed= app% mask(ATTR_TYPE), default= SENSOR_TYPE_NAMES(SENSOR_TYPE_NONE))
484+ call dm_arg_get(args(OPT_X), app% sensor% x, passed= app% mask(ATTR_X))
485+ call dm_arg_get(args(OPT_Y), app% sensor% y, passed= app% mask(ATTR_Y))
486+ call dm_arg_get(args(OPT_Z), app% sensor% z, passed= app% mask(ATTR_Z))
487+ call dm_arg_get(args(OPT_LON), app% sensor% lon, passed= app% mask(ATTR_LON))
488+ call dm_arg_get(args(OPT_LAT), app% sensor% lat, passed= app% mask(ATTR_LAT))
489+ call dm_arg_get(args(OPT_ALT), app% sensor% alt, passed= app% mask(ATTR_ALT))
473490
474491 app% sensor% type = dm_sensor_type_from_name(sensor)
475492
476493 case (TYPE_TARGET)
477494 ! Get target attributes.
478- call dm_arg_get(args( 6 ), app% target % id)
479- call dm_arg_get(args( 7 ), app% target % name, passed= app% mask(ATTR_NAME))
480- call dm_arg_get(args( 8 ), app% target % meta, passed= app% mask(ATTR_META))
481- call dm_arg_get(args(12 ), app% target % state, passed= app% mask(ATTR_STATE))
482- call dm_arg_get(args(13 ), app% target % x, passed= app% mask(ATTR_X))
483- call dm_arg_get(args(14 ), app% target % y, passed= app% mask(ATTR_Y))
484- call dm_arg_get(args(15 ), app% target % z, passed= app% mask(ATTR_Z))
485- call dm_arg_get(args(16 ), app% target % lon, passed= app% mask(ATTR_LON))
486- call dm_arg_get(args(17 ), app% target % lat, passed= app% mask(ATTR_LAT))
487- call dm_arg_get(args(18 ), app% target % alt, passed= app% mask(ATTR_ALT))
495+ call dm_arg_get(args(OPT_ID), app% target % id)
496+ call dm_arg_get(args(OPT_NAME), app% target % name, passed= app% mask(ATTR_NAME))
497+ call dm_arg_get(args(OPT_META), app% target % meta, passed= app% mask(ATTR_META))
498+ call dm_arg_get(args(OPT_STATE ), app% target % state, passed= app% mask(ATTR_STATE))
499+ call dm_arg_get(args(OPT_X), app% target % x, passed= app% mask(ATTR_X))
500+ call dm_arg_get(args(OPT_Y), app% target % y, passed= app% mask(ATTR_Y))
501+ call dm_arg_get(args(OPT_Z), app% target % z, passed= app% mask(ATTR_Z))
502+ call dm_arg_get(args(OPT_LON), app% target % lon, passed= app% mask(ATTR_LON))
503+ call dm_arg_get(args(OPT_LAT), app% target % lat, passed= app% mask(ATTR_LAT))
504+ call dm_arg_get(args(OPT_ALT), app% target % alt, passed= app% mask(ATTR_ALT))
488505
489506 case default
490507 rc = E_INVALID
491508 call dm_error_out(rc, ' invalid data type ' // trim (type) // ' (either node, sensor, or target)' )
492509 return
493510 end select
494511
495- call dm_arg_get(args(19 ), app% verbose)
512+ call dm_arg_get(args(OPT_VERBOSE ), app% verbose)
496513
497514 ! Validate options.
498515 rc = E_INVALID
0 commit comments