Previous: rdb_map_cols_arst, Up: Mapping /rdb Columns
Create a map between user requested columns and those in an /rdb file. The `stst' signifies that the function is called with [1] a STructure containing column names and type arguments, and [2] expects subsequent reads to go into elements of a STructure.
#include <mst_rdb/mst_rdb.h>DataColumnMap_st *rdb_map_cols_stst( rdbHeader const *hdr, unsigned long ncols, RDBFieldStInfo const fields[] );
rdbHeader const *hdr
- the rdb header
unsigned long ncols
- the number of columns to read
RDBFieldStInfo const fields[]
- an array of RDBFieldStInfo structs containing names of the columns to map, data types (string or numeric), and offsets into the user-supplied target struct for each column to be read
When reading an /rdb file, the user may wish data to be returned in an order different from that in the data file. This routine takes a set of column names and creates a map between it and the names read from an /rdb header. The map is used by other /rdb data input routines.
The RDBFieldStInfo struct is defined in <mst_rdb.h> as follows:
typedef struct
{
char *name;
RDB_Type type;
size_t offset;
} RDBFieldStInfo
There is a macro defined in <mst_rdb.h> to aid in filling up an array of these structures; it is called RDBentry(name, type, structid). Here is an example of how to use it:
typedef struct{ double x; double y; char * string } my_rdb_struct; RDBFieldStInfo fields[]={ RDBentry( x, RDB_Num, my_rdb_struct), RDBentry( y, RDB_Num, my_rdb_struct), RDBentry( string, RDB_String, my_rdb_struct), }; #define NFIELDS ( sizeof(fields) / sizeof(RDBFieldStInfo) ) infile = fopen("my_database.rdb","r"); head = rdb_rd_hdr(infile); map = rdb_map_cols_stst(head, NFIELDS, fields );
a pointer to a dynamically allocated DataColumnMap_st structure (filled in with appropriate values). It prints a message to stderr and exits if a user supplied column is not found in the /rdb hdr. When the user is finished with the data structures allocated here, their memory should be freed with the rdb_free_map() function.
Diab Jerius, Richard J. Edgar