Table of contents
CSPICE_EKGC returns an element of string (character) data from a
specified row in a specified column of the set of rows matching
the previous cspice_ekfind SELECT query.
Given:
selidx the scalar integer index for a column of interest satisfying the
SELECT clause, the column indices range from 0 to N-1 where N
equals the total number of columns satisfying the SELECT clause.
help, selidx
LONG = Scalar
row the scalar integer index for a row in the column identified by
'selidx', the column indices range from 0 to M-1 where M equals
the total number of rows satisfying the SELECT clause.
help, row
LONG = Scalar
elment the scalar integer index for a element of the data at the
'selidx','row' position; a scalar value at 'selidx','row' has
'elment' value zero.
help, elment
LONG = Scalar
cdatln the scalar integer defining the maximum length of the 'cdata'
output string.
help, cdatln
LONG = Scalar
the call:
cspice_ekgc, selidx, row, elment, cdatln, cdata, null, found
returns:
cdata the string value of the requested element at data location
'selidx', 'row', 'elment'.
help, cdata
STRING = Scalar
null a scalar boolean indicating if the 'idata' has a null value.
help, null
BOOLEAN = Scalar
found a scalar boolean indicating whether the specified value at
'selidx', 'row', 'elment' was found.
help, found
BOOLEAN = Scalar
None.
Any numerical results shown for these examples may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Perform a query on an EK file that contains a database with
the Supplementary Engineering Data Records of the Viking
Project in order to retrieve the IMAGE_ID values (character
strings) that correspond to the images with IMAGE_NUMBER
smaller than a given value, ordered by IMAGE_NUMBER.
Use the EK kernel below to load the information from the
original Supplementary Engineering Data Record (SEDR) data
set generated by the Viking Project.
vo_sedr.bdb
Example code begins here.
PRO ekgc_ex1
;;
;; Local parameters
;;
EKNAME = 'vo_sedr.bdb'
MAXSTR = 1024
;;
;; Open an EK file.
;;
cspice_furnsh, EKNAME
;;
;; The table 'VIKING_SEDR_DATA' has a column 'IMAGE_ID'
;; of scalar strings.
;;
;; Define a set of constraints to perform a query on
;; all loaded EK files (the SELECT clause). In this
;; case select the column 'IMAGE_ID' from table
;; 'VIKING_SEDR_DATA' sorted by 'IMAGE_NUMBER'.
;;
query = 'Select IMAGE_ID from VIKING_SEDR_DATA ' + $
'where IMAGE_NUMBER < 25860000 order by IMAGE_NUMBER'
;;
;; Query the EK system for data rows matching the
;; SELECT constraints.
;;
cspice_ekfind, query, nmrows, error, errmsg
;;
;; Check whether an error occurred while processing the
;; SELECT clause. If so, output the error message.
;;
if ( error ) then begin
print, 'SELECT clause error: ', errmsg
endif else begin
;;
;; Fetch the character data. We know the query returned
;; one column and the column contains only scalar data,
;; so the index of all elements is 0.
;;
selidx = 0
eltidx = 0
;;
;; Loop over each row found matching the query.
;;
for rowno=0, nmrows-1L do begin
print, format='(A,I3,A,$)', 'Row ', rowno, $
': Character data: '
;;
;; Use cspice_ekgc to retrieve the string from
;;
cspice_ekgc, selidx, rowno, eltidx, MAXSTR, $
cdata, isnull, found
if ( isnull ) then begin
print, '<Null>'
endif else begin
print, cdata
endelse
endfor
endelse
;;
;; It's always good form to unload kernels after use,
;; particularly in IDL due to data persistence.
;;
cspice_kclear
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Row 0: Character data: 168C09
Row 1: Character data: 168C10
Row 2: Character data: 168C11
Row 3: Character data: 168C12
Row 4: Character data: 169C01
Row 5: Character data: 169C02
Row 6: Character data: 169C03
Row 7: Character data: 169C04
Row 8: Character data: 169C05
Row 9: Character data: 169C09
Row 10: Character data: 169C11
Row 11: Character data: 169C19
Row 12: Character data: 169C23
Row 13: Character data: 169C25
Row 14: Character data: 169C26
Row 15: Character data: 169C30
Row 16: Character data: 169C32
Row 17: Character data: 169C33
Row 18: Character data: 169C37
Row 19: Character data: 169C39
Row 20: Character data: 169C40
Row 21: Character data: 169C44
Row 22: Character data: 169C46
Row 23: Character data: 169C47
Row 24: Character data: 169C51
Row 25: Character data: 169C53
2) This example demonstrates how to fetch string values from a
column in three different cases: single values, variable-size
arrays and static-size arrays.
Create an EK that contains a table TAB that has the following
columns:
Column name Data Type Size
----------- --------- ----
CHR_COL_1 CHR 1
CHR_COL_2 CHR VARIABLE
CHR_COL_3 CHR 3
Issue the following query
query = 'SELECT CHR_COL_1, CHR_COL_2, CHR_COL_3 FROM TAB'
to fetch and dump column values from the rows that satisfy the
query.
Example code begins here.
PRO ekgc_ex2
;;
;; Local parameters
;;
EKNAME = 'ekgc_ex2.bdb'
TABLE = 'TAB'
CHRSLN = 4
COL3SZ = 3
MXC2SZ = 8
MAXSTR = 1024
NCOLS = 3
NROWS = 4
STRSIZ = 31
SPICEFALSE = 0B
;;
;; Local variables
;;
cnames = strarr( NCOLS )
cdecls = strarr( NCOLS )
col2 = strarr( MXC2SZ )
col3 = strarr( COL3SZ )
cvals = strarr( MXC2SZ )
;;
;; Open a new EK file. For simplicity, we will not
;; reserve any space for the comment area, so the
;; number of reserved comment characters is zero.
;; The variable `ifname' is the internal file name.
;;
nresvc = 0
ifname = 'Test EK/Created 13-JUN-2019'
cspice_ekopn, EKNAME, ifname, nresvc, handle
;;
;; Set up the column names and declarations
;; for the TAB segment. We'll index all of
;; the columns.
;;
cnames[0] = 'CHR_COL_1'
cdecls[0] = 'DATATYPE = CHARACTER*(*), INDEXED = TRUE'
cnames[1] = 'CHR_COL_2'
cdecls[1] = 'DATATYPE = CHARACTER*(3), SIZE = VARIABLE'
cnames[2] = 'CHR_COL_3'
cdecls[2] = 'DATATYPE = CHARACTER*(3), SIZE = 3'
;;
;; Start the segment.
;;
cspice_ekbseg, handle, TABLE, NCOLS, cnames, cdecls, segno
;;
;; At the records to the table.
;;
for i=1, NROWS do begin
;;
;; Append a new record to the EK.
;;
cspice_ekappr, handle, segno, recno
;;
;; Add CHR_COL_1
;;
col1 = [ STRING( format='(%"Column #2 has %1d elements.")', $
i*2 ) ]
cspice_ekacec, handle, segno, recno, cnames[0], $
1, STRSIZ, col1, SPICEFALSE
;;
;; Add i*2 items to CHR_COL_2
;;
for j=0, i*2 - 1L do begin
col2[j] = STRING( format='(%"%d")', j+1 + i*100 )
endfor
cspice_ekacec, handle, segno, recno, cnames[1], $
i*2, CHRSLN, col2, SPICEFALSE
;;
;; Add 3 items to CHR_COL_3
;;
for j=0, 2 do begin
col3[j]= STRING( format='(%"%d")', i + (j+1)*100 )
endfor
cspice_ekacec, handle, segno, recno, cnames[2], $
3, CHRSLN, col3, SPICEFALSE
endfor
;;
;; Close the file.
;;
cspice_ekcls, handle
;;
;; Open the created file. Perform the query and show the
;; results.
;;
cspice_furnsh, EKNAME
query = 'SELECT CHR_COL_1, CHR_COL_2, CHR_COL_3 FROM TAB'
;;
;; Query the EK system for data rows matching the
;; SELECT constraints.
;;
cspice_ekfind, query, nmrows, error, errmsg
;;
;; Check whether an error occurred while processing the
;; SELECT clause. If so, output the error message.
;;
if ( error ) then begin
print, 'SELECT clause error: ', errmsg
endif else begin
for row=0, nmrows-1L do begin
print, ' '
print, format='(A,I3)', 'ROW = ', row
;;
;; Fetch values from column `chr_col_1'. Since
;; `chr_col_1' was the first column selected, the
;; selection index `selidx' is set to 0.
;;
selidx = 0
eltidx = 0
cspice_ekgc, selidx, row, eltidx, STRSIZ, cval, isnull, found
cvals[0] = cval
print, format='(A,$)', ' COLUMN = CHR_COL_1: '
if ( isnull ) then begin
print, '<Null>'
endif else begin
print, cvals[0]
endelse
;;
;; Fetch values from column `chr_col_2' in the current
;; row. Since `chr_col_2' contains variable-size array
;; elements, we call cspice_eknelt to determine how many
;; elements to fetch.
;;
selidx = 1
nelt = cspice_eknelt( selidx, row )
eltidx = 0
isnull = SPICEFALSE
while ( ( eltidx lt nelt ) && ( ~isnull ) ) do begin
cspice_ekgc, selidx, row, eltidx, STRSIZ, $
cval, isnull, found
cvals[eltidx] = cval
eltidx = eltidx + 1
;;
;; If the column entry is null, we'll be kicked
;; out of this loop after the first iteration.
;;
endwhile
print, format='(A,$)', ' COLUMN = CHR_COL_2: '
if ( isnull ) then begin
print, '<Null>'
endif else begin
print, cvals[0:nelt-1]
endelse
;;
;; Fetch values from column `chr_col_3' in the current
;; row. We need not call cspice_eknelt since we know how
;; many elements are in each column entry.
;;
selidx = 2
eltidx = 0
isnull = SPICEFALSE
while ( ( eltidx lt COL3SZ ) && ( ~isnull ) ) do begin
cspice_ekgc, selidx, row, eltidx, STRSIZ, $
cval, isnull, found
cvals[eltidx] = cval
eltidx = eltidx + 1
endwhile
print, format='(A,$)', ' COLUMN = CHR_COL_3: '
if ( isnull ) then begin
print, '<Null>'
endif else begin
print, cvals[0:2]
endelse
endfor
;;
;; We either parsed the SELECT clause or had an error.
;;
endelse
;;
;; It's always good form to unload kernels after use,
;; particularly in IDL due to data persistence.
;;
cspice_kclear
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
ROW = 0
COLUMN = CHR_COL_1: Column #2 has 2 elements.
COLUMN = CHR_COL_2: 101 102
COLUMN = CHR_COL_3: 101 201 301
ROW = 1
COLUMN = CHR_COL_1: Column #2 has 4 elements.
COLUMN = CHR_COL_2: 201 202 203 204
COLUMN = CHR_COL_3: 102 202 302
ROW = 2
COLUMN = CHR_COL_1: Column #2 has 6 elements.
COLUMN = CHR_COL_2: 301 302 303 304 305 306
COLUMN = CHR_COL_3: 103 203 303
ROW = 3
COLUMN = CHR_COL_1: Column #2 has 8 elements.
COLUMN = CHR_COL_2: 401 402 403 404 405 406 407 408
COLUMN = CHR_COL_3: 104 204 304
Note that after run completion, a new EK file exists in the
output directory.
3) Query the EK system and fetch data matching that query.
The program shown here does not rely on advance
knowledge of the input query or the contents of any loaded EK
files.
To simplify the example, we assume that all data are scalar.
This assumption relieves us of the need to test the size of
column entries before fetching them. In the event that a
column contains variable-size array entries, the entry point
cspice_eknelt may be called to obtain the size of column entries to
be fetched. See cspice_eknelt for an example.
Use the EK kernel below to load the information from the
original Supplementary Engineering Data Record (SEDR) data
set generated by the Viking Project.
vo_sedr.bdb
Use the LSK kernel below to load the leap seconds and time
constants required for the conversions.
naif0012.tls
Example code begins here.
PRO ekgc_ex3
;;
;; Local parameters
;;
EKNAME = 'vo_sedr.bdb'
LSKNAM = 'naif0012.tls'
MAXSTR = 1024
;;
;; Define the types of expression that may appear
;; in the SELECT clause of EK queries.
;;
SPICE_EK_EXP_COL = 0
SPICE_EK_EXP_FUNC = 1
SPICE_EK_EXP_EXPR = 2
;;
;; Define the types of EK columns.
;;
SPICE_CHR = 0
SPICE_DP = 1
SPICE_INT = 2
SPICE_TIME = 3
;;
;; Load leapseconds file for time conversion.
;;
cspice_furnsh, LSKNAM
;;
;; Load EK.
;;
cspice_eklef, EKNAME, handle
;;
;; Setup the query. Parse the SELECT clause using
;; cspice_ekpsel.
;;
query = 'Select IMAGE_NUMBER, IMAGE_ID, ' + $
'PLATFORM_CLOCK, IMAGE_TIME ' + $
'from VIKING_SEDR_DATA where IMAGE_NUMBER < 25850000 ' + $
'order by IMAGE_NUMBER'
cspice_ekpsel, query, n, xbegs, xends, xtypes, $
xclass, tabs, cols, error, errmsg
if ( error ) then begin
print, errmsg
endif else begin
;;
;; Submit query to the EK query system.
;;
cspice_ekfind, query, nmrows, error, errmsg
if ( error ) then begin
print, errmsg
endif else begin
;;
;; Fetch the rows that matched the query.
;;
for row=0, nmrows-1L do begin
;;
;; Fetch data from the ith row.
;;
print, ' '
print, 'ROW = ', row
for colno=0, n-1L do begin
;;
;; Fetch the data from the jth selected
;; column.
;;
if ( xclass[colno] eq SPICE_EK_EXP_COL ) then begin
outstr = tabs[colno] + '.' + cols[colno]
print, format='(A-33,A,$)', ' ' + outstr, ': '
endif else begin
b = xbegs[colno]
e = xends[colno]
print, format='(2A,$)', 'ITEM = ', query(b:e)
endelse
if ( xtypes[colno] eq SPICE_CHR ) then begin
cspice_ekgc, colno, row, 0, MAXSTR, cdata, null, found
if ( null ) then begin
print, '<Null>'
endif else begin
print, cdata
endelse
endif else if ( xtypes[colno] eq SPICE_DP ) then begin
cspice_ekgd, colno, row, 0, ddata, null, found
if ( null ) then begin
print, '<Null>'
endif else begin
print, ddata
endelse
endif else if ( xtypes[colno] eq SPICE_INT ) then begin
cspice_ekgi, colno, row, 0, idata, null, found
if ( null ) then begin
print, '<Null>'
endif else begin
print, idata
endelse
endif else begin
;;
;; The item is a time value. Convert it
;; to UTC for output.
;;
cspice_ekgd, colno, row, 1, tdata, null, found
if ( null ) then begin
print, '<Null>'
endif else begin
cspice_et2utc, tdata, 'C', 3, utcstr
print, utcstr
endelse
endelse
;;
;; We're done with the column having index `colno'.
;;
endfor
;;
;; We're done with the row having index `row'.
;;
endfor
;;
;; We either processed the query or had an error.
;;
endelse
;;
;; We either parsed the SELECT clause or had an error.
;;
endelse
;;
;; It's always good form to unload kernels after use,
;; particularly in IDL due to data persistence.
;;
cspice_kclear
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
ROW = 0
VIKING_SEDR_DATA.IMAGE_NUMBER : 25837050
VIKING_SEDR_DATA.IMAGE_ID : 168C09
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.88000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 16 16:50:55.925
ROW = 1
VIKING_SEDR_DATA.IMAGE_NUMBER : 25837051
VIKING_SEDR_DATA.IMAGE_ID : 168C10
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.27000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 16 16:51:00.269
ROW = 2
VIKING_SEDR_DATA.IMAGE_NUMBER : 25840344
VIKING_SEDR_DATA.IMAGE_ID : 168C11
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.88000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 16 20:56:53.051
ROW = 3
VIKING_SEDR_DATA.IMAGE_NUMBER : 25840345
VIKING_SEDR_DATA.IMAGE_ID : 168C12
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.27000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 16 20:56:57.395
ROW = 4
VIKING_SEDR_DATA.IMAGE_NUMBER : 25843638
VIKING_SEDR_DATA.IMAGE_ID : 169C01
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.88000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 01:02:50.177
ROW = 5
VIKING_SEDR_DATA.IMAGE_NUMBER : 25843639
VIKING_SEDR_DATA.IMAGE_ID : 169C02
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.27000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 01:02:54.521
ROW = 6
VIKING_SEDR_DATA.IMAGE_NUMBER : 25846934
VIKING_SEDR_DATA.IMAGE_ID : 169C03
VIKING_SEDR_DATA.PLATFORM_CLOCK: 120.14000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 05:08:56.263
ROW = 7
VIKING_SEDR_DATA.IMAGE_NUMBER : 25846935
VIKING_SEDR_DATA.IMAGE_ID : 169C04
VIKING_SEDR_DATA.PLATFORM_CLOCK: 119.52000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 05:09:00.607
ROW = 8
VIKING_SEDR_DATA.IMAGE_NUMBER : 25848026
VIKING_SEDR_DATA.IMAGE_ID : 169C05
VIKING_SEDR_DATA.PLATFORM_CLOCK: 120.14000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 06:30:28.424
ROW = 9
VIKING_SEDR_DATA.IMAGE_NUMBER : 25848030
VIKING_SEDR_DATA.IMAGE_ID : 169C09
VIKING_SEDR_DATA.PLATFORM_CLOCK: 120.14000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 06:30:46.174
ROW = 10
VIKING_SEDR_DATA.IMAGE_NUMBER : 25848032
VIKING_SEDR_DATA.IMAGE_ID : 169C11
VIKING_SEDR_DATA.PLATFORM_CLOCK: 120.14000
VIKING_SEDR_DATA.IMAGE_TIME : 1976 JUN 17 06:30:55.168
This routine allows retrieval of data from character columns.
This routine returns one element at a time in order to save the
caller from imposing a limit on the size of the column entries
that can be handled.
If a SELECT clause returns data consisting of three
columns (N=3) and four rows (M=4),
col 0 col 1 col 2
row 0 val_00 val_01 val_02
row 1 val_10 val_11 val_12
row 2 val_20 val_21 val_22
row 3 val_30 val_31 val_32
with "col 1" and "col 2" containing scalar string data
and the "val_31" a vector of K strings, the data position
relates to the data:
fetch scalar "val_21"
'selidx' = 1, 'row' = 2, 'elment' = 0
fetch scalar "val_32"
'selidx' = 2, 'row' = 3, 'elment' = 0
fetch the final element of vector "val_31"
'selidx' = 1, 'row' = 3, 'elment' = K-1
'elment' is allowed to exceed the number of elements in
the column entry; if it does, 'found' returns
as SPICEFALSE. This allows the caller to read data
from the column entry in a loop without checking the
number of available elements first.
1) If the input argument `elment' is less than 0, the error
SPICE(INVALIDINDEX) is signaled by a routine in the call tree
of this routine and `found' is returned False. However, `elment'
is allowed to be greater than the number of elements in the
specified column entry; this allows the caller to read data
from the column entry in a loop without checking the number of
available elements first. If `elment' is greater than the number
of available elements, `found' is returned False.
2) If `selidx' is outside of the range established by the last query
passed to the EK search engine, the error SPICE(INVALIDINDEX) is
signaled by a routine in the call tree of this routine and `found'
is returned False.
3) If `row' is outside of the range established by the last query
passed to the EK search engine, the error SPICE(INVALIDINDEX) is
signaled by a routine in the call tree of this routine and `found'
is returned False.
4) If the specified column does not have character type, the
error SPICE(INVALIDTYPE) is signaled by a routine in the call
tree of this routine.
5) If this routine is called when no E-kernels have been loaded,
the error SPICE(NOLOADEDFILES) is signaled by a routine in the
call tree of this routine.
6) If any of the input arguments, `selidx', `row', `elment' or
`cdatln', is undefined, an error is signaled by the IDL error
handling system.
7) If any of the input arguments, `selidx', `row', `elment' or
`cdatln', is not of the expected type, or it does not have the
expected dimensions and size, an error is signaled by the Icy
interface.
8) If any of the output arguments, `cdata', `null' or `found', is
not a named variable, an error is signaled by the Icy
interface.
This routine reads binary "sequence component" EK files.
In order for a binary EK file to be accessible to this routine,
the file must be "loaded" via a call to the routine cspice_eklef.
Text format EK files cannot be used by this routine; they must
first be converted by binary format by the NAIF Toolkit utility
SPACIT.
None.
ICY.REQ
EK.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.1.0, 10-AUG-2021 (JDR)
Changed input argument "lenout" to "cdatln" for consistency with other
routines.
Edited the -Examples section to comply with NAIF standard. Added
complete code examples.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections. Extended
-Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.1, 24-JAN-2010 (EDW)
Corrected errors in the description of the indices behavior
as given in 'elment' argument. That description is now
in the "Particulars" section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
fetch element from character column entry
|