Mapper
get_isohyet_coord.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 void get_isohyet_coord(char *fname,int smonth,int emonth)
4 
5 {
6 
7  extern char *mon[];
8  extern int isohyets_used;
9  int i,j,ier,maxj,maxi,max_value,k,kk;
10  float lat,lon;
11  extern struct isoh *isoh;
12  FILE *fp;
13  char *p,kbuf[20000],fbuf[100];
15 
16  max_value=0;
17 
18  isoh=(struct isoh *) calloc(1,sizeof(struct isoh));
19  if(isoh==NULL) {
20 
21  printf("could not allocate isoh space\n");
22  exit(1);
23 
24  }
25 
26  strcpy(fbuf,fname);
27  strcat(fbuf,"jan");
28 
29  fp=fopen(fbuf,"r");
30 
31  if(fp==NULL) {
32 
33  printf("could not open %s\n",fname);
34  exit(1);
35 
36  }
37 
38 
39  p=fgets(kbuf,80,fp);
40 
41  ier=sscanf(kbuf,"%f %f %f %f %f %f",&max_lat,&max_lon,&total_lat,
43 
44  fclose(fp);
45 
46  delta_lat=delta_lat/60.;
47  delta_lon=delta_lon/60.;
48 
49  maxi=(total_lon/delta_lon+.00001);
50  maxj=(total_lat/delta_lat+.00001);
51 
52  isoh->maxi=maxi;
53  isoh->maxj=maxj;
60 
61  isoh->coord=(struct icoord**) calloc(maxi,sizeof(struct icoord *));
62 
63  isoh->value=(short int***) calloc(12,sizeof(short int **));
64 
65  if(isoh->coord==NULL || isoh->value==NULL) {
66 
67  printf("no memory for isoh array\n");
68  exit(1);
69 
70  }
71 
72  for(k=0;k<12;k++) {
73 
74  ier=is_good(k,smonth,emonth);
75 
76  if(ier == -1)
77  continue;
78 
79  isoh->value[k]=(short int **)calloc(maxi,sizeof(short int *));
80 
81  if(isoh->value[k]==NULL) {
82 
83  printf("no memory for isoh array\n");
84  exit(1);
85 
86  }
87 
88  }
89 
90  for(i=0;i<maxi;i++) {
91 
92  isoh->coord[i]=(struct icoord *) calloc(maxj,sizeof(struct icoord));
93 
94  if(isoh->coord[i]==NULL) {
95 
96  printf("no memory for isoh array\n");
97  exit(1);
98 
99  }
100 
101  for(k=0;k<12;k++) {
102 
103  ier=is_good(k,smonth,emonth);
104 
105  if(ier==-1)
106  continue;
107 
108  isoh->value[k][i]=(short int *) calloc(maxj,sizeof(short int));
109 
110  if(isoh->value[k][i]==NULL) {
111 
112  printf("no memory for isoh array\n");
113  exit(1);
114 
115  }
116 
117  }
118 
119  }
120 
121 /*create screen coordinates */
122 
123 /* j increments latitude i increments longitude */
124 
125  for(j=0;j<maxj;j++) {
126 
127  for(i=0;i<maxi;i++) {
128 
129  lat=max_lat-(float)j*delta_lat;
130  lon=max_lon-(float)i*delta_lon;
131 
133 
134  }
135 
136 }
137 
138 for(k=0;k<12;k++) {
139 
140  ier=is_good(k,smonth,emonth);
141 
142  if(ier==-1)
143  continue;
144 
145  sprintf(fbuf,"%s%s",fname,mon[k]);
146 
147  fp=fopen(fbuf,"r");
148 
149  if(fp==NULL) {
150 
151  printf("could not open %s\n",fbuf);
152  exit(1);
153 
154  }
155 
156  p=fgets(kbuf,80,fp);
157 
158 
159 /* read in data file */
160 /* i is longitude j is latitude */
161 
162  for(j=0;j<maxj;j++) {
163 
164  fread(kbuf,sizeof(char),maxi*5,fp);
165  kbuf[maxi*5]=0;
166  kk=0;
167 
168 /* read in longitude records */
169 
170  for(i=0;i<maxi;i++) {
171 
172  isoh->value[k][i][j]=atoi(&kbuf[kk]);
173 
174  kk=kk+5;
175 
176  }
177 
178 }
179 
180 fclose(fp);
181 
182 }
183 
184 isohyets_used=1;
185 return;
186 
187 }
188 void get_isoh_pixels(int i, int j, float lat,float lon)
189 
190  {
191 
192  extern struct dval dval;
193  long r,s;
194  float conv=.0174;
195  extern struct isoh *isoh;
196 
197 
198 
199  r=dval.a * cos(lat*conv)/(1+sin(lat*conv))
200  * cos((lon-dval.lo-90)*conv) + dval.xo +.5;
201 
202  isoh->coord[i][j].x=r;
203 
204  s=dval.a * cos(lat*conv)/(1+sin(lat*conv))
205  * sin((lon-dval.lo-90)*conv) + dval.yo + .5;
206 
207  isoh->coord[i][j].y=s;
208 
209  return;
210 
211  }
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
static int i
char fbuf[100]
Definition: decode_HDP.c:2
void get_isohyet_coord(char *fname, int smonth, int emonth)
void get_isoh_pixels(int i, int j, float lat, float lon)
char * mon[]
int is_good(int k, int smonth, int emonth)
Definition: is_good.c:4
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
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
struct isoh * isoh
Definition: mapper.c:144
double max_lat
Definition: mapper.c:22
char fname[100]
Definition: send_afos.c:6
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:538
float delta_lon
Definition: misc.h:549
float max_lon
Definition: misc.h:545
struct coord ** coord
Definition: misc.h:540
float max_lat
Definition: misc.h:544
int maxi
Definition: misc.h:542
float total_lon
Definition: misc.h:547
float total_lat
Definition: misc.h:546
short int *** value
Definition: misc.h:541
float delta_lat
Definition: misc.h:548
int maxj
Definition: misc.h:543