File: topoinfo.c

package info (click to toggle)
vis5d 4.3-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 16,856 kB
  • ctags: 6,127
  • sloc: ansic: 66,158; fortran: 4,470; makefile: 1,683; tcl: 414; sh: 69
file content (117 lines) | stat: -rw-r--r-- 2,850 bytes parent folder | download
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
/* topoinfo.c */

/*
vis5d program for visualizing five dimensional gridded data sets
Copyright (C) 1990, 1991, 1992  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.
*/


/*
 * Print information about a Vis5D topo file.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "binio.h"




main( argc, argv )
int argc;
char *argv[];
{
   char id[40];
   float west, east, north, south;
   int rows, columns;
   mode_t mask;
   int fd;
   short *data;
   int i;
   float min, max;
   int water;

   if (argc==1) {
      printf("Usage:\n");
      printf("   topoinfo topofile\n");
      exit(0);
   }

   fd = open( argv[1], O_RDONLY );
   if (fd==-1) {
      printf("Error: couldn't open %s for reading\n", argv[1] );
      return 0;
   }

   /* read the header */
   read_bytes( fd, id, 40 );
   if (strcmp(id,"TOPO2")==0) {
      /* floating point values */
      read_float4( fd, &west );
      read_float4( fd, &east );
      read_float4( fd, &north );
      read_float4( fd, &south );
   }
   else {
      /* integer values */
      read_int4( fd, &i );   west = i / 100.0;
      read_int4( fd, &i );   east = i / 100.0;
      read_int4( fd, &i );   north = i / 100.0;
      read_int4( fd, &i );   south = i / 100.0;
   }
   read_int4( fd, &rows );
   read_int4( fd, &columns );

   data = (short *) malloc( rows * columns * sizeof(short) );
   if (!data) {
      printf("malloc failed!\n");
      exit(0);
   }

   read_int2_array( fd, data, rows*columns );

   close(fd);

   min = 1.0e30;
   max = -min;
   water = 0;
   for (i=0;i<rows*columns;i++) {
      float height;
      if (data[i]&1) {
         water++;
      }
      height = data[i] / 2;
      if (height<min)  min = height;
      if (height>max)  max = height;
   }

   printf("Topo file: %s\n", argv[1] );
   printf("North bound: %g deg\n", north );
   printf("South bound: %g deg\n", south );
   printf("West bound: %g deg\n", west );
   printf("East bound: %g deg\n", east );
   printf("Rows: %d\n", rows );
   printf("Columns: %d\n", columns);

   printf("min height: %g meters\n", min);
   printf("max height: %g meters\n", max);

   printf("%% water flags: %d\n",  100 * water / (rows*columns) );
}