Esempio n. 1
0
int main(int argc,char *argv[]) {
  char *envstr;
  FILE *fp;
  int codenum=0;
  char *code=NULL;
  int st,c;

  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);
  }
  
  st=atoi(argv[argc-1]);

  codenum=RadarGetCodeNum(network,st);

  fprintf(stdout,"RadarGetCode\n"); 
  for (c=0;c<codenum;c++) {
    code=RadarGetCode(network,st,c);
    fprintf(stdout,"%s\n",code);
  }

  return 0;
}
Esempio n. 2
0
int main(int argc,char *argv[])
{

  /* File format transistion
   * ------------------------
   *
   * When we switch to the new file format remove any reference
   * to "new". Change the command line option "new" to "old" and
   * remove "old=!new".
   */


  char *envstr;
  int status;
  int arg;

  unsigned char help=0;
  unsigned char option=0;

  unsigned char vb=0;

  FILE *fp=NULL;
  struct OldRawFp *rawfp=NULL;
  int irec=1;
  int drec=2;
  int dnum=0;

  time_t ctime;
  int c,n;
  char command[128];
  char tmstr[40];

  prm=RadarParmMake();
  raw=RawMake();

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
  OptionAdd(&opt,"vb",'x',&vb);

  arg=OptionProcess(1,argc,argv,&opt,NULL);

  if (help==1)
	{
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1)
	{
    OptionDump(stdout,&opt);
    exit(0);
  }


  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 (arg==argc) fp=stdin;
	else fp=fopen(argv[arg],"r");

	if (fp==NULL)
	{
		fprintf(stderr,"File not found.\n");
		exit(-1);
	}
	status=RawFread(fp,prm,raw);


  radar=RadarGetRadar(network,prm->stid);
  if (radar==NULL)
	{
    fprintf(stderr,"Failed to get radar information.\n");
    exit(-1);
  }

  site=RadarYMDHMSGetSite(radar,prm->time.yr,prm->time.mo,
		          prm->time.dy,prm->time.hr,prm->time.mt,
                          prm->time.sc);

  if (site==NULL)
	{
    fprintf(stderr,"Failed to get site information.\n");
    exit(-1);
  }


  command[0]=0;
  n=0;
  for (c=0;c<argc;c++)
	{
    n+=strlen(argv[c])+1;
    if (n>127) break;
    if (c !=0) strcat(command," ");
    strcat(command,argv[c]);
  }



  if (vb)
      fprintf(stderr,"%d-%d-%d %d:%d:%d beam=%d\n",prm->time.yr,prm->time.mo,
	     prm->time.dy,prm->time.hr,prm->time.mt,prm->time.sc,prm->bmnum);

  do
  {
    ctime = time((time_t) 0);
    RadarParmSetOriginCommand(prm,command);
    strcpy(tmstr,asctime(gmtime(&ctime)));
    tmstr[24]=0;
    RadarParmSetOriginTime(prm,tmstr);

		prm->lagfr = 2400;
		prm->frang = 360;

    status=RawFwrite(stdout,prm,raw);

    status=RawFread(fp,prm,raw);

     if (vb)
      fprintf(stderr,"%d-%d-%d %d:%d:%d beam=%d\n",prm->time.yr,prm->time.mo,
	     prm->time.dy,prm->time.hr,prm->time.mt,prm->time.sc,prm->bmnum);



  } while (status==0);


  return 0;
}
Esempio n. 3
0
int main(int argc,char *argv[]) {
  char *envstr; 
  FILE *fp;

  int s;

  int state=0;

  int yr,mo,dy,hr,mt;
  double sc;

  int iflg=0;
  int avlen=120;
  unsigned char xtd=0;
  char wrtlog[256];

  int pval=0;
  double min[4]={35,3,10,0};
  double max[4]={2000,50,1000,200};
  int tflg=0;

  double alt=300.0;

  grid.st_time=-1;
  grid.status=0;
  grid.pnt=NULL;  
  grid.gsct=0;
  grid.chn=0;


  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);


  fp=fopen(argv[1],"r");

  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }

  while(FitFreadRadarScan(fp,&state,&scn,&prm,&fit,0,0,0) !=-1) {
    TimeEpochToYMDHMS(scn.st_time,&yr,&mo,&dy,&hr,&mt,&sc);

    fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
            yr,mo,dy,hr,mt,(int) sc);

    FilterBoundType(&scn,tflg);
    FilterBound(pval,&scn,min,max);
 

    if (site==NULL) {
       radar=RadarGetRadar(network,scn.stid);
       if (radar==NULL) {
         fprintf(stderr,"Failed to get radar information.\n");
         exit(-1);
       }

       site=RadarYMDHMSGetSite(radar,prm.time.yr,prm.time.mo,
		          prm.time.dy,prm.time.hr,prm.time.mt,
                          prm.time.sc);
     
    }

    s=GridTableTest(&grid,&scn,avlen);
    
    if (s==1) {
      GridTableFwrite(stdout,&grid,wrtlog,xtd);

    }
    
    if (scn.num>=16) GridTableMap(&grid,&scn,site,avlen,iflg,alt);     
  
  }


  
 
  fclose(fp);


  return 0;
}
Esempio n. 4
0
int main(int argc,char *argv[]) {
 
  FILE *fp;
  char *envstr;
  int s;
 
  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);

  fp=fopen(argv[1],"r");

  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }

  s=RawFread(fp,&prm,&raw);

  if (s==-1) {
     fprintf(stderr,"Error reading file.\n");
    exit(-1);
  }
    
  radar=RadarGetRadar(network,prm.stid);
  if (radar==NULL) {
    fprintf(stderr,"Failed to get radar information.\n");
    exit(-1);
  }

  site=RadarYMDHMSGetSite(radar,prm.time.yr,prm.time.mo,
		          prm.time.dy,prm.time.hr,prm.time.mt,
                          prm.time.sc);

  if (site==NULL) {
    fprintf(stderr,"Failed to get site information.\n");
    exit(-1);
  }

  FitACFStart(site,prm.time.yr,&fblk); 

  do {
    fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
             prm.time.yr,prm.time.mo,prm.time.dy,
             prm.time.hr,prm.time.mt,prm.time.sc);

    FitACF(&prm,&raw,&fblk,&fit);
    s=FitFwrite(stdout,&prm,&fit);
    s=RawFread(fp,&prm,&raw);


  } while (s !=-1);
 
  FitACFEnd(&fblk);

  fclose(fp);


  return 0;
}
Esempio n. 5
0
int main(int argc,char *argv[])
{
  /*declarations*/
  int arg = 0;
  double pi = 3.14159;
  FILE *fp;
  FILE *mfp = NULL;
  char *envstr;
  unsigned char help = 0;
  unsigned char option = 0;
  int s = 0, vb=0;


  envstr=getenv("SD_RADAR");
  if(envstr==NULL)
  {
    fprintf(stderr,"Environment variable 'SD_RADAR' must be defined.\n");
    return -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);

  /*add options to control performance*/
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
  OptionAdd(&opt,"vb",'x',&vb);

  /*process the options*/
  arg=OptionProcess(1,argc,argv,&opt,NULL);
  if(option == 1)
  {
    OptionDump(stdout,&opt);
    exit(0);
  }


	struct MergeData * data = malloc(sizeof(struct MergeData));
	memset(data,0,sizeof(struct MergeData));

	mfp=fopen(argv[arg],"r");
	fprintf(stderr,"%s\n",argv[arg]);
	if(fp==NULL)
  {
    fprintf(stderr,"File %s not found.\n",argv[arg]);
    exit(-1);
  }

	MergeFread(mfp,data);

  radar1=RadarGetRadar(network,data->radar1.stid);
  if (radar1==NULL)
  {
    fprintf(stderr,"Failed to get radar information.\n");
    exit(-1);
  }

  radar2=RadarGetRadar(network,data->radar2.stid);
  if (radar1==NULL)
  {
    fprintf(stderr,"Failed to get radar information.\n");
    exit(-1);
  }


	fclose(mfp);
	free(data);

  return 0;
}
Esempio n. 6
0
int main(int argc,char *argv[]) {



#ifdef _XLIB_
  int xdf=0;
  int xd=0;
  struct XwinDisplay *dp;
  struct XwinWindow *win;
  char *display_name=NULL;
  char *wname="fov_plot";
  int xdoff=-1;
  int ydoff=-1;
#endif

  struct FrameBuffer *img=NULL;
  struct PostScript *psdata=NULL;
  FILE *fontfp=NULL;
  char *fntdbfname=NULL;
  struct FrameBufferFontDB *fontdb=NULL;
  unsigned int bgcol;
  unsigned int txtcol;

  int arg;

  char *envstr=NULL;
  char *cfname=NULL;
  FILE *fp;



  float wdt=540,hgt=540;
  float pad=0;

  char *fontname=NULL;
  float fontsize=10.0;
  char *dfontname="Helvetica";

  float width=0.5;

  struct Plot *plot=NULL;
  struct Splot *splot=NULL;

  float xpoff=40,ypoff=40;
  unsigned char psflg=0;
  unsigned char xmlflg=0;
  unsigned char ppmflg=0;
  unsigned char ppmxflg=0;
  unsigned char pngflg=0;

  unsigned char gflg=0;
  unsigned char pflg=0;


  unsigned char help=0; 
  unsigned char option=0; 

  char *bgcol_txt=NULL;
  char *txtcol_txt=NULL;


  unsigned char sqflg=0;
  MapTFunction  tfunc;

  unsigned char flip=0;
  unsigned char gvp=0;
  unsigned char ortho=0;
  unsigned char stereo=0;
  unsigned char cylind=0;

  float lat=90,lon=0;
  float latmin=50.0;
  float sf=1.0;
  float alt=0.0; 

  unsigned char magflg=0;
  unsigned char rotflg=0;

  unsigned char mapflg=0;
  unsigned char fmapflg=0;
  unsigned char bndflg=0;
  unsigned char grdflg=0;
  unsigned char tmkflg=0;
  unsigned char tlblflg=0;
  unsigned char ofovflg=0;
  unsigned char fofovflg=0;

  unsigned char cfovflg=0;
  unsigned char fcfovflg=0;

  unsigned char fovflg=0;
  unsigned char ffovflg=0;

  unsigned char grdontop=0;

  unsigned char dotflg=0;

  int tmtick=3;

  unsigned char lstflg=0;
  unsigned char trmflg=0;
  unsigned char ftrmflg=0;

  char *grdcol_txt=NULL;
  char *cstcol_txt=NULL;
  char *bndcol_txt=NULL;
  char *lndcol_txt=NULL;
  char *seacol_txt=NULL;
  char *trmcol_txt=NULL;
  char *ftrmcol_txt=NULL;
  char *tmkcol_txt=NULL;
  char *ofovcol_txt=NULL;
  char *fofovcol_txt=NULL;
  char *fovcol_txt=NULL;
  char *ffovcol_txt=NULL;

  char *cfovcol_txt=NULL;
  char *fcfovcol_txt=NULL;


  unsigned int grdcol;
  unsigned int cstcol;
  unsigned int bndcol;
  unsigned int lndcol;
  unsigned int seacol;
  unsigned int trmcol;
  unsigned int ftrmcol;
  unsigned int tmkcol;
  unsigned int ofovcol;
  unsigned int fofovcol;
  unsigned int fovcol;
  unsigned int ffovcol;

  unsigned int cfovcol;
  unsigned int fcfovcol;
  

  FILE *mapfp;
  float marg[4];
  int i;

  char *tmetxt=NULL;
  char *dtetxt=NULL;

  double tval=-1;
  double dval=-1;

  int yr,mo,dy,hr,mt;
  double sc;
  int yrsec;
  float tme_shft;



  double LsoT,LT,Hangle,dec,eqt;
  
  float dotr=2; 
 
  int stid=-1;
  char *ststr=NULL;
  int stnum=0;

  char tsfx[16];


  envstr=getenv("MAPDATA");

  mapfp=fopen(envstr,"r");
  map=MapFread(mapfp);
  fclose(mapfp);   

  envstr=getenv("BNDDATA");
  mapfp=fopen(envstr,"r");
  bnd=MapBndFread(mapfp);
  fclose(mapfp);

 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);


  bgcol=PlotColor(0xff,0xff,0xff,0xff);
  txtcol=PlotColor(0x00,0x00,0x00,0xff);

  grdcol=PlotColor(0x20,0x40,0x60,0xff);
  cstcol=PlotColor(0xa0,0xa0,0xa0,0xff);
  bndcol=PlotColor(0x80,0x80,0x80,0xff);
  lndcol=PlotColor(0xff,0xff,0xf0,0xff);
  seacol=PlotColor(0xe0,0xf0,0xff,0xff);
  tmkcol=PlotColor(0x00,0x00,0x00,0xff);
  ofovcol=PlotColor(0x00,0x00,0x00,0xff);
  fofovcol=PlotColor(0xff,0xff,0xff,0xff);
  fovcol=PlotColor(0x00,0x00,0x00,0xff);
  ffovcol=PlotColor(0xc0,0x00,0x00,0xff);
  trmcol=PlotColor(0x80,0x80,0x80,0xff);
  ftrmcol=PlotColor(0x80,0x80,0x80,0xff);

  cfovcol=PlotColor(0x00,0x00,0x00,0xff);
  fcfovcol=PlotColor(0xff,0xff,0xff,0xff);
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"cf",'t',&cfname);


