Exemplo n.º 1
0
void xyline2lab(int npts, float *x, float *y, float *y2, const char *xlab,
                const char *ylab, const char *ylab2, int id)
{
    float xmin, xmax, ymin, ymax, ymin2, ymax2;
    float overy, over = 0.1;

    /* Determine min and max values to plot and scaling: */
    find_min_max_arr(npts, x, &xmin, &xmax);
    find_min_max_arr(npts, y, &ymin, &ymax);
    find_min_max_arr(npts, y2, &ymin2, &ymax2);
    overy = over * (ymax - ymin);
    ymax += overy;
    ymin -= overy;
    overy = over * (ymax2 - ymin2);
    ymax2 += overy;
    ymin2 -= overy;

    /* Choose the font: */
    cpgscf(2);

    /* Setup the plot screen for the first set of y's: */
    cpgpage();
    cpgvstd();
    cpgswin(xmin, xmax, ymin, ymax);
    cpgbox("BCNST", 0.0, 0, "BNST", 0.0, 0);
    cpgmtxt("B", 3.0, 0.5, 0.5, xlab);
    cpgmtxt("L", 2.6, 0.5, 0.5, ylab);

    /* Plot the points for the 1st y axis: */
    cpgline(npts, x, y);

    /* Setup the plot screen for the second set of y's: */
    cpgvstd();
    cpgswin(xmin, xmax, ymin2, ymax2);
    cpgbox("", 0.0, 0, "CMST", 0.0, 0);
    cpgmtxt("R", 3.0, 0.5, 0.5, ylab2);

    /* Plot the points for the 2nd y axis: */
    cpgline(npts, x, y2);

    /* Add ID line if required */
    if (id == 1)
        cpgiden();

}
Exemplo n.º 2
0
void plot_spectrum(fcomplex * spect, int numspect,
                   double lor, double dr, double T, double average)
/* Plot a chunk of the Fourier power spectrum normalized by average  */
/* The viewing area is left defined with the xvals as _bins_.        */
{
    int ii;
    float *yvals, *xvals, maxy = 0.0;
    double offsetr, hir;
    char lab[100];

    if (lor > 10000) {
        offsetr = floor(lor / 1000.0) * 1000.0;
        sprintf(lab, "Fourier Frequency - %.0f (bins)", offsetr);
    } else {
        offsetr = 0.0;
        sprintf(lab, "Fourier Frequency (bins)");
    }
    lor = lor - offsetr;
    hir = lor + numspect * dr;
    xvals = (float *) malloc(sizeof(float) * numspect);
    yvals = (float *) malloc(sizeof(float) * numspect);
    for (ii = 0; ii < numspect; ii++) {
        xvals[ii] = lor + ii * dr;
        yvals[ii] =
            (spect[ii].r * spect[ii].r + spect[ii].i * spect[ii].i) / average;
        if (yvals[ii] > maxy)
            maxy = yvals[ii];
    }
    maxy *= 1.1;

    /* Setup the plot screen for the first set of y's: */
    cpgpage();
    cpgvstd();

    /* Draw the box for the frequency (Hz) axis */
    cpgswin((lor + offsetr) / T, (hir + offsetr) / T, 0.0, maxy);
    cpgbox("BNST", 0.0, 0, "BCNST", 0.0, 0);
    cpgmtxt("B", 2.5, 0.5, 0.5, "Frequency (Hz)");

    /* Draw the box for the Fourier frequency (bins) axis */
    cpgswin(lor, hir, 0.0, maxy);
    cpgbox("CMST", 0.0, 0, "", 0.0, 0);
    cpgmtxt("T", 2.0, 0.5, 0.5, lab);
    cpgmtxt("L", 2.0, 0.5, 0.5, "Normalized Power");

    /* Plot the points */
    cpgline(numspect, xvals, yvals);

    free(xvals);
    free(yvals);
}
Exemplo n.º 3
0
static int plot_dataview(dataview * dv, float minval, float maxval, float charhgt)
/* The return value is offsetn */
{
   int ii, lon, hin, offsetn = 0, tmpn;
   double lot, hit, offsett = 0.0;
   float ns[MAXDISPNUM], hiavg[MAXDISPNUM], loavg[MAXDISPNUM];
   float scalemin = 0.0, scalemax = 0.0, dscale;

   cpgsave();
   cpgbbuf();

   /* Set the "Normal" plotting attributes */

   cpgsls(1);
   cpgslw(1);
   cpgsch(charhgt);
   cpgsci(1);
   cpgvstd();

   /* Autoscale for the maximum value */
   if (maxval > 0.5 * LARGENUM)
      scalemax = dv->maxval;
   else
      scalemax = maxval;
   /* Autoscale for the minimum value */
   if (minval < 0.5 * SMALLNUM)
      scalemin = dv->minval;
   else
      scalemin = minval;
   dscale = 0.1 * (scalemax - scalemin);
   if (maxval > 0.5 * LARGENUM)
      maxval = scalemax + dscale;
   if (minval < 0.5 * SMALLNUM)
      minval = scalemin - dscale;

   lon = dv->lon;
   lot = lon * idata.dt;
   hin = lon + dv->numsamps;
   hit = hin * idata.dt;

   /* Time Labels (top of box) */

   if ((hit - lot) / hit < 0.001) {
      int numchar;
      char label[50];

      offsett = 0.5 * (hit + lot);
      numchar = snprintf(label, 50, "Time - %.15g (s)", offsett);
      cpgmtxt("T", 2.5, 0.5, 0.5, label);
   } else {
      cpgmtxt("T", 2.5, 0.5, 0.5, "Time (s)");
   }
   cpgswin(lot - offsett, hit - offsett, minval, maxval);
   cpgbox("CMST", 0.0, 0, "", 0.0, 0);

   /* Sample number labels */

   if (lon > 10000000 || (double) (hin - lon) / (double) hin < 0.001) {
      int numchar;
      char label[50];

      offsetn = (lon / 10000) * 10000;
      numchar = snprintf(label, 50, "Sample - %d", offsetn);
      cpgmtxt("B", 2.8, 0.5, 0.5, label);
   } else {
      cpgmtxt("B", 2.8, 0.5, 0.5, "Sample");
   }
   cpgswin(lon - offsetn, hin - offsetn, minval, maxval);
   cpgbox("BNST", 0.0, 0, "BCNST", 0.0, 0);

   /* Plot the rawdata if required */

   tmpn = lon - offsetn;
   if (plotstats == 0 || plotstats == 2) {
      if (dv->zoomlevel > 0) {
         for (ii = 0; ii < dv->dispnum; ii++)
            ns[ii] = tmpn + ii;
         cpgbin(dv->dispnum, ns, dv->vals, 0);
      } else {                  /* Plot the min/max values */
         for (ii = 0; ii < dv->numchunks; ii++, tmpn += dv->chunklen) {
            cpgmove((float) tmpn, dv->mins[ii]);
            cpgdraw((float) tmpn, dv->maxs[ii]);
         }
      }
   }

   /* Plot the other statistics if requested */

   if (plotstats == 0 || plotstats == 1) {
      tmpn = lon - offsetn;
      for (ii = 0; ii < dv->numchunks; ii++, tmpn += dv->chunklen) {
         ns[ii] = tmpn;
         hiavg[ii] = dv->avgmeds[ii] + dv->stds[ii];
         loavg[ii] = dv->avgmeds[ii] - dv->stds[ii];
      }
      if (dv->numchunks > 512) {
         if (plotstats == 1) {
            cpgline(dv->numchunks, ns, dv->mins);
            cpgline(dv->numchunks, ns, dv->maxs);
         }
         cpgsci(AVGMED_COLOR);
         cpgline(dv->numchunks, ns, dv->avgmeds);
         if (usemedian)
            cpgmtxt("T", -1.4, 0.02, 0.0, "Median");
         else
            cpgmtxt("T", -1.4, 0.02, 0.0, "Average");
         cpgsci(STDDEV_COLOR);
         cpgline(dv->numchunks, ns, hiavg);
         cpgline(dv->numchunks, ns, loavg);
         cpgmtxt("T", -2.6, 0.02, 0.0, "+/- 1 Std Dev");
      } else {
         if (plotstats == 1) {
            cpgbin(dv->numchunks, ns, dv->mins, 0);
            cpgbin(dv->numchunks, ns, dv->maxs, 0);
         }
         cpgsci(AVGMED_COLOR);
         cpgbin(dv->numchunks, ns, dv->avgmeds, 0);
         if (usemedian)
            cpgmtxt("T", -1.4, 0.02, 0.0, "Median");
         else
            cpgmtxt("T", -1.4, 0.02, 0.0, "Average");
         cpgsci(STDDEV_COLOR);
         cpgbin(dv->numchunks, ns, hiavg, 0);
         cpgbin(dv->numchunks, ns, loavg, 0);
         cpgmtxt("T", -2.6, 0.02, 0.0, "+/- 1 Std Dev");
      }
   }
   cpgsci(1);
   cpgmtxt("L", 2.5, 0.5, 0.5, "Sample Value");
   cpgebuf();
   cpgunsa();
   return offsetn;
}
Exemplo n.º 4
0
int main()

