Beispiel #1
0
int main(int argc,char *argv[]) {
  int arg;
 
  double ilon=0.0,ilat=0.0,alt=0.0;
  double olon=0.0,olat=0.0,r;
  char *fmt=NULL;
  char *dfmt="%f %f\n";
  char *fname=NULL;
  FILE *fp;

  unsigned char option=0;
  unsigned char help=0;
  unsigned char flag=0;
  int c;

  char txt[256];
  
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
  OptionAdd(&opt,"i",'x',&flag);
  OptionAdd(&opt,"lon",'d',&ilon);
  OptionAdd(&opt,"lat",'d',&ilat);
  OptionAdd(&opt,"alt",'d',&alt);
  OptionAdd(&opt,"fmt",'t',&fmt);
  OptionAdd(&opt,"f",'t',&fname);

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

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

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

  if (fmt==NULL) fmt=dfmt;

  if (fname==NULL) {
    AACGMConvert(ilat,ilon,alt,&olat,&olon,&r,flag);
    fprintf(stdout,fmt,olat,olon);    
  } else {
    if (strcmp(fname,"-")==0) fp=stdin;
    else fp=fopen(fname,"r");
    if (fp==NULL) exit(1);
    while(fgets(txt,255,fp) !=NULL) {
      for (c=0;(txt[c] !=0) && (c<256);c++) 
      if (txt[c]=='#') break;
      if (txt[c]=='#') continue;
      if (sscanf(txt,"%lf %lf %lf\n",
          &ilat,&ilon,&alt) !=3) continue;
      AACGMConvert(ilat,ilon,alt,&olat,&olon,&r,flag);
      fprintf(stdout,fmt,olat,olon);    
    }
  }
  return 0;
}
Beispiel #2
0
int main(int argc,char *argv[]) {
  
  int s=0;
  int arg=0;
  FILE *fp;
  char lbuf[256];
  struct FrameBuffer *img=NULL;
  struct XMLdata *xmldata=NULL;
  struct FrameBufferXML xmlimg;
 

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

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

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

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

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

  xmldata=XMLMake();
  xmlimg.xml=xmldata;
  xmlimg.img=&img;

  XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg);
  XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }
  if (s !=0) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  if (img !=NULL) FrameBufferSavePPMX(img,stdout);
  return 0;
}
Beispiel #3
0
int main (int argc,char *argv[]) {

  FILE *fp;

  int arg;
  unsigned char help=0;
  unsigned char option=0;
  unsigned char startstop=0;
  int st=0;
  double tme[2];
  int32 inx;
  int yr,mo,dy,hr,mt;
  double sc; 

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

  arg=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) fp=stdin;
  else fp=fopen(argv[arg],"r");
  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }


  do {
    st=ConvertFreadDouble(fp,&tme[0]);
    if (st !=0) break;
    if (startstop) {
      st=ConvertFreadDouble(fp,&tme[1]);
      if (st !=0) break;
    }
    st=ConvertFreadInt(fp,&inx);
    if (st !=0) break;
    TimeEpochToYMDHMS(tme[0],&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    if (startstop) {
      TimeEpochToYMDHMS(tme[1],&yr,&mo,&dy,&hr,&mt,&sc);
      fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    }
    fprintf(stdout,"%d\n",inx);
  } while (1);
  return 0;
}
Beispiel #4
0
int main (int argc,char *argv[]) {

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

  unsigned char vb=0;

  FILE *fp;
  
  int yr,mo,dy,hr,mt;
  double sc; 
  int s;

  grd=GridMake();
  map=CnvMapMake();

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


  if (arg==argc) fp=stdin;
  else fp=fopen(argv[arg],"r");
  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }
    
  while (CnvMapFread(fp,map,grd) !=-1) {
   if (vb) {
      TimeEpochToYMDHMS(map->st_time,&yr,&mo,&dy,&hr,&mt,&sc);
      fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
              yr,mo,dy,hr,mt,(int) sc);
    }
    s=OldCnvMapFwrite(stdout,map,grd);
  }
  if (fp !=stdin) fclose(fp);
  return 0;
} 
Beispiel #5
0
int main(int argc,char *argv[]) {
  int ptr;
  int arg;
  FILE *fp;
  int yr,mo,dy,hr,mt; 
  double sc;
  double tme[2];
  void *tptr[2];
  unsigned char help=0;
  unsigned char option=0;

 

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

  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"File not found.\n");
      exit(-1);
    }
  } else fp=stdin;
  
  tptr[0]=tme;

  ptr=ftell(fp);

  while (RfileRead(fp,0,NULL,tptr) !=-1) {
    TimeEpochToYMDHMS(tme[0],&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    TimeEpochToYMDHMS(tme[1],&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    fprintf(stdout,"%d\n",ptr);
    ptr=ftell(fp);
  }
  if (arg<argc) fclose(fp);
  return 0;

}
Beispiel #6
0
int main(int argc,char *argv[]) {
  unsigned char help=0;
  unsigned char option=0;

  int s;
  double store[2];
  double val;
  char *cast=NULL;
  char *format=NULL;
  char *dformat="%lg\n";
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"c",'t',&cast);
  OptionAdd(&opt,"f",'t',&format);
 
  arg=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(stderr,errstr);
    exit(0);
  }
  if (format==NULL) format=dformat;
  else decode_format(format);
  store[0]=PI;
  s=Eval(argv[arg],&val,decode_value,store,decode_function,store);
  if (cast==NULL) fprintf(stdout,format,val);
  else if (cast[0]=='c') fprintf(stdout,format,(unsigned char) val);
  else if (cast[0]=='u') fprintf(stdout,format,(unsigned int) val);
  else if (cast[0]=='i') fprintf(stdout,format,(int) val);
  else if (cast[0]=='d') fprintf(stdout,format,val);
  return 0;
} 
Beispiel #7
0
int main(int argc,char *argv[]) {
 
  int arg=0;
  FILE *fp;
  struct FrameBuffer *img=NULL;
  char *name=NULL;  

  unsigned char help=0;
  unsigned char option=0;
 
  OptionAdd(&opt,"-help",'x',&help);  
  OptionAdd(&opt,"-option",'x',&option);
  OptionAdd(&opt,"name",'t',&name);


  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  img=FrameBufferLoadPNG(fp,name);
 
  if (img==NULL) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);
  if (img !=NULL) FrameBufferSavePPMX(img,stdout);
  return 0;
}
Beispiel #8
0
int main(int argc,char *argv[]) {

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

  struct DataMap *dmap=NULL;
  struct IDLFile *fp=NULL;

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

  arg=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) fp=IDLOpen(argv[arg],zflg);
  else fp=IDLFdopen(fileno(stdin),zflg);

  dmap=IDLReadSave(fp);

  if (dmap==NULL) return 0;

  if (zflg) {
    gzFile gz=0;
    gz=gzdopen(fileno(stdout),"w");
    DataMapWriteZ(gz,dmap);
    gzclose(gz);
  } else DataMapFwrite(stdout,dmap);
  
  return 0;


}
Beispiel #9
0
int main(int argc,char *argv[]) {
  
  
  int arg=0;
  FILE *fp;
  
  struct FrameBuffer *src=NULL;
  struct FrameBuffer *dst=NULL;
  struct FrameBufferMatrix m;
 
  unsigned char sflg=0;
  float wdt=-1;
  float hgt=-1;
  float sf=1.0;


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


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

  OptionAdd(&opt,"smooth",'x',&sflg);
  OptionAdd(&opt,"wdt",'f',&wdt);
  OptionAdd(&opt,"hgt",'f',&hgt);
   OptionAdd(&opt,"sf",'f',&sf);
  
  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while ((src=FrameBufferLoadPPMX(fp)) !=NULL) {

    if (dst==NULL) {
      if ((wdt==-1) && (hgt==-1)) {
         wdt=src->wdt*sf;
         hgt=src->hgt*sf;
      } else if (wdt==-1) {
         wdt=src->wdt*hgt/src->hgt;
      } else if (hgt==-1) {
         hgt=src->hgt*wdt/src->wdt;
      }
      if ((wdt==0) || (hgt==0)) {
        fprintf(stderr,"Invalid image size.\n");
        exit(-1);
      }
      dst=FrameBufferMake(NULL,wdt,hgt,src->depth);
    }

    if ((wdt==src->wdt) && (hgt==src->hgt))
      FrameBufferImage(dst,NULL,src,0xf0,0,0,0,NULL);  
    else {
      float xsc=wdt/src->wdt;
      float ysc=hgt/src->hgt;
      m.a=xsc;
      m.b=0;
      m.c=0;
      m.d=ysc;
      FrameBufferImage(dst,&m,src,0xf0,0,0,sflg,NULL); 
    }
 
    FrameBufferSavePPMX(dst,stdout); 

    FrameBufferFree(src);
    src=NULL;
  }

  if (arg<argc) fclose(fp);



  return 0;
}
Beispiel #10
0
int main(int argc,char *argv[]) {

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

  unsigned char vb=0;
  int arg=0;

  int s;
  int thr=-1;

  struct RadarParm rprm;
  struct RawData rawacf;
  FILE *fp;

  int rtab[ORIG_MAX_RANGE];
  float snr[MAX_RANGE];
  int inx,l,step;
  float maxval;
  int cnt=0;

  int recnum=0;

  char vstring[256];
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"vb",'x',&vb);
  OptionAdd(&opt,"t",'i',&thr);
 
  arg=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) { 
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    } 
  } else fp=stdin;

  
  s=RawFread(fp,&rprm,&rawacf);
  if (s==-1) {
    fprintf(stderr,"Error reading file.\n");
    exit(-1);
  }
  if (thr !=-1) rawacf.thr=thr;

  sprintf(vstring,"%d.%.3d",rawacf.revision.major,rawacf.revision.minor);
