Mapper
get_lisohyet.c
Go to the documentation of this file.
1 #include "prototypes_new.h"
2 
3 float get_lisohyet(float lat,float lon,int mon)
4 
5 {
6 
7 extern struct isoh *isoh;
8 int kk,jj,ix,iy;
9 double distance,value,dist1,dist2,dist,lat1,lon1;
10 float isohyet;
11 float conv=.0174;
12 
13 iy=((isoh->max_lat-lat)/isoh->delta_lat+.00001);
14 ix=((isoh->max_lon-lon)/isoh->delta_lon+.00001);
15 
16 if(ix < 0 || iy < 0 || ix >= isoh->maxi-1 || iy>= isoh->maxj-1)
17  return(-1.0);
18 
19 distance=0.0;
20 value=0.0;
21 
22 for(kk=ix;kk<=ix+1;kk++) {
23 
24 for(jj=iy;jj<=iy+1;jj++) {
25 
26  lat1=isoh->max_lat-isoh->delta_lat*jj;
27 
28  lon1=isoh->max_lon-isoh->delta_lon*kk;
29 
30  dist1=(lon1-lon)*cos((lat1+lat)/2*conv);
31 
32  dist2=lat-lat1;
33 
34  dist=pow(dist1,2)+pow(dist2,2);
35 
36  if(dist < 0.00001)
37  dist=.00001;
38 
39  dist=1/dist;
40 
41  if(isoh->value[mon][kk][jj] <= 0)
42  continue;
43 
44  value=value+dist*(float)isoh->value[mon][kk][jj];
45  distance=distance+dist;
46 
47  }
48  }
49 
50 if(distance==0)
51  return(-1.0);
52 
53 isohyet=value/distance;
54 
55 return(isohyet);
56 
57 
58 }
59 
60 
61 
62 
63 
64 
65 
char * mon[]
float get_lisohyet(float lat, float lon, int mon)
Definition: get_lisohyet.c:3
double lat
Definition: mapp2h.h:41
double lon
Definition: mapp2h.h:41
struct isoh * isoh
Definition: mapper.c:144
float value
Definition: misc.h:538
float delta_lon
Definition: misc.h:549
float max_lon
Definition: misc.h:545
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