cis_config
Public Attributes | List of all members
psiAsciiTableOutput_t Struct Reference

Structure for handling output to an ASCII table. More...

#include <PsiInterface.h>

Public Attributes

int _valid
 Success or failure of initializing the structure.
 
const char * _name
 Path to local table or name of message queue.
 
int _type
 0 if _name is a local table, 1 if it is a message queue.
 
asciiTable_t _table
 Associated output handler for local tables.
 
psiOutput_t _psi
 Associated output handler for queues.
 

Detailed Description

Structure for handling output to an ASCII table.

Table IO

Handle I/O from/to a local or remote ASCII table either line-by-line or as an array.

Row-by-Row

Input by Row Usage:

  1. One-time: Create file interface by providing either a channel name or a path to a local file. psiAsciiTableInput_t fin = psiAsciiTableInput("file_channel", 1); // channel psiAsciiTableInput_t fin = psiAsciiTableInput("/local/file.txt", 0); // local table
  2. Prepare: Allocate space for variables in row (the format in this example is "%5s %d %f\n" like the output example below). char a[5]; int b; double c;
  3. Receive each row, terminating when receive returns -1 (EOF or channel closed). int ret = 1; while (ret > 0) { ret = at_recv_row(fin, &a, &b, &c); Do something with the row }
  4. Cleanup. Call functions to deallocate structures and close files. cleanup_pati(&fin);

Output by Row Usage:

  1. One-time: Create file interface by providing either a channel name or a path to a local file and a format string for rows. psiAsciiTableOutput_t fout = psiAsciiTableOutput("file_channel", // channel "%5s %d %f\n", 1); psiAsciiTableOutput_t fout = psiAsciiTableOutput("/local/file.txt", // local table "%5s %d %f\n", 0);
  2. Send rows to the file by providing entries. Formatting is handled by the interface. If return value is not 0, the send was not succesful. int ret; ret = at_send_row(fout, "one", 1, 1.0); ret = at_send_row(fout, "two", 2, 2.0);
  3. Send EOF message when done to close the file. ret = at_send_eof(fout);
  4. Cleanup. Call functions to deallocate structures and close files. cleanup_pato(&fout);

Array

Input by Array Usage:

  1. One-time: Create file interface by providing either a channel name or a path to a local file. psiAsciiTableInput_t fin = psiAsciiTableInput("file_channel", 1); // channel psiAsciiTableInput_t fin = psiAsciiTableInput("/local/file.txt", 0); // local table
  2. Prepare: Declare pointers for table columns (they will be allocated by the interface once the number of rows is known). char *aCol; int *bCol; double *cCol;
  3. Receive entire table as columns. Return value will be the number of elements in each column (the number of table rows). Negative values indicate errors. int ret = at_recv_array(fin, &a, &b, &c);
  4. Cleanup. Call functions to deallocate structures and close files. cleanup_pati(&fin);

Output by Array Usage:

  1. One-time: Create file interface by providing either a channel name or a path to a local file and a format string for rows. psiAsciiTableOutput_t fout = psiAsciiTableOutput("file_channel", // channel "%5s %d %f\n", 1); psiAsciiTableOutput_t fout = psiAsciiTableOutput("/local/file.txt", // local table "%5s %d %f\n", 0);
  2. Send columns to the file by providing pointers (or arrays). Formatting is handled by the interface. If return value is not 0, the send was not succesful. char aCol[] = {"one ", "two ", "three"}; \ Each str is of len 5 int bCol[3] = {1, 2, 3}; float cCol[3] = {1.0, 2.0, 3.0}; int ret = at_send_array(fout, a, b, c);
  3. Cleanup. Call functions to deallocate structures and close files. cleanup_pato(&fout);

The documentation for this struct was generated from the following file: