Mapper
get_topo_coord.c
Go to the documentation of this file.
1 #include "prototypes.h"
2 
3 void get_topo_coord(char *fname)
4 
5 {
6 
7  int i,j,ier,maxj,maxi,max_value,k;
8  float lat,lon;
9  extern struct topo *topo;
10  FILE *fp;
11  char *p,kbuf[10000];
13 
14  topo=(struct topo *) calloc(1,sizeof(struct topo));
15  if(topo==NULL) {
16 
17  printf("could not allocate topo space\n");
18  exit(1);
19 
20  }
21 
22  max_value=0;
23 
24  fp=fopen(fname,"r");
25 
26  if(fp==NULL) {
27 
28  printf("could not open %s\n",fname);
29  exit(1);
30 
31  }
32 
33  p=fgets(kbuf,80,fp);
34 
35  ier=sscanf(kbuf,"%f %f %f %f %f %f",&max_lat,&max_lon,&total_lat,&total_lon,&delta_lat,&delta_lon);
36  delta_lat=delta_lat/60.;
37  delta_lon=delta_lon/60.;
38 
41 
42  topo->maxi=maxi;
43  topo->maxj=maxj;
50 
51  topo->coord=(struct coord**) calloc(maxi,sizeof(struct coord *));
52  topo->value=(short int**) calloc(maxi,sizeof(short int *));
53 
54  if(topo->coord==NULL || topo->value==NULL) {
55 
56  printf("no memory for topo array\n");
57  exit(1);
58 
59  }
60 
61  for(i=0;i<maxi;i++) {
62 
63  topo->coord[i]=(struct coord *) calloc(maxj,sizeof(struct coord));
64 
65  topo->value[i]=(short int *) calloc(maxj,sizeof(short int));
66 
67  if(topo->coord[i]==NULL || topo->value[i]==NULL) {
68 
69  printf("no memory for topo array\n");
70  exit(1);
71 
72  }
73 
74  }
75 
76  for(j=0;j<maxj;j++) {
77 
78  fread(kbuf,sizeof(char),maxi*4,fp);
79 
80  k=0;
81 
82  for(i=0;i<maxi;i++) {
83 
84  topo->value[i][j]=atoi(&kbuf[k]);
85 
86  lat=max_lat-(float)j*delta_lat;
87  lon=max_lon-(float)i*delta_lon;
88 
90 
91  k=k+4;
92 
93  }
94 
95  }
96 
97 fclose(fp);
98 
99 return;
100 
101 }
102 void get_topo_pixels(int i, int j, float lat,float lon)
103 
104  {
105 
106  extern struct dval dval;
107  long r,s;
108  float conv=.0174;
109  extern struct topo *topo;
110 
111  r=dval.a * cos(lat*conv)/(1+sin(lat*conv))
112  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
113 
114  topo->coord[i][j].x=r;
115 
116  s=dval.a * cos(lat*conv)/(1+sin(lat*conv))
117  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
118 
119  topo->coord[i][j].y=s;
120 
121  return;
122 
123  }
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
struct top * topo
Definition: build_hrap.c:3
static int i
void get_topo_coord(char *fname)
Definition: get_topo_coord.c:3
void get_topo_pixels(int i, int j, float lat, float lon)
fclose(fp)
printf("fbuf is %s\n", fbuf)
fp
Definition: make_NEXRAD.c:339
int j
Definition: mapp2h.h:48
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int k
Definition: mapp2h.h:48
double max_lat
Definition: mapper.c:22
char fname[100]
Definition: send_afos.c:6
Definition: misc.h:495
short int y
Definition: misc.h:498
short int x
Definition: misc.h:497
Definition: misc.h:470
double lo
Definition: misc.h:475
double a
Definition: misc.h:472
double yo
Definition: misc.h:474
double xo
Definition: misc.h:473
Definition: misc.h:523
struct coord ** coord
Definition: misc.h:525
float delta_lat
Definition: misc.h:533
float max_lat
Definition: misc.h:529
int maxi
Definition: misc.h:527
float total_lat
Definition: misc.h:531
float delta_lon
Definition: misc.h:534
short int ** value
Definition: misc.h:526
float max_lon
Definition: misc.h:530
float total_lon
Definition: misc.h:532
int maxj
Definition: misc.h:528