#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef __APPLE__
#include <malloc.h>
#endif

#define SQ(x)   (x) * (x)
#define RANSEED        367367
#define BIGNUM         1E37
#define EPSILON        0.00001
#define EQ             ==
#define NE             !=
#define AND            &&
#define OR             ||

double  **points, **joints, wbit, 
        horilap = -1., vertlap = -1., bI = 1.5, bJ = 7.0, nuldat = 0.0,
        xstart, ystart, xend, yend,
        maxhoriz, aaa, bbb, ccc, det,
        work3[3][3], xx, sumx, sumy, sumz,
        sumx2, sumy2, sumxy, sumxz, sumyz,
        asum, nn_pi, piby2, piby32, rad2deg,
        bigtri[3][3], horilap_save, vertlap_save;

double  magx = 1, magy = 1, magz = 1, magx_orig, magy_orig, magz_orig, 
        maxxy[2][3],
        magx_auto, magy_auto, magz_auto;

int     igrad = 0, non_neg = 0, densi, sdip = 0, rads = 0, southhemi = 0,
        extrap = 1, adf = 0, nndup = 1;

int     datcnt, datcnt3, numtri, imag, numnei, iscale,
        ext, *jndx, neicnt, optim = 1, goodflag, updir = 1,
        scor[3][2] = {{1,2}, {2,0}, {0,1}}, auto_scale = 1,
        single_point = 0, first_single = 1, asflag = 1,
        error_status = 0;

char    tri_file[256] = {"nnalg.dat"}, error_file[256] = {"stderr"},
        emsg[256];

FILE    *filee = NULL;

extern void   Gradient(void);
extern void   ErrorHnd(int, char *, FILE *, char *);
extern void   CircOut(void);

extern void   c_nnsetc(char *, char *);
extern void   c_nngetc(char *, char *);
extern void   c_nnseti(char *, int);
extern void   c_nngeti(char *, int *);

extern void     Terminate(void);
extern void     ErrorHnd(int, char *, FILE *, char *);

void            FindNeigh(void);
void            TriNeigh(void);
void            Gradient(void);
void            FindProp(void);
double          Surface(void);
double          Meld(void);
void            TooSteep(void);
void            TooShallow(void);
void            TooNarrow(void);
struct datum    *IMakeDatum(void);
struct simp     *IMakeSimp(void);
struct temp     *IMakeTemp(void);
struct neig     *IMakeNeig(void);
int             *IntVect(int ncols);
void            FreeVecti(int *vectptr);
double          *DoubleVect(int ncols);
void            FreeVectd(double *vectptr);
int             **IntMatrix(int nrows, int ncols);
void            FreeMatrixi(int **matptr);
float           **FloatMatrix(int nrows, int ncols);
void            FreeMatrixf(float **matptr);
double          **DoubleMatrix(int nrows, int ncols);
void            FreeMatrixd(double **matptr);