{
  char infile[] = "pih.fits";
  char devtyp[16], idents[3][80], nlcprm[1], opt[2];
  int  c0[] = {-1, -1, -1, -1, -1, -1, -1};
  int  i, ic, gcode[2], naxis[2], nkeyrec, nreject, nwcs, relax, status;
  float  blc[2], trc[2];
  double cache[257][4], grid1[1], grid2[1], nldprm[1];
  struct wcsprm *wcs;
  nlfunc_t pgwcsl_;
#if defined HAVE_CFITSIO && defined DO_CFITSIO
  char *header;
  fitsfile *fptr;
#else
  char keyrec[81], header[28801];
  int  gotend, j, k;
  FILE *fptr;
#endif


  /* Set line buffering in case stdout is redirected to a file, otherwise
   * stdout and stderr messages will be jumbled (stderr is unbuffered). */
  setvbuf(stdout, NULL, _IOLBF, 0);

  printf("Testing WCSLIB parser for FITS image headers (tpih2.c)\n"
         "------------------------------------------------------\n\n");

  /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */
#if defined HAVE_CFITSIO && defined DO_CFITSIO
  status = 0;

  if (fits_open_file(&fptr, infile, READONLY, &status)) {
    fits_report_error(stderr, status);
    return 1;
  }

  if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) {
    fits_report_error(stderr, status);
    return 1;
  }

  fits_close_file(fptr, &status);
#else
  if ((fptr = fopen(infile, "r")) == 0x0) {
    printf("ERROR opening %s\n", infile);
    return 1;
  }

  k = 0;
  nkeyrec = 0;
  gotend = 0;
  for (j = 0; j < 10; j++) {
    for (i = 0; i < 36; i++) {
      if (fgets(keyrec, 81, fptr) == 0) {
        break;
      }

      if (strncmp(keyrec, "        ", 8) == 0) continue;
      if (strncmp(keyrec, "COMMENT ", 8) == 0) continue;
      if (strncmp(keyrec, "HISTORY ", 8) == 0) continue;

      strncpy(header+k, keyrec, 80);
      k += 80;
      nkeyrec++;

      if (strncmp(keyrec, "END     ", 8) == 0) {
        /* An END keyrecord was read, but read the rest of the block. */
        gotend = 1;
      }
    }

    if (gotend) break;
  }
  fclose(fptr);