/*
  if (OldRawHeaderFwrite(stdout,"rawwrite",vstring,rawacf.thr,            
			"example file") !=0) {
    fprintf(stderr,"Error writing header.\n");
    exit(-1);
  }
*/

  do {
    recnum++;

    if (thr !=-1) rawacf.thr=thr;

    for (l=0;l<rprm.nrang;l++) {
      if (rprm.noise.search>0)
        snr[l]=rawacf.pwr0[l]/rprm.noise.search;
      else snr[l]=0;
    }

/*
    if (rprm.nrang>ORIG_MAX_RANGE) {
      step=rprm.nrang/ORIG_MAX_RANGE;
      for (l=0;l<ORIG_MAX_RANGE;l++) {
        maxval=0.0;
        inx=l*step;
        for (s=0;s<step;s++) {
          if (snr[l*step+s]>maxval) {
            maxval=snr[l*step+s];
            inx=l*step+s;
          }
        }
        rtab[l]=inx;
      }
      rprm.rsep=rprm.rsep*step;
      s=OldRawFwrite(stdout,"rawwrite",&rprm,&rawacf,recnum,rtab);  
    } else  s=OldRawFwrite(stdout,"rawwrite",&rprm,&rawacf,recnum,NULL);
    if (s !=0) {
      cnt=-1;
      break;
    }
*/
/*
    rprm.stid=(int16)40;
*/
/*
    fprintf(stderr,"%d %d\n",rprm.lagfr,rprm.frang);
*/
    if (rprm.lagfr==600 && rprm.smsep==300)rprm.lagfr=(int16)1200;
    if (rprm.lagfr==400 && rprm.smsep==100)rprm.lagfr=(int16)800;
    s=RawFwrite(stdout,&rprm,&rawacf);
    if (s==-1) {
      cnt=-1;
      break;
    }

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

     cnt++;
  } while ((s=RawFread(fp,&rprm,&rawacf)) !=-1);

  if (cnt==-1) exit(EXIT_FAILURE);
  exit(EXIT_SUCCESS);
  return 0;
}
Beispiel #11
0
int main(int argc,char *argv[]) {
  char lbuf[256];
  int s=0;
  int arg=0;
  FILE *fp;
  struct FrameBuffer *src=NULL;
  struct FrameBuffer *dst=NULL;

  struct XMLdata *xmldata=NULL;
  struct FrameBufferXML xmlimg;

  unsigned int bgcolor=0;
  char *bgtxt=NULL;

  unsigned char alpha=0;

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

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

  OptionAdd(&opt,"bgcol",'t',&bgtxt);
  OptionAdd(&opt,"alpha",'x',&alpha);
   
  arg=OptionProcess(1,argc,argv,&opt,NULL);   

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

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

  xmldata=XMLMake();
  xmlimg.xml=xmldata;
  xmlimg.img=&src;

  XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg);
  XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }
  if (s !=0) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  bgcolor=FrameBufferColor(0x00,0x00,0x00,0x00);


  if (bgtxt !=NULL) {
     sscanf(bgtxt,"%x",&bgcolor);
  }

  if (src==NULL) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }



  if (bgcolor !=0) {
    dst=FrameBufferMake(NULL,src->wdt,src->hgt,24);
    if (dst==NULL) {
      fprintf(stderr,"Error creating image.\n");
      exit(-1);
    }
    FrameBufferClear(dst,bgcolor,0x0f);
    FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL);
    if (alpha==0) FrameBufferSavePPM(dst,stdout);
    else FrameBufferSavePPMAlpha(dst,stdout);
  } else {
    if (alpha==0)  FrameBufferSavePPM(src,stdout);
    else FrameBufferSavePPMAlpha(src,stdout);
  }


  



  return 0;
}
Beispiel #12
0
int main(int argc,char *argv[]) {
  FILE *fp;
  unsigned char help=0;  
  unsigned char option=0;
  
  pid_t pid;

  int arg,j;
  int dtime=5;
  int fildes,rc;
  int status;
  struct stat buf;
  struct flock rflock;
  
  char *logstr=NULL;
  char *outfnamestr=NULL;

  char *pidstr=NULL;


  char command[256];  

  char outfname[64]=OUTFNAME;
  char *infname=NULL;

  rflock.l_type=F_RDLCK;
  rflock.l_whence=SEEK_SET;
  rflock.l_start=0;
  rflock.l_len=0;

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

  OptionAdd(&opt,"L",'t',&logstr);
  OptionAdd(&opt,"d",'i',&dtime);
  OptionAdd(&opt,"if",'t',&pidstr);
  OptionAdd(&opt,"f",'t',&outfnamestr);

  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) {
     OptionPrintInfo(stdout,errstr);
     exit(-1);
  }

  if (logstr !=NULL) strcpy(logfname,logstr);
  if (outfnamestr !=NULL) strcpy(outfname,outfnamestr);
  if (pidstr !=NULL) strcpy(pidname,pidstr);


  infname=argv[arg];
  command[0]=0;
  for (j=arg+1;j<argc;j++) {
      strcat(command,argv[j]);
      strcat(command," ");
  }
  
  if (command[0] !=0) {
    sprintf(log_buf,"Command\t:%s",command);
    log_info(logfname,log_buf);
  }
  sprintf(log_buf,"Input file:%s",infname);

  log_info(logfname,log_buf);

  sprintf(log_buf,"Output file:%s",outfname);

  log_info(logfname,log_buf);
  sprintf(log_buf,"Poll Interval:%ds",dtime);
  log_info(logfname,log_buf);

  fp=fopen(pidname,"w");
  pid=getpid();
  sprintf(log_buf,"Process ID recorded in file %s.",pidname);
  log_info(logfname,log_buf);
  sprintf(log_buf,"PID %d.",(int) pid);
  log_info(logfname,log_buf);
  fprintf(fp,"%d\n",(int) pid);
  fclose(fp);

  while (1) {

     sleep(dtime);
     fildes=open(infname,O_RDONLY); 
     if (fildes==-1) continue;
     rflock.l_type=F_RDLCK;
     status=fcntl(fildes,F_SETLKW,&rflock);
     rc=fstat(fildes,&buf);
     rflock.l_type=F_UNLCK;  
     status=fcntl(fildes,F_SETLKW,&rflock);
     close(fildes);
     if (buf.st_mtime !=tval) {

       tval=buf.st_mtime; 
       log_info(logfname,"File changed.");
       if (command[0] !=0) {
         sprintf(log_buf,"Executing command:%s",command);
         log_info(logfname,log_buf);
         system(command);
       }
       fp=fopen(outfname,"w");
       fprintf(fp,"%ld\n",(long) tval);
       fclose(fp);
     }
  }
  return 0;
}
Beispiel #13
0
int main(int argc,char *argv[]) {
  
  int arg=0;
  FILE *fp;
  struct FrameBuffer *src=NULL;
  struct FrameBuffer *dst=NULL;

  unsigned int bgcolor=0;
  char *bgtxt=NULL;

  unsigned alpha=0;

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

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

  OptionAdd(&opt,"bgcol",'t',&bgtxt);
  OptionAdd(&opt,"alpha",'x',&alpha);
   
  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  bgcolor=FrameBufferColor(0x00,0x00,0x00,0x00);

  if (bgtxt !=NULL) {
     sscanf(bgtxt,"%x",&bgcolor);
  }

  while ((src=FrameBufferLoadPNG(fp,"image")) !=NULL) {
 
    if (bgcolor !=0) {
      if (dst==NULL) {
        dst=FrameBufferMake(NULL,src->wdt,src->hgt,24);
         if (dst==NULL) {
          fprintf(stderr,"Error creating image.\n");
          exit(-1);
         }
      }
      FrameBufferClear(dst,bgcolor,0x0f);
      FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL); 
      if (alpha==0) FrameBufferSavePPM(dst,stdout);
      else  FrameBufferSavePPMAlpha(dst,stdout);
    } else {
      if (alpha==0) FrameBufferSavePPM(src,stdout);
      else FrameBufferSavePPMAlpha(src,stdout);
    }
    FrameBufferFree(src);
    src=NULL;
  }


  if (arg<argc) fclose(fp);



  return 0;
}
Beispiel #14
0
int main(int argc,char *argv[]) {

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


  int arg=0;

  struct rawfp *rawfpA=NULL;
  struct rawfp *rawfpB=NULL;
  
  int sA,sB;
  int c,x;

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
 
  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);
  }


  rawfpA=raw_open(argv[arg],NULL);
  rawfpB=raw_open(argv[arg+1],NULL);

  while (1) {
    sA=raw_read(rawfpA,&rawA);
    sB=raw_read(rawfpB,&rawB);
    if ((sA==-1) || (sB==-1)) break;
  
    fprintf(stdout,
    "%.4d-%.2d-%.2d %.2d:%.2d:%.2d\t%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n",
	    rawA.PARMS.YEAR,rawA.PARMS.MONTH,rawA.PARMS.DAY,
            rawA.PARMS.HOUR,rawA.PARMS.MINUT,rawA.PARMS.SEC,
            rawB.PARMS.YEAR,rawB.PARMS.MONTH,rawB.PARMS.DAY,
            rawB.PARMS.HOUR,rawB.PARMS.MINUT,rawB.PARMS.SEC);
    
    if (rawA.PARMS.REV.MAJOR !=rawB.PARMS.REV.MAJOR) fprintf(stdout,"raw.PARMS.REV.MAJOR: %d !=%d \n",rawA.PARMS.REV.MAJOR,rawB.PARMS.REV.MAJOR);


    if (rawA.PARMS.REV.MINOR !=rawB.PARMS.REV.MINOR) fprintf(stdout,"raw.PARMS.REV.MINOR: %d !=%d \n",rawA.PARMS.REV.MINOR,rawB.PARMS.REV.MINOR);

    if (rawA.PARMS.NPARM !=rawB.PARMS.NPARM) fprintf(stdout,"raw.PARMS.NPARM: %d !=%d \n",rawA.PARMS.NPARM,rawB.PARMS.NPARM);

   if (rawA.PARMS.ST_ID !=rawB.PARMS.ST_ID) fprintf(stdout,"raw.PARMS.ST_ID: %d !=%d \n",rawA.PARMS.ST_ID,rawB.PARMS.ST_ID);

   if (rawA.PARMS.YEAR !=rawB.PARMS.YEAR) fprintf(stdout,"raw.PARMS.YEAR: %d !=%d \n",rawA.PARMS.YEAR,rawB.PARMS.YEAR);

   if (rawA.PARMS.MONTH !=rawB.PARMS.MONTH) fprintf(stdout,"raw.PARMS.MONTH: %d !=%d \n",rawA.PARMS.MONTH,rawB.PARMS.MONTH);

   if (rawA.PARMS.DAY !=rawB.PARMS.DAY) fprintf(stdout,"raw.PARMS.DAY: %d !=%d \n",rawA.PARMS.DAY,rawB.PARMS.DAY);

   if (rawA.PARMS.HOUR !=rawB.PARMS.HOUR) fprintf(stdout,"raw.PARMS.HOUR: %d !=%d \n",rawA.PARMS.HOUR,rawB.PARMS.HOUR);

   if (rawA.PARMS.MINUT !=rawB.PARMS.MINUT) fprintf(stdout,"raw.PARMS.MINUT: %d !=%d \n",rawA.PARMS.MINUT,rawB.PARMS.MINUT);

   if (rawA.PARMS.SEC !=rawB.PARMS.SEC) fprintf(stdout,"raw.PARMS.SEC: %d !=%d \n",rawA.PARMS.SEC,rawB.PARMS.SEC);

   if (rawA.PARMS.TXPOW !=rawB.PARMS.TXPOW) fprintf(stdout,"raw.PARMS.TXPOW: %d !=%d \n",rawA.PARMS.TXPOW,rawB.PARMS.TXPOW);

   if (rawA.PARMS.NAVE !=rawB.PARMS.NAVE) fprintf(stdout,"raw.PARMS.NAVE: %d !=%d \n",rawA.PARMS.NAVE,rawB.PARMS.NAVE);

   if (rawA.PARMS.ATTEN !=rawB.PARMS.ATTEN) fprintf(stdout,"raw.PARMS.ATTEN: %d !=%d \n",rawA.PARMS.ATTEN,rawB.PARMS.ATTEN);

   if (rawA.PARMS.LAGFR !=rawB.PARMS.LAGFR) fprintf(stdout,"raw.PARMS.LAGFR: %d !=%d \n",rawA.PARMS.LAGFR,rawB.PARMS.LAGFR); 

   if (rawA.PARMS.SMSEP !=rawB.PARMS.SMSEP) fprintf(stdout,"raw.PARMS.SMSEP: %d !=%d \n",rawA.PARMS.SMSEP,rawB.PARMS.SMSEP);


   if (rawA.PARMS.ERCOD !=rawB.PARMS.ERCOD) fprintf(stdout,"raw.PARMS.ERCOD: %d !=%d \n",rawA.PARMS.ERCOD,rawB.PARMS.ERCOD);

   if (rawA.PARMS.AGC_STAT !=rawB.PARMS.AGC_STAT) fprintf(stdout,"raw.PARMS.AGC_STAT: %d !=%d \n",rawA.PARMS.AGC_STAT,rawB.PARMS.AGC_STAT);

   if (rawA.PARMS.LOPWR_STAT !=rawB.PARMS.LOPWR_STAT) fprintf(stdout,"raw.PARMS.LOPWR_STAT: %d !=%d \n",rawA.PARMS.LOPWR_STAT,rawB.PARMS.LOPWR_STAT);

   if (rawA.PARMS.NBAUD !=rawB.PARMS.NBAUD) fprintf(stdout,"raw.PARMS.NBAUD: %d !=%d \n",rawA.PARMS.NBAUD,rawB.PARMS.NBAUD);

   if (rawA.PARMS.NOISE !=rawB.PARMS.NOISE) fprintf(stdout,"raw.PARMS.NOISE: %d !=%d \n",rawA.PARMS.NOISE,rawB.PARMS.NOISE);

   if (rawA.PARMS.NOISE_MEAN !=rawB.PARMS.NOISE_MEAN) fprintf(stdout,"raw.PARMS.NOISE_MEAN: %d !=%d \n",rawA.PARMS.NOISE_MEAN,rawB.PARMS.NOISE_MEAN);

   if (rawA.PARMS.CHANNEL !=rawB.PARMS.CHANNEL) fprintf(stdout,"raw.PARMS.CHANNEL: %d !=%d \n",rawA.PARMS.CHANNEL,rawB.PARMS.CHANNEL);


   if (rawA.PARMS.RXRISE !=rawB.PARMS.RXRISE) fprintf(stdout,"raw.PARMS.RXRISE: %d !=%d \n",rawA.PARMS.RXRISE,rawB.PARMS.RXRISE);


   if (rawA.PARMS.INTT !=rawB.PARMS.INTT) fprintf(stdout,"raw.PARMS.INTT: %d !=%d \n",rawA.PARMS.INTT,rawB.PARMS.INTT);


   if (rawA.PARMS.TXPL !=rawB.PARMS.TXPL) fprintf(stdout,"raw.PARMS.TXPL: %d !=%d \n",rawA.PARMS.TXPL,rawB.PARMS.TXPL);


   if (rawA.PARMS.MPINC !=rawB.PARMS.MPINC) fprintf(stdout,"raw.PARMS.MPINC: %d !=%d \n",rawA.PARMS.MPINC,rawB.PARMS.MPINC);




   if (rawA.PARMS.MPPUL !=rawB.PARMS.MPPUL) fprintf(stdout,"raw.PARMS.MPPUL: %d !=%d \n",rawA.PARMS.MPPUL,rawB.PARMS.MPPUL);


   if (rawA.PARMS.MPLGS !=rawB.PARMS.MPLGS) fprintf(stdout,"raw.PARMS.MPLGS: %d !=%d \n",rawA.PARMS.MPLGS,rawB.PARMS.MPLGS);


   if (rawA.PARMS.NRANG !=rawB.PARMS.NRANG) fprintf(stdout,"raw.PARMS.NRANG: %d !=%d \n",rawA.PARMS.NRANG,rawB.PARMS.NRANG);


   if (rawA.PARMS.FRANG !=rawB.PARMS.FRANG) fprintf(stdout,"raw.PARMS.FRANG: %d !=%d \n",rawA.PARMS.FRANG,rawB.PARMS.FRANG);


   if (rawA.PARMS.RSEP !=rawB.PARMS.RSEP) fprintf(stdout,"raw.PARMS.RSEP: %d !=%d \n",rawA.PARMS.RSEP,rawB.PARMS.RSEP);

   if (rawA.PARMS.BMNUM !=rawB.PARMS.BMNUM) fprintf(stdout,"raw.PARMS.BMNUM: %d !=%d \n",rawA.PARMS.BMNUM,rawB.PARMS.BMNUM);


   if (rawA.PARMS.XCF !=rawB.PARMS.XCF) fprintf(stdout,"raw.PARMS.XCF: %d !=%d \n",rawA.PARMS.XCF,rawB.PARMS.XCF);

 
   if (rawA.PARMS.TFREQ !=rawB.PARMS.TFREQ) fprintf(stdout,"raw.PARMS.TFREQ: %d !=%d \n",rawA.PARMS.TFREQ,rawB.PARMS.TFREQ);

   if (rawA.PARMS.SCAN !=rawB.PARMS.SCAN) fprintf(stdout,"raw.PARMS.SCAN: %d !=%d \n",rawA.PARMS.SCAN,rawB.PARMS.SCAN);

   if (rawA.PARMS.MXPWR !=rawB.PARMS.MXPWR) fprintf(stdout,"raw.PARMS.MXPWR: %d !=%d \n",rawA.PARMS.MXPWR,rawB.PARMS.MXPWR);


   if (rawA.PARMS.LVMAX !=rawB.PARMS.LVMAX) fprintf(stdout,"raw.PARMS.LVMAX: %d !=%d \n",rawA.PARMS.LVMAX,rawB.PARMS.LVMAX);


   if (rawA.PARMS.CP !=rawB.PARMS.CP) fprintf(stdout,"raw.PARMS.CP: %d !=%d \n",rawA.PARMS.CP,rawB.PARMS.CP);

   if (strcmp(rawA.COMBF,rawB.COMBF) !=0)  fprintf(stdout,"raw.combf: %s !=%s \n",rawA.COMBF,rawB.COMBF);

   for (c=0;c<rawA.PARMS.MPPUL;c++) if (rawA.PULSE_PATTERN[c] !=rawB.PULSE_PATTERN[c]) break;
   if (c !=rawA.PARMS.MPPUL) fprintf(stdout,"Pulse pattern does not match\n");

   for (c=0;c<rawA.PARMS.MPLGS;c++) {
     if (rawA.LAG_TABLE[0][c] !=rawB.LAG_TABLE[0][c]) break;
     if (rawA.LAG_TABLE[1][c] !=rawB.LAG_TABLE[1][c]) break;

   }
   if (c !=rawA.PARMS.MPLGS) fprintf(stdout,"Lag table does not match\n");

 
   for (c=0;c<rawA.PARMS.NRANG;c++) {
     if (rawA.pwr0[c] !=rawB.pwr0[c]) {
       fprintf(stdout,"pwr0[%d]: %g != %g\n",c,rawA.pwr0[c],rawB.pwr0[c]);
     }
   }

   if (c !=rawA.PARMS.NRANG) fprintf(stdout,"Lag-zero power does not match\n");

   for (c=0;c<rawA.PARMS.NRANG;c++) {
     for (x=0;x<rawA.PARMS.MPLGS;x++) {
     
       if (rawA.acfd[c][x][0] !=rawB.acfd[c][x][0]) {
         fprintf(stdout,"acfd[%d][%d][0]: %g != %g\n",c,x,rawA.acfd[c][x][0],
	         rawB.acfd[c][x][0]);
       }

       if (rawA.acfd[c][x][1] !=rawB.acfd[c][x][1]) {
         fprintf(stdout,"acfd[%d][%d][1]: %g != %g\n",c,x,rawA.acfd[c][x][1],
	       rawB.acfd[c][x][1]);
       }
     }
   }

   if (rawA.PARMS.XCF) {

     for (c=0;c<rawA.PARMS.NRANG;c++) {
       for (x=0;x<rawA.PARMS.MPLGS;x++) {
     
         if (rawA.acfd[c][x][0] !=rawB.acfd[c][x][0]) {
           fprintf(stdout,"acfd[%d][%d][0]: %g != %g\n",c,x,rawA.acfd[c][x][0],
	         rawB.acfd[c][x][0]);
         }

         if (rawA.acfd[c][x][1] !=rawB.acfd[c][x][1]) {
           fprintf(stdout,"acfd[%d][%d][1]: %g != %g\n",c,x,rawA.acfd[c][x][1],
	         rawB.acfd[c][x][1]);
         }
       }
     }

   }


   if (c !=rawA.PARMS.NRANG) fprintf(stdout,"Data does not match\n");

  }
  return 0;
}
Beispiel #15
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;
}
Beispiel #16
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;
}  
Beispiel #17
0
int main(int argc,char *argv[]) {
  int arg;
  int sock;
  socklen_t length;
  socklen_t clength;  
  int sc_reuseaddr=1,temp;

  struct sockaddr_in server;
  struct sockaddr_in master;
  struct sockaddr_in client;


  fd_set ready;
  int port=0;
 
  unsigned char help=0;
  unsigned char option=0;

  int remote_port=0;
  char chost[256];

  char *host=NULL;
  char *file=NULL;
  char *log=NULL;

  char *dflog=LOG_FILE;
  char *dffile=PORT_ID_FILE;

  int status=0;
  FILE *fp;
  struct hostent *hp,*gethostbyname();
 
  struct hostent *cname;
  pid_t root;

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
  OptionAdd(&opt,"l",'i',&port);
  OptionAdd(&opt,"f",'t',&file);
  OptionAdd(&opt,"lf",'t',&log);
  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);
  }
    
  host=argv[argc-2];
  remote_port=atoi(argv[argc-1]);

  if (file==NULL) file=dffile;
  if (log==NULL) log=dflog;


  /* get the address and port of the master server */
  
  master.sin_family=AF_INET;
  hp=gethostbyname(host);
  if (hp==0) {
    fprintf(stderr,"%s: unknown host0,\n",host);
    exit(2);
  }
  memcpy(&master.sin_addr,hp->h_addr,hp->h_length);
  master.sin_port=htons(remote_port);
 
  sock=socket(AF_INET,SOCK_STREAM,0); /* create our listening socket */
  if (sock<0) {
    perror("opening stream socket");
    exit(1);
  }

  /* set socket options */
  temp=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sc_reuseaddr,
                 sizeof(sc_reuseaddr));

  /* name and bind socket to an address and port number */

  server.sin_family=AF_INET;
  server.sin_addr.s_addr=INADDR_ANY;
  if (port !=0) server.sin_port=htons(port); 
  else server.sin_port=0;
  
  if (bind(sock,(struct sockaddr *) &server,sizeof(server))) {
     perror("binding stream socket");
     exit(1);
  }

  /* Find out assigned port number and print it out */

  length=sizeof(server);
  if (getsockname(sock,(struct sockaddr *) &server,&length)) {
     perror("getting socket name");
     exit(1);
  }

  fprintf(stdout,"Connected to host : %s:%d\n",host,remote_port);  
  fprintf(stdout,"Socket has port #%d\n",ntohs(server.sin_port));

  if (port==0) {
    fp=fopen(file,"w");
    fprintf(fp,"%d\n",ntohs(server.sin_port));
    fclose(fp);
    fprintf(stdout,"Recorded port number in file:%s\n",file);
  }

  fprintf(stdout,"Recording log in file:%s\n",log);

  root=getpid();

  fprintf(stdout,"Root PID is %d\n",root);

  /* if socket gets broken by the client we have to trap the SIGPIPE
   * signal
   */

   signal(SIGPIPE,SIG_IGN);
   signal(SIGCHLD,SIG_IGN); 
    

  /* the heart of the program */

  listen(sock,5); /* mark our socket willing to accept connections */
  
  do {

      /* block until someone wants to attach to us */

      FD_ZERO(&ready);
      FD_SET(sock,&ready);
      if (select(sock+1,&ready,0,0,NULL) < 0) { 
       perror("while testing for connections");
       continue;
      }
     
      /* Accept the connection from the client */

      fprintf(stdout,"Accepting a new connection...\n");
      clength=sizeof(client);
      msgout_sock=accept(sock,(struct sockaddr *) &client,&clength);
        
      if (msgout_sock==-1) {
         perror("accept"); 
         continue;
      }

      cname=gethostbyaddr((char *) &client.sin_addr,
                          sizeof (client.sin_addr),AF_INET);

      if ((cname !=NULL) && (cname->h_name !=NULL))
         sprintf(chost,"[%s (%s)]",cname->h_name,inet_ntoa(client.sin_addr));
      else sprintf(chost,"[%s]",inet_ntoa(client.sin_addr));

      msgin_sock=socket(AF_INET,SOCK_STREAM,0);
      if (msgin_sock<0) {
        perror("opening stream socket to master");        
        close(msgout_sock);
		continue;
      }      

      /* Make the sockets non-blocking */
      
      
      if ((status=fcntl(msgout_sock,F_GETFL))==-1) {
        close(msgin_sock);
        close(msgout_sock);
        msgout_sock=-1;
        msgin_sock=-1;
        continue;
      }
      
      status|=O_NONBLOCK;
      if ((status=fcntl(msgout_sock,F_SETFL,status))==-1) {
        close(msgin_sock);
        close(msgout_sock);
        msgin_sock=-1;
        msgout_sock=-1;
        continue;
      }
          
      fprintf(stdout,"Getting fcntl block...\n");
      if ((status=fcntl(msgin_sock,F_GETFL))==-1) {
        close(msgin_sock);
        close(msgout_sock);
        msgin_sock=-1;
        msgout_sock=-1;
        continue;
      }

      fprintf(stdout,"Making the socket non-blocking...\n");
      status|=O_NONBLOCK;
      if ((status=fcntl(msgin_sock,F_SETFL,status))==-1) {
        close(msgin_sock);
        close(msgout_sock);
        msgin_sock=-1;
        msgout_sock=-1;
        continue;
      } 
      
 
      fprintf(stdout,"Connecting socket to server...\n");
      if ((connect(msgin_sock,(struct sockaddr *) &master,
				  sizeof(master)) ==-1) && 
          (errno !=EINPROGRESS)) {
        perror("connecting to the master server");
        close(msgin_sock);
        close(msgout_sock);
        msgin_sock=-1;
        continue;
      }
      
      /* Connection to master server established */

      fprintf(stdout,"Creating child process...\n");
      
      if (fork() == 0) {
        close(sock);
        operate(root,msgin_sock,msgout_sock,chost,log);
      }
      
      
      fprintf(stderr,"closing the root files\n");

      close(msgin_sock);  /* close the new socket in the parent so */
      close(msgout_sock); /* that only the child has these files open */
  } while(1);

  return 0;
}
Beispiel #18
0
int main(int argc,char *argv[]) {
  int s=0,m,n;
  FILE *fp;
  FILE *xmlfp;
  unsigned char help=0;
  unsigned char option=0;
  unsigned char ilf=0; 
  char *pathstr=NULL;
  char *scstr=NULL;
  int sctype=0;

  struct XMLDBbuffer *scbuf=NULL;  

  struct XMLdata *xmldata=NULL;
  struct XMLDBdata *xmldbdata=NULL;
  struct XMLDBtree *tree=NULL;

  char *symbol[]={"\"","\\","<",">","&",0};
  char *entity[]={"&quot;","&apos;","&lt;","&gt;","&amp;",0};
  struct Entitydata *entptr;

  struct OptionText *ignore=NULL;
  struct OptionText *remove=NULL;


  char lbuf[255];
  char zero[1]={0};

  entptr=EntityMake();
 
  EntityAddEntityStringArray(entptr,entity);
  EntityAddSymbolStringArray(entptr,symbol);
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

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

  OptionAdd(&opt,"i",'a',&ignore);
  OptionAdd(&opt,"r",'a',&remove);

  OptionAdd(&opt,"path",'t',&pathstr);
  OptionAdd(&opt,"script",'t',&scstr);
  OptionAdd(&opt,"sctype",'i',&sctype);

  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)<3) {
    fprintf(stderr,"xmldoc pwd cfgfile xmldata\n");
    exit(-1);
  }
 
  xmlfp=fopen(argv[arg+2],"r");
  if (xmlfp==NULL) {
    fprintf(stderr,"file not found.\n");
    exit(-1);
  }

  chdir(argv[arg]);

  fp=fopen(argv[arg+1],"r");
  loadconfig(fp,&xmldoc);
  fclose(fp);

 
  if (argc>3) xmldoc.compare.data=argv[arg+3];
  else xmldoc.compare.data=NULL;

  xmldoc.compare.check=cmp;  

  xmldoc.map.iflg=-1;

  if (pathstr !=NULL) {
    free(xmldoc.tree.path);
    xmldoc.tree.path=pathstr;   
  }

  if (scstr !=NULL) {
    xmldoc.sc.type=sctype;
    scbuf=XMLDBMakeBuffer(64);
    XMLDBAddBuffer(scbuf,scstr,strlen(scstr));
    XMLDBFreeBuffer(xmldoc.sc.buf);

    if (sctype==1) {
      xmldoc.sc.buf=XMLDBCopyBuffer(scbuf);
      XMLDBAddBuffer(xmldoc.sc.buf,zero,1);
    } else xmldoc.sc.buf=EntityDecodeBuffer(entptr,scbuf);
    XMLDBFreeBuffer(scbuf);
  }
  
  xmldata=XMLMake();
  xmldbdata=XMLDBMake(xmldata);
  tree=XMLDBMakeTree();

  XMLDBBuildTree(xmldoc.tree.path,xmldoc.tree.delim,tree);
  XMLDBSetTree(xmldbdata,tree);
    
  /* Set the renderer to XMLrender */

  XMLDBSetText(xmldbdata,render,&xmldoc);

  XMLSetStart(xmldata,XMLDBStart,xmldbdata);
  XMLSetEnd(xmldata,XMLDBEnd,xmldbdata); 
  XMLSetComment(xmldata,redirect,xmldata);  

  xmldoc.script=ScriptMake();
  ScriptSetText(xmldoc.script,mapxml,&xmldoc);

  XMLdocSetText(xmldoc.doc,stream_output,stdout);

  if (remove !=NULL) {

    xmldoc.map.remove.num=remove->num;
    xmldoc.map.remove.txt=remove->txt;
  }

  if (ignore !=NULL) {
    xmldoc.map.ignore.num=ignore->num;
    xmldoc.map.ignore.txt=ignore->txt;
  }


  while(fgets(lbuf,255,xmlfp) !=NULL) {
    if (ilf) {
      m=0;
      for (n=0;(lbuf[n] !=0) && (n<256);n++) {
        if (lbuf[n]=='\n') continue;
        lbuf[m]=lbuf[n];
        m++;
      }    
      lbuf[m]=0;
    }
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }

  XMLFree(xmldata);
  XMLDBFree(xmldbdata);
  XMLDBFreeTree(tree);
  ScriptFree(xmldoc.script);
  fclose(xmlfp); 
  fflush(stdout);  
  return 0;

}
Beispiel #19
0
int main (int argc,char *argv[]) {



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

  FILE *fp;
  struct RadarParm *prm;
  struct IQ *iq;
  unsigned int *badtr=NULL;
  int16 *samples=NULL;  

  int sze=0;
  double tval;

  prm=RadarParmMake();
  iq=IQMake();

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

  if (arg==argc) fp=stdin;
  else fp=fopen(argv[arg],"r");
  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }
    
  while (IQFread(fp,prm,iq,&badtr,&samples) !=-1) {
    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);

    tval=TimeYMDHMSToEpoch(prm->time.yr,
		           prm->time.mo,
                           prm->time.dy,
                           prm->time.hr,
		           prm->time.mt,
                           prm->time.sc+prm->time.us/1.0e6);
    ConvertFwriteDouble(stdout,tval);
    ConvertFwriteInt(stdout,sze);
    sze+=IQWrite(-1,prm,iq,badtr,samples);
  }
  if (fp !=stdin) fclose(fp);
  return 0;
} 
Beispiel #20
0
int main(int argc,char *argv[]) {
 

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


  int s=0;
  int arg=0;
  FILE *fp;
  char lbuf[256];
  struct FrameBuffer *img=NULL;
  struct FrameBufferRplot *fbplot=NULL;
  struct PostScriptRplot *psplot=NULL;
  struct PostScript *psdata=NULL;
  struct FrameBufferFontDB *fontdb=NULL;
  struct FrameBufferDB *imagedb=NULL;
  struct XMLdata *xmldata=NULL;
  struct RplotInPlot *rplotin=NULL;
  struct RplotRplot *rplotrplot=NULL;
  struct Rplot *rplot=NULL;
 
  unsigned char land=0;
  float xpoff=40,ypoff=40;
  
  char *fntdbfname=NULL;
  unsigned char psflg=0;
  unsigned char xmlflg=0;
  unsigned char ppmflg=0;
  unsigned char ppmxflg=0;

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

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

 
  struct OptionText *ppmnme=NULL;
  struct OptionText *ppmxnme=NULL;
  struct OptionText *xmlnme=NULL;

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

  OptionAdd(&opt,"ps",'x',&psflg);
  OptionAdd(&opt,"ppm",'x',&ppmflg);
  OptionAdd(&opt,"ppmx",'x',&ppmxflg);
  OptionAdd(&opt,"xml",'x',&xmlflg);
  OptionAdd(&opt,"land",'x',&land);
  OptionAdd(&opt,"xp",'f',&xpoff);
  OptionAdd(&opt,"yp",'f',&ypoff);

  OptionAdd(&opt,"ippm",'a',&ppmnme);
  OptionAdd(&opt,"ippmx",'a',&ppmxnme);
  OptionAdd(&opt,"ixml",'a',&xmlnme);
 
#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,"fdb",'t',&fntdbfname);

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

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

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


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

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

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

  if (gflg) {
    if (fntdbfname==NULL) fntdbfname=getenv("FONTDB");
    if (fntdbfname !=NULL) {
      fp=fopen(fntdbfname,"r");
      if (fp !=NULL) {
        fontdb=FrameBufferFontDBLoad(fp);
        fclose(fp);
      }
    }
    if (fontdb==NULL) {
      fprintf(stderr,"Could not load fonts.\n");
      exit(-1);
    }
  }
   
  imagedb=FrameBufferDBMake();
  loadxml(imagedb,xmlnme);
  loadppm(imagedb,ppmnme);
  loadppmx(imagedb,ppmxnme);

  xmldata=XMLMake();
  rplotin=RplotInMake(xmldata);

  if (gflg) {
      fbplot=FrameBufferRplotMake(fontdb,imagedb);
      FrameBufferRplotSetAll(rplotin,fbplot);
  }
  if (pflg) {
    psdata=PostScriptMake();
    PostScriptSetText(psdata,stream,stdout);
    psplot=PostScriptRplotMake(psdata,imagedb);
    PostScriptRplotSetAll(rplotin,psplot);
    psplot->land=land;
    psplot->xoff=xpoff;
    psplot->yoff=ypoff;
  }
  if (rflg) {
    rplot=RplotMake();
    RplotSetText(rplot,stream,stdout);
    rplotrplot=RplotRplotMake(rplot,imagedb);
    RplotRplotSetAll(rplotin,rplotrplot);
    RplotInSetPass(rplotin,clean_newline,stdout);
  }

  XMLSetStart(xmldata,RplotInStart,rplotin);
  XMLSetEnd(xmldata,RplotInEnd,rplotin);
  XMLSetText(xmldata,RplotInText,rplotin);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
          
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;

  }
  if (s !=0) {
    fprintf(stderr,"Error parsing document.\n");
    exit(0);
  }
 
  if (arg<argc) fclose(fp);
  if (fbplot==NULL) exit(0);
  if (fbplot->img==NULL) {
    fprintf(stderr,"Nothing to plot.\n");
    exit(-1);
  }
  img=fbplot->img;

