Commit ad66d8ac authored by Karl Wette's avatar Karl Wette

Remove deprecated function LALOpenDataFile()

- replace with either fopen() (in tests) or LALFopen() (everywhere else)
  with mode "rb" (for SFTs) or "r" (everywhere else)
- in XLALFindFiles(), remove prefixing of relative file names with './'
  to avoid LAL_DATA_PATH look-up; this is no longer necessary
- no longer set LAL_DATA_PATH in environment scripts and pkg-config files,
  but do set LAL..._DATADIR in environment scripts to $(pkgdatadir)
- refs #1676
Original: 933fe1e25ccbb8c8549ad939888d45d0552abaed
parent b669edcb
......@@ -32,7 +32,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LAL_DATA_PATH=@datadir@/@PACKAGE@
LAL_OCTAVE_PATH=@octexecdir@
LAL_PYTHON_PATH=@pyexecdir@
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALSUPPORT_DATA_PATH=@datadir@/@PACKAGE@
LALSUPPORT_OCTAVE_PATH=@octexecdir@
LALSUPPORT_PYTHON_PATH=@pyexecdir@
......
......@@ -44,8 +44,6 @@ extern "C" {
*/
/*@{*/
FILE *LALOpenDataFile( const char* );
typedef struct tagLALFILE LALFILE;
LALFILE *lalstdin(void);
......
......@@ -17,51 +17,6 @@
* MA 02111-1307 USA
*/
/**
* \addtogroup FileIO_h
*
* ### Obsolete LAL Prototypes ###
*
* \code
* FILE *LALFopen( const char *path, const char *mode );
* int LALFclose( FILE *stream );
* \endcode
*
* ### Description ###
*
* The routines <tt>LALFopen()</tt> and <tt>LALFclose()</tt> are macro defined to be
* the same as the standard C routines <tt>LALFopen()</tt> and <tt>fclose()</tt>. These
* should only be used in test programs.
*
* The routine <tt>LALOpenDataFile()</tt> is used to open a data file for reading.
* This routine is also to be used in test programs only. Unless the data file
* is specified with an absolute path (beginning with a <tt>/</tt>), or a specific
* path (beginning with a <tt>./</tt> or a <tt>../</tt>), the directory
* that the file is in is obtained from the environment variable
* \c LAL_DATA_PATH, which must be set at run-time. (If the environment
* variable is not set, the default path is <tt>.</tt> --- i.e., the current
* directory.)
*
* \c LAL_DATA_PATH should typically be set to
* <tt>/usr/local/share/lal</tt>, or wherever LAL data is installed in your system
* (which may be different if you used a <tt>--prefix</tt> argument when
* configuring LAL), but when the test suite is run with <tt>make check</tt>, the
* variable \c LAL_DATA_PATH is set to the current source directory. If the
* filename (including the directory path) is too long (more than 256
* characters), <tt>LALOpenDataFile()</tt> returns \c NULL and sets
* \c errno to \c ENAMETOOLONG.
*
* \c LAL_DATA_PATH can be any colon-delimeted list of directories, which
* are searched in order (just like the \c PATH environment variable).
* An extra colon inserts the default data directory
* (\f$\langle\f$prefix\f$\rangle\f$<tt>/share/lal</tt>) into the search path at that
* point. E.g., a leading/trailing colon will look for the default data
* directory at the start/end of the list of directories.
*
* It is strongly recommended that <tt>LALOpenDataFile()</tt> be used when writing test code.
*
*/
#include <config.h>
#include <stdarg.h>
......@@ -109,120 +64,12 @@ LALFILE *lalstderr( void )
return &_lalstderr;
}
#define STR( x ) #x
#define XSTR( x ) STR( x )
#define INFOMSG( msg, file ) ( ( lalDebugLevel & LALINFO ) ? \
LALPrintError( "Info: function LALOpenDataFile, file " __FILE__ ", line " \
XSTR( __LINE__ ) ", $Id$\n\t%s %s\n", msg, file ) : 0 )
#define ERRORMSG( file ) ( ( lalDebugLevel & LALERROR ) ? \
LALPrintError( "Info: function LALOpenDataFile, file " __FILE__ ", line " \
XSTR( __LINE__ ) ", $Id$\n\tCould not open data file %s\n", file ) : 0 )
#ifndef LAL_PREFIX
#define LAL_PREFIX "/usr/local"
#endif
FILE *
LALOpenDataFile( const char *fname )
{
FILE *fp;
const char *path;
char *datapath; /* locally allocated copy of env-var LAL_DATA_PATH */
const char *p0; /* pointer to current sub-path of datapath*/
char *p1; /* pointer to next sub-path */
char fdata[32768];
int n;
XLAL_PRINT_DEPRECATION_WARNING("XLALFileResolvePathLong");
if ( (fname==NULL) || ( strlen(fname)==0) ) {
return NULL;
}
if ( *fname == '/' ) /* absolute path is given */
{
fp = LALFopen( fname, "r" );
if ( ! fp )
ERRORMSG( fname );
else
INFOMSG( "Opening data file", fname );
return fp;
}
n = strlen( fname );
if ( *fname == '.' && n > 0 && ( fname[1] == '/' || ( n > 1 && fname[1] == '.'
&& fname[2] == '/' ) ) ) /* specific path is given */
{
fp = LALFopen( fname, "r" );
if ( ! fp )
ERRORMSG( fname );
else
INFOMSG( "Opening data file", fname );
return fp;
}
path = getenv( "LAL_DATA_PATH" );
if ( ! path || ! strlen( path ) ) /* path is NULL or empty */
{
fp = LALFopen( fname, "r" );
if ( ! fp )
ERRORMSG( fname );
else
INFOMSG( "Opening data file", fname );
return fp;
}
/* scan through all directories in colon-delmited list of directories */
if ( (datapath = LALCalloc (strlen(path)+1, 1)) == NULL) /* we need local copy */
{
ERRORMSG( fname );
return NULL;
}
strcpy (datapath, path);
p0 = datapath;
do {
p1 = strchr( p0, ':' ); /* look for additional directories */
if ( p1 ) /* there are more things in the list */
*p1++ = 0; /* NUL-terminate current directory */
if ( ! strlen( p0 ) ) /* this directory is empty */
p0 = LAL_PREFIX "/share/lal"; /* default data directory */
n = snprintf( fdata, sizeof(fdata), "%s/%s", p0 ? p0 : ".", fname );
if ( n > (int) sizeof( fdata ) ) /* data file name too long */
{
errno = ENAMETOOLONG;
LALFree (datapath);
return NULL;
}
INFOMSG( "Looking for file", fdata );
fp = LALFopen( fdata, "r" );
if ( fp ) /* we've found it! */
{
INFOMSG( "Opening data file", fdata );
LALFree (datapath);
return fp;
}
p0 = p1;
}
while ( p0 );
LALFree (datapath);
ERRORMSG( fname );
return NULL;
}
/** 'Resolve' a given filename 'fname', returning a file path where the
* file can successfully be opened by fopen() using mode='rb'.
*
* Return: successful file-path or NULL if failed.
*
* Resolving follows an algorithm similar to what LALOpenDataFile() did,
* namely if 'fname' contains a
* Resolving uses the following algorithm: if 'fname' contains a
* i) (relative or absolute) path: only tries to open that path directly
* ii) pure filename: try 1) local dir, then 2) search LAL_DATA_PATH, then 3) try fallbackdir
* return first successful hit
......
......@@ -42,7 +42,7 @@ void FUNC ( LALStatus* status,
/* if (filename == NULL) return; */
fp = LALOpenDataFile( filename );
fp = LALFopen( filename, "r" );
if (fp == NULL)
{
ABORT( status, READFTSERIESH_EFILENOTFOUND,
......
......@@ -103,7 +103,7 @@ LALReadNoiseSpectrum(LALStatus *stat, REAL4FrequencySeries *spectrum, CHAR *fnam
ATTATCHSTATUSPTR(stat);
/* this is the file containing the spectrum data */
if ( !(fp = LALOpenDataFile( fname )) )
if ( !(fp = LALFopen( fname, "r" )) )
{
ABORT(stat, LALREADNOISESPECTRUMH_EOPEN, LALREADNOISESPECTRUMH_MSGEOPEN);
}
......
......@@ -44,7 +44,7 @@ FUNC ( LALStatus* status,
/* if (filename == NULL) return; */
fp = LALOpenDataFile( filename );
fp = LALFopen( filename, "r" );
if (fp == NULL)
{
ABORT( status, READFTSERIESH_EFILENOTFOUND,
......
......@@ -382,7 +382,7 @@ main(int argc, char **argv)
/* Open input and output files. */
if ( strcmp( infile, "stdin" ) ) {
if ( !( fpIn = LALOpenDataFile( infile ) ) ) {
if ( !( fpIn = fopen( infile, "r" ) ) ) {
ERROR( STREAMINPUTTESTC_EFILE, "- " STREAMINPUTTESTC_MSGEFILE,
infile );
return STREAMINPUTTESTC_EFILE;
......
......@@ -192,7 +192,7 @@ main(int argc, char **argv)
/* Open input and output files. */
if ( strcmp( infile, "stdin" ) ) {
if ( !( fpIn = LALOpenDataFile( infile ) ) ) {
if ( !( fpIn = fopen( infile, "r" ) ) ) {
ERROR( STREAMSERIESINPUTTESTC_EFILE, "- "
STREAMSERIESINPUTTESTC_MSGEFILE, infile );
return STREAMSERIESINPUTTESTC_EFILE;
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend PATH $(bindir); \
prepend PYTHONPATH $(pyexecdir) $(pythondir); \
......
......@@ -30,7 +30,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALBURST_DATA_PATH=@datadir@/@PACKAGE@
LALBURST_OCTAVE_PATH=@octexecdir@
LALBURST_PYTHON_PATH=@pyexecdir@
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALDETCHAR_DATA_PATH=@datadir@/@PACKAGE@
LALDETCHAR_OCTAVE_PATH=@octexecdir@
LADETCHARL_PYTHON_PATH=@pyexecdir@
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALFRAME_DATA_PATH=@datadir@/@PACKAGE@
LALFRAME_OCTAVE_PATH=@octexecdir@
LALFRAME_PYTHON_PATH=@pyexecdir@
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALINFERENCE_DATA_PATH=@datadir@/@PACKAGE@
LALINFERENCE_OCTAVE_PATH=@octexecdir@
LALINFERENCE_PYTHON_PATH=@pyexecdir@
......
......@@ -30,7 +30,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALINSPIRAL_DATA_PATH=@datadir@/@PACKAGE@
LALINSPIRAL_OCTAVE_PATH=@octexecdir@
LALINSPIRAL_PYTHON_PATH=@pyexecdir@
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALMETAIO_DATA_PATH=@datadir@/@PACKAGE@
LALMETAIO_OCTAVE_PATH=@octexecdir@
LALMETAIO_PYTHON_PATH=@pyexecdir@
......
......@@ -30,7 +30,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALPULSAR_DATA_PATH=@datadir@/@PACKAGE@
LALPULSAR_OCTAVE_PATH=@octexecdir@
LALPULSAR_PYTHON_PATH=@pyexecdir@
......
......@@ -820,7 +820,7 @@ loadFullGridFile ( LALStatus *status,
} /* for s < max_spins */
/* open input data file */
if ( (fp = LALOpenDataFile (init->gridFile)) == NULL) {
if ( (fp = LALFopen (init->gridFile, "r")) == NULL) {
XLALPrintError ("Could not open data-file: `%s`\n\n", init->gridFile);
ABORT (status, CONFIGFILEH_EFILE, CONFIGFILEH_MSGEFILE);
}
......
......@@ -922,7 +922,7 @@ LALReadSFTheader (LALStatus *status, /**< pointer to LALStatus structure */
ASSERT (fname, status, SFTFILEIO_ENULL, SFTFILEIO_MSGENULL);
/* opening the SFT binary file */
fp = LALOpenDataFile( fname );
fp = LALFopen( fname, "rb" );
if (fp == NULL) {
ABORT (status, SFTFILEIO_EFILE, SFTFILEIO_MSGEFILE);
}
......@@ -1072,7 +1072,7 @@ LALReadSFTdata(LALStatus *status, /**< pointer to LALStatus structure */
offset = fminBinIndex - header.fminBinIndex;
/* open file for reading */
if ( (fp = LALOpenDataFile( fname )) == NULL) {
if ( (fp = LALFopen( fname, "rb" )) == NULL) {
ABORT (status, SFTFILEIO_EFILE, SFTFILEIO_MSGEFILE);
}
......
......@@ -48,6 +48,7 @@
#endif
#include <lal/LALStdio.h>
#include <lal/LALString.h>
#include <lal/FileIO.h>
#include <lal/SFTfileIO.h>
#include <lal/StringVector.h>
......@@ -2482,17 +2483,10 @@ XLALFindFiles (const CHAR *globstring)
LALParsedDataFile *list = NULL;
CHAR* listfname = NULL;
/* create list file name
prefix with "./" if not an absolute file name (see LALOpenDataFile()) */
if ((listfname = LALCalloc(1, strlen(globstring) + 3)) == NULL) {
/* extract list file name */
if ((listfname = XLALStringDuplicate(globstring + strlen(LIST_PREFIX))) == NULL) {
XLAL_ERROR_NULL ( XLAL_ENOMEM ) ;
}
ptr1 = globstring + strlen(LIST_PREFIX);
if (*ptr1 == '/')
*listfname = '\0';
else
strcpy(listfname, "./");
strcat(listfname, ptr1);
#undef LIST_PREFIX
/* read list of file names from file */
......
......@@ -269,21 +269,21 @@ main(int argc, char **argv)
if ( eigenfile ) {
/* Read input files into vector sequences. */
if ( !( fp = LALOpenDataFile( eigenfile ) ) ) {
if ( !( fp = fopen( eigenfile, "r" ) ) ) {
ERROR( FLATMESHTESTC_EFILE, "- " FLATMESHTESTC_MSGEFILE,
eigenfile );
return FLATMESHTESTC_EFILE;
}
SUB( LALSReadVectorSequence( &stat, &matrix, fp ), &stat );
fclose( fp );
if ( !( fp = LALOpenDataFile( inversefile ) ) ) {
if ( !( fp = fopen( inversefile, "r" ) ) ) {
ERROR( FLATMESHTESTC_EFILE, "- " FLATMESHTESTC_MSGEFILE,
inversefile );
return FLATMESHTESTC_EFILE;
}
SUB( LALSReadVectorSequence( &stat, &matrixInv, fp ), &stat );
fclose( fp );
if ( !( fp = LALOpenDataFile( rangefile ) ) ) {
if ( !( fp = fopen( rangefile, "r" ) ) ) {
ERROR( FLATMESHTESTC_EFILE, "- " FLATMESHTESTC_MSGEFILE,
rangefile );
return FLATMESHTESTC_EFILE;
......
......@@ -188,8 +188,6 @@
* \code
* lalDebugLevel
* LALMalloc()
* LALFopen()
* LALFclose()
* LALSCreateVector()
* LALCreateRandomParams()
* LALNormalDeviates()
......@@ -354,7 +352,7 @@ int main(int argc, char **argv)
{
strcpy(basicInputsFile, argv[++arg]);
arg++;
if(LALOpenDataFile(basicInputsFile)==NULL)
if(fopen(basicInputsFile, "r")==NULL)
{
ERROR(LALDEMODH_ENOFILE, LALDEMODH_MSGENOFILE, 0);
XLALPrintError(USAGE, *argv);
......@@ -392,7 +390,7 @@ int main(int argc, char **argv)
/* default: no input file specified */
else if(basicInputsFile==NULL)
{
bif=LALOpenDataFile("in.data");
bif=fopen("in.data", "r");
}
/* erroneous command line argument */
......@@ -427,7 +425,7 @@ int main(int argc, char **argv)
/***** GET INPUTS FROM FILES *****/
bif=LALOpenDataFile(basicInputsFile);
bif=fopen(basicInputsFile, "r");
fscanf(bif, "%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n%lf\n%d\n%le\n%le\n%le\n%le\n%le\n%lf\n"
" %lf\n%d\n%le\n%le\n%le\n%le\n%le\n%lf\n%lf\n",
......@@ -443,7 +441,7 @@ int main(int argc, char **argv)
&templateParams->spind->spParams[4],
&templateParams->skyP->alpha, &templateParams->skyP->delta);
LALFclose(bif);
fclose(bif);
/***** END FILE INPUT *****/
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALSIMULATION_DATA_PATH=@datadir@/@PACKAGE@
LALSIMULATION_OCTAVE_PATH=@octexecdir@
LALSIMULATION_PYTHON_PATH=@pyexecdir@
......
......@@ -30,7 +30,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALSTOCHASTIC_DATA_PATH=@datadir@/@PACKAGE@
LALSTOCHASTIC_OCTAVE_PATH=@octexecdir@
LALSTOCHASTIC_PYTHON_PATH=@pyexecdir@
......
......@@ -29,7 +29,7 @@ SUBDIRS = \
user_environment = \
set $(PACKAGE)_PREFIX $(prefix); \
prepend LAL_DATA_PATH $(pkgdatadir); \
set $(PACKAGE)_DATADIR $(pkgdatadir); \
prepend MANPATH $(mandir); \
prepend OCTAVE_PATH $(octexecdir); \
prepend PATH $(bindir); \
......
......@@ -3,7 +3,6 @@ exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
LALXML_DATA_PATH=@datadir@/@PACKAGE@
LALXML_OCTAVE_PATH=@octexecdir@
LALXML_PYTHON_PATH=@pyexecdir@
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment