78 #define STREAMINPUTTESTC_ENORM 0
79 #define STREAMINPUTTESTC_ESUB 1
80 #define STREAMINPUTTESTC_EARG 2
81 #define STREAMINPUTTESTC_EFILE 3
86 #define STREAMINPUTTESTC_MSGENORM "Normal exit"
87 #define STREAMINPUTTESTC_MSGESUB "Subroutine failed"
88 #define STREAMINPUTTESTC_MSGEARG "Error parsing arguments"
89 #define STREAMINPUTTESTC_MSGEFILE "Could not open file"
95 #include <lal/LALStdio.h>
96 #include <lal/FileIO.h>
97 #include <lal/LALStdlib.h>
98 #include <lal/SeqFactories.h>
99 #include <lal/StreamInput.h>
102 #define INFILE TEST_DATA_DIR "StreamInput.data"
105 #define USAGE "Usage: %s [-o outfile] [-d debuglevel] [-t]\n" \
106 "\t[-v {ch | i2 | i4 | i8 | u2 | u4 | u8 | s | d} infile]\n" \
107 "\t[-s {ch | i2 | i4 | i8 | u2 | u4 | u8 | s | d | c | z} infile]\n"
110 #define VTYPES "ch i2 i4 i8 u2 u4 u8 s d"
111 #define STYPES "ch i2 i4 i8 u2 u4 u8 s d c z"
114 #define ERROR( code, msg, statement ) \
115 if ( lalDebugLevel & LALERROR ) \
117 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
118 " %s %s\n", (code), *argv, __FILE__, \
119 __LINE__, "$Id$", statement ? statement : \
124 #define INFO( statement ) \
125 if ( lalDebugLevel & LALINFO ) \
127 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
128 " %s\n", *argv, __FILE__, __LINE__, \
129 "$Id$", (statement) ); \
133 #define SUB( func, statusptr ) \
134 if ( (func), (statusptr)->statusCode ) \
136 ERROR( STREAMINPUTTESTC_ESUB, STREAMINPUTTESTC_MSGESUB, \
137 "Function call \"" #func "\" failed:" ); \
138 return STREAMINPUTTESTC_ESUB; \
143 #define GETINTFORMAT \
146 UINT4 nTot = values->length*dim; \
149 for ( i = 0; i < nTot; i++ ) { \
150 REAL8 x = (REAL8)( values->data[i] ); \
151 REAL8 y = fabs( x ); \
160 sprintf( format, "%%%ui", (UINT4)( log( max )/log( 10 ) ) + 2 ); \
164 #define GETUINTFORMAT \
167 UINT4 nTot = values->length*dim; \
170 for ( i = 0; i < nTot; i++ ) { \
171 REAL8 x = (REAL8)( values->data[i] ); \
172 REAL8 y = fabs( x ); \
181 sprintf( format, "%%%uu", (UINT4)( log( max )/log( 10 ) ) + 1 ); \
185 #define GETREALFORMAT \
188 UINT4 nTot = values->length*dim; \
190 for ( i = 0; i < nTot; i++ ) \
191 if ( values->data[i] < 0.0 ) \
194 sprintf( format, "%%10.3e" ); \
196 sprintf( format, "%%9.3e" ); \
200 #define GETCOMPLEX8FORMAT \
203 UINT4 nTot = values->length*dim; \
205 for ( i = 0; i < nTot; i++ ) \
206 if ( crealf(values->data[i]) < 0.0 || cimagf(values->data[i]) < 0.0 ) \
209 sprintf( format, "%%10.3e" ); \
211 sprintf( format, "%%9.3e" ); \
215 #define GETCOMPLEX16FORMAT \
218 UINT4 nTot = values->length*dim; \
220 for ( i = 0; i < nTot; i++ ) \
221 if ( creal(values->data[i]) < 0.0 || cimag(values->data[i]) < 0.0 ) \
224 sprintf( format, "%%10.3e" ); \
226 sprintf( format, "%%9.3e" ); \
231 #define PRINTCHARVECTORSEQUENCE \
234 for ( i = 0; i < values->length; i++ ) { \
235 for ( j = 0; j < dim; j++ ) { \
236 int c = (int)( values->data[i*dim+j] ); \
237 if ( isgraph( c ) ) \
240 fputc( (int)(' '), fpOut ); \
242 fputc( (int)('\n'), fpOut ); \
246 #define PRINTVECTORSEQUENCE \
249 for ( i = 0; i < values->length; i++ ) { \
250 fprintf( fpOut, format, values->data[i*dim] ); \
251 for ( j = 1; j < dim; j++ ) { \
252 fprintf( fpOut, " " ); \
253 fprintf( fpOut, format, values->data[i*dim+j] ); \
255 fprintf( fpOut, "\n" ); \
259 #define PRINTCHARSEQUENCE \
262 for ( i = 0; i < values->length; i++ ) \
263 fputc( (int)( values->data[i] ), fpOut ); \
266 #define PRINTSEQUENCE \
269 for ( i = 0; i < values->length; i++ ) { \
270 fprintf( fpOut, format, values->data[i] ); \
271 fprintf( fpOut, "\n" ); \
275 #define PRINTCOMPLEX8SEQUENCE \
278 for ( i = 0; i < values->length; i++ ) { \
279 fprintf( fpOut, format, crealf(values->data[i]) ); \
280 fprintf( fpOut, " " ); \
281 fprintf( fpOut, format, cimagf(values->data[i]) ); \
282 fprintf( fpOut, "\n" ); \
286 #define PRINTCOMPLEX16SEQUENCE \
289 for ( i = 0; i < values->length; i++ ) { \
290 fprintf( fpOut, format, creal(values->data[i]) ); \
291 fprintf( fpOut, " " ); \
292 fprintf( fpOut, format, cimag(values->data[i]) ); \
293 fprintf( fpOut, "\n" ); \
298 main(
int argc,
char **argv)
307 CHAR *outfile = NULL;
308 const CHAR *infile = INFILE;
309 const CHAR *datatype =
"s";
312 clock_t start = 0, stop = 0;
317 while ( arg < argc ) {
319 if ( !strcmp( argv[arg],
"-o" ) ) {
320 if ( argc > arg + 1 ) {
322 outfile = argv[arg++];
330 else if ( !strcmp( argv[arg],
"-d" ) ) {
331 if ( argc > arg + 1 ) {
340 else if ( !strcmp( argv[arg],
"-t" ) ) {
345 else if ( !strcmp( argv[arg],
"-v" ) ) {
346 if ( argc > arg + 2 ) {
348 datatype = argv[arg++];
349 infile = argv[arg++];
358 else if ( !strcmp( argv[arg],
"-s" ) ) {
359 if ( argc > arg + 2 ) {
361 datatype = argv[arg++];
362 infile = argv[arg++];
379 if ( strcmp( infile,
"stdin" ) ) {
380 if ( !( fpIn = fopen( infile,
"r" ) ) ) {
388 if ( strcmp( outfile,
"stdout" ) ) {
389 if ( !( fpOut = fopen( outfile,
"w" ) ) ) {
401 if ( !strcmp( datatype,
"ch" ) ) {
407 PRINTCHARVECTORSEQUENCE;
409 }
else if ( !strcmp( datatype,
"i2" ) ) {
418 }
else if ( !strcmp( datatype,
"i4" ) ) {
427 }
else if ( !strcmp( datatype,
"i8" ) ) {
436 }
else if ( !strcmp( datatype,
"u2" ) ) {
445 }
else if ( !strcmp( datatype,
"u4" ) ) {
454 }
else if ( !strcmp( datatype,
"u8" ) ) {
463 }
else if ( !strcmp( datatype,
"s" ) ) {
472 }
else if ( !strcmp( datatype,
"d" ) ) {
482 ERROR( -1,
"Internal consistency error!", 0 );
489 if ( !strcmp( datatype,
"ch" ) ) {
496 }
else if ( !strcmp( datatype,
"i2" ) ) {
504 }
else if ( !strcmp( datatype,
"i4" ) ) {
512 }
else if ( !strcmp( datatype,
"i8" ) ) {
520 }
else if ( !strcmp( datatype,
"u2" ) ) {
528 }
else if ( !strcmp( datatype,
"u4" ) ) {
536 }
else if ( !strcmp( datatype,
"u8" ) ) {
544 }
else if ( !strcmp( datatype,
"s" ) ) {
552 }
else if ( !strcmp( datatype,
"d" ) ) {
560 }
else if ( !strcmp( datatype,
"c" ) ) {
566 PRINTCOMPLEX8SEQUENCE;
568 }
else if ( !strcmp( datatype,
"z" ) ) {
574 PRINTCOMPLEX16SEQUENCE;
577 ERROR( -1,
"Internal consistency error!", 0 );
583 fprintf( stderr,
"CPU time required to read data: %.2f s\n",
584 (
double)( stop - start )/CLOCKS_PER_SEC );
587 if ( infile && strcmp( infile,
"stdin" ) )
589 if ( outfile && strcmp( outfile,
"stdout" ) )
592 INFO( STREAMINPUTTESTC_MSGENORM );
void LALCheckMemoryLeaks(void)
#define SUB(func, statusptr)
#define ERROR(code, msg, statement)
int main(int argc, char *argv[])
void LALSDestroyVectorSequence(LALStatus *status, REAL4VectorSequence **vectorSequence)
void LALU2DestroyVectorSequence(LALStatus *status, UINT2VectorSequence **vectorSequence)
void LALI4DestroyVectorSequence(LALStatus *status, INT4VectorSequence **vectorSequence)
void LALU4DestroyVectorSequence(LALStatus *status, UINT4VectorSequence **vectorSequence)
void LALDDestroyVectorSequence(LALStatus *status, REAL8VectorSequence **vectorSequence)
void LALU8DestroyVectorSequence(LALStatus *status, UINT8VectorSequence **vectorSequence)
void LALI2DestroyVectorSequence(LALStatus *status, INT2VectorSequence **vectorSequence)
void LALI8DestroyVectorSequence(LALStatus *status, INT8VectorSequence **vectorSequence)
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
int LALPrintError(const char *fmt,...)
void LALZDestroyVector(LALStatus *, COMPLEX16Vector **)
void LALCHARDestroyVector(LALStatus *, CHARVector **)
void LALI4DestroyVector(LALStatus *, INT4Vector **)
void LALCDestroyVector(LALStatus *, COMPLEX8Vector **)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALU2DestroyVector(LALStatus *, UINT2Vector **)
void LALU8DestroyVector(LALStatus *, UINT8Vector **)
void LALU4DestroyVector(LALStatus *, UINT4Vector **)
void LALI8DestroyVector(LALStatus *, INT8Vector **)
void LALI2DestroyVector(LALStatus *, INT2Vector **)
void LALCHARDestroyVectorSequence(LALStatus *status, CHARVectorSequence **vectorSequence)
Vector of type CHAR, see DATATYPE-Vector types for more details.
Sequence of CHAR Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type COMPLEX16, see DATATYPE-Vector types for more details.
Vector of type COMPLEX8, see DATATYPE-Vector types for more details.
Vector of type INT2, see DATATYPE-Vector types for more details.
Sequence of INT2 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type INT4, see DATATYPE-Vector types for more details.
Sequence of INT4 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type INT8, see DATATYPE-Vector types for more details.
Sequence of INT8 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
LAL status structure, see The LALStatus structure for more details.
Vector of type REAL4, see DATATYPE-Vector types for more details.
Sequence of REAL4 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type REAL8, see DATATYPE-Vector types for more details.
Sequence of REAL8 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type UINT2, see DATATYPE-Vector types for more details.
Sequence of UINT2 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type UINT4, see DATATYPE-Vector types for more details.
Sequence of UINT4 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.
Vector of type UINT8, see DATATYPE-Vector types for more details.
Sequence of UINT8 Vectors, see DATATYPE-VectorSequence types for more details.
UINT4 vectorLength
The length n of each vector.