#ifdef _XLIB_ 
  OptionAdd(&opt,"x",'x',&xd);
  OptionAdd(&opt,"display",'t',&display_name);
  OptionAdd(&opt,"xoff",'i',&xdoff);
  OptionAdd(&opt,"yoff",'i',&ydoff);
#endif

  OptionAdd(&opt,"ppm",'x',&ppmflg);
  OptionAdd(&opt,"ppmx",'x',&ppmxflg);
  OptionAdd(&opt,"xml",'x',&xmlflg);
  OptionAdd(&opt,"png",'x',&pngflg);
  OptionAdd(&opt,"ps",'x',&psflg); 

  OptionAdd(&opt,"xp",'f',&xpoff);
  OptionAdd(&opt,"yp",'f',&ypoff);
  OptionAdd(&opt,"wdt",'f',&wdt);
  OptionAdd(&opt,"hgt",'f',&hgt);
  OptionAdd(&opt,"pad",'f',&pad);

  OptionAdd(&opt,"bgcol",'t',&bgcol_txt);
  OptionAdd(&opt,"txtcol",'t',&txtcol_txt);

  OptionAdd(&opt,"square",'x',&sqflg);

  OptionAdd(&opt,"ortho",'x',&ortho);
  OptionAdd(&opt,"stereo",'x',&stereo);
  OptionAdd(&opt,"gvp",'x',&gvp);

  OptionAdd(&opt,"lat",'f',&lat);
  OptionAdd(&opt,"lon",'f',&lon);
  OptionAdd(&opt,"latmin",'f',&latmin);
  OptionAdd(&opt,"sf",'f',&sf);
  OptionAdd(&opt,"mag",'x',&magflg);
  OptionAdd(&opt,"rotate",'x',&rotflg);
  OptionAdd(&opt,"alt",'f',&alt);
  OptionAdd(&opt,"flip",'x',&flip);

  OptionAdd(&opt,"coast",'x',&mapflg);
  OptionAdd(&opt,"fcoast",'x',&fmapflg);
  OptionAdd(&opt,"bnd",'x',&bndflg);
  OptionAdd(&opt,"grd",'x',&grdflg);
  OptionAdd(&opt,"tmk",'x',&tmkflg);

 OptionAdd(&opt,"grdontop",'x',&grdontop);


  OptionAdd(&opt,"fov",'x',&fovflg);
  OptionAdd(&opt,"ffov",'x',&ffovflg);

  OptionAdd(&opt,"ofov",'x',&ofovflg);
  OptionAdd(&opt,"fofov",'x',&fofovflg);

  OptionAdd(&opt,"cfov",'x',&cfovflg);
  OptionAdd(&opt,"fcfov",'x',&fcfovflg);

  OptionAdd(&opt,"tmtick",'i',&tmtick);
  OptionAdd(&opt,"lst",'x',&lstflg);
  OptionAdd(&opt,"term",'x',&trmflg);
  OptionAdd(&opt,"fterm",'x',&ftrmflg);

  OptionAdd(&opt,"grdcol",'t',&grdcol_txt);
  OptionAdd(&opt,"cstcol",'t',&cstcol_txt);
  OptionAdd(&opt,"bndcol",'t',&bndcol_txt);
  OptionAdd(&opt,"lndcol",'t',&lndcol_txt);
  OptionAdd(&opt,"seacol",'t',&seacol_txt);
  OptionAdd(&opt,"trmcol",'t',&trmcol_txt);
  OptionAdd(&opt,"tmkcol",'t',&tmkcol_txt);
 
  OptionAdd(&opt,"fovcol",'t',&fovcol_txt);
  OptionAdd(&opt,"ffovcol",'t',&ffovcol_txt);
  OptionAdd(&opt,"ofovcol",'t',&ofovcol_txt);
  OptionAdd(&opt,"fofovcol",'t',&fofovcol_txt);

  OptionAdd(&opt,"cfovcol",'t',&cfovcol_txt);
  OptionAdd(&opt,"fcfovcol",'t',&fcfovcol_txt);

  OptionAdd(&opt,"st",'t',&ststr);

  OptionAdd(&opt,"t",'t',&tmetxt);
  OptionAdd(&opt,"d",'t',&dtetxt);
  
  OptionAdd(&opt,"tmlbl",'x',&tlblflg);

  OptionAdd(&opt,"fontname",'t',&fontname);
  OptionAdd(&opt,"fontsize",'f',&fontsize);
  OptionAdd(&opt,"lnewdt",'f',&width);

  OptionAdd(&opt,"dotr",'f',&dotr);
  OptionAdd(&opt,"dot",'x',&dotflg);


  arg=OptionProcess(1,argc,argv,&opt,NULL);  

  if (cfname !=NULL) { /* load the configuration file */
    int farg;
    do {
      fp=fopen(cfname,"r");
      if (fp==NULL) break;
      free(cfname);
      cfname=NULL;
      optf=OptionProcessFile(fp);
      if (optf !=NULL) {
        farg=OptionProcess(0,optf->argc,optf->argv,&opt,NULL);
        OptionFreeFile(optf);
       }   
       fclose(fp);
    } while (cfname !=NULL);
  }

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }


  if (tmetxt !=NULL) tval=strtime(tmetxt);
  if (dtetxt !=NULL) dval=strdate(dtetxt);

  tval+=dval;
  TimeEpochToYMDHMS(tval,&yr,&mo,&dy,&hr,&mt,&sc);
  yrsec=TimeYMDHMSToYrsec(yr,mo,dy,hr,mt,sc);

  if (magflg) {
    MapModify(map,AACGMtransform,NULL);
    MapModify(bnd,AACGMtransform,NULL);
  }

  fov=make_fov(tval,network,alt); 

  if (magflg) MapModify(fov,AACGMtransform,NULL);


  if (tmtick<1) tmtick=1;
  if (tmtick>6) tmtick=6;

  if ((ortho==0) && (stereo==0)) cylind=1;

  if (grdflg) grd=make_grid(15,10,cylind);   
 
  if (tmkflg) tmk=make_grid(30*tmtick,10,cylind);

  if ((lat<0) && (latmin>0)) latmin=-latmin;
  if ((lat>0) && (latmin<0)) latmin=-latmin;

  if (trmflg || ftrmflg) {
    if ((cylind) || (ortho) | (gvp))
       trm=SZATerminator(yr,mo,dy,hr,mt,sc,0,magflg,
                           1.0,90.0);
     else if (lat>0) trm=SZATerminator(yr,mo,dy,hr,mt,sc,1,magflg,
                                     1.0,90.0);
     else trm=SZATerminator(yr,mo,dy,hr,mt,sc,-1,magflg,1.0,90.0);
  }
 
  marg[0]=lat;
  marg[1]=lon;

  tfunc=MapCylindrical;
  if (ortho) tfunc=MapOrthographic;
  if (stereo) tfunc=MapStereographic;
  if (gvp) tfunc=MapGeneralVerticalPerspective;

  if ((ortho) || (gvp)) marg[2]=sf;
  else if (stereo) marg[2]=1.25*0.5*sf*90.0/(90-fabs(latmin));
  else marg[2]=1;
  marg[3]=flip;

  strcpy(tsfx,"LT");
  if (magflg) strcpy(tsfx,"MLT");
  else if (lstflg) strcpy(tsfx,"LST");

  dec=SZASolarDec(yr,mo,dy,hr,mt,sc);
  eqt=SZAEqOfTime(yr,mo,dy,hr,mt,sc);

  if (magflg) tme_shft=-MLTConvertYrsec(yr,yrsec,0.0)*15.0; 
    else {
      if (lstflg) {
        LsoT=(hr*3600+mt*60+sc)+eqt;
        Hangle=15*(LsoT/3600);
        tme_shft=-Hangle;
      } else {
        LT=(hr*3600+mt*60+sc);
        Hangle=15*(LT/3600);
        tme_shft=-Hangle;
      }
    }
  if (lat<0) tme_shft+=180.0;

  if (rotflg)  marg[1]=lon+tme_shft;
  
  if ((cylind) || (sqflg)) clip=MapSquareClip(); 
  else clip=MapCircleClip(10); 

  if (mapflg || fmapflg) {
     nmap=MapTransform(map,2*sizeof(float),PolygonXYbbox,
                           tfunc,marg);
     if (cylind) nmap=wrap(nmap);
     pmap=PolygonClip(clip,nmap); 
  }
  if (bndflg) {
     nbnd=MapTransform(bnd,2*sizeof(float),PolygonXYbbox,
                      tfunc,marg);
     if (cylind) nbnd=wrap(nbnd);
     pbnd=PolygonClip(clip,nbnd);
  }
  if (grdflg) {
     ngrd=MapTransform(grd,2*sizeof(float),PolygonXYbbox,
                      tfunc,marg);
     if (cylind) ngrd=wrap(ngrd);
     pgrd=PolygonClip(clip,ngrd);
  }
  if (trmflg || ftrmflg) {
     ntrm=MapTransform(trm,2*sizeof(float),PolygonXYbbox,
                           tfunc,marg);
     if (cylind) ntrm=wrap(ntrm);
     ptrm=PolygonClip(clip,ntrm); 
  }

  nfov=MapTransform(fov,2*sizeof(float),PolygonXYbbox,
                     tfunc,marg);
  if (cylind) nfov=wrap(nfov);
  pfov=PolygonClip(clip,nfov);

  if (tmkflg) {
     float tmp;
     tmp=marg[1];
     if (rotflg) marg[1]=0;
     else marg[1]=lon-tme_shft;
     ntmk=MapTransform(tmk,2*sizeof(float),PolygonXYbbox,
                        tfunc,marg);
     ptmk=PolygonClip(clip,ntmk);
     marg[1]=tmp;
  }


  if (bgcol_txt !=NULL) bgcol=PlotColorStringRGBA(bgcol_txt);
  if (txtcol_txt !=NULL) txtcol=PlotColorStringRGBA(txtcol_txt);

  if (grdcol_txt !=NULL) grdcol=PlotColorStringRGBA(grdcol_txt);
  if (cstcol_txt !=NULL) cstcol=PlotColorStringRGBA(cstcol_txt);
  if (bndcol_txt !=NULL) bndcol=PlotColorStringRGBA(bndcol_txt);
  if (lndcol_txt !=NULL) lndcol=PlotColorStringRGBA(lndcol_txt);
  if (seacol_txt !=NULL) seacol=PlotColorStringRGBA(seacol_txt);
  if (trmcol_txt !=NULL) trmcol=PlotColorStringRGBA(trmcol_txt);
  if (ftrmcol_txt !=NULL) ftrmcol=PlotColorStringRGBA(ftrmcol_txt);

  if (tmkcol_txt !=NULL) tmkcol=PlotColorStringRGBA(tmkcol_txt);

  if (fovcol_txt !=NULL) fovcol=PlotColorStringRGBA(fovcol_txt);
  if (ofovcol_txt !=NULL) ofovcol=PlotColorStringRGBA(ofovcol_txt);
  if (cfovcol_txt !=NULL) cfovcol=PlotColorStringRGBA(cfovcol_txt);
 
  if (ffovcol_txt !=NULL) ffovcol=PlotColorStringRGBA(ffovcol_txt);
  if (fofovcol_txt !=NULL) fofovcol=PlotColorStringRGBA(fofovcol_txt);
  if (fcfovcol_txt !=NULL) fcfovcol=PlotColorStringRGBA(fcfovcol_txt);


  if ((wdt==0) || (hgt==0)) {
    fprintf(stderr,"invalid plot size.\n");
    exit(-1);
  }


  if (tlblflg) pad=10+fontsize;
  
  if (fontname==NULL) fontname=dfontname;

  fntdbfname=getenv("FONTDB");
  fontfp=fopen(fntdbfname,"r");
  if (fontfp !=NULL) {
   fontdb=FrameBufferFontDBLoad(fontfp);
   fclose(fontfp);
  }
 
  if (fontdb==NULL) {
   fprintf(stderr,"Could not load fonts.\n");
   exit(-1);
  }


  if (ststr !=NULL) stid=RadarGetID(network,ststr);
  for (stnum=0;stnum<network->rnum;stnum++) 
     if (stid==network->radar[stnum].id) break;  
  if (stnum==network->rnum) stnum=0;



  /* now determine our output type */

  if (psflg) pflg=1;
  if (xmlflg) gflg=1;
  if (ppmflg) gflg=1;
  if (ppmxflg) gflg=1;
  if (pngflg) gflg=1;