#endif

  fprintf(stderr, "Found %d non-comment header keyrecords.\n", nkeyrec);

  relax = WCSHDR_all;
  if ((status = wcspih(header, nkeyrec, relax, 2, &nreject, &nwcs, &wcs))) {
    fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcs_errmsg[status]);
  }
#if defined HAVE_CFITSIO && defined DO_CFITSIO
  free(header);
#endif

  /* Plot setup. */
  naxis[0] = 1024;
  naxis[1] = 1024;

  blc[0] = 0.5f;
  blc[1] = 0.5f;
  trc[0] = naxis[0] + 0.5f;
  trc[1] = naxis[1] + 0.5f;

  strcpy(devtyp, "/XWINDOW");
  cpgbeg(0, devtyp, 1, 1);
  cpgvstd();

  cpgwnad(0.0f, 1.0f, 0.0f, 1.0f);
  cpgask(1);
  cpgpage();

  /* Annotation. */
  strcpy(idents[0], "Right ascension");
  strcpy(idents[1], "Declination");

  opt[0] = 'G';
  opt[1] = 'E';

  /* Compact lettering. */
  cpgsch(0.8f);

  /* Draw full grid lines. */
  cpgsci(1);
  gcode[0] = 2;
  gcode[1] = 2;
  grid1[0] = 0.0;
  grid2[0] = 0.0;

  for (i = 0; i < nwcs; i++) {
    if ((status = wcsset(wcs+i))) {
      fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]);
      continue;
    }

    /* Get WCSNAME out of the wcsprm struct. */
    strcpy(idents[2], (wcs+i)->wcsname);
    printf("\n%s\n", idents[2]);

    /* Draw the celestial grid.  The grid density is set for each world */
    /* coordinate by specifying LABDEN = 1224. */
    ic = -1;
    cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0,
      grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256,
      &ic, cache, &status);

    /* Draw the frame. */
    cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0);

    cpgpage();
  }

  status = wcsvfree(&nwcs, &wcs);

  return 0;
}
Exemplo n.º 5
0
int main()

