Mapper
get_isohyet.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 float get_isohyet(int newx,int newy,int isom)
4 
5 {
6 
7 extern struct isoh *isoh;
8 extern struct dval dval;
9 int kk,jj,ix,iy;
10 float distance,value,dist1,dist2,dist,isohyet;
11 double conv=.0174,lat,lon,c,lonf;
12 double t1,t2,t3,t4,t5,lat1,lat2;
13 
14 t1=.0001;
15 
16 lonf= atan(((double)newy-dval.yo)/(t1))/conv-90.;
17 
18 t1=(double)newx-dval.xo;
19 
20 lon= atan(((double)newy-dval.yo)/(t1))/conv;
21 
22 if(lon > 0)
23  lon=-180+lon-2*lonf;
24 
25 lon=lon+90+dval.lo;
26 
27 c=dval.a*cos((lon-dval.lo-90)*conv)/((double)newx-dval.xo);
28 c=pow(c,2);
29 
30 t1=1/(1+c);
31 t2=1-c;
32 t3=pow(2*t1,2);
33 t4=4*t2*t1;
34 t5=pow(t3-t4,.5)/2;
35 
36 if(fabs(-t1+t5) > 1.0)
37  lat1=-9999;
38 else
39  lat1=asin(-t1+t5)/conv;
40 
41 if(fabs(-t1-t5) > 1.0)
42  lat2=-9999;
43 else
44  lat2=asin(-t1-t5)/conv;
45 
46 if(lat1 > 0 && lat1 < 90)
47  lat=lat1;
48 
49 else
50  lat=lat2;
51 
54 
55 if(ix < 0 || iy < 0 || ix > isoh->maxi-1 || iy> isoh->maxj-1)
56  return(-1.0);
57 
58 distance=0.0;
59 value=0.0;
60 
61 for(kk=ix;kk<=ix+1;kk++) {
62 
63 for(jj=iy;jj<=iy+1;jj++) {
64 
65  dist1=(float)newx-(float)isoh->coord[kk][jj].x;
66  dist2=(float)newy-(float)isoh->coord[kk][jj].y;
67 
68  dist=pow(dist1,2)+pow(dist2,2);
69 
70  if(dist==0.0)
71  dist=1.0;
72 
73  dist=1/dist;
74 
75  value=value+dist*(float)isoh->value[isom][kk][jj];
76  distance=distance+dist;
77 
78  }
79  }
80 
81 isohyet=value/distance;
82 
83 return(isohyet);
84 
85 
86 }
87 
88 
89 
90 
91 
92 
93 
float get_isohyet(int newx, int newy, int isom)
Definition: get_isohyet.c:3
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
struct isoh * isoh
Definition: mapper.c:144
float value
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
short int *** value
Definition: misc.h:541
float delta_lat
Definition: misc.h:548
int maxj
Definition: misc.h:543