#ifdef _XLIB_ 
   if (xd !=0) {
     pflg=0; 
     gflg=1;
   }
#endif

  if (pflg) gflg=0;
  if ((!gflg) && (!pflg)) pflg=1;

  plot=PlotMake();
  splot=SplotMake();
  SplotSetPlot(plot,splot);

  if (gflg) SplotSetFrameBuffer(splot,&img,fontdb,NULL,NULL);
  if (pflg) {
    psdata=PostScriptMake();
    PostScriptSetText(psdata,stream,stdout);
    SplotSetPostScript(splot,psdata,0,xpoff,ypoff);
  }



  PlotDocumentStart(plot,"fov_plot",NULL,wdt,hgt,24);
  PlotPlotStart(plot,"fov_plot",wdt,hgt,24);

  PlotRectangle(plot,NULL,0,0,wdt,hgt,1,bgcol,0x0f,0,NULL);
     
  if (fmapflg) {
      if ((cylind) || (sqflg)) PlotRectangle(plot,NULL,pad,pad,
                               wdt-2*pad,hgt-2*pad,  
                             1,seacol,0x0f,0,NULL);
      PlotEllipse(plot,NULL,wdt/2,hgt/2,wdt/2-pad,hgt/2-pad,
                   1,seacol,0x0f,0,NULL);
  }

  if ((grdflg) && (!grdontop)) {
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                                grdcol,0x0f,width,NULL,
                                pgrd,1);
  }

  if (fmapflg) {
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   lndcol,0x0f,0,NULL,pmap,1);
  
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   lndcol,0x0f,0,NULL,pmap,3);
  
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   seacol,0x0f,0,NULL,pmap,0);
  }

  if (ftrmflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                             1,ftrmcol,0x0f,0,NULL,ptrm,1);

  
  if (fofovflg) {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=1) continue;
      MapPlotPolygon(plot,NULL,pad,pad,
                   wdt-2*pad,hgt-2*pad,1,fofovcol,0x0f,0,NULL,pfov,i); 
    }
  }

  if (fcfovflg) {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status!=0) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                       fcfovcol,0x0f,0,NULL,pfov,i); 
    }
  }


   if (ffovflg) {
    MapPlotPolygon(plot,NULL,pad,pad,
                 wdt-2*pad,hgt-2*pad,1,ffovcol,0x0f,0,NULL,pfov,stnum); 
   }
  

  if (mapflg) {
     MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,cstcol,0x0f,
                    width,NULL,
                    pmap,1);
  
     MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,cstcol,0x0f,
                    width,NULL,
                    pmap,2);
  
     MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,cstcol,0x0f,
                    width,NULL,
                    pmap,0);
  }

  if (ofovflg)  {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=1) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    ofovcol,0x0f,width,NULL,
                    pfov,i);
    } 
  }

 if (cfovflg)  {
   
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=0) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    cfovcol,0x0f,width,NULL,
                    pfov,i);
    } 
  }

 if (dotflg) {
   int s=0;
   struct RadarSite *site; 
   float pnt[2]; 
   if (cfovflg | fcfovflg)  {
     for (i=0;i<network->rnum;i++) {
       if (network->radar[i].id==stid) continue;
       if (network->radar[i].status !=0) continue;
       site=RadarYMDHMSGetSite(&(network->radar[i]),yr,mo,dy,hr,mt,sc);
       pnt[0]=site->geolat;
       pnt[1]=site->geolon; 
       s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
       if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,fcfovcol,0x0f,0,NULL);
           
     } 
   }
   if (ofovflg | fofovflg)  {
     for (i=0;i<network->rnum;i++) {
       if (network->radar[i].id==stid) continue;
       if (network->radar[i].status !=1) continue;
       site=RadarYMDHMSGetSite(&(network->radar[i]),yr,mo,dy,hr,mt,sc);
       pnt[0]=site->geolat;
       pnt[1]=site->geolon; 
       s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
       if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,fofovcol,0x0f,0,NULL);
           
     } 
   }

   if (fovflg) {
     
     site=RadarYMDHMSGetSite(&(network->radar[stnum]),yr,mo,dy,hr,mt,sc);
     pnt[0]=site->geolat;
     pnt[1]=site->geolon; 
     s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
     if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,ffovcol,0x0f,0,NULL);
   }


 }

  if (fovflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    fovcol,0x0f,width,NULL,
                    pfov,stnum);

  if (bndflg) MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                                bndcol,0x0f,width,NULL,
                                pbnd,-1);

  if (trmflg) MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                                trmcol,0x0f,width,NULL,
                                ptrm,1);

  if (tmkflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                                tmkcol,0x0f,width,NULL,
                                ptmk,1);

  if ((grdflg) && (grdontop)) {
    MapPlotPolygon(plot,NULL,0,0,wdt-2*pad,hgt-2*pad,0,
                                grdcol,0x0f,width,NULL,
                                pgrd,1);
  }


  if ((cylind) || (sqflg)) 
     PlotRectangle(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
               0,grdcol,0x0f,width,NULL);
  else PlotEllipse(plot,NULL,wdt/2,hgt/2,wdt/2-pad,hgt/2-pad,
               0,grdcol,0x0f,width,NULL);

  if (tlblflg){
      if (lat>0) plot_time_label(plot,pad,pad,wdt-2*pad,hgt-2*pad,
				 90,flip,tsfx,
                                 lon-tme_shft*(! rotflg),
                                 (wdt/2)-pad,6,
                                 txtcol,0x0f,fontname,fontsize,fontdb);
      else plot_time_label(plot,pad,pad,wdt-2*pad,hgt-2*pad,
			   -90,flip,tsfx,
                           lon-tme_shft*(! rotflg),
                           (wdt/2)-pad,6,
                           txtcol,0x0f,fontname,fontsize,fontdb);
  }

  PlotPlotEnd(plot);  
  PlotDocumentEnd(plot);

  if (!gflg) exit(0);
  if (img==NULL) {
    fprintf(stderr,"Nothing to plot.\n");
    exit(-1);
  }

