void plot_channel_data()
{
  int samp=0;
  int pg_id;

  pg_id = cpgopen("/XSERVE");
  cpgpap(8.0, 0.8);
  cpgask(0);
  cpgpage();
  cpgslct(pg_id);
  cpgsci(3);
  cpgeras();
  cpgsvp(0.15f, 0.95f, 0.2f, 0.8f);
  cpgupdt();
  cpgsch(2.0);
  cpgswin(0, read_count, -0.1f, 0.1f);
  cpgbox("BC1NST",0.0,0,"BCNST",0.0,0);
  cpglab("Time [samples]", "Voltage [volts]", "Antenna Measurement Receiver");
  cpgmove(samp, voltarray[0]);
  for (samp=2; samp<read_count; samp++)
	 {
	   cpgdraw(samp, voltarray[samp]);
	 }
  return 0;
}
int plot_freq_data(void)
{
  int bin=0;

  printf("\nPlotting ...");
  cpgask(0);
  cpgpage();
  cpgslct(pg_id);
  cpgsci(1);
  cpgeras();
  cpgsvp(0.15f, 0.95f, 0.2f, 0.8f);
  cpgupdt();
  cpgsch(2.0);
  cpgswin(0, (N/2)+1, 0.0f, 0.005f);
  //  cpgswin(80, 120, 0.0f, 0.01f);
  cpgbox("BC1NST",0.0,0,"BCNST",0.0,0);
  cpglab("Frequency [bins]", "Peak Voltage [volts]", "Antenna Measurement Receiver");
  cpgmove(bin, accumFreqData[0]);
  for (bin=1; bin<(N/2)+1; bin++)
	 {
	   cpgdraw(bin, accumFreqData[bin]);
	 }
  return 0;
}
Пример #3
0
int main(int argc, char *argv[])
{
   float minval = SMALLNUM, maxval = LARGENUM, inx = 0, iny = 0;
   int centern, offsetn;
   int zoomlevel, maxzoom = 0, minzoom, xid, psid;
   char *rootfilenm, inchar;
   datapart *lodp;
   dataview *dv;
   basicstats *statvals;

   if (argc == 1) {
      printf("\nusage:  exploredat datafilename\n\n");
      exit(0);
   }

   printf("\n\n");
   printf("      Interactive Data Explorer\n");
   printf("         by Scott M. Ransom\n");
   printf("            November, 2001\n");
   print_help();

   {
      int hassuffix = 0;
      char *suffix;

      hassuffix = split_root_suffix(argv[1], &rootfilenm, &suffix);
      if (hassuffix) {
         if (strcmp(suffix, "dat") != 0) {
            printf
                ("\nInput file ('%s') must be a single PRESTO data file ('.dat')!\n\n",
                 argv[1]);
            free(suffix);
            exit(0);
         }
         free(suffix);
      } else {
         printf("\nInput file ('%s') must be a PRESTO data file ('.dat')!\n\n",
                argv[1]);
         exit(0);
      }
   }

   /* Read the info file */

   readinf(&idata, rootfilenm);
   if (idata.object) {
      printf("Examining %s data from '%s'.\n\n",
             remove_whitespace(idata.object), argv[1]);
   } else {
      printf("Examining data from '%s'.\n\n", argv[1]);
   }
#ifdef USEMMAP
   mmap_file = open(argv[1], O_RDONLY);
   {
      int rt;
      struct stat buf;

      rt = fstat(mmap_file, &buf);
      if (rt == -1) {
         perror("\nError in fstat() in exploredat.c");
         printf("\n");
         exit(-1);
      }
      Ndat = buf.st_size / sizeof(float);
   }
   lodp = get_datapart(0, Ndat);
#else
   {
      int numsamp;

      datfile = chkfopen(argv[1], "rb");
      Ndat = chkfilelen(datfile, sizeof(float));
      numsamp = (Ndat > MAXPTS) ? (int) MAXPTS : (int) Ndat;
      lodp = get_datapart(0, numsamp);
   }
#endif

   /* Plot the initial data */

   centern = 0.5 * INITIALNUMPTS;
   if (centern > lodp->nn)
      centern = lodp->nn / 2;
   zoomlevel = LOGMAXDISPNUM - LOGINITIALNUMPTS;
   minzoom = LOGMAXDISPNUM - LOGMAXPTS;
   maxzoom = LOGMAXDISPNUM - LOGMINDISPNUM;
   dv = get_dataview(centern, zoomlevel, lodp);

   /* Prep the XWIN device for PGPLOT */

   xid = cpgopen("/XWIN");
   if (xid <= 0) {
      free_datapart(lodp);
#ifdef USEMMAP
      close(mmap_file);
#else
      fclose(datfile);
#endif
      free(dv);
      exit(EXIT_FAILURE);
   }
   cpgask(0);
   cpgpage();
   offsetn = plot_dataview(dv, minval, maxval, 1.0);

   do {
      cpgcurs(&inx, &iny, &inchar);
      if (DEBUGOUT)
         printf("You pressed '%c'\n", inchar);

      switch (inchar) {
      case ' ':                /* Toggle stats and sample plotting on/off */
         /* 0 = both, 1 = stats only, 2 = data only */
         plotstats++;
         plotstats = plotstats % 3;
         cpgpage();
         offsetn = plot_dataview(dv, minval, maxval, 1.0);
         break;
      case 'M':                /* Toggle between median and average */
      case 'm':
         usemedian = (usemedian) ? 0 : 1;
         free(dv);
         dv = get_dataview(centern, zoomlevel, lodp);
         cpgpage();
         offsetn = plot_dataview(dv, minval, maxval, 1.0);
         break;
      case 'A':                /* Zoom in */
      case 'a':
         centern = inx + offsetn;
      case 'I':
      case 'i':
         if (DEBUGOUT)
            printf("  Zooming in  (zoomlevel = %d)...\n", zoomlevel);
         if (zoomlevel < maxzoom) {
            zoomlevel++;
            free(dv);
            dv = get_dataview(centern, zoomlevel, lodp);
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
         } else
            printf("  Already at maximum zoom level (%d).\n", zoomlevel);
         break;
      case 'X':                /* Zoom out */
      case 'x':
      case 'O':
      case 'o':
         if (DEBUGOUT)
            printf("  Zooming out  (zoomlevel = %d)...\n", zoomlevel);
         if (zoomlevel > minzoom) {
            zoomlevel--;
            free(dv);
            dv = get_dataview(centern, zoomlevel, lodp);
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
         } else
            printf("  Already at minimum zoom level (%d).\n", zoomlevel);
         break;
      case '<':                /* Shift left 1 full screen */
         centern -= dv->numsamps + dv->numsamps / 8;
      case ',':                /* Shift left 1/8 screen */
         if (DEBUGOUT)
            printf("  Shifting left...\n");
         centern -= dv->numsamps / 8;
         {                      /* Should probably get the previous chunk from the datfile... */
            double lowestr;

            lowestr = 0.5 * dv->numsamps;
            if (centern < lowestr)
               centern = lowestr;
         }
         free(dv);
         dv = get_dataview(centern, zoomlevel, lodp);
         cpgpage();
         offsetn = plot_dataview(dv, minval, maxval, 1.0);
         break;
      case '>':                /* Shift right 1 full screen */
         centern += dv->numsamps - dv->numsamps / 8;
      case '.':                /* Shift right 1/8 screen */
         centern += dv->numsamps / 8;
         if (DEBUGOUT)
            printf("  Shifting right...\n");
         {                      /* Should probably get the next chunk from the datfile... */
            double highestr;

            highestr = lodp->nlo + lodp->nn - 0.5 * dv->numsamps;
            if (centern > highestr)
               centern = highestr;
         }
         free(dv);
         dv = get_dataview(centern, zoomlevel, lodp);
         cpgpage();
         offsetn = plot_dataview(dv, minval, maxval, 1.0);
         break;
      case '+':                /* Increase height of top edge */
         {
            float dy;

            if (maxval > 0.5 * LARGENUM) {
               printf("  Auto-scaling of top edge is off.\n");
               if (minval < 0.5 * SMALLNUM)
                  dy = dv->maxval - dv->minval;
               else
                  dy = dv->maxval - minval;
               maxval = dv->maxval + 0.1 * dy;
            } else {
               if (minval < 0.5 * SMALLNUM)
                  dy = maxval - dv->minval;
               else
                  dy = maxval - minval;
               maxval += 0.1 * dy;
            }
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
            break;
         }
      case '_':                /* Decrease height of top edge */
         {
            float dy;

            if (maxval > 0.5 * LARGENUM) {
               printf("  Auto-scaling of top edge is off.\n");
               if (minval < 0.5 * SMALLNUM)
                  dy = dv->maxval - dv->minval;
               else
                  dy = dv->maxval - minval;
               maxval = dv->maxval - 0.1 * dy;
            } else {
               if (minval < 0.5 * SMALLNUM)
                  dy = maxval - dv->minval;
               else
                  dy = maxval - minval;
               maxval -= 0.1 * dy;
            }
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
            break;
         }
      case '=':                /* Increase height of bottom edge */
         {
            float dy;

            if (minval < 0.5 * SMALLNUM) {
               printf("  Auto-scaling of bottom edge is off.\n");
               if (maxval > 0.5 * LARGENUM)
                  dy = dv->maxval - dv->minval;
               else
                  dy = maxval - dv->minval;
               minval = dv->minval + 0.1 * dy;
            } else {
               if (maxval > 0.5 * LARGENUM)
                  dy = dv->maxval - minval;
               else
                  dy = maxval - minval;
               minval += 0.1 * dy;
            }
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
            break;
         }
      case '-':                /* Decrease height of bottom edge */
         {
            float dy;

            if (minval < 0.5 * SMALLNUM) {
               printf("  Auto-scaling of bottom edge is off.\n");
               if (maxval > 0.5 * LARGENUM)
                  dy = dv->maxval - dv->minval;
               else
                  dy = maxval - dv->minval;
               minval = dv->minval - 0.1 * dy;
            } else {
               if (maxval > 0.5 * LARGENUM)
                  dy = dv->maxval - minval;
               else
                  dy = maxval - minval;
               minval -= 0.1 * dy;
            }
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
            break;
         }
      case 'S':                /* Auto-scale */
      case 's':
         printf("  Auto-scaling is on.\n");
         minval = SMALLNUM;
         maxval = LARGENUM;
         cpgpage();
         offsetn = plot_dataview(dv, minval, maxval, 1.0);
         break;
      case 'G':                /* Goto a time */
      case 'g':
         {
            char timestr[50];
            double time = -1.0;

            while (time < 0.0) {
               printf
                   ("  Enter the time (s) from the beginning of the file to go to:\n");
               fgets(timestr, 50, stdin);
               timestr[strlen(timestr) - 1] = '\0';
               time = atof(timestr);
            }
            offsetn = 0.0;
            centern = (int) (time / idata.dt + 0.5);
            printf("  Moving to time %.15g (data point %d).\n", time, centern);
            free(dv);
            dv = get_dataview(centern, zoomlevel, lodp);
            cpgpage();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
         }
         break;
      case '?':                /* Print help screen */
         print_help();
         break;
      case 'P':                /* Print the current plot */
      case 'p':
         {
            int len;
            char filename[200];

            printf("  Enter the filename to save the plot as:\n");
            fgets(filename, 195, stdin);
            len = strlen(filename) - 1;
            filename[len + 0] = '/';
            filename[len + 1] = 'C';
            filename[len + 2] = 'P';
            filename[len + 3] = 'S';
            filename[len + 4] = '\0';
            psid = cpgopen(filename);
            cpgslct(psid);
            cpgpap(10.25, 8.5 / 11.0);
            cpgiden();
            offsetn = plot_dataview(dv, minval, maxval, 1.0);
            cpgclos();
            cpgslct(xid);
            filename[len] = '\0';
            printf("  Wrote the plot to the file '%s'.\n", filename);
         }
         break;
      case 'V':                /* Show the basic statistics for the current dataview */
      case 'v':
         statvals = calc_stats(dv, lodp);
         printf("\n  Statistics:\n"
                "    Low sample               %d\n"
                "    Number of samples        %d\n"
                "    Low time (s)             %.7g\n"
                "    Duration of samples (s)  %.7g\n"
                "    Maximum value            %.7g\n"
                "    Minimum value            %.7g\n"
                "    Average value            %.7g\n"
                "    Median value             %.7g\n"
                "    Standard Deviation       %.7g\n"
                "    Skewness                 %.7g\n"
                "    Kurtosis                 %.7g\n\n",
                dv->lon, dv->numsamps, dv->lon * idata.dt, dv->numsamps * idata.dt,
                statvals->max, statvals->min, statvals->average,
                statvals->median, statvals->stdev,
                statvals->skewness, statvals->kurtosis);
         free(statvals);
         break;
      case 'Q':                /* Quit */
      case 'q':
         printf("  Quitting...\n");
         free(dv);
         cpgclos();
         break;
      default:
         printf("  Unrecognized option '%c'.\n", inchar);
         break;
      }
   } while (inchar != 'Q' && inchar != 'q');

   free_datapart(lodp);
#ifdef USEMMAP
   close(mmap_file);
#else
   fclose(datfile);
#endif
   printf("Done\n\n");
   return 0;
}
Пример #4
0
int main(int argc, char *argv[])
{
  int no_error=1;       /* Flag set to 0 on error */
  int usefile=0;        /* Flag set to 1 to use input setup file */
  int ncat1,ncat2;      /* Number of catalog objects */
  int nshift=0;         /* Number of matching objects */
  int another_loop=1;   /* Flag set to 0 when ending a loop */
  char fitsfile1[MAXC]; /* The name of the 1st FITS file to load */
  char catfile1[MAXC];  /* The name of the 1st SExtractor catalog file */
  char fitsfile2[MAXC]; /* The name of the 2nd FITS file to load */
  char catfile2[MAXC];  /* The name of the 2nd SExtractor catalog file */
  char setupfile[MAXC]; /* Name of the optional setup file */
  char line[MAXC];      /* General string to read input */
  Pos initshift;        /* Initial shift between two images */
  Pos shiftmean;        /* Mean shift */
  Pos shiftrms;         /* RMS on shift */
  Pos shiftmed;         /* Median shift */
  Image *image1;        /* The container of the 1st FITS image array */
  Image *image2;        /* The container of the 2nd FITS image array */
  Setup *setup1;        /* Container for the 1st image display info */
  Setup *setup2;        /* Container for the 2nd image display info */
  Secat *catdat1=NULL;  /* SExtractor data for 1st catalog */
  Secat *catdat2=NULL;  /* SExtractor data for 2nd catalog */
  Secat *shiftcat=NULL; /* Catalog of shifts between 1st and 2nd catalogs */

  /*
   * Check the command line
   */

  if(argc < 5) {
    fprintf(stderr,"\nfind_dither fitsfile1 catfile1 fitsfile2 catfile2 ");
    fprintf(stderr,"(setupfile)\n\n");
    return 1;
  }

  /*
   * Get the names of the files.
   */

  strcpy(fitsfile1,argv[1]);
  strcpy(catfile1,argv[2]);
  strcpy(fitsfile2,argv[3]);
  strcpy(catfile2,argv[4]);
  if(argc == 6) {
    usefile = 1;
    strcpy(setupfile,argv[5]);
  }
  else
    sprintf(setupfile,"");

  /*
   * Read the 1st data array.
   */

  if(!(image1 = new_Image(fitsfile1))) {
    fprintf(stderr,"ERROR.  Exiting program. Could not open %s\n\n",
	    fitsfile1);
    return 1;
  }

  if(load_image_data(image1) == ERROR)
    no_error = 0;

  /*
   * Create setup structure and fill with information used to set plotting
   *  parameters.
   */

  if(no_error) 
    if(!(setup1 = fill_setup(image1,setupfile,usefile,PIXEL)))
      no_error = 0;

  /*
   * Loop over displaying image until happy with results
   */

  if(no_error) {
    open_plot_window();
    if(display_image(image1,setup1))
      no_error = 0;
    else
      while(no_error && another_loop) {
	switch(another_loop = setup_menu(image1,setup1)) {
	case 1:
	  if(display_image(image1,setup1))
	    no_error = 0;
	  break;
	case 0:
	  break;
	case -1:
	  no_error = 0;
	  break;
	default:
	  break;
	}
      }
  }

  another_loop = 1;

  /*
   * Read the 2nd data array.
   */

  if(!(image2 = new_Image(fitsfile2))) {
    fprintf(stderr,"ERROR.  Exiting program. Could not open %s\n\n",
	    fitsfile1);
    return 1;
  }

  if(load_image_data(image2) == ERROR)
    no_error = 0;

  /*
   * Create setup structure and fill with information used to set plotting
   *  parameters.
   */

  if(no_error)
    if(!(setup2 = fill_setup(image2,setupfile,usefile,PIXEL)))
      no_error = 0;

  /*
   * Loop over displaying image until happy with results
   */

  if(no_error) {
    open_plot_window();
    if(display_image(image2,setup2))
      no_error = 0;
    else
      while(no_error && another_loop) {
	switch(another_loop = setup_menu(image2,setup2)) {
	case 1:
	  if(display_image(image2,setup2))
	    no_error = 0;
	  break;
	case 0:
	  break;
	case -1:
	  no_error = 0;
	  break;
	default:
	  break;
	}
      }
  }

  another_loop = 1;

  /*
   * Read in the first SExtractor catalog file
   */

  printf("---------------------------------------------------------------\n");
  if(no_error)
    if(!(catdat1 = read_secat(catfile1,'#',&ncat1,6)))
      no_error = 0;

  /*
   * Plot the catalog
   */

  if(no_error) {
    cpgslct(1);
    printf("\nPlotting SExtractor positions for first catalog\n");
    if(plot_secat(setup1,catdat1,ncat1,2,3,2.0))
      no_error = 0;
  }

  /*
   * Read in second SExtractor catalog file
   */

  if(no_error)
    if(!(catdat2 = read_secat(catfile2,'#',&ncat2,6)))
      no_error = 0;

  /*
   * Plot the catalog
   */

  if(no_error) {
    cpgslct(2);
    printf("\nPlotting SExtractor positions for second catalog\n");
    if(plot_secat(setup2,catdat2,ncat2,2,3,2.0))
      no_error = 0;
  }

  /*
   * Get initial shift
   */

  if(no_error) {
    get_init_shift(catdat1,ncat1,catdat2,ncat2,&initshift);
  }

  /*
   * Calculate shifts between first and second catalogs
   */

  if(no_error)
    if(!(shiftcat = find_shifts(catdat1,ncat1,catdat2,ncat2,initshift,
				setup2,&nshift,0)))
      no_error = 0;
    else
      printf("\nCalculated shifts between %d pairs.\n",nshift);

  /*
   * Get statistics on the shifts and plot results
   */

  if(no_error)
    plot_shifts(shiftcat,nshift);

  /*
   * Clean up and exit
   */

  cpgend();
  cpgend();
  image1 = del_Image(image1);
  setup1 = del_setup(setup1);
  catdat1 = del_secat(catdat1);
  image2 = del_Image(image2);
  setup2 = del_setup(setup2);
  catdat2 = del_secat(catdat2);
  shiftcat = del_secat(shiftcat);
  
  if(no_error) {
    printf("\nProgram find_dither.c completed.\n\n");
    return 0;
  }
  else {
    fprintf(stderr,"\nERROR. Exiting find_dither.c\n\n");
    return 1;
  }
}
Пример #5
0
int plot_shifts(Secat *shiftcat, int nshift)
{
  int i;                     /* Looping variable */
  int no_error=1;            /* Flag set to 0 on error */
  float x1,x2,y1,y2;         /* Limits on plot */
  float *fdx=NULL;           /* float version of x offsets */
  float *fdy=NULL;           /* float version of y offsets */
  float *fxptr,*fyptr;       /* Navigation pointers */
  double *dx=NULL;           /* x offsets */
  double *dy=NULL;           /* y offsets */
  double *xptr,*yptr;        /* Navigation pointers */
  double xmean, xsig, xmed;  /* Statistics on dx */
  double ymean, ysig, ymed;  /* Statistics on dx */
  Secat *sptr;               /* Pointer to navigate shiftcat */
  FILE *ofp=NULL;            /* Output file pointer */

  /*
   * Allocate memory for dx and dy arrays
   */

  if(!(dx = new_doubarray(nshift))) {
    fprintf(stderr,"ERROR: calc_shift_stats\n");
    return 1;
  }
  if(!(dy = new_doubarray(nshift)))
    no_error = 0;
  if(!(fdx = new_array(nshift,1)))
    no_error = 0;
  if(!(fdy = new_array(nshift,1)))
    no_error = 0;

  if(no_error) {

    /*
     * Transfer info to new arrays
     */

    for(i=0,sptr=shiftcat,xptr=dx,yptr=dy,fxptr=fdx,fyptr=fdy; 
	i<nshift; i++,sptr++,xptr++,yptr++,fxptr++,fyptr++) {
      *xptr = sptr->dx;
      *yptr = sptr->dy;
      *fxptr = (float) sptr->dx;
      *fyptr = (float) sptr->dy;
    }

    /*
     * Calculate statistics on dx and dy
     */

    doubstats(dx,nshift,&xmean,&xsig,&xmed);
    doubstats(dy,nshift,&ymean,&ysig,&ymed);

    /*
     * Give output values
     */

    printf("\nStatistics on x shift:\n");
    printf("  mean = %f\n",xmean);
    printf("  rms = %f\n",xsig);
    printf("  median = %f\n",xmed);
    printf("Statistics on y shift:\n");
    printf("  mean = %f\n",ymean);
    printf("  rms = %f\n",ysig);
    printf("  median = %f\n",ymed);

    /*
     * Set the limits and median
     */


    x1 = xmed - 5.0 * xsig;
    x2 = xmed + 5.0 * xsig;
    y1 = ymed - 5.0 * ysig;
    y2 = ymed + 5.0 * ysig;

    /*
     * Plot distribution
     */

    cpgslct(2);
    cpgenv(x1,x2,y1,y2,0,1);
    cpglab("x shift","y shift","Calculated Shifts");
    cpgpt(nshift,fdx,fdy,9);

    /*
     * Plot median
     */

    cpgsci(2);
    cpgslw(5);
    fdx[0] = fdx[1] = xmed;
    fdy[0] = y1;
    fdy[1] = y2;
    cpgline(2,fdx,fdy);
    fdy[0] = fdy[1] = ymed;
    fdx[0] = x1;
    fdx[1] = x2;
    cpgline(2,fdx,fdy);
    cpgsci(1);
    cpgslw(1);
  }

  /*
   * Write median shifts to output file -- NB: for these to be the
   *  proper shifts for an iraf imcombine offsets file, the value
   *  need to be the negative of what the above calculation gives.
   */

  if(!(ofp = open_writefile("tmp.offsets")))
    no_error = 0;
  else
    fprintf(ofp,"%8.2f %8.2f\n",-xmed,-ymed);

  /*
   * Clean up and exit
   */

  dx = del_doubarray(dx);
  dy = del_doubarray(dy);
  fdx = del_array(fdx);
  fdy = del_array(fdy);
  if(ofp)
    fclose(ofp);
  if(no_error)
    return 0;
  else {
    fprintf(stderr,"ERROR: calc_shift_stats\n");
    return 1;
  }
}
Пример #6
0
void get_init_shift(Secat *cat1, int ncat1, Secat *cat2, int ncat2, 
		    Pos *initshift)
{
  int no_error = 1;    /* Flag set to 0 on error */
  float cx,cy;         /* Cursor position */
  char cchar='0';      /* Character returned by cursor command */
  Pos cpos;            /* Cursor position */
  Secat bestmatch1;    /* Closest match to cursor position in image 1 */
  Secat bestmatch2;    /* Closest match to cursor position in image 2 */


  /*
   * Get the desired position in image 1
   */

  printf("---------------------------------------------------------------\n");
  if(no_error) {
    cx = 0.0;
    cy = 0.0;
    printf("\n");
    printf("Find a compact object that is clearly detected in both images\n");
    printf("Click the mouse on the object in the FIRST image\n");
    cpgslct(1);
    if(cpgcurs(&cx,&cy,&cchar)>0) {
      printf("\nMouse clicked at: %7.2f %7.2f\n",cx,cy);
      cpos.x = cx;
      cpos.y = cy;
      bestmatch1 = find_closest(cpos,cat1,ncat1);
      printf("Position of closest match is: %7.2f %7.2f\n",
	     bestmatch1.x,bestmatch1.y);
      markcatobj(bestmatch1);
    }
    else {
      fprintf(stderr,"*** Invalid cursor input ***\n");
      no_error = 0;
    }
  }

  /*
   * Now get position in image 2
   */

  if(no_error) {
    printf("\n Now click the mouse on the object in the SECOND image\n");
    cpgslct(2);
    if(cpgcurs(&cx,&cy,&cchar)>0) {
      printf("\nMouse clicked at: %7.2f %7.2f\n",cx,cy);
      cpos.x = cx;
      cpos.y = cy;
      bestmatch2 = find_closest(cpos,cat2,ncat2);
      printf("Position of closest match is: %7.2f %7.2f\n\n",
	     bestmatch2.x,bestmatch2.y);
      markcatobj(bestmatch2);
    }
    else {
      fprintf(stderr,"*** Invalid cursor input ***\n");
      no_error = 0;
    }
  }

  /*
   * Calculate x,y offsets from selected position in image 1
   */

  printf("---------------------------------------------------------------\n");
  if(no_error) {
    initshift->x = bestmatch2.x - bestmatch1.x;
    initshift->y = bestmatch2.y - bestmatch1.y;
    printf("\nInital estimate of shift between images: %8.2f %8.2f\n",
	   initshift->x,initshift->y);
  }

}
Пример #7
0
int main(int argc, char **argv) {
	float lm, hm;
	int ID;
	float x1, y1, x2, y2;
	char ch;
	char filename[1024];
	int enhanceid = -1;
	int sectionmode = LON;
	int histmode = DEP;
	float binw = 10.0;

	reset(&mainset);
	load(&mainset);

	rangeadjust(&control, &mainset, NULL, NULL, NULL, NULL);

	ID = cpgopen("/xwindow");
	resizemax(0.85);
	cpgask(0);

	/*
	 * This a bug-fix for the gmt command that outputs the borders wrapped.
	 */
	int i;
	for(i=0; i < nborders; i++)
		if (borders[i][0] != -999 && borders[i][0] > 180)
			borders[i][0] = borders[i][0] - 360.0;

	lm = hm = -1.0;
	while (ch != 'Q') {
		if (control.printout) {
			lerchar("Entre com o nome do arquivo", filename, 1000);
			if (strlen(filename) == 0) {
				strcpy(message, "Nome invalido.");
				alert(ERROR);
				control.printout = 0;
			} else {
				if (strlen(filename) < 3 || strncasecmp( &filename[strlen(filename)-3], ".ps", 3) != 0) {
					sprintf(filename,"%s.ps/cps",filename);
				} else {
					sprintf(filename,"%s/cps",filename);
				}
				cpgopen(filename);
				cpgask(0);
			}
		}

		plot(&control, &mainset);

		if (control.printout == 0 && enhanceid != -1) {
			enhanceid = enhance(&control, &mainset, enhanceid);
		}

		if (mainset.region) {
			plotsection(&mainset, &control, sectionmode);
			plothistogram(&mainset, binw, histmode, lm, hm);
		}

		if (control.printout) {
			cpgclos();
			cpgslct(ID);
			control.printout = 0;

			filename[strlen(filename) - 4] = '\0';
			sprintf(message, "Print Out saved to file %s", filename);
			alert(INFO);

			continue;
		}

		// Restore default map position
		cpgsvp(0.07, 0.93, 0.35, 0.9);
		cpgswin(control.xmin, control.xmax, control.ymin, control.ymax);
		ch = getonechar(&x1, &y1, 0);
		switch(ch) {
		case('='): {
			control.printout = 1;
			break;
		}
		case('R'): {
			reset(&mainset);
			load(&mainset);
			break;
		}

		case('B'): {
			binw = lerfloat("Entre com o valor da largura do bin?");
			break;
		}

		case('A'): {
			enhanceid = findpt(&mainset, x1, y1);
			break;
		}

		case('2'): {
			control.hasplates = (control.hasplates == 1) ? 0 : 1;
			break;
		}

		case('1'): {
			control.hascontinents++;
			if (control.hascontinents > 2) control.hascontinents = 0;
			break;
		}

		case ('W'): {
			control.xmax = 180;
			control.xmin = -180;
			control.ymax = 90;
			control.ymin = -90;
			break;
		}

		case('0'): {
			mainset.lon1 = -180;
			mainset.lon2 = 180;
			mainset.lat1 = -90;
			mainset.lat2 = 90;
			load(&mainset);
			mainset.region = 0;
			break;
		}

		case ('L'): {
			sectionmode = (sectionmode == LAT) ? LON : LAT;
			break;
		}

		case ('H'): {
			histmode = (histmode == MAG) ? DEP : MAG;
			binw = (histmode == MAG) ? 0.1 : 10.0;
			break;
		}

		case ('S'): {
			x2 = x1;
			y2 = y1;
			getonechar(&x2, &y2, 1);
			order(&x1,&x2);
			order(&y1,&y2);
			mainset.lon1 = x1;
			mainset.lon2 = x2;
			mainset.lat1 = y1;
			mainset.lat2 = y2;
			load(&mainset);
			mainset.region = 1;
			break;
		}

		case('X'): { // ZOOM
			x2 = x1;
			y2 = y1;
			getonechar(&x2, &y2, 1);
			order(&x1,&x2);
			order(&y1,&y2);
			rangeadjust(&control, &mainset, &x1, &x2, &y1, &y2);
			break;
		}

		case('C'): { // Color mode
			control.colormode ++;
			if (control.colormode>COLORMAG) control.colormode = COLORNONE;
			break;
		}

		case('N'): { /* Ano */
			int y1, y2;
			y1 = lerint("Entre com ano inicial?");
			y2 = lerint("Entre com ano final?");
			orderint(&y1,&y2);
			mainset.y1 = y1;
			mainset.y2 = y2;
			load(&mainset);
			break;
		}

		case('M'): { /* Magnitude */
			float m1, m2;
			m1 = lerfloat("Entre com a Magnitude Inicial?");
			m2 = lerfloat("Entre com a Magnitude Final?");
			order(&m1,&m2);
			mainset.m1 = m1;
			mainset.m2 = m2;
			load(&mainset);
			break;
		}

		case('J'): { /* Ajuste */
			lm = lerfloat("Entre com o menor valor de mag. para ajuste.");
			hm = lerfloat("Entre com o maior valor de mag. para ajuste.");
			if (lm == hm) {
				lm = hm = -1;
			}
			break;
		}
		case('P'): { /* Profundidade */
			float d1, d2;
			d1 = lerfloat("Entre com a Profundidade Minima?");
			d2 = lerfloat("Entre com a Profundidade Maxima?");
			order(&d1,&d2);
			mainset.d1 = d1;
			mainset.d2 = d2;
			load(&mainset);
			break;
		}

		}
	}

	cpgclos();
}
Пример #8
0
int main(int argc, char *argv[])
{
   float maxpow = 0.0, inx = 0.0, iny = 0.0;
   double centerr, offsetf;
   int zoomlevel, maxzoom, minzoom, xid, psid;
   char *rootfilenm, inchar;
   fftpart *lofp;
   fftview *fv;

   if (argc == 1) {
      printf("\nusage:  explorefft fftfilename\n\n");
      exit(0);
   }

   printf("\n\n");
   printf("      Interactive FFT Explorer\n");
   printf("         by Scott M. Ransom\n");
   printf("            October, 2001\n");
   print_help();

   {
      int hassuffix = 0;
      char *suffix;

      hassuffix = split_root_suffix(argv[1], &rootfilenm, &suffix);
      if (hassuffix) {
         if (strcmp(suffix, "fft") != 0) {
            printf("\nInput file ('%s') must be a FFT file ('.fft')!\n\n", argv[1]);
            free(suffix);
            exit(0);
         }
         free(suffix);
      } else {
         printf("\nInput file ('%s') must be a FFT file ('.fft')!\n\n", argv[1]);
         exit(0);
      }
   }

   /* Read the info file */

   readinf(&idata, rootfilenm);
   if (strlen(remove_whitespace(idata.object)) > 0) {
      printf("Examining %s data from '%s'.\n\n",
             remove_whitespace(idata.object), argv[1]);
   } else {
      printf("Examining data from '%s'.\n\n", argv[1]);
   }
   N = idata.N;
   T = idata.dt * idata.N;
#ifdef USEMMAP
   printf("Memory mapping the input FFT.  This may take a while...\n");
   mmap_file = open(argv[1], O_RDONLY);
   {
      int rt;
      struct stat buf;

      rt = fstat(mmap_file, &buf);
      if (rt == -1) {
         perror("\nError in fstat() in explorefft.c");
         printf("\n");
         exit(-1);
      }
      Nfft = buf.st_size / sizeof(fcomplex);
   }
   lofp = get_fftpart(0, Nfft);
#else
   {
      int numamps;

      fftfile = chkfopen(argv[1], "rb");
      Nfft = chkfilelen(fftfile, sizeof(fcomplex));
      numamps = (Nfft > MAXBINS) ? (int) MAXBINS : (int) Nfft;
      lofp = get_fftpart(0, numamps);
   }
#endif

   /* Plot the initial data */

   {
      int initnumbins = INITIALNUMBINS;

      if (initnumbins > Nfft) {
         initnumbins = next2_to_n(Nfft) / 2;
         zoomlevel = LOGDISPLAYNUM - (int) (log(initnumbins) / log(2.0));
         minzoom = zoomlevel;
      } else {
         zoomlevel = LOGDISPLAYNUM - LOGINITIALNUMBINS;
         minzoom = LOGDISPLAYNUM - LOGMAXBINS;
      }
      maxzoom = LOGDISPLAYNUM - LOGMINBINS;
      centerr = initnumbins / 2;
   }
   fv = get_fftview(centerr, zoomlevel, lofp);

   /* Prep the XWIN device for PGPLOT */

   xid = cpgopen("/XWIN");
   if (xid <= 0) {
      free(fv);
#ifdef USEMMAP
      close(mmap_file);
#else
      fclose(fftfile);
#endif
      free_fftpart(lofp);
      exit(EXIT_FAILURE);
   }
   cpgscr(15, 0.4, 0.4, 0.4);
   cpgask(0);
   cpgpage();
   offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);

   do {
      cpgcurs(&inx, &iny, &inchar);
      if (DEBUGOUT)
         printf("You pressed '%c'\n", inchar);

      switch (inchar) {
      case 'A':                /* Zoom in */
      case 'a':
         centerr = (inx + offsetf) * T;
      case 'I':
      case 'i':
         if (DEBUGOUT)
            printf("  Zooming in  (zoomlevel = %d)...\n", zoomlevel);
         if (zoomlevel < maxzoom) {
            zoomlevel++;
            free(fv);
            fv = get_fftview(centerr, zoomlevel, lofp);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         } else
            printf("  Already at maximum zoom level (%d).\n", zoomlevel);
         break;
      case 'X':                /* Zoom out */
      case 'x':
      case 'O':
      case 'o':
         if (DEBUGOUT)
            printf("  Zooming out  (zoomlevel = %d)...\n", zoomlevel);
         if (zoomlevel > minzoom) {
            zoomlevel--;
            free(fv);
            fv = get_fftview(centerr, zoomlevel, lofp);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         } else
            printf("  Already at minimum zoom level (%d).\n", zoomlevel);
         break;
      case '<':                /* Shift left 1 full screen */
         centerr -= fv->numbins + fv->numbins / 8;
      case ',':                /* Shift left 1/8 screen */
         if (DEBUGOUT)
            printf("  Shifting left...\n");
         centerr -= fv->numbins / 8;
         {                      /* Should probably get the previous chunk from the fftfile... */
            double lowestr;

            lowestr = 0.5 * fv->numbins;
            if (centerr < lowestr)
               centerr = lowestr;
         }
         free(fv);
         fv = get_fftview(centerr, zoomlevel, lofp);
         cpgpage();
         offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         break;
      case '>':                /* Shift right 1 full screen */
         centerr += fv->numbins - fv->numbins / 8;
      case '.':                /* Shift right 1/8 screen */
         if (DEBUGOUT)
            printf("  Shifting right...\n");
         centerr += fv->numbins / 8;
         {                      /* Should probably get the next chunk from the fftfile... */
            double highestr;

            highestr = lofp->rlo + lofp->numamps - 0.5 * fv->numbins;
            if (centerr > highestr)
               centerr = highestr;
         }
         free(fv);
         fv = get_fftview(centerr, zoomlevel, lofp);
         cpgpage();
         offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         break;
      case '+':                /* Increase height of powers */
      case '=':
         if (maxpow == 0.0) {
            printf("  Auto-scaling is off.\n");
            maxpow = 1.1 * fv->maxpow;
         }
         maxpow = 3.0 / 4.0 * maxpow;
         cpgpage();
         offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         break;
      case '-':                /* Decrease height of powers */
      case '_':
         if (maxpow == 0.0) {
            printf("  Auto-scaling is off.\n");
            maxpow = 1.1 * fv->maxpow;
         }
         maxpow = 4.0 / 3.0 * maxpow;
         cpgpage();
         offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         break;
      case 'S':                /* Auto-scale */
      case 's':
         if (maxpow == 0.0)
            break;
         else {
            printf("  Auto-scaling is on.\n");
            maxpow = 0.0;
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
            break;
         }
      case 'G':                /* Goto a frequency */
      case 'g':
         {
            char freqstr[50];
            double freq = -1.0;

            while (freq < 0.0) {
               printf("  Enter the frequency (Hz) to go to:\n");
               fgets(freqstr, 50, stdin);
               freqstr[strlen(freqstr) - 1] = '\0';
               freq = atof(freqstr);
            }
            offsetf = 0.0;
            centerr = freq * T;
            printf("  Moving to frequency %.15g.\n", freq);
            free(fv);
            fv = get_fftview(centerr, zoomlevel, lofp);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2);
         }
         break;
      case 'H':                /* Show harmonics */
      case 'h':
         {
            double retval;

            retval = harmonic_loop(xid, centerr, zoomlevel, lofp);
            if (retval > 0.0) {
               offsetf = 0.0;
               centerr = retval;
               free(fv);
               fv = get_fftview(centerr, zoomlevel, lofp);
               cpgpage();
               offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2);
            }
         }
         break;
      case '?':                /* Print help screen */
         print_help();
         break;
      case 'D':                /* Show details about a selected point  */
      case 'd':
         {
            double newr;

            printf("  Searching for peak near freq = %.7g Hz...\n", (inx + offsetf));
            newr = find_peak(inx + offsetf, fv, lofp);
            centerr = newr;
            free(fv);
            fv = get_fftview(centerr, zoomlevel, lofp);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, centerr, 2);
         }
         break;
      case 'L':                /* Load a zaplist */
      case 'l':
         {
            int ii, len;
            char filename[200];
            double *lobins, *hibins;

            printf("  Enter the filename containing the zaplist to load:\n");
            fgets(filename, 199, stdin);
            len = strlen(filename) - 1;
            filename[len] = '\0';
            numzaplist = get_birdies(filename, T, 0.0, &lobins, &hibins);
            lenzaplist = numzaplist + 20;       /* Allow some room to add more */
            if (lenzaplist)
               free(zaplist);
            zaplist = (bird *) malloc(sizeof(bird) * lenzaplist);
            for (ii = 0; ii < numzaplist; ii++) {
               zaplist[ii].lobin = lobins[ii];
               zaplist[ii].hibin = hibins[ii];
            }
            vect_free(lobins);
            vect_free(hibins);
            printf("\n");
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         }
         break;
      case 'Z':                /* Add a birdie to a zaplist */
      case 'z':
         {
            int badchoice = 2;
            float lox, hix, loy, hiy;
            double rs[2];
            char choice;

            if (numzaplist + 1 > lenzaplist) {
               lenzaplist += 10;
               zaplist = (bird *) realloc(zaplist, sizeof(bird) * lenzaplist);
            }
            cpgqwin(&lox, &hix, &loy, &hiy);
            printf("  Click the left mouse button on the first frequency limit.\n");
            while (badchoice) {
               cpgcurs(&inx, &iny, &choice);
               if (choice == 'A' || choice == 'a') {
                  rs[2 - badchoice] = ((double) inx + offsetf) * T;
                  cpgsave();
                  cpgsci(7);
                  cpgmove(inx, 0.0);
                  cpgdraw(inx, hiy);
                  cpgunsa();
                  badchoice--;
                  if (badchoice == 1)
                     printf
                         ("  Click the left mouse button on the second frequency limit.\n");
               } else {
                  printf("  Option not recognized.\n");
               }
            };
            if (rs[1] > rs[0]) {
               zaplist[numzaplist].lobin = rs[0];
               zaplist[numzaplist].hibin = rs[1];
            } else {
               zaplist[numzaplist].lobin = rs[1];
               zaplist[numzaplist].hibin = rs[0];
            }
            printf("    The new birdie has:  f_avg = %.15g  f_width = %.15g\n\n",
                   0.5 * (zaplist[numzaplist].hibin + zaplist[numzaplist].lobin) / T,
                   (zaplist[numzaplist].hibin - zaplist[numzaplist].lobin) / T);
            numzaplist++;
            qsort(zaplist, numzaplist, sizeof(bird), compare_birds);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         }
         break;
      case 'P':                /* Print the current plot */
      case 'p':
         {
            int len;
            char filename[200];

            printf("  Enter the filename to save the plot as:\n");
            fgets(filename, 196, stdin);
            len = strlen(filename) - 1;
            filename[len + 0] = '/';
            filename[len + 1] = 'P';
            filename[len + 2] = 'S';
            filename[len + 3] = '\0';
            psid = cpgopen(filename);
            cpgslct(psid);
            cpgpap(10.25, 8.5 / 11.0);
            cpgiden();
            cpgscr(15, 0.8, 0.8, 0.8);
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
            cpgclos();
            cpgslct(xid);
            cpgscr(15, 0.4, 0.4, 0.4);
            filename[len] = '\0';
            printf("  Wrote the plot to the file '%s'.\n", filename);
         }
         break;
      case 'N':                /* Changing power normalization */
      case 'n':
         {
            float inx2 = 0.0, iny2 = 0.0;
            char choice;
            unsigned char badchoice = 1;

            printf("  Specify the type of power normalization:\n"
                   "       m,M  :  Median values determined locally\n"
                   "       d,D  :  DC frequency amplitude\n"
                   "       r,R  :  Raw powers (i.e. no normalization)\n"
                   "       u,U  :  User specified interval (the average powers)\n");
            while (badchoice) {
               cpgcurs(&inx2, &iny2, &choice);
               switch (choice) {
               case 'M':
               case 'm':
                  norm_const = 0.0;
                  maxpow = 0.0;
                  badchoice = 0;
                  printf
                      ("  Using local median normalization.  Autoscaling is on.\n");
                  break;
               case 'D':
               case 'd':
                  norm_const = 1.0 / r0;
                  maxpow = 0.0;
                  badchoice = 0;
                  printf
                      ("  Using DC frequency (%f) normalization.  Autoscaling is on.\n",
                       r0);
                  break;
               case 'R':
               case 'r':
                  norm_const = 1.0;
                  maxpow = 0.0;
                  badchoice = 0;
                  printf
                      ("  Using raw powers (i.e. no normalization).  Autoscaling is on.\n");
                  break;
               case 'U':
               case 'u':
                  {
                     char choice2;
                     float xx = inx, yy = iny;
                     int lor, hir, numr;
                     double avg, var;

                     printf
                         ("  Use the left mouse button to select a left and right boundary\n"
                          "  of a region to calculate the average power.\n");
                     do {
                        cpgcurs(&xx, &yy, &choice2);
                     } while (choice2 != 'A' && choice2 != 'a');
                     lor = (int) ((xx + offsetf) * T);
                     cpgsci(7);
                     cpgmove(xx, 0.0);
                     cpgdraw(xx, 10.0 * fv->maxpow);
                     do {
                        cpgcurs(&xx, &yy, &choice2);
                     } while (choice2 != 'A' && choice2 != 'a');
                     hir = (int) ((xx + offsetf) * T);
                     cpgmove(xx, 0.0);
                     cpgdraw(xx, 10.0 * fv->maxpow);
                     cpgsci(1);
                     if (lor > hir) {
                        int tempr;
                        tempr = hir;
                        hir = lor;
                        lor = tempr;
                     }
                     numr = hir - lor + 1;
                     avg_var(lofp->rawpowers + lor - lofp->rlo, numr, &avg, &var);
                     printf("  Selection has:  average = %.5g\n"
                            "                  std dev = %.5g\n", avg, sqrt(var));
                     norm_const = 1.0 / avg;
                     maxpow = 0.0;
                     badchoice = 0;
                     printf
                         ("  Using %.5g as the normalization constant.  Autoscaling is on.\n",
                          avg);
                     break;
                  }
               default:
                  printf("  Unrecognized choice '%c'.\n", choice);
                  break;
               }
            }
            free(fv);
            fv = get_fftview(centerr, zoomlevel, lofp);
            cpgpage();
            offsetf = plot_fftview(fv, maxpow, 1.0, 0.0, 0);
         }
         break;
      case 'Q':                /* Quit */
      case 'q':
         printf("  Quitting...\n");
         free(fv);
         cpgclos();
         break;
      default:
         printf("  Unrecognized option '%c'.\n", inchar);
         break;
      }
   } while (inchar != 'Q' && inchar != 'q');

   free_fftpart(lofp);
