Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
FileIOTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2014 Reinhard Prix
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#include <lal/XLALError.h>
21#include <lal/LALMalloc.h>
22#include <lal/AVFactories.h>
23#include <lal/StreamInput.h>
24#include <lal/LogPrintf.h>
25#include <lal/FileIO.h>
26#include <lal/ConfigFile.h>
27
28// some basic consistency checks of the (XLAL) FileIO and Configfile module
29
30int
31main( int argc, char *argv[] )
32{
33 XLAL_CHECK( argc == 1, XLAL_EINVAL, "No input arguments allowed.\n" );
34 XLAL_CHECK( argv != NULL, XLAL_EINVAL );
35
36 char testFilePath[] = TEST_PKG_DATA_DIR "earth00-40-DE405.dat.gz";
37
38// read gzipped ephemeris file once with XLALCHARReadSequence() and once with XLALFileLoad()
39 CHARSequence *sequence = NULL;
40 char *data = NULL;
41 REAL8 tic;
42 // ----- 1. XLALCHARReadSequence() -----
43 FILE *fp0;
44 tic = XLALGetTimeOfDay();
45 XLAL_CHECK( ( fp0 = fopen( testFilePath, "rb" ) ) != NULL, XLAL_EIO, "Failed to fopen('%s', 'rb')\n", testFilePath );
47 fclose( fp0 );
48 REAL8 time_CHARReadSequence = XLALGetTimeOfDay() - tic;
49
50 // ----- 2. XLALFileLoad() -----
51 tic = XLALGetTimeOfDay();
52 XLAL_CHECK( ( data = XLALFileLoad( testFilePath ) ) != NULL, XLAL_EFUNC );
53 REAL8 time_FileLoad = XLALGetTimeOfDay() - tic;
54
55 // and compare them against each other
56 XLAL_CHECK( strcmp( data, sequence->data ) == 0, XLAL_EFAILED, "Strings read by XLALCHARReadSequence() and XLALFileLoadData() differ!\n" );
57
58 // time XLALCreateTokenList()
59 TokenList *tokens = NULL;
60 tic = XLALGetTimeOfDay();
62 REAL8 time_CreateTokenList = XLALGetTimeOfDay() - tic;
63
64 // time ParseDatafileContent() [ = 'cleanConfig()' + 'XLALCreateTokenList()' ]
65 LALParsedDataFile *content = NULL;
66 tic = XLALGetTimeOfDay();
68 REAL8 time_ParseDataFileContent = XLALGetTimeOfDay() - tic;
69
70 // output results
71 XLALPrintInfo( "'earth00-40-DE405.dat.gz' read and uncompressed by XLALCHARReadSequence() and XLALFileLoadData() is identical!\n" );
72 XLALPrintInfo( "time XLALCHARReadSequence(): %f s\n", time_CHARReadSequence );
73 XLALPrintInfo( "time XLALFileLoad(): %f s\n", time_FileLoad );
74 XLALPrintInfo( "time XLALCreateTokenList(): %f s\n", time_CreateTokenList );
75 XLALPrintInfo( "time XLALParseDataFileContent(): %f s\n", time_ParseDataFileContent );
76
77 // free remaining memory
78 XLALFree( data );
79 XLALDestroyCHARVector( sequence );
80 XLALDestroyTokenList( tokens );
82
84
85 return XLAL_SUCCESS;
86
87} // main()
int main(int argc, char *argv[])
Definition: FileIOTest.c:31
void LALCheckMemoryLeaks(void)
void XLALDestroyTokenList(TokenList *list)
int XLALCreateTokenList(TokenList **list, const CHAR *string, const CHAR *delimiters)
int XLALParseDataFileContent(LALParsedDataFile **cfgdata, const CHAR *string)
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
char * XLALFileLoad(const char *path)
double REAL8
void XLALFree(void *p)
REAL8 XLALGetTimeOfDay(void)
int XLALCHARReadSequence(CHARSequence **sequence, FILE *stream)
void XLALDestroyCHARVector(CHARVector *vector)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK(assertion,...)
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EIO
XLAL_EINVAL
XLAL_EFAILED
float data[BLOCKSIZE]
Definition: hwinject.c:360
CHAR * data