-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_zonesites.cpp
179 lines (158 loc) · 4.18 KB
/
get_zonesites.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*******************************************************************
* get_zonesites.cpp
* June 12, 2006
* MMFuller
*
* Derived from get_sitedistance_4.cpp
* Updated December 22, 2006: added new zone (AL-MI)
*
* Purpose: Generates a list of BBS sites that occur within a given
* longitudinal range.
*
* Requests name for input file.
* Longitude limit zones are pre-set (switch statement).
* Member variables of struct "site":
* * Year
* * longitude_zone
* * elevation
* * frostfree_days
* * bird_count1
* * bird_count2
*
*
* FILE FORMAT
*
* Bird Data input file format:
* First Line: integer for file size
* Data Lines (order & type of data):
string: Name
double: Latitude, Longitude,
int: Year,
double: Birds per Hour, Birds per Mile
*
*
* Required Files:
* GSL_long
*
*
******************************************************************/
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;
struct site {
double lat, lon;
string name;
int year;
int longitude_zone;
double birds_perhour;
double birds_permile;
};
int main()
{
ifstream fin1;
ifstream fin2;
ofstream fout;
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(4);
int i,j;
int Bird_Data_size;
int zone; //longitude zone
double X1,Y1;
double long_min, long_max; //min and max values for longitude
string Bird_Data;
string outfile;
site* Bird_Data_sites;
cout << "\nEnter Datafile: ";
cin >> Bird_Data;
cout << "\nEnter outfile name: ";
cin >> outfile;
fout.open(outfile.c_str());
fout << "Sites Present in Zone\n"
<< "Zone\tSite\tLat1\tLong1\tBPH\tBPM\tYear\n";
fin1.open(Bird_Data.c_str());
if(fin1.fail()){
cout << "open failure for file: " << Bird_Data << endl;
exit(1);
}
fin1 >> Bird_Data_size;
Bird_Data_sites = new site[Bird_Data_size];
for(i = 0; i < Bird_Data_size; i++){
fin1 >> Bird_Data_sites[i].name
>> Bird_Data_sites[i].lat
>> Bird_Data_sites[i].lon
>> Bird_Data_sites[i].year
>> Bird_Data_sites[i].birds_perhour
>> Bird_Data_sites[i].birds_permile;
}
fin1.close();
cout << "\nSet limits on longitude."
<< "\nAVAILABLE LONGITUDE ZONES\n-----------------------\n"
<< "\n1 = 80.625 - 82.375"
<< "\n3 = 89.625 - 91.375"
<< "\n4 = 97.375 - 99.125"
<< "\n5 = 109.125 - 110.875"
<< "\n6 = 120.125 - 121.875\n"
<< "\n7 = 95.0 - 96.175\n"
<< "\nEnter Zone: " << flush;
cin >> zone;
switch(zone)
{
case 1:
long_min = 80.625;
long_max = 82.375;
break;
case 2:
cout << "\nZone 2 not available!"
<< "\nSetting zone to Zone 3";
long_min = 89.625;
long_max = 91.375;
break;
case 3:
long_min = 89.625;
long_max = 91.375;
break;
case 4:
long_min = 97.375;
long_max = 99.125;
break;
case 5:
long_min = 109.125;
long_max = 110.875;
break;
case 6:
long_min = 120.125;
long_max = 121.875;
break;
case 7:
long_min = 95.0;
long_max = 96.175;
break;
default:
cout << "\nUnknown Zone\n";
exit(1);
}
cout << "\nmin = " << long_min << "\nmax = " << long_max << flush;
//determine whether site located within zone
for(i = 0; i < Bird_Data_size; i++) {
X1 = Bird_Data_sites[i].lat;
Y1 = Bird_Data_sites[i].lon;
//calculate distances constrained to longitude limits
if(Y1 >= long_min && Y1 <= long_max) {
fout << zone << "\t"
<< Bird_Data_sites[i].name << "\t"
<< Bird_Data_sites[i].lat << "\t" << Bird_Data_sites[i].lon << "\t"
<< Bird_Data_sites[i].birds_perhour << "\t"
<< Bird_Data_sites[i].birds_permile << "\t"
<< Bird_Data_sites[i].year << "\n";
}
}
fout.close();
delete [] Bird_Data_sites;
cout << "\nEnd get_zonesites\n";
return 0;
}
/**************************************************************/