#ifdef USEMMAP
   close(mmap_file);
#else
   fclose(fftfile);
#endif
   if (lenzaplist)
      free(zaplist);
   printf("Done\n\n");
   return 0;
}
Пример #9
0
static double harmonic_loop(int xid, double rr, int zoomlevel, fftpart * fp)
{
   float inx = 0.0, iny = 0.0;
   double retval = 0.0;
   int xid2, psid, badchoice = 1;
   char choice;

   xid2 = cpgopen("/XWIN");
   cpgpap(10.25, 8.5 / 11.0);
   cpgask(0);
   cpgslct(xid2);
   plot_harmonics(rr, zoomlevel, fp);
   printf("  Click on the harmonic to go it,\n"
          "    press 'P' to print, or press 'Q' to close.\n");
   while (badchoice) {
      cpgcurs(&inx, &iny, &choice);
      if (choice == 'Q' || choice == 'q') {
         badchoice = 0;
      } else if (choice == 'P' || choice == 'p') {
         int len, numharmbins;
         double offsetf;
         char filename[200];
         fftpart *harmpart;
         fftview *harmview;

         printf("  Enter the filename to save the plot as:\n");
         fgets(filename, 195, stdin);
         len = strlen(filename) - 1;
         strcpy(filename + len, "/CPS");
         psid = cpgopen(filename);
         cpgslct(psid);
         cpgpap(10.25, 8.5 / 11.0);
         cpgiden();
         cpgscr(15, 0.8, 0.8, 0.8);
         numharmbins = (1 << (LOGDISPLAYNUM - zoomlevel));
         harmpart = get_fftpart((int) (rr - numharmbins), 2 * numharmbins);
         harmview = get_fftview(rr, zoomlevel, harmpart);
         free_fftpart(harmpart);
         offsetf = plot_fftview(harmview, 0.0, 1.0, rr, 2);
         cpgpage();
         plot_harmonics(rr, zoomlevel, fp);
         cpgclos();
         cpgslct(xid2);
         cpgscr(15, 0.4, 0.4, 0.4);
         filename[len] = '\0';
         printf("  Wrote the plot to the file '%s'.\n", filename);
      } else if (choice == 'A' || choice == 'a') {
         if (iny > 1.0)
            retval = rr * (int) (inx);
         else if (iny > 0.0)
            retval = rr * ((int) (inx) + 4.0);
         else if (iny > -1.0)
            retval = rr / (int) (inx);
         else
            retval = rr / ((int) (inx) + 4.0);
         badchoice = 0;
      } else {
         printf("  Option not recognized.\n");
      }
   };
   cpgclos();
   cpgslct(xid);
   return retval;
}
Пример #10
0
int plot_map()
{
  int nx=720;
  int ny=180;
  int deli, delj;
  float value;
  int counter;
  float mapplot[720][180];

  int i=0, j=0, k=0;
  float tr[6]= {0.0, 0.5, 0.0, 0.0, 0.0, 0.5};

  float fmin=1, fmax=0;
  //  float RL[9]={-0.5, 0.004, 0.006, 0.008, 0.02, 0.04, 0.06, 0.08, 0.1};
  float RL[9]={-0.5, 0.0, 0.04, 0.08, 0.2, 0.4, 0.6, 0.8, 1.0};
  float RR[9]={0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 1.0, 1.0, 1.0};
  float RG[9]={0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.6, 1.1, 1.0};
  float RB[9]={0.0, 0.3, 0.8, 1.0, 0.3, 0.0, 0.0, 0.0, 1.0};
  float bright=0.5; //0.53
  float contra=1.0; //1.0

  //map larger array into smaller array

  for (j=1; j<ny; j++)
    {
      for (i=1; i<nx; i++)
	{
	  value=0;
	  counter=0;
	  for (deli=0; deli<=5; deli++)
	    {
	      for (delj=0; delj<=5; delj++)
		{
		  value=value+mapx[sat_choice][(5*i)+deli][(5*j)+delj];		
		  if (mapx[sat_choice][(5*i)+deli][(5*j)+delj]>0)
		  {
		    counter++;
		    //		    printf("%i %f\n", counter, value/counter);
		  }
	      }
	    }
	  if (counter==0) mapplot[i][j]=value;
	  else mapplot[i][j]=value/counter;
	}
    }


 
  for (j=1; j<ny; j++)
    {
      for (i=1; i<nx; i++)
	{
	  k=(j-1)*nx + (i-1);
	  f[k]=mapplot[i][j];
	  if (f[k] <fmin) fmin = f[k];
	  if (f[k] >fmax) fmax = f[k];
	}
    }

  printf("min=%f max=%f\n", fmin, fmax);
  fmax=0.1;
  cpgslct(pg_id);
  cpgeras();
  cpgenv(0.0, 360, 0.0, 90, 1.0, -2); 
    cpglab("Azimuth", "Elevation", "Antenna Power Pattern  [Data: May 7-22, 2006]");
  cpgctab(RL, RR, RG, RB, 9, contra, bright);
    cpgimag(f, (float)nx, (float)ny, 1.0, (float)nx, 1.0, (float)ny,  fmin, fmax, tr);
  cpgbox("BCNST1",0.0,0,"BCNST1",0.0,0);
     return 0;
}
Пример #11
0
/* select an open graphics device */
static void _pgslct (int *id)
{
   cpgslct (*id);
}