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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/* makemap.c */
/* Vis5D version 4.3 */
/*
vis5d program for visualizing five dimensional gridded data sets
Copyright (C) 1990-1997 Bill Hibbard, Brian Paul, Dave Santek,
and Andre Battaiola.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Utility program to make your own map outline files.
*
* A map outline file consists of a number of polylines. A polyline
* is a sequence of connected line segments. The end points (vertices)
* of the lines are defined in degrees of latitude and longitude.
*
* Compile with: make -f makemap.m
*
*/
#include <stdio.h>
#include "binio.h"
main( argc, argv )
int argc;
char *argv[];
{
/****** Replace this example code with your own! *****/
/* this example writes a mapfile which spells out "ABC" like this:
|
| L
2* 7*-*8 12*-----*11 +50 a
/ \ | \ | | t
/ \ | \ | | i
1*-----*3 6*----*9 | +35 t
| | | | | | u
| | | | | | d
0* *4 5*----*10 13*-----*14 +20 e
|
-----+-----+-----+----+------+-----+---------+---
130 120 110 100 90 80 |0
Longitude |
The asterisks are the vertices. The polylines are defined by:
0,1,2,3,4
1,3
5,6,7,8,9,10,5
6,9
11,12,13,14
Below is the code to make this map. All you have to do is call
these functions:
vertex( lat, lon ) - to specify the next vertex in lat/lon
end_line() - to signal the end of a polyline
done( filename ) - to write the named map file
If you use this example unchanged then you can view the map with:
vis5d LAMPS.v5d -map util/OUTLABC
*/
/* Letter A */
vertex( 20.0, 130.0 ); /* vertex 0 */
vertex( 35.0, 130.0 ); /* vertex 1 */
vertex( 50.0, 125.0 ); /* vertex 2 */
vertex( 35.0, 120.0 ); /* vertex 3 */
vertex( 20.0, 120.0 ); /* vertex 4 */
end_line();
vertex( 35.0, 130.0 ); /* vertex 1 */
vertex( 35.0, 120.0 ); /* vertex 3 */
end_line();
/* Letter B */
vertex( 20.0, 110.0 ); /* vertex 5 */
vertex( 35.0, 110.0 );
vertex( 50.0, 110.0 );
vertex( 50.0, 104.0 );
vertex( 35.0, 100.0 );
vertex( 20.0, 100.0 ); /* vertex 10 */
vertex( 20.0, 110.0 ); /* vertex 5 */
end_line();
vertex( 35.0, 110.0 );
vertex( 35.0, 100.0 );
end_line();
/* Letter C */
vertex( 50.0, 80.0 );
vertex( 50.0, 90.0 );
vertex( 20.0, 90.0 );
vertex( 20.0, 80.0 );
end_line();
/* Write the file! */
done( "OUTLABC" );
exit(0);
}
/**********************************************************************/
/*** No changes beyond this point should be necessary. ***/
/**********************************************************************/
struct polyline {
int minlat;
int maxlat;
int minlon;
int maxlon;
int start;
int len;
};
#define MAXLINES 100000
struct polyline MapLine[MAXLINES];
int NumLines = 0;
struct vertex {
int lat, lon;
};
#define MAXVERTS 100000
struct vertex VertexList[MAXVERTS];
int NumVertices = 0;
initialize()
{
NumLines = NumVertices = 0;
MapLine[0].minlat = 10000000;
MapLine[0].maxlat = -10000000;
MapLine[0].minlon = 10000000;
MapLine[0].maxlon = -10000000;
MapLine[0].start = 0;
MapLine[0].len = 0;
}
vertex( lat, lon )
float lat, lon;
{
static int init_flag = 1;
if (init_flag) {
initialize();
init_flag = 0;
}
if (NumVertices>=MAXVERTS) {
printf("Out of space for map vertices!\n");
exit(1);
}
else {
int ilat = (int) (lat * 10000.0);
int ilon = (int) (lon * 10000.0);
VertexList[NumVertices].lat = ilat;
VertexList[NumVertices].lon = ilon;
NumVertices++;
MapLine[NumLines].len++;
if (ilat > MapLine[NumLines].maxlat) MapLine[NumLines].maxlat = ilat;
if (ilat < MapLine[NumLines].minlat) MapLine[NumLines].minlat = ilat;
if (ilon > MapLine[NumLines].maxlon) MapLine[NumLines].maxlon = ilon;
if (ilon < MapLine[NumLines].minlon) MapLine[NumLines].minlon = ilon;
}
}
end_line()
{
if (NumVertices==0 || MapLine[NumLines].len==0) {
printf("Error: must call vertex() before end_line()!\n");
exit(1);
}
MapLine[NumLines].len *= 2;
NumLines++;
if (NumLines>=MAXLINES) {
printf("Error: out of space for lines!\n");
exit(1);
}
MapLine[NumLines].minlat = 10000000;
MapLine[NumLines].maxlat = -10000000;
MapLine[NumLines].minlon = 10000000;
MapLine[NumLines].maxlon = -10000000;
MapLine[NumLines].start = NumVertices;
MapLine[NumLines].len = 0;
}
done( filename )
char *filename;
{
int f;
mode_t mask;
int i;
/* Convert MapLine[].start values from index into VertexList to
* absolute file positions (in 4-byte units).
*/
for (i=0;i<NumLines;i++) {
int index, pos;
index = MapLine[i].start;
pos = 6*NumLines + index*2 + 1;
MapLine[i].start = pos;
}
mask = 0666;
f = open( filename, O_WRONLY | O_CREAT | O_TRUNC, mask );
if (f<0) {
printf("Error: unable to open %s for writing\n", filename );
exit(0);
}
write_int4( f, NumLines );
if (write_int4_array( f, (int *) MapLine, 6*NumLines ) < 6*NumLines) {
printf("Error: bad file write (disk full?)\n");
exit(0);
}
if (write_int4_array( f, (int *) VertexList, 2*NumVertices ) < 2*NumVertices) {
printf("Error: bad file write (disk full?)\n");
exit(0);
}
close( f );
}
|