diff options
Diffstat (limited to 'src/Hill.cxx')
-rw-r--r-- | src/Hill.cxx | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/Hill.cxx b/src/Hill.cxx index 02d3728..6df8d34 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hill.cxx,v 1.12 2005/05/10 17:05:32 hofmann Exp $" +// "$Id: Hill.cxx,v 1.13 2005/05/10 17:16:54 hofmann Exp $" // // Hill routines. // @@ -24,9 +24,12 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <math.h> #include "Hill.H" +static double pi_d, deg2rad; + Hill::Hill(const char *n, double p, double l, double h) { name = strdup(n); phi = p; @@ -58,8 +61,48 @@ Hills::Hills() { num = 0; cap = 100; m = (Hill **) malloc(cap * sizeof(Hill *)); + + pi_d = asin(1.0) * 2.0; + deg2rad = pi_d / 180.0; +} + +int +Hills::load(const char *file) { + FILE *fp; + char buf[4000]; + char *vals[10]; + char **ap, *bp; + double phi, lam, height; + Hill *m; + + fp = fopen(file, "r"); + if (!fp) { + perror("fopen"); + return 1; + } + + while (fgets(buf, sizeof(buf), fp)) { + bp = buf; + for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;) + if (++ap >= &vals[10]) + break; + + phi = atof(vals[3]) * deg2rad; + lam = atof(vals[4]) * deg2rad; + + height = atof(vals[5]); + + m = new Hill(vals[1], phi, lam, height); + + add(m); + } + + fclose(fp); + + return 0; } + Hills::~Hills() { if (m) { free(m); |