#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,name,
                       name,argv[0],name,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 FrameBufferSavePPMX(img,stdout);
  }
  #else 
  if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
  else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
  else FrameBufferSavePPMX(img,stdout);
  #endif
  return 0;
}
Beispiel #21
0
int main (int argc,char *argv[]) {

  int arg=0;


  int status=0;
  double atime;

  char *stmestr=NULL;
  char *etmestr=NULL;
  char *sdtestr=NULL;
  char *edtestr=NULL;
  char *exstr=NULL;

  double stime=-1;
  double etime=-1;
  double extime=0;

  double sdate=-1;
  double edate=-1;

  int yr,mo,dy,hr,mt;
  double sc;
  unsigned char vb=0;
  unsigned char help=0;
  unsigned char option=0;


  FILE *fp=NULL;

  int n;

  prm=RadarParmMake();
  iq=IQMake();

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


  OptionAdd(&opt,"vb",'x',&vb);
  OptionAdd(&opt,"st",'t',&stmestr);
  OptionAdd(&opt,"et",'t',&etmestr);
  OptionAdd(&opt,"sd",'t',&sdtestr);
  OptionAdd(&opt,"ed",'t',&edtestr);
  OptionAdd(&opt,"ex",'t',&exstr);

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

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

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

  if (exstr !=NULL) extime=strtime(exstr);
  if (stmestr !=NULL) stime=strtime(stmestr);
  if (etmestr !=NULL) etime=strtime(etmestr);
  if (sdtestr !=NULL) sdate=strdate(sdtestr);
  if (edtestr !=NULL) edate=strdate(edtestr);



  if ((argc-arg)>1) {
    fp=fopen(argv[arg+1],"r");
    if (fp==NULL) {
      fprintf(stderr,"Index not found.\n");
      exit(-1);
    }
    inx=IQIndexFload(fp);
   
    fclose(fp);
    if (inx==NULL) {
      fprintf(stderr,"Error loading index.\n");
      exit(-1);
    }
  }
  if (arg==argc) fp=stdin;
  else fp=fopen(argv[arg],"r");
  if (fp==NULL) {
    fprintf(stderr,"File not found.\n");
    exit(-1);
  }
  

  if (IQFread(fp,prm,iq,&badtr,&samples)==-1)  {
    fprintf(stderr,"Error reading file\n");
    exit(-1);
  }

  atime=TimeYMDHMSToEpoch(prm->time.yr,
	   	           prm->time.mo,
                           prm->time.dy,
                           prm->time.hr,
		           prm->time.mt,
                           prm->time.sc+prm->time.us/1.0e6);

   /* skip here */

    if ((stime !=-1) || (sdate !=-1)) { 
      /* we must skip the start of the files */
      int yr,mo,dy,hr,mt;
      double sc; 
      if (stime==-1) stime= ( (int) atime % (24*3600));
      if (sdate==-1) stime+=atime - ( (int) atime % (24*3600));
      else stime+=sdate;

      TimeEpochToYMDHMS(stime,&yr,&mo,&dy,&hr,&mt,&sc);
      status=IQFseek(fp,yr,mo,dy,hr,mt,sc,NULL,inx); 
    
      if (status ==-1) {
        fprintf(stderr,"File does not contain the requested interval.\n");
        exit(-1);
      }
      if (IQFread(fp,prm,iq,&badtr,&samples)==-1)  {
         fprintf(stderr,"Error reading file\n");
         exit(-1);
      }
  
    } else stime=atime;
   
    if (etime !=-1) {
       if (edate==-1) etime+=atime - ( (int) atime % (24*3600));
       else etime+=edate;
    }

   if (extime !=0) etime=stime+extime;
 
   do {

     fprintf(stderr,"%s\n",prm->origin.time);
     fprintf(stderr,"%s\n",prm->origin.command);
     fprintf(stderr,"%s\n",prm->combf);
     fprintf(stderr,"%d:",prm->mppul);
     for (n=0;n<prm->mppul;n++) fprintf(stderr,"%d ",prm->pulse[n]);
     fprintf(stderr,"\n");
     fprintf(stderr,"%d\n",prm->mplgs);
     for (n=0;n<=prm->mplgs;n++) fprintf(stderr,"%d,%d ",
          prm->lag[0][n],prm->lag[1][n]);
     fprintf(stderr,"\n");


         
     IQFwrite(stdout,prm,iq,badtr,samples);
     
     atime=TimeYMDHMSToEpoch(prm->time.yr,
		    prm->time.mo,
                    prm->time.dy,
                    prm->time.hr,
		    prm->time.mt,
                    prm->time.sc+prm->time.us/1.0e6);
     TimeEpochToYMDHMS(atime,&yr,&mo,&dy,&hr,&mt,&sc);
     if (vb==1) fprintf(stderr,"%d-%d-%d %d:%d:%d\n",yr,mo,dy,hr,mt,(int) sc);

      if ((etime !=-1) && (atime>=etime)) break;
      status=IQFread(fp,prm,iq,&badtr,&samples);
 
  } while (status !=-1);  
 
  if (fp !=stdin) fclose(fp);
  return 0;


}
Beispiel #22
0
int main(int argc,char *argv[]) {
  
  int rport=DEF_PORT,tport=1024,arg=0;
  int sock;

  int sc_reuseaddr=1,temp;

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

  socklen_t length;
  socklen_t clength;

  struct sockaddr_in server;
  struct sockaddr_in client;

  fd_set ready;

  struct hostent *gethostbyname();
  pid_t root;

  char *chstr=NULL;

  int msgsock=0;

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

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

  OptionAdd(&opt,"rp",'i',&rport);
  OptionAdd(&opt,"tp",'i',&tport);


  OptionAdd(&opt,"eh",'t',&errhost);
  OptionAdd(&opt,"ep",'i',&errport);

  OptionAdd(&opt,"c",'t',&chstr);

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

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

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

  if (chstr !=NULL) {
    if (tolower(chstr[0])=='a') channel=1;
    if (tolower(chstr[0])=='b') channel=2;
  }


  if (errhost==NULL) errhost=derrhost;
  errsock=TCPIPMsgOpen(errhost,errport);

  sprintf(errbuf,"Started (version %s.%s) listening on port %d for control program, and on port %d for clients",
          MAJOR_VERSION,MINOR_VERSION,rport,tport);
  ErrLog(errsock,taskname,errbuf);  


  signal(SIGCHLD,SIG_IGN); 
  signal(SIGPIPE,SIG_IGN);

  root=getpid();

  sock=socket(AF_INET,SOCK_STREAM,0); /* create our listening socket */
  if (sock<0) {
    perror("opening stream socket");
    exit(1);
  }

  /* set socket options */
  temp=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sc_reuseaddr,
                 sizeof(sc_reuseaddr));

  /* name and bind socket to an address and port number */

  server.sin_family=AF_INET;
  server.sin_addr.s_addr=INADDR_ANY;
  if (rport !=0) server.sin_port=htons(rport); 
  else server.sin_port=0;
  
  if (bind(sock,(struct sockaddr *) &server,sizeof(server))) {
     perror("binding stream socket");
     exit(1);
  }

  /* Find out assigned port number and print it out */

  length=sizeof(server);
  if (getsockname(sock,(struct sockaddr *) &server,&length)) {
     perror("getting socket name");
     exit(1);
  }

  listen(sock,5); /* mark our socket willing to accept connections */
  
  do {

      /* block until someone wants to attach to us */

      FD_ZERO(&ready);
      FD_SET(sock,&ready);
      if (select(sock+1,&ready,0,0,NULL) < 0) { 
       perror("while testing for connections");
       continue;
      }
     
      /* Accept the connection from the client */

      fprintf(stdout,"Accepting a new connection...\n");
      clength=sizeof(client);
      msgsock=accept(sock,(struct sockaddr *) &client,&clength);
        
      if (msgsock==-1) {
         perror("accept"); 
         continue;
      }

      if (fork() == 0) {
        close(sock);
        operate(root,msgsock,tport);
        exit(0);
      }
      close (msgsock);
  } while(1);

 
  return 0;

}
Beispiel #23
0
int main(int argc,char *argv[]) {
  int status=0;
  struct DataMap *ptr=NULL;
  struct DataMapScalar *sx=NULL,*sy=NULL;
  struct DataMapArray *ax=NULL,*ay=NULL;
  struct DimMap *dx=NULL;

  unsigned char vbflg=0;
  unsigned char help=0;
  unsigned char option=0;
  unsigned char zflg=0;


  FILE *fp=NULL;
  int c,i;
  gzFile zfp=0;
  int x=0,n=0;

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


  if (argc>1) {
    arg=OptionProcess(1,argc,argv,&opt,NULL); 
    if (help==1) {
      OptionPrintInfo(stdout,hlpstr);
      exit(0);
    }
    if (option==1) {
      OptionDump(stdout,&opt);
      exit(0);
    }

    if (zflg) {
      zfp=gzopen(argv[arg],"r");
      if (zfp==0) {
        fprintf(stderr,"File not found.\n");
        exit(-1);
      }
    } else {
      fp=fopen(argv[arg],"r");
      if (fp==NULL) {
        fprintf(stderr,"File not found.\n");
        exit(-1);
      }
    }  
  } else {
    OptionPrintInfo(stdout,errstr);
    exit(-1);
  }

  while (1) {

   if (zflg) ptr=DataMapReadZ(zfp);
    else ptr=DataMapFread(fp);

    if (ptr==NULL) break;


    for (c=0;c<ptr->snum;c++) {
      sx=ptr->scl[c];
      for (n=0;n<snum;n++) {
	sy=sptr[n];
        if (strcmp(sx->name,sy->name) !=0) continue;
        if (sx->type !=sy->type) continue;
        break;
      }
      if (n==snum) {
	/* copy the scalar */
        if (sptr==NULL) sptr=malloc(sizeof(struct DataMapScalar *));
        else {
          struct DataMapScalar **tmp;
          tmp=realloc(sptr,(snum+1)*sizeof(struct DataMapScalar *));
          if (tmp==NULL) break;
          sptr=tmp;
	}
        sptr[snum]=DataMapMakeScalar(sx->name,0,sx->type,NULL);
        snum++;
      }
    }
    if (c !=ptr->snum) {      
      status=-1;
      break;
    }
    for (c=0;c<ptr->anum;c++) {
      ax=ptr->arr[c];
      for (n=0;n<anum;n++) {
        ay=aptr[n];
        if (strcmp(ax->name,ay->name) !=0) continue;
        if (ax->type != ay->type) continue;
        if (ax->dim != ay->dim) continue;
        break;
      }
      if (n !=anum) {
        /* check the ranges */
        for (i=0;i<ax->dim;i++)
          if (ax->rng[i]>rptr[roff[n]+i]) rptr[roff[n]+i]=ax->rng[i];
      }

      if (n==anum) {
	/* copy the array */
      
        if (roff==NULL) roff=malloc(sizeof(int32));
        else {
          int32 *tmp;
          tmp=realloc(roff,(anum+1)*sizeof(int32));
          if (tmp==NULL) break;
	  roff=tmp;
	}
        roff[anum]=rnum;
        if (rptr==NULL) rptr=malloc(sizeof(int32)*ax->dim);
        else {
          int32 *tmp;
          tmp=realloc(rptr,(rnum+ax->dim)*sizeof(int32));
          if (tmp==NULL) break;
	  rptr=tmp;
	}
        for (i=0;i<ax->dim;i++) rptr[rnum+i]=ax->rng[i];
        rnum+=ax->dim;
	
        if (aptr==NULL) aptr=malloc(sizeof(struct DataMapArray *));
        else {
          struct DataMapArray **tmp;
          tmp=realloc(aptr,(anum+1)*sizeof(struct DataMapArray *));
          if (tmp==NULL) break;
          aptr=tmp;
	}
        aptr[anum]=DataMapMakeArray(ax->name,0,ax->type,ax->dim,NULL,
				    NULL);
        anum++;
       

      }

    }
    if (c !=ptr->anum) {
       status=-1;
       break;
    }
    DataMapFree(ptr);
  }
  if (zflg) gzclose(zfp);
  else fclose(fp);

  if (status==-1) {
    fprintf(stderr,"Error processing file.\n");
    exit(-1);
  }

  for (n=0;n<anum;n++) { 
     ax=aptr[n];
     ax->rng=rptr+roff[n];
     for (c=0;c<ax->dim;c++) if (ax->rng[c]==0) break; /* bad data */
     if (c !=ax->dim) ax->dim=0;
  }


  cdfsname=malloc(sizeof(char *)*snum);
  if (cdfsname==NULL) {
    fprintf(stderr,"Could not allocate scalar name table.\n");
    exit(-1);
  }

  cdfaname=malloc(sizeof(char *)*anum);
  if (cdfaname==NULL) {
    fprintf(stderr,"Could not allocate array name table.\n");
    exit(-1);
  }



  for (n=0;n<snum;n++) { 
    sx=sptr[n];
    cdfsname[n]=malloc(strlen(sx->name)+1);
    for (c=0;sx->name[c] !=0;c++) 
       if (isalnum(sx->name[c])) cdfsname[n][c]=sx->name[c];
	   else cdfsname[n][c]='_';
    cdfsname[n][c]=0;
    x=0;
    for (c=0;c<n;c++) if (strncmp(cdfsname[c],cdfsname[n],
                          strlen(cdfsname[n]))==0) x++;; 
    if (x !=0) {
      char *tmp;
      char txt[4];
      x++;
      sprintf(txt,"%.3d",x);
      tmp=realloc(cdfsname[n],strlen(cdfsname[n])+4);
      if (tmp==NULL) break;
      cdfsname[n]=tmp;
      strcat(cdfsname[n],txt);
    }
  }

  if (n !=snum) {
    fprintf(stderr,"Error generating names.\n");
    exit(-1);
  }

  for (n=0;n<anum;n++) { 
    ax=aptr[n];
    cdfaname[n]=NULL;
    if (ax->dim==0) continue;
    cdfaname[n]=malloc(strlen(ax->name)+1);
    for (c=0;ax->name[c] !=0;c++) 
       if (isalnum(ax->name[c])) cdfaname[n][c]=ax->name[c];
	   else cdfaname[n][c]='_';
    cdfaname[n][c]=0;
    for (c=0;c<n;c++) if (strncmp(cdfaname[c],cdfaname[n],
                          strlen(cdfaname[n]))==0) x++;
    if (x !=0) {
      char *tmp;
      char txt[4];
      x++;
      sprintf(txt,"%.3d",x);
      tmp=realloc(cdfaname[n],strlen(cdfaname[n])+4);
      if (tmp==NULL) break;
      cdfaname[n]=tmp;
      strcat(cdfaname[n],txt);
    }

  }

  if (n !=anum) {
    fprintf(stderr,"Error generating names.\n");
    exit(-1);
  }


  /* build the dimension table */

  for (n=0;n<snum;n++) {
    sx=sptr[n];
    if (sx->type != DATASTRING) continue;
    if (dnum==0) dptr=malloc(sizeof(struct DimMap *));
    else {
      struct DimMap **tmp;
      tmp=realloc(dptr,(dnum+1)*sizeof(struct DimMap *));
      if (tmp==NULL) break;
      dptr=tmp;
    }
    dx=malloc(sizeof(struct DimMap));
    dptr[dnum]=dx;
    dx->flg=0;
    dx->num=n;
    dx->dim=0;    
    dx->value=STRINGSIZE;  
    dx->name=malloc(strlen(cdfsname[n])+1);
    strcpy(dx->name,cdfsname[n]);
    x=0;
    for (c=0;c<dnum;c++) if (strncmp(dptr[c]->name,dx->name,
                          strlen(dx->name))==0) x++;
    if (x !=0) {
      char *tmp;
      char txt[4];
      x++;
      sprintf(txt,"%.3d",x);
      tmp=realloc(dx->name,strlen(dx->name)+4);
      if (tmp==NULL) break;
      dx->name=tmp;
      strcat(dx->name,txt);
    }
    dnum++;
  }
  if (n !=snum) {
    fprintf(stderr,"Error building dimension table.\n");
    exit(-1);
  }


 for (n=0;n<anum;n++) {
    ax=aptr[n];
    if (ax->dim==0) continue;
    for (i=0;i<ax->dim;i++) {
      if (dnum==0) dptr=malloc(sizeof(struct DimMap *));
      else {
        struct DimMap **tmp;
        tmp=realloc(dptr,(dnum+1)*sizeof(struct DimMap *));
        if (tmp==NULL) break;
        dptr=tmp;
      }
      dx=malloc(sizeof(struct DimMap));
      dptr[dnum]=dx;
      dx->flg=1;
      dx->num=n;
      dx->dim=i;
      dx->value=ax->rng[i];    
      dx->name=malloc(strlen(cdfaname[n])+1);
      strcpy(dx->name,cdfaname[n]);
      x=0;
      for (c=0;c<dnum;c++) if (strncmp(dptr[c]->name,dx->name,
                          strlen(dx->name))==0) x++;
      if (x !=0) {
        char *tmp;
        char txt[4];
        x++;
        sprintf(txt,"%.3d",x);
        tmp=realloc(dx->name,strlen(dx->name)+4);
        if (tmp==NULL) break;
        dx->name=tmp;
        strcat(dx->name,txt);
      }
      dnum++;
    }
    if (ax->type==DATASTRING) {
      if (dnum==0) dptr=malloc(sizeof(struct DimMap *));
      else {
        struct DimMap **tmp;
        tmp=realloc(dptr,(dnum+1)*sizeof(struct DimMap *));
        if (tmp==NULL) break;
        dptr=tmp;
      }
      dx=malloc(sizeof(struct DimMap));
      dptr[dnum]=dx;
      dx->flg=1;
      dx->num=n;
      dx->dim=i;
      dx->value=STRINGSIZE;    
      dx->name=malloc(strlen(cdfaname[n])+1);
      strcpy(dx->name,cdfaname[n]);
      x=0;
      for (c=0;c<dnum;c++) if (strncmp(dptr[c]->name,dx->name,
                          strlen(dx->name))==0) x++;
      if (x !=0) {
        char *tmp;
        char txt[4];
        x++;
        sprintf(txt,"%.3d",x);
        tmp=realloc(dx->name,strlen(dx->name)+4);
        if (tmp==NULL) break;
        dx->name=tmp;
        strcat(dx->name,txt);
      }
      dnum++;
    }
  }

  if (n !=anum) {
    fprintf(stderr,"Error building dimension table.\n");
    exit(-1);
  }


  fp=fopen(argv[2],"w");
  fprintf(fp,"netcdf dmap {\n\n");
  fprintf(fp,"dimensions:\n");
  fprintf(fp,"\tblock=unlimited;\n");
  for (n=0;n<dnum;n++) {
    dx=dptr[n];
    fprintf(fp,"\t%s=%d;\n",dx->name,dx->value);
  }


  fprintf(fp,"variables:\n");
   for (n=0;n<snum;n++) {
     fprintf(fp,"\t");
     sx=sptr[n];
     switch(sx->type) {
     case DATACHAR:
        fprintf(fp,"char");
        break;
     case DATASHORT:
        fprintf(fp,"short");
        break;
     case DATAINT:
        fprintf(fp,"int");
        break;
     case DATAFLOAT:
        fprintf(fp,"float");
        break;
     case DATADOUBLE:
        fprintf(fp,"double");
        break;
     case DATASTRING:
        fprintf(fp,"char"); 
    }
    fprintf(fp," %s",cdfsname[n]);
    if (sx->type==DATASTRING) {
      for (x=0;x<dnum;x++) {
	dx=dptr[x];
        if (dx->flg !=0) continue;
        if (dx->num==n) break;
      }
      fprintf(fp,"(block,%s);\n",dx->name);
    } else fprintf(fp,"(block);\n");

    
  }


  for (n=0;n<anum;n++) {
     fprintf(fp,"\t");
     ax=aptr[n];
     if (ax->dim==0) continue;
     switch(ax->type) {
     case DATACHAR:
        fprintf(fp,"char");
        break;
     case DATASHORT:
        fprintf(fp,"short");
        break;
     case DATAINT:
        fprintf(fp,"int");
        break;
     case DATAFLOAT:
        fprintf(fp,"float");
        break;
     case DATADOUBLE:
        fprintf(fp,"double");
        break;
     case DATASTRING:
        fprintf(fp,"char"); 
    }
    fprintf(fp," %s",cdfaname[n]);
    fprintf(fp,"(block");
    for (x=0;x<dnum;x++) {
      dx=dptr[x];
      if (dx->flg !=1) continue;
      if (dx->num!=n) continue;
      fprintf(fp,",%s",dx->name);
    }
    fprintf(fp,");\n");
    
  }
  fprintf(fp,"}");
  fclose(fp);
  
  fp=fopen(argv[3],"w");
  for (n=0;n<snum;n++) {
   fprintf(fp,"\t");
     sx=sptr[n];
     switch(sx->type) {
     case DATACHAR:
        fprintf(fp,"char 0");
        break;
     case DATASHORT:
        fprintf(fp,"short 0");
        break;
     case DATAINT:
        fprintf(fp,"int 0");
        break;
     case DATAFLOAT:
        fprintf(fp,"float 0");
        break;
     case DATADOUBLE:
        fprintf(fp,"double 0");
        break;
     case DATASTRING:
        fprintf(fp,"string 0"); 
    }
    fprintf(fp," %c%s%c=%s;\n",'"',sx->name,'"',cdfsname[n]);
  }

  for (n=0;n<anum;n++) {
   fprintf(fp,"\t");
     ax=aptr[n];
     if (ax->dim==0) continue;
     switch(ax->type) {
     case DATACHAR:
        fprintf(fp,"char");
        break;
     case DATASHORT:
        fprintf(fp,"short");
        break;
     case DATAINT:
        fprintf(fp,"int");
        break;
     case DATAFLOAT:
        fprintf(fp,"float");
        break;
     case DATADOUBLE:
        fprintf(fp,"double");
        break;
     case DATASTRING:
        fprintf(fp,"string"); 
    }
    fprintf(fp," %d",ax->dim); 
    fprintf(fp," %c%s%c=%s;\n",'"',ax->name,'"',cdfaname[n]);
  }
  fclose(fp);
  return 0;
}
Beispiel #24
0
int main(int argc,char *argv[]) {

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

  int arg=0;
  FILE *fp;

  unsigned int bgcolor=0;
  struct FrameBufferMatrix m;
  struct FrameBuffer *src=NULL;
  struct FrameBuffer *dst=NULL;
 
  char *bgtxt=NULL;
  unsigned char cflg=0;
  unsigned char sflg=0;
  float scale=100;

  float wdt=-1;
  float hgt=-1;
  unsigned char help=0;
  unsigned char option=0;

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

  OptionAdd(&opt,"smooth",'x',&sflg);
  OptionAdd(&opt,"scale",'f',&scale);
  OptionAdd(&opt,"check",'x',&cflg);
  OptionAdd(&opt,"bgcol",'t',&bgtxt);


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

  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;
 
  src=FrameBufferLoadPPMX(fp);

  if (src==NULL) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  bgcolor=FrameBufferColor(0x00,0x00,0x00,0xff);

  if (bgtxt !=NULL) {
     sscanf(bgtxt,"%x",&bgcolor);
     bgcolor=bgcolor | 0xff000000;
  }
  
  
  if (scale<=0) scale=0.5;
  
  if (scale !=100) {
    wdt=src->wdt*scale/100.0;
    hgt=src->hgt*scale/100.0;
  } else {
    wdt=src->wdt;
    hgt=src->hgt;
  }

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

  dst=FrameBufferMake(NULL,wdt,hgt,24);
  FrameBufferClear(dst,bgcolor,0x0f);

  if (cflg !=0) { /* plot checker board */
    int x,y;
    int c=0,d=0;
    for (x=0;x<wdt;x+=8) {
      c=d;
      d=!d;
      for (y=0;y<hgt;y+=8) {
        c=!c;
        if (c==0) FrameBufferRectangle(dst,NULL,x,y,8,8,1,
                             0xffc0c0c0,0x0f,0,NULL,NULL);
        else FrameBufferRectangle(dst,NULL,x,y,8,8,1,
                             0xffffffff,0x0f,0,NULL,NULL);
     
      }
    }
  } 


  if (scale==100)
    FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL);  
  else {
    m.a=scale/100.0;
    m.b=0;
    m.c=0;
    m.d=scale/100.0;
    FrameBufferImage(dst,&m,src,0x0f,0,0,sflg,NULL); 
  }  

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

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

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

  XwinFrameBufferWindow(dst,win);

  XwinShowWindow(win);

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

  XwinFreeWindow(win);
  XwinCloseDisplay(dp); 
