Skip to content

Commit

Permalink
separate library and executable
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed May 14, 2004
1 parent e60d748 commit eb8b9dc
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 58 deletions.
27 changes: 24 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
bin_PROGRAMS = harminv
lib_LTLIBRARIES = libharminv.la
include_HEADERS = harminv.h
dist_man_MANS = harminv.1
noinst_PROGRAMS = sines

harminv_SOURCES = harminv-main.c harminv.c check.h config.h \
copyright.h harminv.h
sines_SOURCES = sines.c harminv.c
EXTRA_DIST = COPYRIGHT

libharminv_la_SOURCES = harminv.c harminv.h harminv-int.h check.h
libharminv_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@

harminv_SOURCES = harminv-main.c copyright.h
harminv_LDADD = libharminv.la

sines_SOURCES = sines.c

BUILT_SOURCES = copyright.h

# Generate built sources only in maintainer mode
if MAINTAINER_MODE

copyright.h: COPYRIGHT
(echo '#define COPYRIGHT \'; sed 's,^/\* *,",;s,^ \* *,",;s,$$,\\n" \\,' COPYRIGHT |egrep -v '^"/|^[^"]'; echo) > $@

maintainer-clean-local:
rm -f $(BUILT_SOURCES)

endif # MAINTAINER_MODE
27 changes: 20 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(harminv, 0.2)
AM_INIT_AUTOMAKE
AC_INIT(harminv, 1.0, [email protected])
AM_INIT_AUTOMAKE(1.6)
AC_CONFIG_SRCDIR(harminv.c)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE

# Shared-library version number; indicates api compatibility, and is
# not the same as the "public" version number. (Don't worry about this
# except for public releases.)
SHARED_VERSION_INFO="1:0:0"
AC_SUBST(SHARED_VERSION_INFO)
AM_ENABLE_SHARED(no) dnl shared libs cause too many headaches to be default

# Checks for programs.
AC_PROG_CC
Expand All @@ -16,7 +24,7 @@ AC_F77_WRAPPERS

# Add lots of compiler warnings to check for if we are using gcc:
# (The variable $GCC is set to "yes" by AC_PROG_CC if we are using gcc.)
if test "$GCC" = "yes"; then
if test "$GCC" = "yes" && test "$USE_MAINTAINER_MODE" = yes; then
CFLAGS="$CFLAGS -Wall -W -Wbad-function-cast -Wcast-qual -Wpointer-arith -Wcast-align -pedantic"
fi

Expand Down Expand Up @@ -74,16 +82,21 @@ fi # C has complex keyword

fi # $with_cxx = no

if test "$have_c_complex" = "yes"; then
AC_CHECK_FUNCS(carg)
fi

###########################################################################

AC_PROG_CXX
if test "$with_cxx" = "yes" -o "$have_c_complex" = "no"; then
AC_PROG_CXX
CC="$CXX"
CFLAGS="$CXXFLAGS"
fi

if test "$have_c_complex" = "yes"; then
AC_CHECK_FUNCS(carg)
fi
###########################################################################

AC_PROG_LIBTOOL
###########################################################################

# Checks for header files.
Expand Down
12 changes: 0 additions & 12 deletions copyright.h

This file was deleted.

58 changes: 58 additions & 0 deletions harminv-int.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (C) 2000 Massachusetts Institute of Technology.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef HARMINV_INT_H
#define HARMINV_INT_H 1

#include "config.h"

#ifndef __cplusplus
/* Require C99 complex number support; this is just too painful
without it. Alternatively, use the complex<double> STL class in
C++. */

# include <complex.h>
#endif

#include "harminv.h"

typedef harminv_complex cmplx; /* shortcut */

#ifdef __cplusplus
# define I cmplx(0,1)
# define creal(c) real(c)
# define cimag(c) imag(c)
# define cabs(c) abs(c)
# define carg(c) arg(c)
# define cexp(c) exp(c)
# define csqrt(c) sqrt(c)
#else
# ifndef HAVE_CARG /* Cray doesn't have this for some reason */
# define carg(c) atan2(cimag(c), creal(c))
# endif
#endif

struct harminv_data_struct {
const cmplx *c;
int n, K, J, nfreqs;
double fmin, fmax;
cmplx *z;
cmplx *U0, *U1;
cmplx *B, *u; /* eigen-solutions of U1*B = u*U0*B */
};

#endif /* HARMINV_INT_H */
4 changes: 2 additions & 2 deletions harminv-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <ctype.h>
#include <math.h>

#include "harminv.h"
#include "harminv-int.h"
#include "check.h"
#include "copyright.h"

Expand Down Expand Up @@ -207,7 +207,7 @@ int main(int argc, char **argv)

hd = harminv_data_create(n, data, fmin*dt, fmax*dt, nf);

harminv_solve(hd);
harminv_solve_once(hd);
prev_nf = cur_nf = harminv_get_num_freqs(hd);

/* keep re-solving as long as spurious solutions are eliminated */
Expand Down
20 changes: 18 additions & 2 deletions harminv.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <stdio.h>
#include <math.h>

#include "harminv.h"
#include "harminv-int.h"
#include "check.h"

/**************************************************************************/
Expand Down Expand Up @@ -432,7 +432,7 @@ static void solve_eigenvects(int n, cmplx *A, cmplx *V, cmplx *v)
/* Solve the eigenvalue problem U1 b = u U0 b, where b is the eigenvector
and u is the eigenvalue. u = exp(iwt - at) then contains both the
frequency and the decay constant. */
void harminv_solve(harminv_data d)
void harminv_solve_once(harminv_data d)
{
int J, i, one=1;
cmplx zone = 1.0, zzero = 0.0;
Expand Down Expand Up @@ -530,7 +530,23 @@ void harminv_solve_again(harminv_data d)
d->nfreqs = 0;
d->B = d->u = NULL;

harminv_solve_once(d);
}

/**************************************************************************/

/* keep re-solving as long as spurious solutions are eliminated */
void harminv_solve(harminv_data d)
{
int prev_nf, cur_nf;

harminv_solve(d);
cur_nf = harminv_get_num_freqs(d);
do {
prev_nf = cur_nf;
harminv_solve_again(d);
cur_nf = harminv_get_num_freqs(d);
} while (cur_nf < prev_nf);
}

/**************************************************************************/
Expand Down
49 changes: 18 additions & 31 deletions harminv.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,45 @@
#ifndef HARMINV_H
#define HARMINV_H

/* Require C99 complex number support; this is just too painful
without it. Alternatively, use the complex<double> STL class in
C++. */

#include <complex.h>
/**************************************************************************/

#include "config.h"
#if defined(__cplusplus)
# include <complex>
extern "C" {
typedef std::complex<double> harminv_complex;

/**************************************************************************/
#elif defined(_Complex_I) && defined(complex) && defined(I)
/* C99 <complex.h> header was included before harminv.h */
typedef double _Complex harminv_complex;

#ifdef __cplusplus
typedef complex<double> cmplx;
# define I cmplx(0,1)
# define creal(c) real(c)
# define cimag(c) imag(c)
# define cabs(c) abs(c)
# define carg(c) arg(c)
# define cexp(c) exp(c)
# define csqrt(c) sqrt(c)
#else
typedef double complex cmplx;
# ifndef HAVE_CARG /* Cray doesn't have this for some reason */
# define carg(c) atan2(cimag(c), creal(c))
# endif
typedef double harminv_complex[2];
#endif

typedef struct harminv_data_struct {
const cmplx *c;
int n, K, J, nfreqs;
double fmin, fmax;
cmplx *z;
cmplx *U0, *U1;
cmplx *B, *u; /* eigen-solutions of U1*B = u*U0*B */
} *harminv_data;
typedef struct harminv_data_struct *harminv_data;

/**************************************************************************/

extern harminv_data harminv_data_create(int n,
const cmplx *signal,
const harminv_complex *signal,
double fmin, double fmax, int nf);
extern void harminv_data_destroy(harminv_data d);

extern void harminv_solve(harminv_data d);
extern void harminv_solve_once(harminv_data d);
extern void harminv_solve_again(harminv_data d);
extern void harminv_solve(harminv_data d);

extern int harminv_get_num_freqs(harminv_data d);
extern double harminv_get_freq(harminv_data d, int k);
extern double harminv_get_decay(harminv_data d, int k);

extern double *harminv_compute_frequency_errors(harminv_data d);
extern cmplx *harminv_compute_amplitudes(harminv_data d);
extern harminv_complex *harminv_compute_amplitudes(harminv_data d);

/**************************************************************************/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* HARMINV_H */
2 changes: 1 addition & 1 deletion sines.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "config.h"
#include "check.h"
#include "harminv.h"
#include "harminv-int.h"
#include "copyright.h"

#ifdef HAVE_UNISTD_H
Expand Down

0 comments on commit eb8b9dc

Please sign in to comment.