-
Notifications
You must be signed in to change notification settings - Fork 1
/
landmarks.c
201 lines (156 loc) · 4.99 KB
/
landmarks.c
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
-------------------------------------------------------------------------
OBJECT NAME: landmarks.c
FULL NAME: Plot WINDS landmarks file.
ENTRY POINTS: ToggleLandMarks()
PlotLandMarksXY()
PlotLandMarks3D()
STATIC FNS: none.
DESCRIPTION:
COPYRIGHT: University Corporation for Atmospheric Research, 1997-2022
-------------------------------------------------------------------------
*/
#include "define.h"
static struct
{
float lat, lon;
char *tag;
} landMark[128];
static size_t nMarks = 0;
/* -------------------------------------------------------------------- */
void ClearLandmarks()
{
for (size_t i = 0; i < nMarks; ++i)
delete landMark[i].tag;
nMarks = 0;
}
/* -------------------------------------------------------------------- */
void ToggleLandMarks(Widget w, XtPointer client, XtPointer call)
{
LandMarks = !LandMarks;
if (Interactive)
DrawMainWindow();
} /* END TOGGLELANDMARKS */
/* -------------------------------------------------------------------- */
static void plotLMx(PLOT_INFO *plot, int x, int y, int i)
{
XDrawLine(plot->dpy, plot->win, plot->gc, x-3, y-3, x+4, y+4);
XDrawLine(plot->dpy, plot->win, plot->gc, x-3, y+3, x+4, y-4);
XDrawString(plot->dpy, plot->win, plot->gc, x+6, y+5, landMark[i].tag,
strlen(landMark[i].tag));
}
/* -------------------------------------------------------------------- */
static void plotLMps(FILE *fp, int x, int y, int i)
{
fprintf(fp, "%d %d m\n", x-10, y+10);
fprintf(fp, "%d %d l\n", x+10, y-10);
fprintf(fp, "%d %d m\n", x-10, y-10);
fprintf(fp, "%d %d l\n", x+10, y+10);
fprintf(fp, "%d %d m\n", x+12, y-10);
fprintf(fp, "(%s) s\n", landMark[i].tag);
}
/* -------------------------------------------------------------------- */
void PlotLandMarksXY(PLOT_INFO *plot, FILE *fp)
{
int x, y;
float xScale, yScale, xMin, yMin, xMax, yMax;
struct plot_offset *plotInfo;
if (!LandMarks)
return;
xMin = plot->Xaxis.min;
xMax = plot->Xaxis.max;
yMin = plot->Yaxis[0].min;
yMax = plot->Yaxis[0].max;
plotInfo = (fp) ? &plot->ps : &plot->x;
xScale = (NR_TYPE)plotInfo->HD / (xMax - xMin);
yScale = (NR_TYPE)plotInfo->VD / (yMax - yMin);
for (size_t i = 0; i < nMarks; ++i)
{
if (landMark[i].lat < yMin || landMark[i].lat > yMax ||
landMark[i].lon < xMin || landMark[i].lon > xMax)
continue;
if (fp) /* PostScript */
{
x = (int)(xScale * (landMark[i].lon - xMin));
y = (int)(yScale * (landMark[i].lat - yMin));
plotLMps(fp, x, y, i);
}
else /* X window */
{
x = (int)(plotInfo->LV + (xScale * (landMark[i].lon - xMin)));
y = (int)(plotInfo->BH - (yScale * (landMark[i].lat - yMin)));
plotLMx(plot, x, y, i);
}
}
} /* END PLOTLANDMARKSXY */
/* -------------------------------------------------------------------- */
void PlotLandMarks3D(
PLOT_INFO *plot,
int ZD,
float cosFac, float sinFac,
FILE *fp) /* PostScript or Xwin */
{
int x, y;
float xScale, yScale, zScale, xMin, zMin, xMax, zMax;
struct plot_offset *plotInfo;
if (!LandMarks)
return;
xMin = plot->Xaxis.min;
xMax = plot->Xaxis.max;
zMin = plot->Zaxis.min;
zMax = plot->Zaxis.max;
plotInfo = (fp) ? &plot->ps : &plot->x;
xScale = (float)plotInfo->HD / (xMax - xMin);
yScale = (float)plotInfo->VD / (plot->Yaxis[0].max - plot->Yaxis[0].min);
zScale = (float)ZD / (zMax - zMin);
for (size_t i = 0; i < nMarks; ++i)
{
if (landMark[i].lat < zMin || landMark[i].lat > zMax ||
landMark[i].lon < xMin || landMark[i].lon > xMax)
continue;
if (fp) /* PostScript */
{
x = (int)(xScale * (landMark[i].lon - xMin));
y = (int)(yScale * (0.0 - plot->Yaxis[0].min));
x += (int)(cosFac * (zScale * (landMark[i].lat - zMin)));
y += (int)(sinFac * (zScale * (landMark[i].lat - zMin)));
plotLMps(fp, x, y, i);
}
else /* X window */
{
x = (int)(plotInfo->LV + (xScale * (landMark[i].lon - xMin)));
y = (int)(plotInfo->BH - (yScale * (0.0 - plot->Yaxis[0].min)));
x += (int)(cosFac * (zScale * (landMark[i].lat - zMin)));
y -= (int)(sinFac * (zScale * (landMark[i].lat - zMin)));
plotLMx(plot, x, y, i);
}
}
} /* END PLOTLANDMARKS3D */
/* -------------------------------------------------------------------- */
static void addLandmark(const char str[])
{
char tempTag[64];
sscanf(str, "%f %f %s\n", &landMark[nMarks].lat, &landMark[nMarks].lon,
tempTag);
landMark[nMarks].tag = new char[strlen(tempTag)+1];
strcpy(landMark[nMarks].tag, tempTag);
++nMarks;
}
/* -------------------------------------------------------------------- */
void
setLandmarks(const std::string lm_str)
{
std::string rest = lm_str;
std::string current;
while (rest.size() > 0)
{
size_t pos = rest.find(',');
current = rest.substr(0, pos);
if (pos == std::string::npos)
rest.clear();
else
rest = rest.substr(pos+1);
addLandmark(current.c_str());
}
} /* END SETLANDMARKS */
/* END LANDMARKS.C */