{
  /* Set up a 2 x 2 lookup table. */
  const int M = 2;
  const int K[] = {K1, K2};
  const int map[] = {0, 1};
  const double crval[] = {0.0, 0.0};

  char text[80];
  int i, j, k, l, l1, l2, l3, lstep, m, stat[NP*NP], status;
  float array[NP][NP], clev[31], v0, v1, w;
  const float scl = 2.0f/(NP-1);
  float ltm[6];
  double x[NP][NP][2], world[NP][NP][2];
  struct tabprm tab;

  printf("Testing WCSLIB coordinate lookup table routines (ttab2.c)\n"
         "---------------------------------------------------------\n");

  /* List status return messages. */
  printf("\nList of tab status return values:\n");
  for (status = 1; status <= 5; status++) {
    printf("%4d: %s.\n", status, tab_errmsg[status]);
  }

  printf("\n");


  /* PGPLOT initialization. */
  strcpy(text, "/xwindow");
  cpgbeg(0, text, 1, 1);
  cpgvstd();
  cpgsch(0.7f);

  /* The viewport is slightly oversized. */
  cpgwnad(-0.65f, 1.65f, -0.65f, 1.65f);

  for (l = 0; l <= 30; l++) {
    clev[l] = 0.2f*(l-10);
  }

  ltm[0] = -scl*(1.0f + (NP-1)/4.0f);
  ltm[1] =  scl;
  ltm[2] =  0.0f;
  ltm[3] = -scl*(1.0f + (NP-1)/4.0f);
  ltm[4] =  0.0f;
  ltm[5] =  scl;


  /* Set up the lookup table. */
  tab.flag = -1;
  if ((status = tabini(1, M, K, &tab))) {
    printf("tabini ERROR %d: %s.\n", status, tab_errmsg[status]);
    return 1;
  }

  tab.M = M;
  for (m = 0; m < tab.M; m++) {
    tab.K[m] = K[m];
    tab.map[m] = map[m];
    tab.crval[m] = crval[m];

    for (k = 0; k < tab.K[m]; k++) {
      tab.index[m][k] = (double)k;
    }
  }

  /* Subdivide the interpolation element. */
  for (i = 0; i < NP; i++) {
    for (j = 0; j < NP; j++) {
      x[i][j][0] = j*(K1-1.0)*scl - 0.5 - crval[0];
      x[i][j][1] = i*(K2-1.0)*scl - 0.5 - crval[1];
    }
  }

  /* The first coordinate element is static. */
  tab.coord[0] = 0.0;
  tab.coord[2] = 0.0;
  tab.coord[4] = 0.0;
  tab.coord[6] = 0.0;

  /* (k1,k2) = (0,0). */
  tab.coord[1] = 0.0;

  /* The second coordinate element varies in three of the corners. */
  for (l3 = 0; l3 <= 100; l3 += 20) {
    /* (k1,k2) = (1,1). */
    tab.coord[7] = 0.01 * l3;

    for (l2 = 0; l2 <= 100; l2 += 20) {
      /* (k1,k2) = (0,1). */
      tab.coord[5] = 0.01 * l2;

      cpgpage();
      for (l1 = 0; l1 <= 100; l1 += 2) {
        /* (k1,k2) = (1,0). */
        tab.coord[3] = 0.01 * l1;

        /* Compute coordinates within the interpolation element. */
        tab.flag = 0;
        if ((status = tabx2s(&tab, NP*NP, 2, (double *)x, (double *)world,
                             stat))) {
          printf("tabx2s ERROR %d: %s.\n", status, tab_errmsg[status]);
        }

        /* Start a new plot. */
        cpgbbuf();
        cpgeras();
        cpgsci(1);
        cpgslw(3);
        cpgbox("BCNST", 0.0f, 0, "BCNSTV", 0.0f, 0);
        cpgmtxt("T", 0.7f, 0.5f, 0.5f, "-TAB coordinates:  "
          "linear interpolation / extrapolation in 2-D");

        /* Draw the boundary of the interpolation element in red. */
        cpgsci(2);
        cpgmove(-0.5f,  0.0f);
        cpgdraw( 1.5f,  0.0f);

        cpgmove( 1.0f, -0.5f);
        cpgdraw( 1.0f,  1.5f);

        cpgmove( 1.5f,  1.0f);
        cpgdraw(-0.5f,  1.0f);

        cpgmove( 0.0f,  1.5f);
        cpgdraw( 0.0f, -0.5f);

        /* Label the value of the coordinate element in each corner. */
        sprintf(text, "%.1f", tab.coord[1]);
        cpgtext(-0.09f, -0.05f, text);
        sprintf(text, "%.2f", tab.coord[3]);
        cpgtext( 1.02f, -0.05f, text);
        sprintf(text, "%.1f", tab.coord[5]);
        cpgtext(-0.13f,  1.02f, text);
        sprintf(text, "%.1f", tab.coord[7]);
        cpgtext( 1.02f,  1.02f, text);

        cpgsci(1);
        /* Contour labelling: bottom. */
        v0 = world[0][0][1];
        v1 = world[0][NP-1][1];
        if (v0 != v1) {
          lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40;
          for (l = -200; l <= 300; l += lstep) {
            w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0);
            if (w < -0.5 || w > 1.5) continue;

            sprintf(text, "%4.1f", l*0.01f);
            cpgptxt(w+0.04f, -0.56f, 0.0f, 1.0f, text);
          }
        }

        /* Contour labelling: left. */
        v0 = world[0][0][1];
        v1 = world[NP-1][0][1];
        if (v0 != v1) {
          lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40;
          for (l = -200; l <= 300; l += lstep) {
            w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0);
            if (w < -0.5 || w > 1.5) continue;

            sprintf(text, "%4.1f", l*0.01f);
            cpgptxt(-0.52f, w-0.02f, 0.0f, 1.0f, text);
          }
        }

        /* Contour labelling: right. */
        v0 = world[0][NP-1][1];
        v1 = world[NP-1][NP-1][1];
        if (v0 != v1) {
          lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40;
          for (l = -200; l <= 300; l += lstep) {
            w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0);
            if (w < -0.5 || w > 1.5) continue;

            sprintf(text, "%.1f", l*0.01f);
            cpgptxt(1.52f, w-0.02f, 0.0f, 0.0f, text);
          }
        }

        /* Contour labelling: top. */
        v0 = world[NP-1][0][1];
        v1 = world[NP-1][NP-1][1];
        if (v0 != v1) {
          lstep = (abs((int)((v1-v0)/0.2f)) < 10) ? 20 : 40;
          for (l = -200; l <= 300; l += lstep) {
            w = -0.5f + 2.0f * (l*0.01f - v0) / (v1 - v0);
            if (w < -0.5 || w > 1.5) continue;

            sprintf(text, "%4.1f", l*0.01f);
            cpgptxt(w+0.04f, 1.52f, 0.0f, 1.0f, text);
          }
        }

        /* Draw contours for the second coordinate element. */
        for (i = 0; i < NP; i++) {
          for (j = 0; j < NP; j++) {
            array[i][j] = world[i][j][1];
          }
        }

        cpgsci(4);
        cpgslw(2);
        cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev, 10, ltm);

        cpgsci(7);
        cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev+10, 1, ltm);

        cpgsci(5);
        cpgcont(array[0], NP, NP, 1, NP, 1, NP, clev+11, 20, ltm);

        cpgebuf();
      }
    }
  }

  cpgend();

  tabfree(&tab);

  return 0;
}
Exemplo n.º 6
0
static double plot_fftview(fftview * fv, float maxpow, float charhgt,
                           float vertline, int vertline_color)
