Next: rdb_map_cols_stst, Previous: Mapping /rdb Columns, Up: Mapping /rdb Columns
Create a map between user requested columns and those in an /rdb file. The `arst' signifies that the function is called with [1] ARrays of 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_arst( rdbHeader const *hdr, unsigned long ncols, char *col[], RDB_Type const type[], size_t const data_offset[] );
rdbHeader const *hdr
- the rdb header
unsigned long ncols
- the number of columns to read
char *col[]
- an array of pointers to strings holding the names of the columns to map
RDB_Type const type[]
- an array of type specifiers; allowed values are RDB_String, RDB_Num (i.e. double)
Possible values for aRDB_Type const
are as follows:RDB_String
,RDB_Num
size_t const data_offset[]
- offsets into struct for data values
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.
a pointer to a dynamically allocated DataColumnMap 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
It is generally cleaner to use rdb_map_cols_stst().
/* mst_rdb: test main program for mst_rdb library 9/18/95 rje */ #include <stdio.h> #include <stddef.h> #include <string.h> #include <tracefct/tracefct.h> #include <mst_rdb/mst_rdb.h> int main(int argc, char* argv[]) { FILE *infile; typedef struct { char *mirror; double x0; double y0; double z0; double rho0; double p; double k; } Tilt; Tilt data; long nlines; rdbHeader *head; DataColumnMap_st *map; char *fields[] = { "x0", "y0", "z0", "mirror", "rho0", "p", "k" }; unsigned long nfields = 7; RDB_Type types[] = { RDB_Num, RDB_Num, RDB_Num, RDB_String, RDB_Num, RDB_Num, RDB_Num }; size_t offsets[7]; tf_init(argv[0],0,-1); infile = fopen("tilt.rdb","r"); offsets[0] = offsetof(Tilt, x0); offsets[1] = offsetof(Tilt, y0); offsets[2] = offsetof(Tilt, z0); offsets[3] = offsetof(Tilt, mirror); offsets[4] = offsetof(Tilt, rho0); offsets[5] = offsetof(Tilt, p); offsets[6] = offsetof(Tilt, k); head = rdb_rd_hdr(infile); map = rdb_map_cols_arst(head,nfields,fields,types,offsets); nlines = rdb_count(infile,head); printf("There are %lu lines in database.\n", (unsigned long) nlines); while(rdb_col_read_st(infile, head, map, &data)) { /* ... */ } rdb_free_hdr(head); fclose(infile); return EXIT_SUCCESS; }