#include #include #include void uv2ddff(double u,double v,size_t *dd,double *ff) { /* pass in the u- and v-components and locations for the wind direction and speed, which are calculated by uv2ddff */ const double pi=3.141592654,deg=180./pi; double hypot,div; hypot=sqrt(u*u+v*v); *ff=hypot+0.5; if (*ff < 0.00001) *dd=0; else { div=fabs(v)/hypot; if (div > 1.) { if (div < 1.00001) div=1.; else { fprintf(stderr,"Error in uv2ddff: bad quotient for acos()\n"); exit(1); } } *dd=acos(div)*deg+0.5; if (u >= 0) *dd= (v >= 0) ? *dd+180 : 360-*dd; else if (u <= 0 && v >= 0) *dd=180-*dd; } } void ddff2uv(size_t dd,double ff,double *u,double *v) { /* pass in the wind direction and wind speed and locations for the u- and v- wind components, which are calculated by ddff2uv */ const double pi=3.141592654,rad=pi/180.; double ang; ang=((double)dd+90.)*rad; *u=ff*cos(ang); *v=-ff*sin(ang); }