#ifdef _XLIB_
  if (xd !=0) {
    dp=XwinOpenDisplay(display_name,&xdf);
 
    if (dp==NULL) {
      fprintf(stderr,"Could not open display.\n");
      exit(-1);
    }

    if (xdoff==-1) xdoff=(dp->wdt-img->wdt)/2;
    if (ydoff==-1) ydoff=(dp->hgt-img->hgt)/2;


    win=XwinMakeWindow(xdoff,ydoff,img->wdt,img->hgt,0,
                       dp,wname,
                       wname,argv[0],wname,argc,argv,&xdf);
    if (win==NULL) {
      fprintf(stderr,"Could not create window.\n");
      exit(-1);
    }

    XwinFrameBufferWindow(img,win);

    XwinShowWindow(win);

    XwinDisplayEvent(dp,1,&win,1,NULL);

    XwinFreeWindow(win);
    XwinCloseDisplay(dp);
  } else {
    if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
    else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
    else if (ppmxflg==1)  FrameBufferSavePPMX(img,stdout);
    else FrameBufferSavePNG(img,stdout);
  }
  #else 
    if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
    else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
    else if (ppmxflg==1) FrameBufferSavePPMX(img,stdout);
    else FrameBufferSavePNG(img,stdout); 
  #endif
    return 0;
}  
static PyObject *
PosMag(PyRPosObject *self, PyObject *args, PyObject *kwds)
{
  PyObject *list=NULL, *timetuple=NULL;
  char *radarcode;
  struct RadarNetwork *network;
  struct Radar *radar;
  struct RadarSite *site;
  int center, bcrd, rcrd;
  int frang,rsep,rxrise,height;
  int yr,mo,dy,hr,mt;
  double sc;
  int stid;
  double rho,lat,lng;
  char *envstr=NULL;
  FILE *fp;
  int r,c;
  static char *kwlist[] = {"center","bcrd","rcrd","frang","rsep","rxrise","height", "radarcode","radarid","time",NULL};
  PyDateTime_IMPORT;
  center=0;
  bcrd=1;
  rcrd=15;
  frang=1200;
  rxrise=0;
  rsep=100;
  height=300;
  radarcode="kod";
  stid=-1;
  yr=2008;
  mo=7;
  dy=12;
  hr=12;
  mt=0;
  sc=0; 

  if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiiiiiisiO", kwlist, 
                                      &center,&bcrd,&rcrd,&frang,&rsep,&rxrise,&height,&radarcode,&stid,&timetuple))
     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);   
    }
  }
  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);
  RPosMag(center,bcrd,rcrd,site,frang,rsep,rxrise,height,&rho,&lat,&lng);
  radar=NULL;
  site=NULL;
  for (r=0;r<network->rnum;r++) {
    for (c=0;c<network->radar[r].cnum;c++) { 
      if (network->radar[r].code[c] !=NULL) free(network->radar[r].code[c]);
    } 
    if (network->radar[r].code !=NULL) free(network->radar[r].code);
    if (network->radar[r].name !=NULL) free(network->radar[r].name);
    if (network->radar[r].operator !=NULL) free(network->radar[r].operator);
    if (network->radar[r].hdwfname !=NULL) free(network->radar[r].hdwfname);
    if (network->radar[r].site !=NULL) free(network->radar[r].site);
  }
  free(network->radar);
  free(network);
  list = PyList_New(0);
  PyList_Append(list,Py_BuildValue("d",rho));
  PyList_Append(list,Py_BuildValue("d",lat));
  PyList_Append(list,Py_BuildValue("d",lng));
  return list;  
}
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;  

}
Esempio n. 9
0
int main(int argc,char *argv[]) {
    int arg=0,farg;
    int yr,mo,dy,hr,mt,isc,usc;
    double sc;
    int st=0;
    FILE *fp;
    char *envstr;
    char *tmetxt=NULL,*dtetxt=NULL;
    double tval=0,dval=0;



    char *nlab[2]= {"","name:"};
    char *slab[2]= {"","status:"};
    char *olab[2]= {"","operator:"};
    char *clab[2]= {"","code:"};
    char *ilab[2]= {"","id:"};
    char *hlab[2]= {"","location:"};
    char *plab[2]= {"","pole:"};

    unsigned char nflg=0;
    unsigned char sflg=0;
    unsigned char oflg=0;
    unsigned char cflg=0;
    unsigned char iflg=0;
    unsigned char hflg=0;
    unsigned char pflg=0;
    unsigned char lflg=0;

    unsigned char aflg=0;

    unsigned char stflg=0;
    unsigned char edflg=0;

    unsigned char vb=0;
    unsigned char help=0;
    unsigned char option=0;

    int status,c;

    char *tmp=NULL;
    char ststr[1024];
    int stid[256];
    int stcnt=0;

    char *nldstr="\n";
    char *tdstr="\t";
    char *dstr=NULL;

    OptionAdd(&opt,"-help",'x',&help);
    OptionAdd(&opt,"-option",'x',&option);

    OptionAdd(&opt,"vb",'x',&vb);
    OptionAdd(&opt,"n",'x',&nflg);
    OptionAdd(&opt,"s",'x',&sflg);
    OptionAdd(&opt,"o",'x',&oflg);
    OptionAdd(&opt,"c",'x',&cflg);
    OptionAdd(&opt,"i",'x',&iflg);
    OptionAdd(&opt,"h",'x',&hflg);
    OptionAdd(&opt,"p",'x',&pflg);

    OptionAdd(&opt,"st",'x',&stflg);
    OptionAdd(&opt,"ed",'x',&edflg);

    OptionAdd(&opt,"l",'x',&lflg);

    OptionAdd(&opt,"a",'x',&aflg);

    OptionAdd(&opt,"t",'t',&tmetxt);
    OptionAdd(&opt,"d",'t',&dtetxt);

    OptionAdd(&opt,"delim",'t',&dstr);

    farg=OptionProcess(1,argc,argv,&opt,NULL);

    if (help==1) {
        OptionPrintInfo(stdout,hlpstr);
        exit(0);
    }

    if (option==1) {
        OptionDump(stdout,&opt);
        exit(0);
    }

    if (arg==argc) {
        OptionPrintInfo(stdout,errstr);
        exit(-1);
    }




    if (tmetxt !=NULL) tval=strtime(tmetxt);
    if (dtetxt !=NULL) dval=strdate(dtetxt);

    tval+=dval;

    if (tval !=0) TimeEpochToYMDHMS(tval,&yr,&mo,&dy,&hr,&mt,&sc);
    else {
        TimeReadClock(&yr,&mo,&dy,&hr,&mt,&isc,&usc);
        sc=isc;
        tval=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc);
    }

    if (dstr==NULL) {
        if (lflg) dstr=tdstr;
        else dstr=nldstr;
    }

    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);

    for (arg=farg; arg<argc; arg++) {
        strcpy(ststr,argv[arg]);
        tmp=strtok(ststr,",");
        do {
            if (isdigit(tmp[0])) stid[stcnt]=atoi(tmp);
            else stid[stcnt]=RadarGetID(network,tmp);
            if (stid[stcnt] !=-1) stcnt++;
        } while ((tmp=strtok(NULL,",")) !=NULL);
    }

    if (stcnt==0) {
        stcnt=network->rnum;
        for (st=0; st<stcnt; st++) stid[st]=network->radar[st].id;
    }

    for (st=0; st<stcnt; st++) {


        status=RadarGetStatus(network,stid[st]);
        /* if ((aflg) && (status !=1)) continue; */

        radar=RadarGetRadar(network,stid[st]);
        if (radar==NULL) continue;

        if (aflg) {
            if (radar->st_time==-1) continue;
            if (tval<radar->st_time) continue;
            if ((radar->ed_time !=-1) && (tval>radar->ed_time)) continue;
        }

        if (iflg==1) fprintf(stdout,"%s%d%s",ilab[vb],stid[st],dstr);

        if (cflg==1) {
            fprintf(stdout,"%s",clab[vb]);
            for (c=0; (c<RadarGetCodeNum(network,stid[st])); c++)
                if (c !=0) fprintf(stdout,",%s",RadarGetCode(network,stid[st],c));
                else fprintf(stdout,"%s",RadarGetCode(network,stid[st],c));
            fprintf(stdout,"%s",dstr);
        }

        if (nflg==1)
            fprintf(stdout,"%s\"%s\"%s",nlab[vb],RadarGetName(network,stid[st]),
                    dstr);

        if (sflg==1) {
            fprintf(stdout,"%s",slab[vb]);
            if (status==1) fprintf(stdout,"active");
            else if (status==0) fprintf(stdout,"under construction");
            else if (status==-1) fprintf(stdout,"defunct");
            fprintf(stdout,"%s",dstr);
        }

        if (oflg==1) fprintf(stdout,"%s\"%s\"%s",olab[vb],
                                 RadarGetOperator(network,stid[st]),dstr);

        if (stflg) {
            if (radar->st_time !=-1) {
                TimeEpochToYMDHMS(radar->st_time,&yr,&mo,&dy,&hr,&mt,&sc);
                fprintf(stdout,"%.4d%.2d%.2d%s",yr,mo,dy,dstr);
            } else fprintf(stdout,"-%s",dstr);
        }


        if (edflg) {
            if (radar->ed_time !=-1) {
                TimeEpochToYMDHMS(radar->ed_time,&yr,&mo,&dy,&hr,&mt,&sc);
                fprintf(stdout,"%.4d%.2d%.2d%s",yr,mo,dy,dstr);
            } else fprintf(stdout,"-%s",dstr);

        }



        TimeEpochToYMDHMS(tval,&yr,&mo,&dy,&hr,&mt,&sc);
        site=RadarYMDHMSGetSite(RadarGetRadar(network,stid[st]),
                                yr,mo,dy,hr,mt,(int) sc);



        if (hflg) {
            if (site !=NULL) fprintf(stdout,"%s%g,%g,%g,%g%s",hlab[vb],
                                         site->geolat,site->geolon,
                                         site->alt,
                                         site->boresite,dstr);
            else fprintf(stdout,"unknown%s",dstr);
        }
        if (pflg) {
            if (site !=NULL) {
                if (site->geolat>0) fprintf(stdout,"%snorth",plab[vb]);
                else fprintf(stdout,"%ssouth",plab[vb]);
            } else if (radar->site !=NULL) {
                if (radar->site[0].geolat>0) fprintf(stdout,"%snorth",plab[vb]);
                else fprintf(stdout,"%ssouth",plab[vb]);
            } else fprintf(stdout,"unknown");

            fprintf(stdout,"%s",dstr);
        }
        if (lflg) fprintf(stdout,"\n");
    }
    return 0;
}
Esempio n. 10
0
int main(int argc,char *argv[])
{
    /*declarations*/
    int arg = 0;
    int i, r;
    FILE *fp;
    FILE *fitfp = NULL;
    FILE *corrfp = NULL;
    char *envstr;
    unsigned char help = 0;
    unsigned char option = 0;
    int s = 0, vb = 0;
    double epoch;

    struct FitData *fit = FitMake();
    struct RadarParm *prm = RadarParmMake();


    envstr=getenv("SD_RADAR");
    if(envstr==NULL)
    {
        fprintf(stderr,"Environment variable 'SD_RADAR' must be defined.\n");
        return -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);

    /*add options to control performance*/
    OptionAdd(&opt,"-help",'x',&help);
    OptionAdd(&opt,"-option",'x',&option);
    OptionAdd(&opt,"vb",'x',&vb);

    /*process the options*/
    arg=OptionProcess(1,argc,argv,&opt,NULL);
    if(option == 1)
    {
        OptionDump(stdout,&opt);
        exit(0);
    }

    /*read the radar's file*/
    fitfp=fopen(argv[arg],"r");
    fprintf(stderr,"%s\n",argv[arg]);
    if(fitfp==NULL)
    {
        fprintf(stderr,"File %s not found.\n",argv[arg]);
        exit(-1);
    }

    s=FitFread(fitfp,prm,fit);

    radar=RadarGetRadar(network,prm->stid);
    if (radar==NULL)
    {
        fprintf(stderr,"Failed to get radar information.\n");
        exit(-1);
    }
    site=RadarYMDHMSGetSite(radar,prm->time.yr,prm->time.mo,prm->time.dy,prm->time.hr,prm->time.mt,prm->time.sc);

    do
    {
        if((prm->channel == 0 || prm->channel == 1)  && prm->bmnum == 10)
        {
            fprintf(stdout,"%d  %d  %d  %d  %d  %d\n",prm->time.yr,prm->time.mo,prm->time.dy,prm->time.hr,prm->time.mt,prm->time.sc);
            fprintf(stdout,"%d  %d  %d  %lf  %d  %d  %d  %d  %d  %d\n",prm->cp,prm->tfreq,prm->bmnum,prm->noise.search,prm->nave,prm->lagfr,prm->mpinc,prm->smsep,prm->rsep,prm->nrang);
            for(i=0; i<prm->nrang; i++)
            {
                fprintf(stdout,"%d  %d  %lf  %lf  %lf\n",i,fit->rng[i].qflg,fit->rng[i].v,fit->rng[i].p_l,fit->rng[i].w_l);
            }
        }
        s=FitFread(fitfp,prm,fit);
    } while(s != -1);


    fclose(fitfp);

    return 0;
}
Esempio n. 11
0
int main(int argc,char *argv[]) {
 
  FILE *fp;
  char *envstr;
  int s,i,j,n;
 
  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);

  fp=fopen(argv[1],"r");

  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }

  s=RawFread(fp,&prm,&raw);

  if (s==-1) {
     fprintf(stderr,"Error reading file.\n");
    exit(-1);
  }
    
  radar=RadarGetRadar(network,prm.stid);
  if (radar==NULL) {
    fprintf(stderr,"Failed to get radar information.\n");
    exit(-1);
  }

  site=RadarYMDHMSGetSite(radar,prm.time.yr,prm.time.mo,
		          prm.time.dy,prm.time.hr,prm.time.mt,
                          prm.time.sc);

  if (site==NULL) {
    fprintf(stderr,"Failed to get site information.\n");
    exit(-1);
  }

  FitACFStart(site,prm.time.yr,&fblk); 

  do {
    fprintf(stdout,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
             prm.time.yr,prm.time.mo,prm.time.dy,
             prm.time.hr,prm.time.mt,prm.time.sc);

    
    fblk.prm.xcf=prm.xcf;
    fblk.prm.tfreq=prm.tfreq;
    fblk.prm.noise=prm.noise.search;
    fblk.prm.nrang=prm.nrang;
    fblk.prm.smsep=prm.smsep;
    fblk.prm.nave=prm.nave;
    fblk.prm.mplgs=prm.mplgs;
    fblk.prm.mpinc=prm.mpinc;
    fblk.prm.txpl=prm.txpl;
    fblk.prm.lagfr=prm.lagfr;
    fblk.prm.mppul=prm.mppul;
    fblk.prm.bmnum=prm.bmnum;
    fblk.prm.cp=prm.cp;
    fblk.prm.channel=prm.channel;
    fblk.prm.offset=prm.offset; /* stereo offset */

    for (i=0;i<fblk.prm.mppul;i++) fblk.prm.pulse[i]=prm.pulse[i];
    for (i=0;i<fblk.prm.mplgs;i++) {
      fblk.prm.lag[0][i]=prm.lag[i][0];
      fblk.prm.lag[1][i]=prm.lag[i][1];
    }

    for (i=0;i<fblk.prm.nrang;i++) {
      fblk.prm.pwr0[i]=raw.pwr0[i];
   
      for (j=0;j<fblk.prm.mplgs;j++) {
        fblk.acfd[i][j].x=raw.acfd[i][j][0];
        fblk.acfd[i][j].y=raw.acfd[i][j][1];
      }
      if (fblk.prm.xcf) {
        for (j=0;j<fblk.prm.mplgs;j++) {
          fblk.xcfd[i][j].x=raw.xcfd[i][j][0];
          fblk.xcfd[i][j].y=raw.xcfd[i][j][1];
        }
      } 
    }   

    FitACFBadlags(&fblk.prm,&bsamp);
    fprintf(stdout,"%d:",bsamp.nbad);
    for (n=0;n<bsamp.nbad;n++) fprintf(stdout,"%d ",bsamp.badsmp[n]);
    fprintf(stdout,"\n");
    s=RawFread(fp,&prm,&raw);


  } while (s !=-1);
 
  fclose(fp);


  return 0;
}
Esempio n. 12
0
int main(int argc,char *argv[]) {

  int arg;
  unsigned char help=0;
  unsigned char option=0;

  unsigned char vb=0;
 
  char *logstr=NULL;
  char *fnamestr=NULL;
  char *pathstr=NULL;
  char *pidstr=NULL;

  char *envstr;

  int sock;

  int remote_port=0;
  char dname[256];
  char logbuf[256];

  pid_t pid;
  FILE *fp;
  gzFile gzfp;
  char host[256];
  int flag,status;

  
  struct RadarParm *prm;
  struct FitData *fit;

  sigset_t set;
  struct sigaction act;

  struct timeval tv; 
  int reset=60;
  int cnt=0; 

  int sval=255;
  unsigned char stream;

  struct RadarNetwork *network=NULL;


  char path[256]={PATH};
  char pidfile[256]={PIDFILE};
  char fname[256]={FNAME};
  char tmpname[256];
  char *port_fname=NULL;
  unsigned char port_flag=0;
  double now=-1;
  double dstart=0;



  int yr,mo,dy,hr,mt;
  double sc;
 
  double minpwr=3.0;

  prm=RadarParmMake();
  fit=FitMake();
  cfit=CFitMake();

  pid=getpid();
 
  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);
  }

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"vb",'x',&vb);

  OptionAdd(&opt,"s",'i',&sval);

  OptionAdd(&opt,"mp",'d',&minpwr);

  OptionAdd(&opt,"rpf",'x',&port_flag);
  
  OptionAdd(&opt,"L",'t',&logstr);
  OptionAdd(&opt,"f",'t',&fnamestr);
  OptionAdd(&opt,"p",'t',&pathstr);
  OptionAdd(&opt,"if",'t',&pidstr);




  arg=OptionProcess(1,argc,argv,&opt,NULL);

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }


  if (argc-arg<2) {
    OptionPrintInfo(stderr,errstr);
    exit(-1);
  }

  if (logstr !=NULL) strcpy(logfname,logstr);
  if (pathstr !=NULL) strcpy(path,pathstr);
  if (pidstr !=NULL) strcpy(pidfile,pidstr);

 
  strcpy(host,argv[argc-2]);
  if (port_flag==0) remote_port=atoi(argv[argc-1]);
  else port_fname=argv[argc-1];

  stream=sval;
 
  strcpy(tmpname,fname);
  strcat(tmpname,"~");

  if (port_flag==0) sprintf(logbuf,"Host:%s %d",host,remote_port);
  else sprintf(logbuf,"Host:%s Port File:%s",host,port_fname);
  loginfo(logfname,logbuf);

  sprintf(logbuf,"File path:%s",path);
  loginfo(logfname,logbuf);
  sprintf(logbuf,"pid file:%s",pidfile);
  loginfo(logfname,logbuf);
  sprintf(logbuf,"pid:%d",(int) pid);
  loginfo(logfname,logbuf);
 
  fp=fopen(pidfile,"w");
  fprintf(fp,"%d\n",pid);
  fclose(fp);
  sigemptyset(&set);
  sigaddset(&set,SIGUSR1);

  act.sa_flags=0;
  act.sa_mask=set;
  act.sa_handler=trapsignal;
  sigaction(SIGUSR1,&act,NULL);

  now=0;

  do {
    resetflg=0;
  
    if (port_flag==1) {
      fp=fopen(port_fname,"r");
      if (fp !=NULL) {
        fscanf(fp,"%d",&remote_port);
        fclose(fp);
      } else remote_port=1024;
    }

    sprintf(logbuf,"Connecting to host:%s %d",host,remote_port);

    loginfo(logfname,logbuf);

    sock=ConnexOpen(host,remote_port,NULL); 
    if (sock<0) {
      loginfo(logfname,"Could not connect to host - retrying.");
      sleep(10);
      continue;
    }
    status=(write(sock,&stream,sizeof(char)) !=1);
    if (status !=0) {
      fprintf(stderr,"Could not set stream to host.\n");
      close(sock);
      sock=-1;
      continue;
    }

    resetflg=0;
    do {
     
       tv.tv_sec=reset; 

       status=FitCnxRead(1,&sock,prm,fit,&flag,&tv);

       if ((status==-1) || (flag==-1) || (resetflg !=0))  break;
       if (status==0) resetflg=1;
          
       if ((status==1) && (flag==1)) {
         fprintf(stderr,".");
         fflush(stderr);
         dotflag=1;
          

         FitToCFit(minpwr,cfit,prm,fit); 
	    
         now=cfit->time;

         if (dstart==0) {
           dstart=now-(int) now % (24*3600); /* start of day */
           TimeEpochToYMDHMS(dstart,&yr,&mo,&dy,&hr,&mt,&sc);
           sprintf(dname,"%s/%.4d%.2d%.2d.%s.cfit",
		       path,yr,mo,dy,RadarGetCode(network,cfit->stid,0));
	 }


         gzfp=gzopen(dname,"a");
         CFitWrite(gzfp,cfit);
         gzclose(gzfp);

         if ((now-dstart) >= 24*3600) { /* advance to the next day */
           dstart=now-(int) now % (24*3600); /* start of day */
           TimeEpochToYMDHMS(dstart,&yr,&mo,&dy,&hr,&mt,&sc);
           sprintf(dname,"%s/%.4d%.2d%.2d.%s.cfit",
		       path,yr,mo,dy,
                       RadarGetCode(network,cfit->stid,0));
	 }
	 
         cnt++;
	    
       } 
  

     
    } while (1);
 
    if (resetflg==0) loginfo(logfname,"Connection failed.");
    if (resetflg==1) loginfo(logfname,"Connection timed out.");
    if (resetflg==2) loginfo(logfname,"Connection reset by signal.");
    ConnexClose(sock);
  } while(1);

  return 0;
}