int main(int argc,char *argv[]) { double alat=58.0; double alon=140.0; double mag=1500.0; double azm=18.0; double blat,blon; RPosCalcVector(alat,alon,mag,azm,&blat,&blon); fprintf(stdout,"RPosCalcVector\n"); fprintf(stdout,"alat=%g, alon=%g, mag=%g, azm=%g\n",alat,alon,mag,azm); fprintf(stdout,"blat=%g blon=%g\n",blat,blon); return 0; }
static PyObject * CalcVector(PyRPosObject *self, PyObject *args, PyObject *kwds) { PyObject *location=NULL,*list=NULL, *timetuple=NULL; double lat=0,lon=0,mag, azm; double clat, clon; char *radarcode; int stid; struct RadarNetwork *network; struct Radar *radar; struct RadarSite *site; static char *kwlist[] = {"mag","azm","location","radarcode","radarid",NULL}; char *envstr=NULL; FILE *fp; int yr,mo,dy,hr,mt; double sc; yr=2008; mo=7; dy=12; hr=12; mt=0; sc=0; radarcode="kod"; stid=-1; if (! PyArg_ParseTupleAndKeywords(args, kwds, "dd|Osi", kwlist, &mag,&azm,&location,&radarcode,&stid)) return NULL; if ( timetuple != NULL) { if (PyDateTime_Check(timetuple)) { yr=PyDateTime_GET_YEAR(timetuple); mo=PyDateTime_GET_MONTH(timetuple); dy=PyDateTime_GET_DAY(timetuple); hr=PyDateTime_DATE_GET_HOUR(timetuple); mt=PyDateTime_DATE_GET_MINUTE(timetuple); sc=PyDateTime_DATE_GET_SECOND(timetuple); } } if ( location != NULL) { if (PyTuple_Check(location) && PyTuple_Size(location)==2) { lat=PyFloat_AS_DOUBLE(PyTuple_GetItem(location,0)); lon=PyFloat_AS_DOUBLE(PyTuple_GetItem(location,1)); } } else { envstr=getenv("SD_RADAR"); if (envstr==NULL) { fprintf(stderr,"Environment variable 'SD_RADAR' must be defined.\n"); exit(-1); } fp=fopen(envstr,"r"); if (fp==NULL) { fprintf(stderr,"Could not locate radar information file.\n"); exit(-1); } network=RadarLoad(fp); fclose(fp); if (network==NULL) { fprintf(stderr,"Failed to read radar information.\n"); exit(-1); } envstr=getenv("SD_HDWPATH"); if (envstr==NULL) { fprintf(stderr,"Environment variable 'SD_HDWPATH' must be defined.\n"); exit(-1); } RadarLoadHardware(envstr,network); if (stid==-1) { stid=RadarGetID(network,radarcode); } radar=RadarGetRadar(network,stid); site=RadarYMDHMSGetSite(radar,yr,mo,dy,hr,mt,(int) sc); lat=site->geolat; lon=site->geolon; } RPosCalcVector(lat,lon,mag,azm,&clat,&clon); list = PyList_New(0); PyList_Append(list,Py_BuildValue("d",clat)); PyList_Append(list,Py_BuildValue("d",clon)); return list; }