#endif

  return 0;
}
Beispiel #25
0
int main(int argc,char *argv[]) {
    int arg;
    int sock;
    int remote_port=0;
    char *host;
    int flag,status,size;
    unsigned char help=0;
    unsigned char option=0;

    unsigned char *buffer=NULL;
    unsigned char stream=255;

    char **tmp;
    struct DataMap *ptr;
    struct DataMapScalar *s;
    struct DataMapArray *a;
    int c,n,x;

    int sval=255;
    unsigned char dflg=0;

    OptionAdd(&opt,"-help",'x',&help);
    OptionAdd(&opt,"-option",'x',&option);
    OptionAdd(&opt,"d",'x',&dflg);
    OptionAdd(&opt,"s",'i',&sval);

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

    host=argv[argc-2];
    remote_port=atoi(argv[argc-1]);
    stream=sval;

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

    do {
        status=ConnexRead(1,&sock,&buffer,&size,&flag,NULL);
        if (status==-1) break;
        if (flag !=-1) {
            fprintf(stderr,"Message size:%d\n",size);
            if (size==0) continue;
            ptr=DataMapDecodeBuffer(buffer,size);
            if (ptr==NULL) fprintf(stderr,"Not a recognized message.\n");
            else {
                fprintf(stdout,"scalars:\n");
                for (c=0; c<ptr->snum; c++) {
                    s=ptr->scl[c];
                    switch (s->type) {
                    case DATACHAR:
                        fprintf(stdout,"\tchar");
                        break;
                    case DATASHORT:
                        fprintf(stdout,"\tshort");
                        break;
                    case DATAINT:
                        fprintf(stdout,"\tint");
                        break;
                    case DATAFLOAT:
                        fprintf(stdout,"\tfloat");
                        break;
                    case DATADOUBLE:
                        fprintf(stdout,"\tdouble");
                        break;
                    case DATASTRING:
                        fprintf(stdout,"\tstring");
                        break;
                    }
                    fprintf(stdout,"\t%c%s%c",'"',s->name,'"');
                    fprintf(stdout," = ");
                    switch (s->type) {
                    case DATACHAR:
                        fprintf(stdout,"%d",*(s->data.cptr));
                        break;
                    case DATASHORT:
                        fprintf(stdout,"%d",*(s->data.sptr));
                        break;
                    case DATAINT:
                        fprintf(stdout,"%d",*(s->data.iptr));
                        break;
                    case DATAFLOAT:
                        fprintf(stdout,"%g",*(s->data.fptr));
                        break;
                    case DATADOUBLE:
                        fprintf(stdout,"%g",*(s->data.dptr));
                        break;
                    case DATASTRING:
                        tmp=(char **) s->data.vptr;
                        fprintf(stdout,"%c%s%c",'"',*tmp,'"');
                        break;
                    }
                    fprintf(stdout,"\n");
                }
                fprintf(stdout,"arrays:\n");
                for (c=0; c<ptr->anum; c++) {
                    a=ptr->arr[c];
                    switch (a->type) {
                    case DATACHAR:
                        fprintf(stdout,"\tchar");
                        break;
                    case DATASHORT:
                        fprintf(stdout,"\tshort");
                        break;
                    case DATAINT:
                        fprintf(stdout,"\tint");
                        break;
                    case DATAFLOAT:
                        fprintf(stdout,"\tfloat");
                        break;
                    case DATADOUBLE:
                        fprintf(stdout,"\tdouble");
                        break;
                    case DATASTRING:
                        fprintf(stdout,"\tstring");
                        break;
                    }
                    fprintf(stdout,"\t%c%s%c",'"',a->name,'"');
                    fprintf(stdout," ");
                    for (x=0; x<a->dim; x++) fprintf(stdout,"[%d]",a->rng[x]);
                    if (dflg) {
                        fprintf(stdout,"=");
                        n=1;
                        for (x=0; x<a->dim; x++) n=a->rng[x]*n;
                        for (x=0; x<n; x++) {
                            if (x % a->rng[a->dim-1]==0) fprintf(stdout,"\n\t\t");
                            else if (x !=0) fprintf(stdout,",\t");
                            switch (a->type) {
                            case DATACHAR:
                                fprintf(stdout,"%d",a->data.cptr[x]);
                                break;
                            case DATASHORT:
                                fprintf(stdout,"%d",a->data.sptr[x]);
                                break;
                            case DATAINT:
                                fprintf(stdout,"%d",a->data.iptr[x]);
                                break;
                            case DATAFLOAT:
                                fprintf(stdout,"%g",a->data.fptr[x]);
                                break;
                            case DATADOUBLE:
                                fprintf(stdout,"%g",a->data.dptr[x]);
                                break;
                            case DATASTRING:
                                tmp=(char **) a->data.vptr;
                                fprintf(stdout,"%c%s%c",'"',tmp[x],'"');
                                break;

                            }
                        }
                        fprintf(stdout,"\n");
                    } else fprintf(stdout,"\n");
                }
                DataMapFree(ptr);
            }
        }
    } while(1);
    fprintf(stderr,"Connection failed.\n");
    return 0;

}
Beispiel #26
0
int main(int argc,char *argv[]) {
  unsigned int color=0;
  unsigned int alpha=255;
  unsigned char nonzero=0;
  int arg=0;
  int c=0,v=0;
  FILE *fp;
  char *name=NULL;
  char *atxt=NULL;
  struct FrameBuffer *img=NULL;
  

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

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

  OptionAdd(&opt,"name",'t',&name);
  OptionAdd(&opt,"alpha",'t',&atxt);
  OptionAdd(&opt,"nz",'x',&nonzero);
  
  arg=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) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  img=FrameBufferLoadPPM(fp,name);

  if (img==NULL) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  if (atxt !=NULL) {
    int alen;
    alen=strlen(atxt);

    if ((alen>2) && (atxt[0]=='0') && (atxt[1]=='x'))
       sscanf(atxt+2,"%x",&alpha);
    else if (atxt[alen-1]=='%') {
      float aflt;
      atxt[alen-1]=0;
      sscanf(atxt,"%g",&aflt);
      if (aflt<0) aflt=0;
      if (aflt>100) aflt=100;
      alpha=255*aflt/100.0;
    } else alpha=atoi(atxt);
    if (alpha>255) alpha=255;
  }
  color=FrameBufferColor(0,0,0,alpha);
  FrameBufferClear(img,color,0x08);
  if (nonzero) {
    for (c=0;c<img->wdt*img->hgt;c++) {
      v=img->img[c]+img->img[c+img->wdt*img->wdt]+
        img->img[c+2*img->wdt*img->wdt];
      if (v==0) img->msk[c]=0;
    }
  }

  if (img !=NULL) FrameBufferSavePPMX(img,stdout);
  return 0;
}
Beispiel #27
0
int main(int argc,char *argv[]) {
  int status=0;
  struct DataMap *ptr;
  struct DataMapScalar *sx=NULL,*sy=NULL;
  struct DataMapArray *ax=NULL,*ay=NULL;

  char buf[1024];
  unsigned char vbflg=0;

  FILE *fp;
  int c,i;
  int x=0,n;
  int tab;

  char *cdfname=NULL;
  char *cdfdef={"dmapcdf"};
  int block=0;
  int rnum=0,znum=0;
  int nelm=0;
  unsigned char help=0;
  unsigned char option=0;


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

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

  if (argc>1) {
    arg=OptionProcess(1,argc,argv,&opt,NULL); 
    if (help==1) {
      OptionPrintInfo(stdout,hlpstr);
      exit(0);
    }
    if (option==1) {
      OptionDump(stdout,&opt);
      exit(0);
    }

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


  if (cdfname==NULL) cdfname=cdfdef;

  while ((ptr=DataMapFread(fp)) !=NULL) {


    for (c=0;c<ptr->snum;c++) {
      sx=ptr->scl[c];
      for (n=0;n<snum;n++) {
	sy=sptr[n];
        if (strcmp(sx->name,sy->name) !=0) continue;
        if (sx->type !=sy->type) continue;
        break;
      }
      if (n==snum) {
	/* copy the scalar */
        if (sptr==NULL) sptr=malloc(sizeof(struct DataMapScalar *));
        else {
          struct DataMapScalar **tmp;
          tmp=realloc(sptr,(snum+1)*sizeof(struct DataMapScalar *));
          if (tmp==NULL) break;
          sptr=tmp;
	}
        sptr[snum]=DataMapMakeScalar(sx->name,sx->type,NULL);
        snum++;
      }
    }
    if (c !=ptr->snum) {      
      status=-1;
      break;
    }
    for (c=0;c<ptr->anum;c++) {
      ax=ptr->arr[c];
      for (n=0;n<anum;n++) {
        ay=aptr[n];
        if (strcmp(ax->name,ay->name) !=0) continue;
        if (ax->type != ay->type) continue;
        if (ax->dim != ay->dim) continue;
        break;
      }
      if (n !=anum) {
        /* check the ranges */
        for (i=0;i<ax->dim;i++)
          if (ax->rng[i]>rptr[roff[n]+i]) rptr[roff[n]+i]=ax->rng[i];
      }

      if (n==anum) {
	/* copy the array */
      
        if (roff==NULL) roff=malloc(sizeof(int32));
        else {
          int32 *tmp;
          tmp=realloc(roff,(anum+1)*sizeof(int32));
          if (tmp==NULL) break;
	  roff=tmp;
	}
        roff[anum]=rnum;
        if (rptr==NULL) rptr=malloc(sizeof(int32)*ax->dim);
        else {
          int32 *tmp;
          tmp=realloc(rptr,(rnum+ax->dim)*sizeof(int32));
          if (tmp==NULL) break;
	  rptr=tmp;
	}
        for (i=0;i<ax->dim;i++) rptr[rnum+i]=ax->rng[i];
        rnum+=ax->dim;
	
        if (aptr==NULL) aptr=malloc(sizeof(struct DataMapArray *));
        else {
          struct DataMapArray **tmp;
          tmp=realloc(aptr,(anum+1)*sizeof(struct DataMapArray *));
          if (tmp==NULL) break;
          aptr=tmp;
	}
        aptr[anum]=DataMapMakeArray(ax->name,ax->type,ax->dim,NULL,
				    NULL);
        anum++;
       

      }

    }
    if (c !=ptr->anum) {
       status=-1;
       break;
    }
    DataMapFree(ptr);
    block++;
  }
  fclose(fp);

  if (status==-1) {
    fprintf(stderr,"Error processing file.\n");
    exit(-1);
  }

  for (n=0;n<anum;n++) { 
     ax=aptr[n];
     ax->rng=rptr+roff[n];
     for (c=0;c<ax->dim;c++) if (ax->rng[c]==0) break; /* bad data */
     if (c !=ax->dim) ax->dim=0;
  }


  cdfsname=malloc(sizeof(char *)*snum);
  if (cdfsname==NULL) {
    fprintf(stderr,"Could not allocate scalar name table.\n");
    exit(-1);
  }

  cdfaname=malloc(sizeof(char *)*anum);
  if (cdfaname==NULL) {
    fprintf(stderr,"Could not allocate array name table.\n");
    exit(-1);
  }



  for (n=0;n<snum;n++) { 
    sx=sptr[n];
    cdfsname[n]=malloc(strlen(sx->name)+1);
    for (c=0;sx->name[c] !=0;c++) 
       if (isalnum(sx->name[c])) cdfsname[n][c]=sx->name[c];
	   else cdfsname[n][c]='_';
    cdfsname[n][c]=0;
    x=0;
    for (c=0;c<n;c++) if (strncmp(cdfsname[c],cdfsname[n],
                          strlen(cdfsname[n]))==0) x++;; 
    if (x !=0) {
      char *tmp;
      char txt[4];
      x++;
      sprintf(txt,"%.3d",x);
      tmp=realloc(cdfsname[n],strlen(cdfsname[n])+4);
      if (tmp==NULL) break;
      cdfsname[n]=tmp;
      strcat(cdfsname[n],txt);
    }
  }

  if (n !=snum) {
    fprintf(stderr,"Error generating names.\n");
    exit(-1);
  }

  for (n=0;n<anum;n++) { 
    ax=aptr[n];
    cdfaname[n]=NULL;
    if (ax->dim==0) continue;
    cdfaname[n]=malloc(strlen(ax->name)+1);
    for (c=0;ax->name[c] !=0;c++) 
       if (isalnum(ax->name[c])) cdfaname[n][c]=ax->name[c];
	   else cdfaname[n][c]='_';
    cdfaname[n][c]=0;
    for (c=0;c<n;c++) if (strncmp(cdfaname[c],cdfaname[n],
                          strlen(cdfaname[n]))==0) x++;
    if (x !=0) {
      char *tmp;
      char txt[4];
      x++;
      sprintf(txt,"%.3d",x);
      tmp=realloc(cdfaname[n],strlen(cdfaname[n])+4);
      if (tmp==NULL) break;
      cdfaname[n]=tmp;
      strcat(cdfaname[n],txt);
    }

  }

  if (n !=anum) {
    fprintf(stderr,"Error generating names.\n");
    exit(-1);
  }

  rnum=snum;
  znum=anum;

  fp=fopen(argv[2],"w");
  fprintf(fp,"#header\n");
  fprintf(fp,"                            CDF NAME: %s\n",cdfname);
  fprintf(fp,"                       DATA ENCODING: NETWORK\n");
  fprintf(fp,"                            MAJORITY: ROW\n");
  fprintf(fp,"                              FORMAT: SINGLE\n\n");
  fprintf(fp,
     "! Variables  G.Attributes  V.Attributes  Records  Dims  Sizes\n");
  fprintf(fp,
     "! ---------  ------------  ------------  -------  ----  -----\n");
  fprintf(fp,
     "  %d/%d           0             0         %d/z    0\n",
     rnum,znum,block);

  fprintf(fp,"\n#GLOBALattributes\n");
  fprintf(fp,"\n#VARIABLEattributes\n");
 
  fprintf(fp,"\n#variables\n\n");
  for (n=0;n<snum;n++) {
    sx=sptr[n];
    fprintf(fp,"! Variable          Data      Number    Record   Dimension\n");
    fprintf(fp,"! Name              Type     Elements  Variance  Variances\n");
    fprintf(fp,"! --------          ----     --------  --------  ---------\n");
    fprintf(fp,"\n");
    sprintf(buf,"  %c%s%c",'"',cdfsname[n],'"');
    fprintf(fp,buf);
    tab=18-strlen(buf);
    if (tab>0) for (c=0;c<tab;c++) fprintf(fp," ");
    else fprintf(fp," ");
    switch (sx->type) {
    case DATACHAR:
      fprintf(fp,"CDF_CHAR  ");
      break;
    case DATASHORT:
      fprintf(fp,"CDF_INT2  ");
      break;
    case DATAINT:
      fprintf(fp,"CDF_INT4  ");
      break;
    case DATAFLOAT:
      fprintf(fp,"CDF_FLOAT ");
      break;
    case DATADOUBLE:
      fprintf(fp,"CDF_DOUBLE");
      break;
    case DATASTRING:
      fprintf(fp,"CDF_CHAR  ");
      break;

    }
    nelm=1;
    if (sx->type==DATASTRING) nelm=STRINGSIZE;
    fprintf(fp,"    %d         T          ",nelm);
    fprintf(fp,"\n\n");
    fprintf(fp,"! Attribute         Data     Value\n");
    fprintf(fp,"! Name              Type\n");
    fprintf(fp,"! --------          ----     --------\n");
    fprintf(fp,"\n.\n\n");


  }  
  fprintf(fp,"\n#zVariables\n\n");


  for (n=0;n<anum;n++) {
    ax=aptr[n];

    fprintf(fp,"! Variable          Data      Number");
    fprintf(fp,"                 Record   Dimension\n");
    fprintf(fp,"! Name              Type     Elements  Dims");
    fprintf(fp,"  Sizes  Variance  Variances\n");
    fprintf(fp, "! --------          ----     --------  ----");
    fprintf(fp,"  -----  --------  ---------\n");
    fprintf(fp,"\n");
    sprintf(buf,"  %c%s%c",'"',cdfaname[n],'"');
    fprintf(fp,buf);
    tab=18-strlen(buf);
    if (tab>0) for (c=0;c<tab;c++) fprintf(fp," ");
    else fprintf(fp," ");
    switch (ax->type) {
    case DATACHAR:
      fprintf(fp,"CDF_CHAR  ");
      break;
    case DATASHORT:
      fprintf(fp,"CDF_INT2  ");
      break;
    case DATAINT:
      fprintf(fp,"CDF_INT4  ");
      break;
    case DATAFLOAT:
      fprintf(fp,"CDF_FLOAT ");
      break;
    case DATADOUBLE:
      fprintf(fp,"CDF_DOUBLE");
      break;
    case DATASTRING:
      fprintf(fp,"CDF_CHAR  ");
      break;

    }

    nelm=1;
    if (ax->type==DATASTRING) nelm=STRINGSIZE;
    fprintf(fp,"    %d         %d     ",nelm,ax->dim);
    for (c=0;c<ax->dim;c++) fprintf(fp,"%d ",ax->rng[c]);
    fprintf(fp,"    T     ");
    for (c=0;c<ax->dim;c++) fprintf(fp,"T ");
    fprintf(fp,"\n\n");
    fprintf(fp,"! Attribute         Data     Value\n");
    fprintf(fp,"! Name              Type\n");
    fprintf(fp,"! --------          ----     --------\n");
    fprintf(fp,"\n.\n\n");

  }

  fprintf(fp,"#end\n\n");

  fp=fopen(argv[3],"w");
  for (n=0;n<snum;n++) {
   fprintf(fp,"\t");
     sx=sptr[n];
     switch(sx->type) {
     case DATACHAR:
        fprintf(fp,"char 0");
        break;
     case DATASHORT:
        fprintf(fp,"short 0");
        break;
     case DATAINT:
        fprintf(fp,"int 0");
        break;
     case DATAFLOAT:
        fprintf(fp,"float 0");
        break;
     case DATADOUBLE:
        fprintf(fp,"double 0");
        break;
     case DATASTRING:
        fprintf(fp,"string 0"); 
    }
    fprintf(fp," %c%s%c=%s;\n",'"',sx->name,'"',cdfsname[n]);
  }

  for (n=0;n<anum;n++) {
   fprintf(fp,"\t");
     ax=aptr[n];
     if (ax->dim==0) continue;
     switch(ax->type) {
     case DATACHAR:
        fprintf(fp,"char");
        break;
     case DATASHORT:
        fprintf(fp,"short");
        break;
     case DATAINT:
        fprintf(fp,"int");
        break;
     case DATAFLOAT:
        fprintf(fp,"float");
        break;
     case DATADOUBLE:
        fprintf(fp,"double");
        break;
     case DATASTRING:
        fprintf(fp,"string"); 
    }
    fprintf(fp," %d",ax->dim); 
    fprintf(fp," %c%s%c=%s;\n",'"',ax->name,'"',cdfaname[n]);
  }
  fclose(fp);
  return 0;
}
Beispiel #28
0
int main(int argc,char *argv[]) {
  
  int port=DEF_PORT,arg=0;
  int sock;
  int sc_reuseaddr=1,temp;



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

  socklen_t length;
  socklen_t clength;

  struct sockaddr_in server;
  struct sockaddr_in client;

  fd_set ready;

  struct hostent *gethostbyname();
  pid_t root;

  int msgsock=0;

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

  OptionAdd(&opt,"lp",'i',&port);

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

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

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

  signal(SIGCHLD,SIG_IGN); 
  signal(SIGPIPE,SIG_IGN);

  root=getpid();

  sock=socket(AF_INET,SOCK_STREAM,0); /* create our listening socket */
  if (sock<0) {
    perror("opening stream socket");
    exit(1);
  }

  /* set socket options */
  temp=setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&sc_reuseaddr,
                 sizeof(sc_reuseaddr));


  /* name and bind socket to an address and port number */

  server.sin_family=AF_INET;
  server.sin_addr.s_addr=INADDR_ANY;
  if (port !=0) server.sin_port=htons(port); 
  else server.sin_port=0;
  
  if (bind(sock,(struct sockaddr *) &server,sizeof(server))) {
     perror("binding stream socket");
     exit(1);
  }

  /* Find out assigned port number and print it out */

  length=sizeof(server);
  if (getsockname(sock,(struct sockaddr *) &server,&length)) {
     perror("getting socket name");
     exit(1);
  }

  listen(sock,5); /* mark our socket willing to accept connections */
  
  do {

      /* block until someone wants to attach to us */

      FD_ZERO(&ready);
      FD_SET(sock,&ready);
      if (select(sock+1,&ready,0,0,NULL) < 0) { 
       perror("while testing for connections");
       continue;
      }
     
      /* Accept the connection from the client */

      fprintf(stdout,"Accepting a new connection...\n");
      clength=sizeof(client);
      msgsock=accept(sock,(struct sockaddr *) &client,&clength);
        
      if (msgsock==-1) {
         perror("accept"); 
         continue;
      }

      if (fork() == 0) {
        close(sock);
        operate(root,msgsock);
        exit(0);
      }
      close (msgsock);
  } while(1);

 
  return 0;

}
Beispiel #29
0
int main(int argc,char *argv[]) {
  struct DataMap *ptr;
  struct DataMapScalar *sx,*sy;
  struct DataMapArray *ax,*ay;
  size_t index[256];
  size_t start[256];
  size_t count[256];

  int s;
  unsigned char vbflg=0;
  unsigned char help=0;
  unsigned char option=0;
  unsigned char zflg=0;

  FILE *fp=NULL;
  gzFile zfp=0;

  FILE *mapfp;
  int n,c,x;
  int ncid;
  int block=0;
 
  int varid;
  
  int strsze;
  char **strptr;
  char *tmpbuf=NULL;

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


  if (argc>1) {
    arg=OptionProcess(1,argc,argv,&opt,NULL); 
    if (help==1) {
      OptionPrintInfo(stdout,hlpstr);
      exit(0);
    }
    if (option==1) {
      OptionDump(stdout,&opt);
      exit(0);
    }

    if (zflg) {
      zfp=gzopen(argv[arg],"r");
      if (zfp==0) {
        fprintf(stderr,"File not found.\n");
        exit(-1);
      }
    } else {
      fp=fopen(argv[arg],"r");
      if (fp==NULL) {
        fprintf(stderr,"File not found.\n");
        exit(-1);
      }
    }  

  } else {
    OptionPrintInfo(stdout,errstr);
    exit(-1);
  }


  /* load the map */

  mapfp=fopen(argv[arg+1],"r");
  loadmap(mapfp);
  fclose(mapfp);

 

  s=nc_open(argv[arg+2],NC_WRITE,&ncid);
  if (s !=NC_NOERR) {
    fprintf(stderr,"Error opening CDF file.\n");
    exit(-1);
  }


   


  block=0;
  while (1) {

    if (zflg) ptr=DataMapReadZ(zfp);
    else ptr=DataMapFread(fp);

    if (ptr==NULL) break;

    for (c=0;c<ptr->snum;c++) {
      sx=ptr->scl[c];
      for (n=0;n<snum;n++) {
        sy=sptr[n];
        if (strcmp(sx->name,sy->name) !=0) continue;
        if (sx->type !=sy->type) continue;
        break;
      }
      if (n !=snum) { /* mapped variable */
        s=nc_inq_varid(ncid,cdfsname[n],&varid);
        if (s !=NC_NOERR) {
          fprintf(stderr,"Error accessing CDF file.\n");
          exit(-1);
        }
        index[0]=block;
        switch (sx->type) {
        case DATACHAR:
          s=nc_put_var1_text(ncid,varid,index,sx->data.cptr);
          break;
        case DATASHORT:
          s=nc_put_var1_short(ncid,varid,index,sx->data.sptr);
          break;
        case DATAINT:
          s=nc_put_var1_int(ncid,varid,index,sx->data.iptr);
          break;
        case DATAFLOAT:
          s=nc_put_var1_float(ncid,varid,index,sx->data.fptr);
          break;
        case DATADOUBLE:
          s=nc_put_var1_double(ncid,varid,index,sx->data.dptr);
          break;
        case DATASTRING:
          start[0]=block;
          start[1]=0;
          count[0]=1;
          count[1]=strlen(*((char **) sx->data.vptr))+1;
          s=nc_put_vara_text(ncid,varid,start,count,
                             *((char **) sx->data.vptr));
          break;
	}
        if (s !=NC_NOERR) {
          fprintf(stderr,"Error writing CDF file (%d).\n",s);
          exit(-1);
        }
       
      }
    }

    for (c=0;c<ptr->anum;c++) {
      ax=ptr->arr[c];
      for (n=0;n<anum;n++) {
        ay=aptr[n];
      
        if (strcmp(ax->name,ay->name) !=0) continue;
        if (ax->type !=ay->type) continue;
        if (ax->dim !=ay->dim) continue;
        break;
      }
      if (n !=anum) { /* mapped variable */
      
        s=nc_inq_varid(ncid,cdfaname[n],&varid);
        if (s !=NC_NOERR) {
          fprintf(stderr,"Error accessing CDF file.\n");
          exit(-1);
        }
        start[0]=block;
        count[0]=1;
        n=1;
        for (x=0;x<ax->dim;x++) {
          start[1+x]=0;
          count[1+x]=ax->rng[x];
          n=n*ax->rng[x];
	}

        if (ax->type==DATASTRING) {
          int ndims;
          int dimids[NC_MAX_VAR_DIMS];
          size_t dimlen;
          s=nc_inq_varndims(ncid,varid,&ndims);
          if (s !=NC_NOERR) {
            fprintf(stderr,"Error accessing CDF file.\n");
            exit(-1);
          }
          s=nc_inq_vardimid(ncid,varid,dimids);
          if (s !=NC_NOERR) {
            fprintf(stderr,"Error accessing CDF file.\n");
            exit(-1);
          }
          if (ndims-2!=ax->dim) {
            fprintf(stderr,"Error matching dimensions.\n");
            exit(-1);
	  }
          
          s=nc_inq_dimlen(ncid,dimids[ndims-1],&dimlen);
          if (s !=NC_NOERR) {
            fprintf(stderr,"Error accessing CDF file.\n");
            exit(-1);
          }
          strsze=dimlen;
          tmpbuf=malloc(n*strsze);
          if (tmpbuf==NULL) {
            fprintf(stderr,"Failed to allocate buffer.\n");
            exit(-1);
	  }
          memset(tmpbuf,0,n*strsze);
          start[1+ax->dim]=0;
          count[1+ax->dim]=strsze;
          strptr=(char **) ax->data.vptr;
          for (x=0;x<n;x++) strncpy(tmpbuf+x*strsze,strptr[x],strsze);
	}               

        switch (ax->type) { 
        case DATACHAR:
           s=nc_put_vara_text(ncid,varid,start,count,ax->data.cptr);
           break;
        case DATASHORT:
           s=nc_put_vara_short(ncid,varid,start,count,ax->data.sptr);
           break;
        case DATAINT:
           s=nc_put_vara_int(ncid,varid,start,count,ax->data.iptr);
           break;
        case DATAFLOAT:
           s=nc_put_vara_float(ncid,varid,start,count,ax->data.fptr);
           break;
        case DATADOUBLE:
           s=nc_put_vara_double(ncid,varid,start,count,ax->data.dptr);
           break;
        case DATASTRING:
           s=nc_put_vara_text(ncid,varid,start,count,tmpbuf);
	   break;
	}
        if (tmpbuf !=NULL) {
	  free(tmpbuf);
          tmpbuf=NULL;
	}

        if (s !=NC_NOERR) {
          fprintf(stderr,"Error writing CDF file (%d).\n",s);
          exit(-1);
        }
 
      }
    }
  

    DataMapFree(ptr);
    block++;
  }
  nc_close(ncid);
  if (zflg) gzclose(zfp);
  else fclose(fp);
  return 0;
}
Beispiel #30
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;
}