summaryrefslogtreecommitdiff
path: root/src/Hill.cxx
diff options
context:
space:
mode:
authorJohannes Hofmann <johannes.hofmann@gmx.de>2005-05-10 15:16:54 +0000
committerJohannes Hofmann <johannes.hofmann@gmx.de>2005-05-10 15:16:54 +0000
commit5e674225ec1d8ff0563030a27fb69f8e89d3ebf3 (patch)
tree4eb2713d497f0132bba4fe163fcead4c1098b009 /src/Hill.cxx
parent2ff3057cf1de8695f2fc6cf5c17a3d074e983017 (diff)
move file loading to Hills.cxx
move file loading to Hills.cxx
Diffstat (limited to 'src/Hill.cxx')
-rw-r--r--src/Hill.cxx45
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);