Mapper
get_topo_coord_new.c
Go to the documentation of this file.
1 #include "prototypes.h"
2 
3 void get_topo_coord(char *fname)
4 
5 {
6 
7  extern double max_lat,min_lat,cen_lon;
8  double max_lon;
9  int i,j,ier,maxj,maxi,max_value,k;
10  double lat,lon;
11  extern struct topo *topo;
12  FILE *fp;
13  char *p,kbuf[10000];
14  double mlat,mlon,delta_lat,delta_lon,total_lat,total_lon;
15  int ii,jj;
16  double xlat,xlon;
17  int taxi,taxj;
18 
19  topo=(struct topo *) calloc(1,sizeof(struct topo));
20  if(topo==NULL) {
21 
22  printf("could not allocate topo space\n");
23  exit(1);
24 
25  }
26 
27  max_value=0;
28 
29  fp=fopen(fname,"r");
30 
31  if(fp==NULL) {
32 
33  printf("could not open %s\n",fname);
34  exit(1);
35 
36  }
37 
38  p=fgets(kbuf,80,fp);
39 
40  ier=sscanf(kbuf,"%lf %lf %lf %lf %lf %lf",&mlat,&mlon,&total_lat,&total_lon,&delta_lat,&delta_lon);
41 
42  delta_lat=delta_lat/60.;
43  delta_lon=delta_lon/60.;
44 
45  taxi=total_lon/delta_lon;
46  taxj=total_lat/delta_lat;
47 
48  maxi=10/delta_lon+1;
50 
51  max_lon=cen_lon+5;
52 
53  topo->maxi=maxi;
54  topo->maxj=maxj;
56  topo->max_lon=cen_lon+5;
58  topo->total_lon=10;
61 
62  topo->coord=(struct coord**) calloc(maxi,sizeof(struct coord *));
63  topo->value=(short int**) calloc(maxi,sizeof(short int *));
64 
65  if(topo->coord==NULL || topo->value==NULL) {
66 
67  printf("no memory for topo array\n");
68  exit(1);
69 
70  }
71 
72  for(i=0;i<maxi;i++) {
73 
74  topo->coord[i]=(struct coord *) calloc(maxj,sizeof(struct coord));
75 
76  topo->value[i]=(short int *) calloc(maxj,sizeof(short int));
77 
78  if(topo->coord[i]==NULL || topo->value[i]==NULL) {
79 
80  printf("no memory for topo array\n");
81  exit(1);
82 
83  }
84 
85  }
86 
87  for(i=0;i<maxi;i++) {
88  for(j=0;j<maxj;j++) {
89 
90 topo->value[i][j]=-9999;
91 
92 }
93 }
94 
95  for(j=0;j<taxj;j++) {
96 
97  ier=fread(kbuf,sizeof(char),taxi*4,fp);
98 
99  xlat=mlat-(double)j*delta_lat;
100 
101  jj=((max_lat-xlat)/delta_lat+.0000001);
102 
103  if(jj < 0 || jj > maxj-1)
104  continue;
105 
106  k=0;
107 
108 
109 
110  for(i=0;i<taxi;i++) {
111 
112  xlon=mlon-(double)i*delta_lon;
113 
114  ii=((max_lon-xlon)/delta_lon+.0000001);
115 
116  if(ii < 0 || ii > maxi-1) {
117 
118  k=k+4;
119 
120  continue;
121 
122  }
123 
124  topo->value[ii][jj]=atoi(&kbuf[k]);
125 
126  lat=mlat-(float)j*delta_lat;
127  lon=mlon-(float)i*delta_lon;
128 
129  get_topo_pixels(ii,jj,lat,lon);
130 
131  k=k+4;
132 
133  }
134 
135  }
136 
137 fclose(fp);
138 
139 return;
140 
141 }
142 void get_topo_pixels(int i, int j, float lat,float lon)
143 
144  {
145 
146  extern struct dval dval;
147  long r,s;
148  float conv=.0174;
149  extern struct topo *topo;
150 
151  r=dval.a * cos(lat*conv)/(1+sin(lat*conv))
152  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
153 
154  topo->coord[i][j].x=r;
155 
156  s=dval.a * cos(lat*conv)/(1+sin(lat*conv))
157  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
158 
159  topo->coord[i][j].y=s;
160 
161  return;
162 
163  }
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
struct top * topo
Definition: build_hrap.c:3
static int i
void get_topo_coord(char *fname)
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 xlat
Definition: mapp2h.h:41
double lat
Definition: mapp2h.h:41
double xlon
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
int k
Definition: mapp2h.h:48
double cen_lon
Definition: mapper.c:22
double min_lat
Definition: mapper.c:22
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