LAL 7.6.1.1-4859cae
StreamVectorSequenceInput.c
Go to the documentation of this file.
1#include <lal/LALStdlib.h>
2#include <lal/AVFactories.h>
3#include <lal/SeqFactories.h>
4#include <lal/StreamInput.h>
5
6/* Define linked-list of pointers to vectors of arbitrary type. */
7typedef union tagVector {
17} Vector;
18typedef struct tagVectorList {
20 struct tagVectorList *next;
22
23static const VectorList empty;
24
25
26#define FREECHARVECTORLIST \
27do { \
28 if ( head.vector.CHV ) { \
29 TRY( LALCHARDestroyVector( stat->statusPtr, \
30 &(head.vector.CHV) ), stat ); \
31 } \
32 here = head.next; \
33 while ( here ) { \
34 VectorList *nextPtr = here->next; \
35 if ( here->vector.CHV ) { \
36 TRY( LALCHARDestroyVector( stat->statusPtr, \
37 &(here->vector.CHV) ), stat ); \
38 } \
39 LALFree( here ); \
40 here = nextPtr; \
41 } \
42} while (0)
43
44
45void
47 CHARVectorSequence **sequence,
48 FILE *stream )
49{
50 VectorList head = empty; /* head of linked list of vectors */
51 VectorList *here; /* pointer to current position in list */
52 CHAR *data; /* pointer to vector data */
53 UINT4 nRows, nCols; /* number and length of lines */
54 CreateVectorSequenceIn in; /* parameters for creating sequence */
55
56 INITSTATUS(stat);
57 ATTATCHSTATUSPTR( stat );
58
59 /* Read the first line. */
60 if ( !feof( stream ) ) {
61 TRY( LALCHARReadVector( stat->statusPtr, &(head.vector.CHV), stream ),
62 stat );
63 }
64 here = &head;
65
66 /* As long as lines remain... */
67 while ( !feof( stream ) ) {
68
69 /* Allocate space for next line. */
70 here->next = (VectorList *)LALCalloc( 1, sizeof(VectorList) );
71 if ( !here->next ) {
74 }
75
76 /* Read in next line. */
77 here = here->next;
78 LALCHARReadVector( stat->statusPtr, &(here->vector.CHV), stream );
79 BEGINFAIL( stat ) {
82 } ENDFAIL( stat );
83 }
84
85 /* Lines have been read. Now determine the maximum line length, and
86 allocate the vector sequence. Ignore lines containing only a
87 single '\0' character. */
88 nRows = nCols = 0;
89 here = &head;
90 while ( here ) {
91 if ( here->vector.CHV->length > 1 ) {
92 nRows++;
93 if ( here->vector.CHV->length > nCols )
94 nCols = here->vector.CHV->length;
95 }
96 here = here->next;
97 }
98 in.length = nRows;
99 in.vectorLength = nCols;
100 LALCHARCreateVectorSequence( stat->statusPtr, sequence, &in );
101 BEGINFAIL( stat ) {
104 } ENDFAIL( stat );
105
106 /* Now assign data to the sequence, padding with zeros as
107 necessary. */
108 here = &head;
109 data = (*sequence)->data;
110 while ( here ) {
111 UINT4 length = here->vector.CHV->length;
112 if ( length > 1 ) {
113 memcpy( data, here->vector.CHV->data, length );
114 if ( nCols - length > 0 )
115 memset( data + length, 0, nCols - length );
116 data += nCols;
117 }
118 here = here->next;
119 }
120
121 /* Free memory and exit. */
123 DETATCHSTATUSPTR( stat );
124 RETURN( stat );
125}
126
127#define TYPECODE I2
128#define TYPE INT2
129#define SIZE 2
130#include "StreamVectorSequenceInput_source.c"
131#undef TYPECODE
132#undef TYPE
133#undef SIZE
134
135#define TYPECODE I4
136#define TYPE INT4
137#define SIZE 4
138#include "StreamVectorSequenceInput_source.c"
139#undef TYPECODE
140#undef TYPE
141#undef SIZE
142
143#define TYPECODE I8
144#define TYPE INT8
145#define SIZE 8
146#include "StreamVectorSequenceInput_source.c"
147#undef TYPECODE
148#undef TYPE
149#undef SIZE
150
151#define TYPECODE U2
152#define TYPE UINT2
153#define SIZE 2
154#include "StreamVectorSequenceInput_source.c"
155#undef TYPECODE
156#undef TYPE
157#undef SIZE
158
159#define TYPECODE U4
160#define TYPE UINT4
161#define SIZE 4
162#include "StreamVectorSequenceInput_source.c"
163#undef TYPECODE
164#undef TYPE
165#undef SIZE
166
167#define TYPECODE U8
168#define TYPE UINT8
169#define SIZE 8
170#include "StreamVectorSequenceInput_source.c"
171#undef TYPECODE
172#undef TYPE
173#undef SIZE
174
175#define TYPECODE S
176#define TYPE REAL4
177#define SIZE 4
178#include "StreamVectorSequenceInput_source.c"
179#undef TYPECODE
180#undef TYPE
181#undef SIZE
182
183#define TYPECODE D
184#define TYPE REAL8
185#define SIZE 8
186#include "StreamVectorSequenceInput_source.c"
187#undef TYPECODE
188#undef TYPE
189#undef SIZE
#define LALCalloc(m, n)
Definition: LALMalloc.h:94
#define ABORT(statusptr, code, mesg)
#define ENDFAIL(statusptr)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define BEGINFAIL(statusptr)
#define STREAMINPUTH_MSGEMEM
Definition: StreamInput.h:95
#define FREECHARVECTORLIST
static const VectorList empty
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
#define STREAMINPUTH_EMEM
Memory allocation error.
Definition: StreamInput.h:82
void LALCHARReadVector(LALStatus *status, CHARVector **vector, FILE *stream)
void LALCHARReadVectorSequence(LALStatus *stat, CHARVectorSequence **sequence, FILE *stream)
void LALCHARCreateVectorSequence(LALStatus *status, CHARVectorSequence **vectorSequence, CreateVectorSequenceIn *vSeqParams)
Vector of type CHAR, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:73
CHAR * data
Pointer to the data array.
Definition: LALDatatypes.h:78
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:77
Sequence of CHAR Vectors, see DATATYPE-VectorSequence types for more details.
Definition: LALDatatypes.h:261
This structure stores the input required for creating a vector sequence.
Definition: SeqFactories.h:104
UINT4 length
The sequence length.
Definition: SeqFactories.h:105
UINT4 vectorLength
The length of each vector in the sequence.
Definition: SeqFactories.h:106
Vector of type INT2, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:91
Vector of type INT4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:109
Vector of type INT8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:127
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
struct tagLALStatus * statusPtr
Pointer to the next node in the list; NULL if this function is not reporting a subroutine error.
Definition: LALDatatypes.h:954
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
Vector of type UINT2, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:100
Vector of type UINT4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:118
Vector of type UINT8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:136
struct tagVectorList * next
INT4Vector * I4V
REAL8Vector * DV
UINT2Vector * U2V
UINT4Vector * U4V
UINT8Vector * U8V
INT2Vector * I2V
REAL4Vector * SV
INT8Vector * I8V
CHARVector * CHV