/* The return value is offsetf */
{
   int ii;
   double lor, lof, hir, hif, offsetf = 0.0;
   float *freqs;

   cpgsave();
   cpgbbuf();

   /* Set the "Normal" plotting attributes */

   cpgsls(1);
   cpgslw(1);
   cpgsch(charhgt);
   cpgsci(1);
   cpgvstd();

   if (maxpow == 0.0)           /* Autoscale for the maximum value */
      maxpow = 1.1 * fv->maxpow;

   lor = fv->lor;
   lof = lor / T;
   hir = lor + fv->dr * DISPLAYNUM;
   hif = hir / T;
   offsetf = 0.0;

   /* Period Labels */

   if (fv->zoomlevel >= 0 && lof > 1.0) {
      double lop, hip, offsetp = 0.0;
      lop = 1.0 / lof;
      hip = 1.0 / hif;
      offsetp = 0.0;

      if ((lop - hip) / hip < 0.001) {
         int numchar;
         char label[50];

         offsetp = 0.5 * (hip + lop);
         numchar = snprintf(label, 50, "Period - %.15g (s)", offsetp);
         cpgmtxt("T", 2.5, 0.5, 0.5, label);
      } else {
         cpgmtxt("T", 2.5, 0.5, 0.5, "Period (s)");
      }
      cpgswin(lop - offsetp, hip - offsetp, 0.0, maxpow);
      cpgbox("CIMST", 0.0, 0, "", 0.0, 0);
   }

   /* Frequency Labels */

   if ((hif - lof) / hif < 0.001) {
      int numchar;
      char label[50];

      offsetf = 0.5 * (hif + lof);
      numchar = snprintf(label, 50, "Frequency - %.15g (Hz)", offsetf);
      cpgmtxt("B", 2.8, 0.5, 0.5, label);
   } else {
      cpgmtxt("B", 2.8, 0.5, 0.5, "Frequency (Hz)");
   }
   cpgswin(lof - offsetf, hif - offsetf, 0.0, maxpow);

   /* Add zapboxes if required */

   if (numzaplist) {
      double zaplo, zaphi;

      cpgsave();
      cpgsci(15);
      cpgsfs(1);
      for (ii = 0; ii < numzaplist; ii++) {
         zaplo = zaplist[ii].lobin;
         zaphi = zaplist[ii].hibin;
         if ((zaplo < hir && zaplo > lor) || (zaphi < hir && zaphi > lor)) {
            cpgrect(zaplo / T - offsetf, zaphi / T - offsetf, 0.0, 0.95 * maxpow);
         }
      }
      cpgunsa();
   }

   /* Add a background vertical line if requested */

   if (vertline != 0.0 && vertline_color != 0) {
      cpgsave();
      cpgsci(vertline_color);
      cpgmove(vertline / T - offsetf, 0.0);
      cpgdraw(vertline / T - offsetf, maxpow);
      cpgunsa();
   }

   if (fv->zoomlevel >= 0 && lof > 1.0)
      cpgbox("BINST", 0.0, 0, "BCNST", 0.0, 0);
   else
      cpgbox("BCINST", 0.0, 0, "BCNST", 0.0, 0);

   /* Plot the spectrum */

   freqs = gen_fvect(DISPLAYNUM);
   for (ii = 0; ii < DISPLAYNUM; ii++)
      freqs[ii] = fv->rs[ii] / T - offsetf;
   if (fv->zoomlevel > 0) {     /* Magnified power spectrum */
      cpgline(DISPLAYNUM, freqs, fv->powers);
   } else {                     /* Down-sampled power spectrum */
      for (ii = 0; ii < DISPLAYNUM; ii++) {
         cpgmove(freqs[ii], 0.0);
         cpgdraw(freqs[ii], fv->powers[ii]);
      }
   }
   vect_free(freqs);
   cpgmtxt("L", 2.5, 0.5, 0.5, "Normalized Power");
   cpgebuf();
   cpgunsa();
   return offsetf;
}
Exemplo n.º 7
0
Arquivo: RGPMain.C Projeto: rjs80/RGIS
int main (int argc,char **argv)

	{
	int argPos, argNum = argc;
	char charBuffer [RGPBufferSIZE], panelTitle [RGPBufferSIZE], *outFile = (char *) "rgisplot";
	int panelRow, panelCol, panelRowNum,panelColNum, defaultLW;
	DBInt dataNum, entryNum = 0;
	DBInt ret, mode = 0, device = 0, format = 0, layout = 0;
	float x0, y0, x1, y1, pWidth = -1.0, pHeight = -1.0;
	DBObjData *dbData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-m","--mode"))
			{
			const char *modes [] = { "interactive", "batch", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing mode!");    return (CMfailed); }
			if ((mode = CMoptLookup (modes,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid mode %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-d","--device"))
			{
			const char *devices [] = { "screen", "file", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing device!");  return (CMfailed); }
			if ((device = CMoptLookup (devices,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid device %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-p","--psize"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing psize!");   return (CMfailed); }
			if ((argv [argPos] == (char *) NULL) || (sscanf (argv [argPos],"%f,%f",&pWidth,&pHeight) != 2))
				{ CMmsgPrint (CMmsgUsrError,"Invalid page size %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-f","--format"))
			{
			const char *formats [] = { "eps", "gif", "ppm", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing format!");  return (CMfailed); }
			if ((format = CMoptLookup (formats,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid format %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-l","--layout"))
			{
			const char *layouts [] = { "portrait","landscape", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing layout!");  return (CMfailed); }
			if ((layout = CMoptLookup (layouts,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid layout %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-o","--output"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing output!");  return (CMfailed); }
			if (argv [argPos] == (char *) NULL)
				{ CMmsgPrint (CMmsgUsrError,"Invalid output file"); goto Usage; }
			outFile = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-h","--help"))
			{
			Usage:
			CMmsgPrint (CMmsgUsrError,"Usage: rgisPlot [-m <>] [-d <>] [-f <>] [-l <>] [-o <>] -h");
			CMmsgPrint (CMmsgUsrError,"                 -m, --mode <interactive | batch>");
			CMmsgPrint (CMmsgUsrError,"                 -d, --device <screen | file>");
			CMmsgPrint (CMmsgUsrError,"                 -p, --psize width,height");
			CMmsgPrint (CMmsgUsrError,"                 -f, --format <eps | gif>");
			CMmsgPrint (CMmsgUsrError,"                 -l, --layout <landscape | portrait>");
			CMmsgPrint (CMmsgUsrError,"                 -o, --output <filename>");
			argNum = CMargShiftLeft (argPos,argv,argNum);
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;

		}

	switch (device)
		{
		case 0: cpgopen ("/XWINDOW");	break;
		case 1:
			{
			char *formatStrings [] = { (char *) "CPS", (char *) "GIF", (char *) "PPM" };
			sprintf (charBuffer,layout == 0 ? "%s/V%s" : "%s/%s", outFile, formatStrings [format]);
			cpgopen (charBuffer);
			} break;
		default: return (CMfailed);
		}
	cpgscrn (0,"WHITE",&ret);
	if ((pWidth > 0.0) && (pHeight > 0.0)) cpgpap (pWidth, pHeight / pWidth);

	do	{
		RGPPrintMessage (mode,&entryNum,"Panel Layout [horizontal,vertical]:");
		while (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL);
		if (sscanf (charBuffer,"%d,%d",&panelColNum,&panelRowNum) == 2) break;
		else
			if (RGPPrintError (mode,entryNum,"Panel layout input error")) goto Stop;
		} while (true);

	RGPInitPenColors ();
	cpgsubp (panelColNum,panelRowNum);
	cpgqlw (&defaultLW);

	ret = DBSuccess;
	for (panelRow = 0;panelRow < panelRowNum;++panelRow)
		for (panelCol = 0;panelCol < panelColNum; ++panelCol)

			{
			cpgpanl (panelCol + 1,panelRow + 1);
			cpgsch (1.8);
			cpgvstd ();
			do	{
				sprintf (charBuffer,"Panel Title [%d,%d]:",panelRow,panelCol);
				RGPPrintMessage (mode,&entryNum,charBuffer);
				if (fgets (panelTitle,sizeof (panelTitle) - 1,stdin) != (char *) NULL)
					{
					if (panelTitle [strlen (panelTitle) - 1] == '\n')
						panelTitle [strlen (panelTitle) - 1] = '\0';
					if (strlen (panelTitle) > 0) break;
					}
				RGPPrintError (mode,entryNum,"Panel Title input error"); goto Stop;
				} while (true);

			dataNum = 0;
			do {
				RGPPrintMessage (mode,&entryNum,"Mapextent [X0,Y0,X1,Y1]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL) continue;
				if (sscanf (charBuffer,"%f,%f,%f,%f",&x0,&y0,&x1,&y1) == 4)	break;
				else	if (RGPPrintError (mode,entryNum,"Mapextent input error")) goto Stop;
				} while (true);
			cpgwnad (x0,x1,y0,y1);

			do	{
				sprintf (charBuffer,"RiverGIS data file [%d]:",++dataNum);
				RGPPrintMessage (mode,&entryNum, charBuffer);
				if ((fgets (charBuffer,sizeof (charBuffer) - 1,stdin) != (char *) NULL) &&
					 (strlen (charBuffer) > 0) && charBuffer [0] != '\n')
					{
					if (charBuffer [strlen (charBuffer) - 1] == '\n') charBuffer [strlen (charBuffer) - 1] = '\0';
					dbData = new DBObjData ();
					if (dbData->Read (charBuffer) != DBSuccess) { dataNum--; continue; }
					switch (dbData->Type ())
						{
						case DBTypeVectorPoint:
							if ((ret = RGPDrawVecPoint (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorLine:
							if ((ret = RGPDrawVecLine (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorPolygon:
							break;
						case DBTypeGridContinuous:
								if ((ret = RGPDrawGridContinuous (mode,&entryNum,dbData)) == DBFault)	goto Stop;
							break;
						case DBTypeGridDiscrete:
							break;
						case DBTypeNetwork:
							if ((ret = RGPDrawNetwork (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						default: CMmsgPrint (CMmsgUsrError,"Invalid data type"); dataNum--; break;
						}
					delete dbData;
					}
				else	break;
				} while (true);
			cpgbox ("BCMTS",0.0,0,"BCNMTS",0.0,0);
			cpgslw (2);
			cpgsch (2.5);
			cpgmtxt ("T",1.5,0.5,0.5,panelTitle);
			cpgslw (defaultLW);
			}
Stop:
	cpgend ();
	return (ret);
	}
Exemplo n.º 8
0
int main()

{
  /* Set up the lookup table. */
  const int M  = 2;
  const int K[] = {K1, K2};
  const int map[] = {0, 1};
  const double crval[] = {135.0, 95.0};

  char text[80];
  int ci, i, ilat, ilng, j, k, m, stat[K2][K1], status;
  float xr[361], yr[361];
  double *dp, world[361][2], x[K1], xy[361][2], y[K2];
  struct tabprm tab;
  struct prjprm prj;

  printf(
    "Testing WCSLIB inverse coordinate lookup table routines (ttab3.c)\n"
    "-----------------------------------------------------------------\n");

  /* List status return messages. */
  printf("\nList of tab status return values:\n");
  for (status = 1; status <= 5; status++) {
    printf("%4d: %s.\n", status, tab_errmsg[status]);
  }

  printf("\n");


  /* PGPLOT initialization. */
  strcpy(text, "/xwindow");
  cpgbeg(0, text, 1, 1);
  cpgvstd();
  cpgsch(0.7f);
  cpgwnad(-135.0f, 135.0f, -95.0f, 140.0f);
  cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0);

  cpgscr(0, 0.00f, 0.00f, 0.00f);
  cpgscr(1, 1.00f, 1.00f, 0.00f);
  cpgscr(2, 1.00f, 1.00f, 1.00f);
  cpgscr(3, 0.50f, 0.50f, 0.80f);
  cpgscr(4, 0.80f, 0.50f, 0.50f);
  cpgscr(5, 0.80f, 0.80f, 0.80f);
  cpgscr(6, 0.50f, 0.50f, 0.80f);
  cpgscr(7, 0.80f, 0.50f, 0.50f);
  cpgscr(8, 0.30f, 0.50f, 0.30f);


  /* Set up the lookup table. */
  tab.flag = -1;
  if ((status = tabini(1, M, K, &tab))) {
    printf("tabini ERROR %d: %s.\n", status, tab_errmsg[status]);
    return 1;
  }

  tab.M = M;
  for (m = 0; m < tab.M; m++) {
    tab.K[m] = K[m];
    tab.map[m] = map[m];
    tab.crval[m] = crval[m];

    for (k = 0; k < tab.K[m]; k++) {
      tab.index[m][k] = (double)k;
    }
  }

  /* Set up the lookup table to approximate Bonne's projection. */
  for (i = 0; i < K1; i++) {
    x[i] = 135 - i;
  }
  for (j = 0; j < K2; j++) {
    y[j] = j - 95;
  }

  prjini(&prj);
  prj.pv[1] = 35.0;
  status = bonx2s(&prj, K1, K2, 1, 2, x, y, tab.coord, tab.coord+1,
                  (int *)stat);

  dp = tab.coord;
  for (j = 0; j < K2; j++) {
    for (i = 0; i < K1; i++) {
      if (stat[j][i]) {
        *dp = 999.0;
        *(dp+1) = 999.0;
      }
      dp += 2;
    }
  }


  /* Draw meridians. */
  ci = 1;
  for (ilng = -180; ilng <= 180; ilng += 15) {
    if (++ci > 7) ci = 2;
    cpgsci(ilng?ci:1);

    for (j = 0, ilat = -90; ilat <= 90; ilat++, j++) {
      world[j][0] = (double)ilng;
      world[j][1] = (double)ilat;
    }

    /* A fudge to account for the singularity at the poles. */
    world[0][0] = 0.0;
    world[180][0] = 0.0;

    status = tabs2x(&tab, 181, 2, (double *)world, (double *)xy,
                    (int *)stat);

    k = 0;
    for (j = 0; j < 181; j++) {
      if (stat[0][j]) {
        if (k > 1) cpgline(k, xr, yr);
        k = 0;
        continue;
      }

      xr[k] = xy[j][0];
      yr[k] = xy[j][1];
      k++;
    }

    cpgline(k, xr, yr);
  }


  /* Draw parallels. */
  ci = 1;
  for (ilat = -75; ilat <= 75; ilat += 15) {
    if (++ci > 7) ci = 2;
    cpgsci(ilat?ci:1);

    for (j = 0, ilng = -180; ilng <= 180; ilng++, j++) {
      world[j][0] = (double)ilng;
      world[j][1] = (double)ilat;
    }

    status = tabs2x(&tab, 361, 2, (double *)world, (double *)xy,
                    (int *)stat);

    k = 0;
    for (j = 0; j < 361; j++) {
      if (stat[0][j]) {
        if (k > 1) cpgline(k, xr, yr);
        k = 0;
        continue;
      }

      xr[k] = xy[j][0];
      yr[k] = xy[j][1];
      k++;
    }

    cpgline(k, xr, yr);
  }

  cpgend();

  return 0;
}
Exemplo n.º 9
0
int main(int argc, char **argv)

{
  char alt = '\0', *header, idents[3][80], *infile, keyword[16], nlcprm[1],
       opt[2], pgdev[16];
  int  c0[] = {-1, -1, -1, -1, -1, -1, -1};
  int  alts[27], gcode[2], hdunum = 1, hdutype, i, ic, naxes, naxis[2],
       nkeyrec, nreject, nwcs, stat[NWCSFIX], status;
  float  blc[2], trc[2];
  double cache[257][4], grid1[3], grid2[3], nldprm[1];
  struct wcsprm *wcs;
  nlfunc_t pgwcsl_;
  fitsfile *fptr;


  /* Parse options. */
  strcpy(pgdev, "/XWINDOW");
  for (i = 1; i < argc && argv[i][0] == '-'; i++) {
    if (!argv[i][1]) break;

    switch (argv[i][1]) {
    case 'a':
      alt = toupper(argv[i][2]);
      break;

    case 'd':
      if (argv[i][2] == '?') {
        cpgldev();
        return 0;
      }

      if (argv[i][2] == '/') {
        strncpy(pgdev+1, argv[i]+3, 15);
      } else {
        strncpy(pgdev+1, argv[i]+2, 15);
      }
      break;

    case 'h':
      hdunum = atoi(argv[i]+2);
      break;

    default:
      fprintf(stderr, "%s", usage);
      return 1;
    }
  }

  if (i < argc) {
    infile = argv[i++];

    if (i < argc) {
      fprintf(stderr, "%s", usage);
      return 1;
    }
  } else {
    infile = "-";
  }

  /* Check accessibility of the input file. */
  if (strcmp(infile, "-") && access(infile, R_OK) == -1) {
    printf("wcsgrid: Cannot access %s.\n", infile);
    return 1;
  }


  /* Open the FITS file and move to the required HDU. */
  status = 0;
  if (fits_open_file(&fptr, infile, READONLY, &status)) goto fitserr;
  if (fits_movabs_hdu(fptr, hdunum, &hdutype, &status)) goto fitserr;
  if (hdutype != IMAGE_HDU) {
    fprintf(stderr, "ERROR, HDU number %d does not contain an image array.\n",
      hdunum);
    return 1;
  }

  /* Check that we have at least two image axes. */
  if (fits_read_key(fptr, TINT, "NAXIS",  &naxes, NULL, &status)) {
    goto fitserr;
  }

  if (naxes < 2) {
    fprintf(stderr, "ERROR, HDU number %d does not contain a 2-D image.\n",
      hdunum);
    return 1;
  } else if (naxes > 2) {
    printf("HDU number %d contains a %d-D image array.\n", hdunum, naxes);
  }

  /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */
  if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) {
    goto fitserr;
  }


  /* Interpret the WCS keywords. */
  if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs,
                       &wcs))) {
    fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcshdr_errmsg[status]);
    return 1;
  }
  free(header);

  /* Read -TAB arrays from the binary table extension (if necessary). */
  if (fits_read_wcstab(fptr, wcs->nwtb, (wtbarr *)wcs->wtb, &status)) {
    goto fitserr;
  }

  /* Translate non-standard WCS keyvalues. */
  if ((status = wcsfix(7, 0, wcs, stat))) {
    status = 0;
    for (i = 0; i < NWCSFIX; i++) {
      if (stat[i] > 0) {
         fprintf(stderr, "wcsfix ERROR %d: %s.\n", stat[i],
                 wcsfix_errmsg[stat[i]]);

        /* Ignore problems with CDi_ja and DATE-OBS. */
        if (!(i == CDFIX || i == DATFIX)) status = 1;
      }
    }

    if (status) return 1;
  }

  /* Sort out alternates. */
  if (alt) {
    wcsidx(nwcs, &wcs, alts);

    if (alt == ' ') {
      if (alts[0] == -1) {
        fprintf(stderr, "WARNING, no primary coordinate representation, "
                        "doing all.\n");
        alt = '\0';
      }

    } else if (alt < 'A' || alt > 'Z') {
      fprintf(stderr, "WARNING, alternate specifier \"%c\" is invalid, "
                      "doing all.\n", alt);
      alt = '\0';

    } else {
      if (alts[alt - 'A' + 1] == -1) {
        fprintf(stderr, "WARNING, no alternate coordinate representation "
                        "\"%c\", doing all.\n", alt);
        alt = '\0';
      }
    }
  }

  /* Get image dimensions from the header. */
  sprintf(keyword, "NAXIS%d", wcs->lng + 1);
  fits_read_key(fptr, TINT, "NAXIS1", naxis,   NULL, &status);
  sprintf(keyword, "NAXIS%d", wcs->lat + 1);
  fits_read_key(fptr, TINT, "NAXIS2", naxis+1, NULL, &status);

  if ((naxis[0] < 2) || (naxis[1] < 2)) {
    fprintf(stderr, "ERROR, HDU number %d contains degenerate image axes.\n",
      hdunum);
    return 1;
  }

  fits_close_file(fptr, &status);


  /* Plot setup. */
  blc[0] = 0.5f;
  blc[1] = 0.5f;
  trc[0] = naxis[0] + 0.5f;
  trc[1] = naxis[1] + 0.5f;

  if (cpgbeg(0, pgdev, 1, 1) != 1) {
    fprintf(stderr, "ERROR, failed to open PGPLOT device %s.\n", pgdev);
    return 1;
  }
  cpgvstd();

  cpgwnad(blc[0], trc[0], blc[0], trc[1]);
  cpgask(1);
  cpgpage();

  /* Compact lettering. */
  cpgsch(0.8f);

  /* Draw full grid lines. */
  gcode[0] = 2;
  gcode[1] = 2;
  grid1[0] =    0.0;
  grid2[0] =    0.0;

  /* These are for the projection boundary. */
  grid1[1] = -180.0;
  grid1[2] =  180.0;
  grid2[1] =  -90.0;
  grid2[2] =   90.0;

  cpgsci(1);

  for (i = 0; i < nwcs; i++) {
    if (alt && (wcs+i)->alt[0] != alt) {
      continue;
    }

    if ((status = wcsset(wcs+i))) {
      fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]);
      continue;
    }

    /* Draw the frame. */
    cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0);

    /* Axis labels; use CNAMEia in preference to CTYPEia. */
    if ((wcs+i)->cname[0][0]) {
      strcpy(idents[0], (wcs+i)->cname[0]);
    } else {
      strcpy(idents[0], (wcs+i)->ctype[0]);
    }

    if ((wcs+i)->cname[1][0]) {
      strcpy(idents[1], (wcs+i)->cname[1]);
    } else {
      strcpy(idents[1], (wcs+i)->ctype[1]);
    }

    /* Title; use WCSNAME. */
    strcpy(idents[2], (wcs+i)->wcsname);
    if (strlen(idents[2])) {
      printf("\n%s\n", idents[2]);
    }

    /* Formatting control for celestial coordinates. */
    if (strncmp((wcs+i)->ctype[0], "RA", 2) == 0) {
      /* Right ascension in HMS, declination in DMS. */
      opt[0] = 'G';
      opt[1] = 'E';
    } else {
      /* Other angles in decimal degrees. */
      opt[0] = 'A';
      opt[1] = 'B';
    }

    /* Draw the celestial grid.  The grid density is set for each world */
    /* coordinate by specifying LABDEN = 1224. */
    ic = -1;
    cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0,
      grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256,
      &ic, cache, &status);

    /* Delimit the projection boundary. */
    if ((wcs+i)->cel.prj.category != ZENITHAL) {
      /* Reset to the native coordinate graticule. */
      (wcs+i)->crval[0] = (wcs+i)->cel.prj.phi0;
      (wcs+i)->crval[1] = (wcs+i)->cel.prj.theta0;
      (wcs+i)->lonpole  = 999.0;
      (wcs+i)->latpole  = 999.0;
      status = wcsset(wcs+i);

      ic = -1;
      cpgsbox(blc, trc, idents, opt, -1, 0, c0, gcode, 0.0, 2, grid1, 2,
        grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256,
        &ic, cache, &status);
    }

    cpgpage();
  }

  status = wcsvfree(&nwcs, &wcs);

  return 0;

fitserr:
  fits_report_error(stderr, status);
  fits_close_file(fptr, &status);
  return 1;
}
Exemplo n.º 10
0
static void _pgvstd (void)
{
   cpgvstd();
}