Пример #1
0
void Cpg_Env(double xmin, double xmax, double ymin, double ymax, int just, int axis)
/* void cpgenv(float xmin, float xmax, float ymin, float ymax, int just, int axis); */
{
	cpgenv((float)xmin, (float)xmax, (float)ymin, (float)ymax, just, axis);

	return;
}
Пример #2
0
void xyline(int npts, float *x, float *y, const char *xlab, const char *ylab, int id)
{
    float xmin, xmax, ymin, ymax;
    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);
    overy = over * (ymax - ymin);
    ymax += overy;
    ymin -= overy;

    /* Setup the plot screen: */
    cpgenv(xmin, xmax, ymin, ymax, 0, 0);

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

    /* Label the axes: */
    cpglab(xlab, ylab, "");

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

    /* Plot the points: */
    cpgline(npts, x, y);

}
Пример #3
0
void display_particles(NBody *data, double max, int n)
/*assume a top-down view (i.e. ignore the z-component*/
{
#ifdef PGPLOT
   int npix=256;
   float tr[6];
   static int firsttime=1;

   if (firsttime)
   {
      assert(NDIM>=2);
      cpgopen("?");
      cpgenv(1,npix,1,npix,0,1);
      firsttime=0;
   }
   tr[0]=0;tr[1]=1;tr[2]=0;tr[3]=0;tr[4]=0;tr[5]=1;
   float **mat=fmatrix(npix,npix);
   for (int i=0;i<npix;i++)
      for (int j=0;j<npix;j++)
         mat[i][j]=0;
  
   for (int i=0;i<n;i++)
   {
      int ii= npix*((data[i].x[0]+max)/(2*max));
      int jj= npix*((data[i].x[1]+max)/(2*max));
      if ((ii>=0)&&(ii<npix)&&(jj>=0)&&(jj<npix))
         mat[ii][jj]++;
   }

   cpgimag(mat[0],npix,npix,1,npix,1,npix,0,5.0,tr);
#endif
  
}
Пример #4
0
static void demo1()
{
  int i;
  static float xs[] = {1.0, 2.0, 3.0, 4.0, 5.0 };
  static float ys[] = {1.0, 4.0, 9.0, 16.0, 25.0 };
  float xr[60], yr[60];
  int n = sizeof(xr) / sizeof(xr[0]);
  /*
   * Call cpgenv to specify the range of the axes and to draw a box, and
   * cpglab to label it. The x-axis runs from 0 to 10, and y from 0 to 20.
   */
  cpgenv(0.0, 10.0, 0.0, 20.0, 0, 1);
  cpglab("(x)", "(y)", "PGPLOT Example 1: y = x\\u2\\d");
  /*
   * Mark five points (coordinates in arrays XS and YS), using symbol
   * number 9.
   */
  cpgpt(5, xs, ys, 9);
  /*
   * Compute the function at 'n=60' points, and use cpgline to draw it.
   */
  for(i=0; i<n; i++) {
    xr[i] = 0.1*i;
    yr[i] = xr[i]*xr[i];
  }
  cpgline(n, xr, yr);
  return;
}
Пример #5
0
void plot_profile(int proflen, float *profile, const char *title,
                  const char *probtxt, const char *foldtxt,
                  int showerr, float *errors, int showid)
{
    int ii;
    float *x, overy, ymin, ymax;
    float errmin = 0.0, errmax = 0.0, offset, avg = 0.0, av[2];

    find_min_max_arr(proflen, profile, &ymin, &ymax);
    if (showerr)
        find_min_max_arr(proflen, errors, &errmin, &errmax);
    overy = 0.1 * (ymax + errmax - ymin - errmin);
    ymax = ymax + overy + errmax;
    ymin = ymin - overy - errmin;
    x = gen_fvect(proflen);
    for (ii = 0; ii < proflen; ii++)
        x[ii] = (float) ii / (float) proflen;
    cpgenv(0.0, 1.00001, ymin, ymax, 0, 0);
    cpgscf(2);
    cpglab("Pulse Phase", "Counts", "");
    if (showid)
        cpgiden();
    cpgslw(5);
    if (showerr) {
        cpgbin(proflen, x, profile, 0);
    } else {
        cpgline(proflen, x, profile);
    }
    cpgslw(1);
    if (showerr) {
        offset = 0.5 / (float) proflen;
        for (ii = 0; ii < proflen; ii++)
            x[ii] += offset;
        cpgerrb(6, proflen, x, profile, errors, 2);
        cpgpt(proflen, x, profile, 5);
    }
    for (ii = 0; ii < proflen; ii++)
        avg += profile[ii];
    avg /= proflen;
    cpgsls(4);
    x[0] = 0.0;
    x[1] = 1.0;
    av[0] = avg;
    av[1] = avg;
    cpgline(2, x, av);
    cpgsls(1);
    cpgsch(1.3);
    cpgmtxt("T", +2.0, 0.5, 0.5, title);
    cpgsch(1.0);
    cpgmtxt("T", +0.8, 0.5, 0.5, foldtxt);
    cpgmtxt("T", -1.5, 0.5, 0.5, probtxt);
    vect_free(x);
}
Пример #6
0
void powerplot(int npts, float *freqs, float *amp, float norm, int id)
{
   float *pwr, xmin, xmax, ymin, ymax;
   float overy, over = 0.1;
   int i, ptr;

   pwr = (float *) malloc((size_t) npts * sizeof(float));
   if (!pwr) {
      printf("Error allocating 'pwr' in powerplot.  Exiting.\n\n");
      exit(EXIT_FAILURE);
   }
   /* Turn the complex amps into a power series: */
   for (i = 0; i < npts; i++) {
      ptr = i * 2;
      pwr[i] = plot_power(amp[ptr], amp[ptr + 1]) / norm;
   }

   /* Determine min and max values to plot and scaling: */
   find_min_max_arr(npts, freqs, &xmin, &xmax);
   find_min_max_arr(npts, pwr, &ymin, &ymax);
   overy = over * (ymax - ymin);
   ymax += overy;

   /* Setup the plot screen: */
   cpgenv(xmin, xmax, ymin, ymax, 0, 1);

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

   /* Label the axes: */
   cpglab("Frequency", "Power", "");

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

   /* Plot the points: */
   cpgline(npts, freqs, pwr);

   free(pwr);
}
// Process dedispersion output
void* process_output(void* output_params)
{
    OUTPUT_PARAMS* params = (OUTPUT_PARAMS *) output_params;
    OBSERVATION *obs = params -> obs;
    int i, iters = 0, ret, loop_counter = 0, pnsamp = params -> obs -> nsamp;
    int ppnsamp = params -> obs-> nsamp;
    time_t start = params -> start, beg_read;
    double pptimestamp = 0, ptimestamp = 0;
    double ppblockRate = 0, pblockRate = 0;

    // Initialise pg plotter
    #if PLOT
        if(cpgbeg(0, "/xwin", 1, 1) != 1)
            printf("Couldn't initialise PGPLOT\n");
        cpgask(false);
    #endif

    printf("%d: Started output thread\n", (int) (time(NULL) - start));

    FILE *fp = fopen("chanOutput.dat", "wb");

    // Processing loop
    while (1) {

        // Wait input barrier
        ret = pthread_barrier_wait(params -> input_barrier);
        if (!(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD)) 
            { fprintf(stderr, "Error during input barrier synchronisation [output]\n"); exit(0); }

        // Process output
        if (loop_counter >= params -> iterations) 
        {
            unsigned nsamp = ppnsamp, nchans = obs -> nchans;
            double timestamp = pptimestamp, blockRate = ppblockRate;
            beg_read = time(NULL);

            #if PLOT
            if (!obs -> folding)
            {
                // Process and plot output
                unsigned startChan = 0, endChan = startChan + 32, decFactor = 512;
//                unsigned startChan = 0, endChan = startChan + 32, decFactor = 4;
                float xr[nsamp / decFactor], yr[endChan - startChan][nsamp / decFactor];
                float ymin = 9e12, ymax=9e-12;

                for (unsigned c = 0; c < endChan - startChan; c++)
                {
                    // Decimate before plotting
                    for (unsigned i = 0; i < nsamp / decFactor; i++)
                    {        
                        unsigned index = (startChan + c) * nsamp + i * decFactor;
                        xr[i] = i;
                        yr[c][i] = 0;

                        for (unsigned j = 0; j < decFactor; j++)
                            yr[c][i] += params -> host_odata[index+j].x * 
                                        params -> host_odata[index+j].x + 
                                        params -> host_odata[index+j].y * 
                                        params -> host_odata[index+j].y;

//                            yr[c][i] = (yr[c][i] / decFactor) + c * 1e5;
                        yr[c][i] = (yr[c][i] / decFactor) + c * 4;
                        if (ymax < yr[c][i]) ymax = yr[c][i];
                        if (ymin > yr[c][i]) ymin = yr[c][i];
                    }
                }

                unsigned plotChan = 1;
                float *chan = (float *) malloc(nsamp * sizeof(float));
                for (unsigned i = 0; i < nsamp; i++)
                  chan[i] = params -> host_odata[plotChan * nsamp + i].x * 
                            params -> host_odata[plotChan * nsamp + i].x + 
                            params -> host_odata[plotChan * nsamp + i].y * 
                            params -> host_odata[plotChan * nsamp + i].y;

                fwrite(chan, sizeof(float), nsamp, fp);
                fflush(fp);
                free(chan);

                cpgenv(0.0, pnsamp / decFactor, ymin, ymax, 0, 1);
                cpgsci(7);
                for (unsigned i = 0; i < endChan - startChan; i++)
                    cpgline(nsamp / decFactor, xr, yr[i]);

                cpgmtxt("T", 2.0, 0.0, 0.0, "Dedispersed Channel Plot");
            }
            else
            {
                unsigned plotChannel = 15;
                unsigned decFactor = 256; 
                float *xr = (float *) malloc(obs -> profile_bins / decFactor * sizeof(float));
                float *yr = (float *) malloc(obs -> profile_bins / decFactor * sizeof(float));
                float ymin = 9e12, ymax = 9e-12;           
    
                unsigned fullProfiles = obs -> nsamp * (loop_counter - 1) / 
                                        obs -> profile_bins;
                unsigned leftover = (obs -> nsamp * (loop_counter - 1)) % obs -> profile_bins;

                if (fullProfiles > 0)
                {
                    // Decimate before plotting
                    for (unsigned i = 0; i < obs -> profile_bins / decFactor; i++)
                    {        
                        unsigned index = plotChannel * obs -> profile_bins + i * decFactor;
                        xr[i] = i;
                        yr[i] = 0;

                        for (unsigned j = 0; j < decFactor; j++)
                            yr[i] += params -> host_profile[index + j];

                        yr[i] = (yr[i] / decFactor);
                        yr[i] = (i < leftover / decFactor) 
                              ? yr[i] / (fullProfiles + 1) 
                              : yr[i] / fullProfiles;

                        if (ymax < yr[i]) ymax = yr[i];
                        if (ymin > yr[i]) ymin = yr[i];
                    }

                    cpgenv(0.0, obs -> profile_bins / decFactor, ymin, ymax, 0, 1);
                    cpgsci(7);
                    cpgline(obs -> profile_bins / decFactor, xr, yr);
                    cpgmtxt("T", 2.0, 0.0, 0.0, "Pulsar Profile");
                    
                    free(xr);
                    free(yr);
                }
            }
            #endif

            printf("%d: Processed output %d [output]: %d\n", (int) (time(NULL) - start), loop_counter,
                   (int) (time(NULL) - beg_read));
        }

    sleep(2);

        // Wait output barrier
        ret = pthread_barrier_wait(params -> output_barrier);
        if (!(ret == 0 || ret == PTHREAD_BARRIER_SERIAL_THREAD))
            { fprintf(stderr, "Error during output barrier synchronisation [output]\n"); exit(0); }

        // Acquire rw lock
        if (pthread_rwlock_rdlock(params -> rw_lock))
            { fprintf(stderr, "Unable to acquire rw_lock [output]\n"); exit(0); } 

        // Update params
        ppnsamp = pnsamp;
        pnsamp = params -> obs -> nsamp;     
        pptimestamp = ptimestamp;
        ptimestamp = params -> obs -> timestamp;
        ppblockRate = pblockRate;
        pblockRate = params -> obs -> blockRate;    

        // Stopping clause
        if (((OUTPUT_PARAMS *) output_params) -> stop) {
            
            if (iters >= params -> iterations - 1) {
               
                // Release rw_lock
                if (pthread_rwlock_unlock(params -> rw_lock))
                    { fprintf(stderr, "Error releasing rw_lock [output]\n"); exit(0); }

                for(i = 0; i < params -> maxiters - params -> iterations; i++) {
                    pthread_barrier_wait(params -> input_barrier);
                    pthread_barrier_wait(params -> output_barrier);
                }
                break;
            }
            else
                iters++;
        }

        // Release rw_lock
        if (pthread_rwlock_unlock(params -> rw_lock))
            { fprintf(stderr, "Error releasing rw_lock [output]\n"); exit(0); }

        loop_counter++;
    }   

    printf("%d: Exited gracefully [output]\n", (int) (time(NULL) - start));
    pthread_exit((void*) output_params);
}
Пример #8
0
int main(int argc, char *argv[])
{
	fitsfile* fptr;
	//char filename[] = "guppi_56590_B1133+16_0003_0001.fits";
	char filename[] = "~/pulsar_data/B0329.fits";
	int status = 0;
	float realDm = 26.8;
	double psrFreq = 1.399541539;
	int i,j; //for loop
	int sampNum;


	fits_open_file(&fptr,filename,READONLY,&status);
	
	//初始化fits文件信息
	struct Fitsinfo* fi = (struct Fitsinfo*)malloc(sizeof(struct Fitsinfo));
	initFitsInfo(fptr,fi,realDm,&status);
	sampNum = fi->nSBLK*fi->nROW;
	//初始化保存所有流量数据的二维数组
	/*
	unsigned char** ptr = (unsigned char**)malloc(fi->nROW*fi->nSBLK*sizeof(unsigned char*));
	for (i=0; i<fi->nROW*fi->nSBLK; i++) {
		ptr[i] = (unsigned char*)malloc(fi->nCHAN*sizeof(unsigned char));
	}
	initTotalData(fptr,fi,ptr,&status);
	*/

	//初始化合适的频道
	unsigned char** ptr = (unsigned char**)malloc(fi->nROW*fi->nSBLK*sizeof(unsigned char*));
	for (i=0; i<fi->nROW*fi->nSBLK; i++) {
		ptr[i] = (unsigned char*)malloc((fi->highF-fi->lowF+1)*sizeof(unsigned char));
	}
	initSuitData(fptr,fi,ptr,&status);
	//给需要处理的某两个通道分配空间	
    	struct FreqData* fdm = (struct FreqData*)malloc(sizeof(struct FreqData));
	fdm->data = (int*)malloc(sizeof(int)*fi->nSBLK*fi->nROW);
	struct FreqData** fd = (struct FreqData**)malloc(DMNUM*sizeof(struct FreqData*));	
	for (i=0; i<DMNUM; i++) {
		fd[i] = (struct FreqData*)malloc(sizeof(struct FreqData));
		fd[i]->data = (int*)malloc(sizeof(int)*fi->nSBLK*fi->nROW);
		//addSuitFreqData(fptr,fd[i],fdm,ptr,fi->dmArr[i],fi,&status);
		addSuitFreqDataWithZeroDm(fptr,fd[i],fdm,ptr,fi->dmArr[i],fi,&status);
	}
	for (i=0; i<fi->nROW*fi->nSBLK; i++) {
		free(ptr[i]);
	}
	free(ptr);

	/* draw fd[DMNUM/2]->data */
	/* draw fd[DMNUM/2]->data */
	if (cpgbeg(0, "/xs", 1, 1) != 1) {
		return EXIT_FAILURE;
	}
	float ns = fi->nROW * fi->nSBLK;
	float *x_coor, *data_adm;
	x_coor = (float *)malloc(sizeof(float) * fi->nROW * fi->nSBLK);
	data_adm = (float *)malloc(sizeof(float) * ns);
	for (i = 0; i < fi->nROW * fi->nSBLK; i++) {
		*(x_coor + i) = i;
		*(data_adm  + i) = (float)fd[DMNUM/2]->data[i];
	}
	
	cpgpage();
	cpgenv(0.0, fi->nROW * fi->nSBLK, -5000.0f, 5000.0f, 0, 1);
	
	cpgline(ns, x_coor, data_adm);
	cpgbbuf();
	cpgend();
	return EXIT_SUCCESS;
	
	float aveData[20000] = {0};
	writeIntData("26.8.dat",26.8,fd[DMNUM/2]->data,fi->nSBLK*fi->nROW);
	calcAveArr(aveData,fd[DMNUM/2]->data,2000000,100);
	writeFloatData("ave26.8.dat",26.8,aveData,20000);
	int foldData[20000] = {0};
	fold(foldData,fd[DMNUM/2]->data,fi->tBIN,psrFreq,fi->nSBLK*fi->nROW);

	writeHistogramData(fd,fi);
	
	

	fits_close_file(fptr,&status);

}
Пример #9
0
int main()

{
  char   text[80];
  int    ci, crval1, crval2, ilat, ilng, j, k, latpole, lonpole, stat[361],
         status;
  float  xr[512], yr[512];
  double lat[181], lng[361], phi[361], theta[361], x[361], y[361];
  struct celprm native, celestial;


  printf(
  "Testing WCSLIB celestial coordinate transformation routines (tcel1.c)\n"
  "---------------------------------------------------------------------\n");

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

  printf("\n");


  /* Initialize. */
  celini(&native);

  /* Reference angles for the native graticule (in fact, the defaults). */
  native.ref[0] = 0.0;
  native.ref[1] = 0.0;

  /* Set up Bonne's projection with conformal latitude at +35. */
  strcpy(native.prj.code, "BON");
  native.prj.pv[1] = 35.0;


  /* Celestial graticule. */
  celini(&celestial);
  celestial.prj = native.prj;


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

  /* Define pen colours. */
  cpgscr(0, 0.0f, 0.0f, 0.0f);
  cpgscr(1, 1.0f, 1.0f, 0.0f);
  cpgscr(2, 1.0f, 1.0f, 1.0f);
  cpgscr(3, 0.5f, 0.5f, 0.8f);
  cpgscr(4, 0.8f, 0.5f, 0.5f);
  cpgscr(5, 0.8f, 0.8f, 0.8f);
  cpgscr(6, 0.5f, 0.5f, 0.8f);
  cpgscr(7, 0.8f, 0.5f, 0.5f);
  cpgscr(8, 0.3f, 0.5f, 0.3f);

  /* Define PGPLOT viewport. */
  cpgenv(-180.0f, 180.0f, -90.0f, 140.0f, 1, -2);

  /* Loop over CRVAL2, LONPOLE, and LATPOLE with CRVAL1 incrementing by */
  /* 15 degrees each time (it has an uninteresting effect).             */
  crval1 = -180;
  for (crval2 = -90; crval2 <=  90; crval2 += 30) {
    for (lonpole = -180; lonpole <= 180; lonpole += 30) {
      for (latpole = -1; latpole <= 1; latpole += 2) {
        /* For the celestial graticule, set the celestial coordinates of
         * the reference point of the projection (which for Bonne's
         * projection is at the intersection of the native equator and
         * prime meridian), the native longitude of the celestial pole,
         * and extra information needed to determine the celestial
         * latitude of the native pole.  These correspond to FITS keywords
         * CRVAL1, CRVAL2, LONPOLE, and LATPOLE.
         */
        celestial.ref[0] = (double)crval1;
        celestial.ref[1] = (double)crval2;
        celestial.ref[2] = (double)lonpole;
        celestial.ref[3] = (double)latpole;

        /* Skip invalid values of LONPOLE. */
        if (celset(&celestial)) {
          continue;
        }

        /* Skip redundant values of LATPOLE. */
        if (latpole == 1 && fabs(celestial.ref[3]) < 0.1) {
          continue;
        }

        /* Buffer PGPLOT output. */
        cpgbbuf();
        cpgeras();

        /* Write a descriptive title. */
        sprintf(text, "Bonne's projection (BON) - 15 degree graticule");
        printf("\n%s\n", text);
        cpgtext(-180.0f, -100.0f, text);

        sprintf(text, "centred on celestial coordinates (%7.2f,%6.2f)",
          celestial.ref[0], celestial.ref[1]);
        printf("%s\n", text);
        cpgtext (-180.0f, -110.0f, text);

        sprintf(text, "with north celestial pole at native coordinates "
          "(%7.2f,%7.2f)", celestial.ref[2], celestial.ref[3]);
        printf("%s\n", text);
        cpgtext(-180.0f, -120.0f, text);


        /* Draw the native graticule faintly in the background. */
        cpgsci(8);

        /* Draw native meridians of longitude. */
        for (j = 0, ilat = -90; ilat <= 90; ilat++, j++) {
          lat[j] = (double)ilat;
        }

        for (ilng = -180; ilng <= 180; ilng += 15) {
          lng[0] = (double)ilng;
          if (ilng == -180) lng[0] = -179.99;
          if (ilng ==  180) lng[0] =  179.99;

          /* Dash the longitude of the celestial pole. */
          if ((ilng-lonpole)%360 == 0) {
            cpgsls(2);
            cpgslw(5);
          }

          cels2x(&native, 1, 181, 1, 1, lng, lat, phi, theta, x, y, stat);

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

            xr[k] = -x[j];
            yr[k] =  y[j];
            k++;
          }

          cpgline(k, xr, yr);
          cpgsls(1);
          cpgslw(1);
        }

        /* Draw native parallels of latitude. */
        lng[0]   = -179.99;
        lng[360] =  179.99;
        for (j = 1, ilng = -179; ilng < 180; ilng++, j++) {
          lng[j] = (double)ilng;
        }

        for (ilat = -90; ilat <= 90; ilat += 15) {
          lat[0] = (double)ilat;

          cels2x(&native, 361, 1, 1, 1, lng, lat, phi, theta, x, y, stat);

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

            xr[k] = -x[j];
            yr[k] =  y[j];
            k++;
          }

          cpgline(k, xr, yr);
        }


        /* Draw a colour-coded celestial coordinate graticule. */
        ci = 1;

        /* Draw celestial meridians of longitude. */
        for (j = 0, ilat = -90; ilat <= 90; ilat++, j++) {
          lat[j] = (double)ilat;
        }

        for (ilng = -180; ilng <= 180; ilng += 15) {
          lng[0] = (double)ilng;

          if (++ci > 7) ci = 2;
          cpgsci(ilng?ci:1);

          /* Dash the reference longitude. */
          if ((ilng-crval1)%360 == 0) {
            cpgsls(2);
            cpgslw(5);
          }

          cels2x(&celestial, 1, 181, 1, 1, lng, lat, phi, theta, x, y, stat);

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

            /* Test for discontinuities. */
            if (j > 0) {
              if (fabs(x[j]-x[j-1]) > 4.0 || fabs(y[j]-y[j-1]) > 4.0) {
                if (k > 1) cpgline(k, xr, yr);
                k = 0;
              }
            }

            xr[k] = -x[j];
            yr[k] =  y[j];
            k++;
          }

          cpgline(k, xr, yr);
          cpgsls(1);
          cpgslw(1);
        }

        /* Draw celestial parallels of latitude. */
        for (j = 0, ilng = -180; ilng <= 180; ilng++, j++) {
          lng[j] = (double)ilng;
        }

        ci = 1;
        for (ilat = -90; ilat <= 90; ilat += 15) {
          lat[0] = (double)ilat;

          if (++ci > 7) ci = 2;
          cpgsci(ilat?ci:1);

          /* Dash the reference latitude. */
          if (ilat == crval2) {
            cpgsls(2);
            cpgslw(5);
          }

          cels2x(&celestial, 361, 1, 1, 1, lng, lat, phi, theta, x, y, stat);

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

            /* Test for discontinuities. */
            if (j > 0) {
              if (fabs(x[j]-x[j-1]) > 4.0 || fabs(y[j]-y[j-1]) > 4.0) {
                if (k > 1) cpgline(k, xr, yr);
                k = 0;
              }
            }

            xr[k] = -x[j];
            yr[k] =  y[j];
            k++;
          }

          cpgline(k, xr, yr);
          cpgsls(1);
          cpgslw(1);
        }

        /* Flush PGPLOT buffer. */
        cpgebuf();
        printf(" Type <RETURN> for next page: ");
        getc(stdin);

        /* Cycle through celestial longitudes. */
        if ((crval1 += 15) > 180) crval1 = -180;

        /* Skip boring celestial latitudes. */
        if (crval2 == 0) break;
      }

      if (crval2 == 0) break;
    }
  }

  cpgask(0);
  cpgend();

  return 0;
}
Пример #10
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;
  }
}
Пример #11
0
void nrpoint(float x[],float y[],float azy[],float ely[],float azmod[],float elmod[],float sig[],int ndata,int num_gauss,int flag,int ant_num,int plotflag,char
*header)
{
	FILE *fp1,*fp2,*fp3,*fp4,*fp5;
	float rms(float *,int);
	float arg, guessed_parameters,xmin,xmax,ymin,ymax,tmp,rms_fac;
	float alamda,chisq,ochisq,**covar,**alpha,*a;
	int i,*ia,itst,j,k,l,numplot,i_maxy,i_miny,MA, NPT;
	char ans[200],f_line[200],c;
	char file_n1[160],file_n2[160],file_n3[160],file_n4[160],file_n5[160];
	char xtitle[60],ytitle[60],title[60],plotant[10];
	FILE *fpsummary, *headerfp;
	char fullfilename[250];
	char buffer[2048]; /* must be larger than length of header */
	char *token[MAX_TOKENS];
	int tokens;
	char rxlabelhigh[30];
	char rxlabellow[30];

	float xx[1600],yy[1600],yyy[1600],res[1600];

/* 	following for aperture efficiency 16 Nov 04, TK */
        char etaCommand[130], rawfilename[256];
        FILE *fpi_eta,*fpo_eta, *fph_eta;
        int  use_beam, time_stamp; 
        float tau_zenith,Tcmbr,Tatm,Thot,Tamb,Tcab,eta_l,delVsource,Vhot,Vsky,err,el,SB;
        float Frequency, TBright, VhotL, VhotH, VskyL, VskyH;
        float PlanetDia, WidthFwhm,fwhm_beam, EtaA, EtaB;
        char  object[20], date[30];
/* 	aperture efficiecny additions end */


	sprintf(file_n1,"/usr/PowerPC/common/data/rpoint/ant%d/load.fitted.dat",ant_num);
	sprintf(file_n2,"/usr/PowerPC/common/data/rpoint/ant%d/load.initial.dat",ant_num);
	sprintf(file_n3,"/usr/PowerPC/common/data/rpoint/ant%d/load.temp.dat",ant_num);
	sprintf(file_n4,"/usr/PowerPC/common/data/rpoint/ant%d/load.results.dat",ant_num);
	sprintf(file_n5,"/usr/PowerPC/common/data/rpoint/ant%d/rpoint.ant%1d",ant_num,ant_num);

	if ((fp1=fopen(file_n1,"w"))==NULL){
	  printf("nrpoint: cannot open n1 = %s\n",file_n1);
	  exit(1);
	}
	chmod(file_n1,0666);
	if ((fp3=fopen(file_n3,"w"))==NULL){
	  printf("nrpoint: cannot open n2 (first time) = %s\n",file_n3);
	  exit(1);
	}
	chmod(file_n3,0666);
	if ((fp4=fopen(file_n4,"a"))==NULL){
	  printf("nrpoint: cannot open n4 = %s\n",file_n4);
	  exit(1);
	}
	chmod(file_n4,0666);
	if ((fp5=fopen(file_n5,"a"))==NULL){
	  printf("nrpoint: cannot open n5 = %s\n",file_n5);
	  exit(1);
	}
	chmod(file_n5,0666);

	NPT=ndata;MA=num_gauss;
/*
	printf("number of data = %d number of fitting components = %d flag = %d\n", NPT,MA/5,flag);

*/
	ia=ivector(1,MA);
	a=vector(1,MA);
	covar=matrix(1,MA,1,MA);
	alpha=matrix(1,MA,1,MA);
	
/* read data */
	xmin=1e6;ymin=1e6;
	xmax=-1e6;ymax=-1e6;
	for (i=1;i<=NPT;i++) {
	  xx[i-1]=x[i];
	  yy[i-1]=y[i];
	  if(xmin>=x[i]) xmin=x[i];
	  if(xmax<x[i]) xmax=x[i];
	  if(ymin>=y[i]){ymin=y[i];i_miny=i;}
	  if(ymax<y[i]) {ymax=y[i];i_maxy=i;}
	  /*
	    if(i<10)	printf("%d %f %f %f %f %f %f\n",i,x[i],y[i],ymin,ymax,azy[i],ely[i],sig[i]);
	  */
	  fprintf(fp3,"%f %f\n",x[i],y[i]);
	}

	tmp=ymax-ymin;
	ymax=tmp*0.2+ymax;
	ymin=ymin-tmp*0.2;
	fclose(fp3);

/*    PGPLOT */
	sprintf(plotant,"%d/xs",(ant_num+10));
	if(plotflag){
	  if(cpgbeg(0,plotant,1,1)!=1) exit(1);
	  cpgenv(xmin,xmax,ymin,ymax,0,0); 
	  cpgpt(NPT,xx,yy,2);
	  cpgline(NPT,xx,yy);
	  tokens = tokenize(header,token);
	  strcpy(rxlabelhigh,token[RX_LABEL_HIGH]);
	  strcpy(rxlabellow,token[RX_LABEL_LOW]);
	  if (lowfreqflag == 0) {
	    sprintf(title,"Antenna %1d  High-frequency (%s) Raw data",ant_num,rxlabelhigh);
	  } else {
	    sprintf(title,"Antenna %1d  Low-frequency (%s) Raw data",ant_num,rxlabellow);
	  }
	  if(flag){
	    sprintf(xtitle,"Antenna %ld  Azoff (arcsec)",ant_num);
	  } else {
	    sprintf(xtitle,"Antenna %ld  Eloff (arcsec)",ant_num);
	  }
	  sprintf(ytitle,"Intensity (Volts)");
	  cpglab(xtitle,ytitle,title);
	  cpgend();
	}
	
/*	initial values of parameters::::::	*/

	if ((fp2=fopen(file_n2,"w"))==NULL){
	  printf("nrpoint: cannot open n2 (second time) = %s\n",file_n2);
	  exit(1);
	}
	chmod(file_n2,0666);

	if(fabs(ymax)>=fabs(ymin)) {
		fprintf(fp2,"%f\n",ymax-ymin);
		fprintf(fp2,"%f\n",x[i_maxy]);
	}
	if(fabs(ymin)>fabs(ymax)) {
		fprintf(fp2,"%f\n",ymin-ymax);
		fprintf(fp2,"%f\n",x[i_miny]);
	}
	fprintf(fp2,"%f\n",20.0);
	fprintf(fp2,"%f\n",0.0);
	fprintf(fp2,"%f\n",y[1]);
	fclose(fp2);

	if ((fp2=fopen(file_n2,"r"))==NULL){
	  printf("nrpoint: cannot open n2 for read = %s\n",file_n2);
	  exit(1);
	}

	for(i=1;i<=MA;i++) 
	{
	  fscanf(fp2,"%f\n",&guessed_parameters);
	  a[i]=guessed_parameters;
	  ia[i]=i;
	}

	fclose(fp2);

/*      start fitting	*/ 
	alamda = -1;
	mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda);
	k=1;
	itst=0;
	for (;;) {
	  /*
	    printf("\n%s %2d %17s %9.3e %10s %9.3e\n","Iteration #",k, "chi-squared:",chisq,"alamda:",alamda);
	    for (i=1;i<=MA;i++) printf("%5.3e ",a[i]);
	    printf("\n");
	  */
	  k++;
	  
	  ochisq=chisq;
	  mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda);
	  if (chisq > ochisq)
	    itst=0;
	  else if ((fabs(ochisq-chisq) < 0.01 &&
		    fabs(chisq) < .1) || (k>10))
	    {itst++;}
	  if (itst < 4) continue;
	  
	  /*
	    if ((fp2=fopen(file_n2,"w"))==NULL){
	    printf("cannot open %s\n",file_n2);
	    exit(1);
	    }
	  */
	  
	  /*
	    for (i=1;i<=MA;i++) fprintf(fp2,"%f\n",a[i]);
	  */
	  for (i=1;i<=MA;i++) fprintf(fp4,"%f ",a[i]);
	  fprintf(fp4,"%f ",chisq);
	  printf("%f\n ",chisq);
	  /*
	    fprintf(fp2,"\n");
	  */
	  fprintf(fp4,"\n\n");
	  /*
	    fclose(fp2);
	  */
	  
	  for(j=1;j<=NPT;j++){
	    yyy[j-1]=0.0;
	    for(k=1;k<=MA;k+=5){
	      arg=(x[j]-a[k+1])/a[k+2];
	      yyy[j-1]+=a[k]*exp(-arg*arg)+a[k+3]*x[j]+a[k+4];
	    }
	    res[j-1]=y[j]-yyy[j-1]+a[5];
	    fprintf (fp1,"%.6f %.6f %.6f %.6f\n",x[j],y[j],yyy[j-1],res[j-1]);
	  }
	  fclose(fp1);
	  
	  alamda=0.0;
	  mrqmin(x,y,sig,NPT,a,ia,MA,covar,alpha,&chisq,fgauss2,&alamda);
	  rms_fac=rms(res,NPT);
	  printf("\nUncertainties:\n");
	  for (i=1;i<=MA;i++) printf("%8.4e ",rms_fac*sqrt(covar[i][i]));
	  printf("\n");
	  
	  fprintf(fp4,"\nUncertainties:\n");
	  for (i=1;i<=MA;i++) fprintf(fp4,"%8.4e ",rms_fac*sqrt(covar[i][i]));
	  fprintf(fp4,"\n");
	  printf("Generating plot....\n");
	  break;
	}
fclose(fp4);

	if(flag){
	  if (lowfreqflag == 0) {
	    sprintf(title,"Antenna %1d  High-frequency (%s) AZ scan  Fitted data",ant_num,rxlabelhigh);
	  } else {
	    sprintf(title,"Antenna %1d  Low-frequency (%s) AZ scan  Fitted data",ant_num,rxlabellow);
	  }
	  sprintf(xtitle,"Antenna %ld  Azoff (arcsec)",ant_num);
	}
	else{
	  if (lowfreqflag == 0) {
	    sprintf(title,"Antenna %1d  High-frequency (%s) El scan  Fitted data",ant_num,rxlabelhigh);
	  } else {
	    sprintf(title,"Antenna %1d  Low-frequency (%s) El scan  Fitted data",ant_num,rxlabellow);
	  }
	  sprintf(xtitle,"Antenna %ld  Eloff (arcsec)",ant_num);
	}
	sprintf(ytitle,"Intensity (Volts)");

/*    PGPLOT */
	sprintf(plotant,"%d/xs",(ant_num+10));
	if(plotflag){
	  if(cpgbeg(0,plotant,1,1)!=1) exit(1);
	  /* These do nothing helpful:
	  cpgeras();
	  cpgupdt();
	  */
	  cpgenv(xmin,xmax,ymin,ymax,0,0); 
	  cpgpt(NPT,xx,yy,2);
	  cpgline(NPT,xx,yyy);
	  cpgpt(NPT,xx,res,-1);
	  cpglab(xtitle,ytitle,title);
	  sprintf(f_line,"az= %10.4f deg",azy[i_maxy]);
	  cpgmtxt("t",-2.5,0.05,0,f_line);
	  sprintf(f_line,"el = %10.4f deg",ely[i_maxy]);
	  cpgmtxt("t",-4.0,0.05,0,f_line);
	  sprintf(f_line,"y= %10.4f",a[1]);
	  cpgmtxt("t",-7.0,0.05,0,f_line);
	  sprintf(f_line,"x = %10.4f arcsec",a[2]);
	  cpgmtxt("t",-5.5,0.05,0,f_line);
	  sprintf(f_line,"width = %10.4f",a[3]*2*0.83255);
	  cpgmtxt("t",-8.5,0.05,0,f_line);
	  sprintf(f_line,"chisq = %10.4e",chisq);
	  cpgmtxt("t",-10.0,0.05,0,f_line);
	  cpgend();
	}
        fpsummary = fopen(summary_file_name,"r");
	if (fpsummary == NULL) {
	  fpsummary = fopen(summary_file_name,"w");
	} else {
	  fclose(fpsummary);
	  fpsummary = fopen(summary_file_name,"a");
	}
	if (fpsummary == NULL) {
	  printf("Could not write to summary file = %s\n",summary_file_name);
	} else {
#if USE_HEADER
	  sprintf(fullfilename,"/data/engineering/rpoint/ant%d/header.dat",ant_num);
	  headerfp = fopen(fullfilename,"r");
	  /* skip the first line */
	  fgets(buffer,sizeof(buffer),headerfp);
	  fgets(buffer,sizeof(buffer),headerfp);
	  fclose(headerfp);
	  /* cut off the final carriage return */
	  buffer[strlen(buffer)-1] = 0;
	  fprintf(fpsummary,"%s,",buffer);
#endif
	  if (flag == 1) {
	    fprintf(fpsummary,"rpoint: azoff %f %f %f %f ",a[1],a[2],
			a[3]*2*0.83255, rms_fac*sqrt(covar[2][2]));
	  } else {
	    fprintf(fpsummary,"rpoint: eloff %f %f %f %f ",a[1],a[2],
			a[3]*2*0.83255, rms_fac*sqrt(covar[2][2]));
	  }
          /* Following lines added 16 Nov 04, for aperture efficiecncy: TK */
          /* create a temporary file eta_tmp and run the aperture efficiency program */
	  /* needed: 
	  /*  4: source - object
	     14: planetdia
	     29: temperature
  	     37: cabin temperature
             40: elcmd
	     91: rest freq
	     92: sidebandA 
	     a[1]=intensity
	     a[2]=offset
	     a[3]*2*0.83255=scanwidth
	  */
	  printf("Computing aperture efficiency....\n");
          fpi_eta=fopen("aperInput.tmp","w");
	  use_beam=USE_BEAM;
	  delVsource=a[1];
	  WidthFwhm=a[3]*2*0.83255;
	  sprintf(etaCommand, "nawk -F, \' (NR>=2) {print $4,$14,$29,$37,$40,$91,$92,$107}\' /data/engineering/rpoint/ant%d/header.dat > picked.tmp",ant_num);
/*	  printf("%s\n", etaCommand); */
	  system(etaCommand);
	  fph_eta=fopen("picked.tmp","r");
	  fscanf(fph_eta,"%s %f %f %f %f %f %f",object,&PlanetDia,&Tamb,&Tcab,&el,&Frequency,&SB);
	  fscanf(fph_eta, "%s %f %d %f %d %f %d %f %d %f %d %f %d %f %d %f %f", rawfilename, &VhotL, &time_stamp, &VhotH, &time_stamp, &VskyL, &time_stamp, &VskyH, &time_stamp, &tau_zenith, &time_stamp, &Tatm , &time_stamp, &eta_l, &time_stamp, &Frequency, &SB);
	  if (lowfreqflag == 0) {
		Vhot=VhotL;
		Vsky=VskyL;
	  }
	  else {
		Vhot=VhotH;
		Vsky=VskyH;
	  }
		
/*	  fscanf(fph_eta, "%s %f %f %f %f %f %f %f %f", rawfilename, &Thot, &tau_zenith, &eta_l, &Vhot, &Vsky, &delVsource,
          &WidthFwhm); */
	  printf("raw file name: %s\n", rawfilename);
	  Tamb = (Tamb+Tcab)/2.0;
	  Thot=Tamb;
/*	  Frequency=Frequency-SB*5.0; */
/*	 
	  Thot=
	  Vhot=
	  Vsky=
	  delVsource=
	  fwhm_beam=52.0;
	  WidthFwhm=
	  Tbright=100;
	  TBright=
*/
	  if (object=="jupiter") TBright=TB_JUP;
	  if (object=="saturn")  TBright=TB_SAT;
	  if (strstr(object,"jupiter")!=NULL) TBright=TB_JUP;
	  if (strstr(object,"saturn")!=NULL)  TBright=TB_SAT;
	  err=0.0;
          fprintf(fpi_eta, "%s %d %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %d\n", rawfilename, ant_num, object, el, tau_zenith, Thot,Tamb,Tatm,eta_l,Vhot,Vsky,delVsource,fwhm_beam,Frequency, PlanetDia, WidthFwhm,TBright,err,use_beam);
	   sprintf(etaCommand, "aperEff aperInput.tmp");
          system(etaCommand);
          fpo_eta=fopen("aperResults.tmp","w");
/*	  fscanf(fpo_eta, "%f %f %f", &EtaA,&EtaB,&fwhm_beam); */
	  fprintf(fpo_eta,"%3.2f %3.2f %4.1f\n",EtaA,EtaB,fwhm_beam);
	  fprintf(fpsummary,"%3.2f %3.2f %4.1f\n",EtaA,EtaB,fwhm_beam);
	  fclose(fpsummary);
	  fclose(fpi_eta);
	  fclose(fpo_eta);
	  fclose(fph_eta);
/*	  remove("aperResults.tmp");
	  remove("aperInput.tmp"); */
	}
	printf("recorded! \n");
	printf("azfit %s  | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f\n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]);
	if(flag==1) fprintf(fp5,"azfit %s  | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f\n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]);
	else fprintf(fp5,"elfit %s | %10.5f %10.5f %10.5f %10.4f %10.2f +- %10.2f %8.1f %8.1f \n",header,azy[i_maxy],ely[i_maxy],a[1],a[3]*2*0.83255,a[2],rms_fac*sqrt(covar[2][2]),azmod[i_maxy],elmod[i_maxy]);

	fclose(fp5);
	free_matrix(alpha,1,MA,1,MA);
	free_matrix(covar,1,MA,1,MA);
	free_ivector(ia,1,MA);
	free_vector(a,1,MA);
}
Пример #12
0
int makePlot (char *fname, char *dname, int number)
{
	FILE *fpt;
	double *on_energy;
	double *off_energy;
	double ave_on, ave_off;
	double on, off;
	int i, j;

	on_energy = (double *)malloc(sizeof(double)*number);
	off_energy = (double *)malloc(sizeof(double)*number);

	if ((fpt = fopen(fname, "r")) == NULL)
	{
		fprintf (stdout, "Can't open file\n");
		exit(1);
	}

	i = 0;
	while (fscanf(fpt, "%lf %lf", &on, &off) == 2)
	{
		on_energy[i] = on;
		off_energy[i] = off;
		i++;
	}

	if (fclose (fpt) != 0)
		fprintf (stderr, "Error closing\n");

	ave_on = 0.0;
	ave_off = 0.0;

	for (i = 0; i < number; i++)
	{
		ave_on += on_energy[i];
		ave_off += off_energy[i];
	}
	ave_on = ave_on/number;
	ave_off = ave_off/number;

	for (i = 0; i < number; i++)
	{
		on_energy[i] = on_energy[i]/ave_on;
		off_energy[i] = off_energy[i]/ave_on;
	}
	/////////////////////////////////////////////////

	float *xHis_on; // x axis of the histogram
	float *val_on;  // data value of the histogram
	float *xHis_off; // x axis of the histogram
	float *val_off;  // data value of the histogram
	int step = 100; // steps in the histogram

	//char caption[1024];
	//char text[1024];

	float max, max1, max2;

	// make histogram
	xHis_on = (float*)malloc(sizeof(float)*step);
	val_on = (float*)malloc(sizeof(float)*step);
	xHis_off = (float*)malloc(sizeof(float)*step);
	val_off = (float*)malloc(sizeof(float)*step);

	histogram (on_energy, number, xHis_on, val_on, -1.0, 4.0, step);
	histogram (off_energy, number, xHis_off, val_off, -1.0, 4.0, step);

	// plot 
	//cpgbeg(0,"/xs",1,1);
	cpgbeg(0,dname,1,1);

	cpgsch(1); // set character height
	cpgscf(1); // set character font

	// find the max
	max1 = find_max_value(step,val_off);
	max2 = find_max_value(step,val_on);
	max = (max1 >= max2 ? max1 : max2);
	//cpgenv(-5,5,0,4500,0,1); // set window and viewport and draw labeled frame
	cpgenv(-1,4,0,max+0.1*max,0,1); // set window and viewport and draw labeled frame

	//sprintf(caption, "%s", "Flux density histogram");
	cpglab("Flux (mJy)","Number","");
	cpgbin(step,xHis_on,val_on,0);
	cpgsci(2);
	cpgbin(step,xHis_off,val_off,0);
	///////////////////////////////////////////////////////
	cpgend();
	////////////////////

	free(on_energy);
	free(off_energy);
	free(xHis_on);
	free(val_on);
	free(xHis_off);
	free(val_off);

	return 0;
}
Пример #13
0
int closure (
  const char ctypeS[9],
  double restfrq,
  double restwav,
  int    naxisj,
  double crpixj,
  double cdeltX,
  double crvalX)

{
  char ptype, sname[32], title[80], units[8], xtype, ylab[80];
  int  nFail = 0, restreq, stat1[NSPEC], stat2[NSPEC], status;
  register int j;
  float  tmp, x[NSPEC], xmin, xmax, y[NSPEC], ymax, ymin;
  double cdeltS, clos[NSPEC], crvalS, dSdX, resid, residmax, spec1[NSPEC],
         spec2[NSPEC];
  struct spcprm spc;


  /* Get keyvalues for the required spectral axis type. */
  if ((status = spcxps(ctypeS, crvalX, restfrq, restwav, &ptype, &xtype,
                       &restreq, &crvalS, &dSdX))) {
    printf("ERROR %d from spcxps() for %s.\n", status, ctypeS);
    return 1;
  }
  cdeltS = cdeltX * dSdX;

  spcini(&spc);

  if (ctypeS[5] == 'G') {
    /* KPNO MARS spectrograph grism parameters. */
    spc.pv[0] = mars[0];
    spc.pv[1] = mars[1];
    spc.pv[2] = mars[2];
    spc.pv[3] = mars[3];
    spc.pv[4] = mars[4];
    spc.pv[5] = mars[5];
    spc.pv[6] = mars[6];
  }

  /* Construct the axis. */
  for (j = 0; j < naxisj; j++) {
    spec1[j] = (j+1 - crpixj)*cdeltS;
  }

  printf("%4s (CRVALk+w) range: %13.6e to %13.6e, step: %13.6e\n", ctypeS,
    crvalS+spec1[0], crvalS+spec1[naxisj-1], cdeltS);


  /* Initialize. */
  spc.flag = 0;
  spc.crval = crvalS;
  spc.restfrq = restfrq;
  spc.restwav = restwav;
  strncpy(spc.type, ctypeS, 4);
  spc.type[4] = '\0';
  strcpy(spc.code, ctypeS+5);

  /* Convert the first to the second. */
  if ((status = spcx2s(&spc, naxisj, 1, 1, spec1, spec2, stat1))) {
    printf("spcx2s ERROR %d: %s.\n", status, spc_errmsg[status]);
  }

  /* Convert the second back to the first. */
  if ((status = spcs2x(&spc, naxisj, 1, 1, spec2, clos, stat2))) {
    printf("spcs2x ERROR %d: %s.\n", status, spc_errmsg[status]);
  }

  residmax = 0.0;

  /* Test closure. */
  for (j = 0; j < naxisj; j++) {
    if (stat1[j]) {
      printf("%s: w =%20.12e -> %s = ???, stat = %d\n", ctypeS, spec1[j],
             spc.type, stat1[j]);
      continue;
    }

    if (stat2[j]) {
      printf("%s: w =%20.12e -> %s =%20.12e -> w = ???, stat = %d\n",
             ctypeS, spec1[j], spc.type, spec2[j], stat2[j]);
      continue;
    }

    resid = fabs((clos[j] - spec1[j])/cdeltS);
    if (resid > residmax) residmax = resid;

    if (resid > tol) {
      nFail++;
      printf("%s: w =%20.12e -> %s =%20.12e ->\n          w =%20.12e,  "
             "resid =%20.12e\n", ctypeS, spec1[j], spc.type, spec2[j],
             clos[j], resid);
    }
  }

  printf("%s: Maximum closure residual = %.1e pixel.\n", ctypeS, residmax);


  /* Draw graph. */
  cpgbbuf();
  cpgeras();

  xmin = (float)(crvalS + spec1[0]);
  xmax = (float)(crvalS + spec1[naxisj-1]);
  ymin = (float)(spec2[0]) - xmin;
  ymax = ymin;
  for (j = 0; j < naxisj; j++) {
    x[j] = (float)(j+1);
    y[j] = (float)(spec2[j] - (crvalS + spec1[j]));
    if (y[j] > ymax) ymax = y[j];
    if (y[j] < ymin) ymin = y[j];
  }

  j = (int)crpixj + 1;
  if (y[j] < 0.0) {
    tmp  = ymin;
    ymin = ymax;
    ymax = tmp;
  }

  cpgask(0);
  cpgenv(1.0f, (float)naxisj, ymin, ymax, 0, -1);

  cpgsci(1);
  cpgbox("ABNTS", 0.0f, 0, "BNTS", 0.0f, 0);
  spctyp(ctypeS, 0x0, 0x0, sname, units, 0x0, 0x0, 0x0);
  sprintf(ylab, "%s - correction [%s]", sname, units);
  sprintf(title, "%s:  CRVALk + w [%s]", ctypeS, units);
  cpglab("Pixel coordinate", ylab, title);

  cpgaxis("N", 0.0f, ymax, (float)naxisj, ymax, xmin, xmax, 0.0f, 0, -0.5f,
    0.0f, 0.5f, -0.5f, 0.0f);

  cpgaxis("N", (float)naxisj, ymin, (float)naxisj, ymax, (float)(ymin/cdeltS),
    (float)(ymax/cdeltS), 0.0f, 0, 0.5f, 0.0f, 0.5f, 0.1f, 0.0f);
  cpgmtxt("R", 2.2f, 0.5f, 0.5f, "Pixel offset");

  cpgline(naxisj, x, y);
  cpgsci(7);
  cpgpt1((float)crpixj, 0.0f, 24);
  cpgebuf();

  printf("Type <RETURN> for next page: ");
  (void)getchar();

  printf("\n");

  return nFail;
}
Пример #14
0
void doPlot(pulsar *psr,int npsr,int overlay)
{
  int i,j,fitFlag=1,exitFlag=0,scale1=0,scale2,count,p,xautoscale=1,k,graphics=1;
  int yautoscale=1,plotpre=1;
  int time=0;
  char xstr[1000],ystr[1000];
  float x[MAX_OBSN],y[MAX_OBSN],yerr1[MAX_OBSN],yerr2[MAX_OBSN],tmax,tmin,tmaxy1,tminy1,tmaxy2,tminy2;
  float minx,maxx,miny,maxy,plotx1,plotx2,ploty1,ploty2,mean;
  float mouseX,mouseY;
  float fontSize=1.8;
  char key;
  float widthPap=0.0,aspectPap=0.618;

  /* Obtain a graphical PGPLOT window */
  if (overlay==1)
    cpgbeg(0,"?",2,1);
  else
    cpgbeg(0,"?",2,npsr);
  cpgpap(widthPap,aspectPap);
  cpgsch(fontSize);
  cpgask(0);

  do {
    for (p=0;p<npsr;p++)
      {
	scale2 = psr[p].nobs;
	for (j=0;j<2;j++)
	  {
	    if (j==0) fitFlag=1;
	    else if (j==1) fitFlag=2;

	    ld_sprintf(xstr,"MJD-%.1Lf",psr[0].param[param_pepoch].val[0]); 
	    sprintf(ystr,"Residual (\\gmsec)");

	    count=0;
	    for (i=0;i<psr[p].nobs;i++)
	      {
		if (psr[p].obsn[i].deleted == 0  &&
	    (psr[p].param[param_start].paramSet[0]!=1 || psr[p].param[param_start].fitFlag[0]!=1 ||
	      psr[p].param[param_start].val[0] < psr[p].obsn[i].bat) &&
	    (psr[p].param[param_finish].paramSet[0]!=1 || psr[p].param[param_finish].fitFlag[0]!=1 ||
	     psr[p].param[param_finish].val[0] > psr[p].obsn[i].bat))
		  {
		    if (xautoscale==1)
		      x[count] = (double)(psr[p].obsn[i].bat-psr[p].param[param_pepoch].val[0]);
		    else
		      x[count] = (double)(psr[p].obsn[i].bat-psr[0].param[param_pepoch].val[0]);
		    
		    if (fitFlag==1)  /* Get pre-fit residual */
		      y[count] = (double)psr[p].obsn[i].prefitResidual*1.0e6;
		    else if (fitFlag==2) /* Post-fit residual */
		      y[count] = (double)psr[p].obsn[i].residual*1.0e6;
		    count++;
		  }
	      }
	    /* Remove mean from the residuals and calculate error bars */
	    mean = findMean(y,psr,p,scale1,count);
	    count=0;
	    for (i=0;i<psr[p].nobs;i++)
	      {
		if (psr[p].obsn[i].deleted==0   &&
	    (psr[p].param[param_start].paramSet[0]!=1 || psr[p].param[param_start].fitFlag[0]!=1 ||
	      psr[p].param[param_start].val[0] < psr[p].obsn[i].bat) &&
	    (psr[p].param[param_finish].paramSet[0]!=1 || psr[p].param[param_finish].fitFlag[0]!=1 ||
	     psr[p].param[param_finish].val[0] > psr[p].obsn[i].bat))
		  {
		    psr[p].obsn[i].residual-=mean/1.0e6;
		    y[count]-=mean;
		    yerr1[count] = y[count]-(float)psr[p].obsn[i].toaErr;
		    yerr2[count] = y[count]+(float)psr[p].obsn[i].toaErr;
		    count++;
		  }
	      }
	    
	    /* Get scaling for graph */
	    minx = findMin(x,psr,p,scale1,count);
	    maxx = findMax(x,psr,p,scale1,count);
	    if (xautoscale==1)
	      {
		plotx1 = minx-(maxx-minx)*0.1;
		plotx2 = maxx+(maxx-minx)*0.1;
	      }
	    else
	      {
		plotx1 = tmin-(tmax-tmin)*0.1;
		plotx2 = tmax+(tmax-tmin)*0.1;
	      }
	    miny = findMin(y,psr,p,scale1,count);
	    maxy = findMax(y,psr,p,scale1,count);

	    if (yautoscale==1)
	      {
		ploty1 = miny-(maxy-miny)*0.1;
		ploty2 = maxy+(maxy-miny)*0.1;
	      }
	    else
	      {
		if (j==0)
		  {
		    ploty1 = tminy1-(tmaxy1-tminy1)*0.1;
		    ploty2 = tmaxy1+(tmaxy1-tminy1)*0.1;
		  }
		else
		  {
		    ploty1 = tminy2-(tmaxy2-tminy2)*0.1;
		    ploty2 = tmaxy2+(tmaxy2-tminy2)*0.1;
		  }
	      }

	    /* Plot the residuals */	    
	    if (plotpre==1 || j!=0)
	      {
		float xx[MAX_OBSN],yy[MAX_OBSN],yyerr1[MAX_OBSN],yyerr2[MAX_OBSN];
		int num=0,colour;
		if (overlay==0 || (overlay==1 && p==0))
		  {
		    cpgenv(plotx1,plotx2,ploty1,ploty2,0,0);
		    cpglab(xstr,ystr,psr[p].name);	    
		  }

		for (colour=0;colour<5;colour++)
		  {
		    num=0;
		    for (i=0;i<count;i++)
		      {
			if ((colour==0 && psr[p].obsn[i].freq<=500) ||
			    (colour==1 && psr[p].obsn[i].freq>500 && psr[p].obsn[i].freq<=1000) ||
			    (colour==2 && psr[p].obsn[i].freq>1000 && psr[p].obsn[i].freq<=1500) ||
			    (colour==3 && psr[p].obsn[i].freq>1500 && psr[p].obsn[i].freq<=3300) ||
			    (colour==4 && psr[p].obsn[i].freq>3300))
			  {
			    xx[num]=x[i];
			    yy[num]=y[i];
			    yyerr1[num]=yerr1[i];
			    yyerr2[num]=yerr2[i];
			    num++;
			  }
		      }
		    cpgsci(colour+1);
		    if (overlay==1)
		      cpgsci(p+1);
		    cpgpt(num,xx,yy,16);
		    cpgerry(num,xx,yyerr1,yyerr2,1);
		  }
		cpgsci(1);
	      }
	  }
      }
    printf("------------------------------\n");
    printf("`a'     set aspect ratio\n");
    printf("`f'     set font size\n");
    printf("`g'     set graphics device\n");
    printf("`q'     quit\n");
    printf("`x'     toggle autoscale x axis\n");
    printf("`y'     toggle autoscale y axis\n");
    printf("`p'     toggle prefit plotting\n");
    printf("`r'     output residuals to file\n");

    if (graphics==1)
      {
	cpgcurs(&mouseX,&mouseY,&key);
	
	/* Check key press */
	if (key=='q') exitFlag=1;
	if (key=='p') {
	  plotpre*=-1;
	  if (plotpre==-1)
	    {
	      cpgend();
	      if (overlay==1)
		cpgbeg(0,"/xs",1,1);
	      else
		cpgbeg(0,"/xs",1,npsr);
	      cpgpap(widthPap,aspectPap);
	      cpgsch(fontSize);
	      cpgask(0);	      
	    }
	  else
	    {
	      cpgend();
	      if (overlay==1)
		cpgbeg(0,"/xs",2,1);
	      else
		cpgbeg(0,"/xs",2,npsr);
	      cpgpap(widthPap,aspectPap);
	      cpgsch(fontSize);
	      cpgask(0);	      
	    }
	}
	else if (key=='a') /* Change aspect ratio */
	  {
	    printf("Please enter a new aspect ratio ");
	    scanf("%f",&aspectPap);
	    cpgend();
	    cpgbeg(0,"/xs",2,npsr);
	    cpgpap(widthPap,aspectPap);
	    cpgsch(fontSize);
	    cpgask(0);	      
	  }
	else if (key=='f') /* Change font size */
	  {
	    printf("Please enter a new font size ");
	    scanf("%f",&fontSize);
	    cpgend();
	    cpgbeg(0,"/xs",2,npsr);
	    cpgpap(widthPap,aspectPap);
	    cpgsch(fontSize);
	    cpgask(0);	      
	  }
	else if (key=='g')
	  {
	    graphics=0;
	    cpgend();
	    if (plotpre==-1)
	      {
		cpgend();
		if (overlay==1)
		  cpgbeg(0,"?",1,1);
		else
		  cpgbeg(0,"?",1,npsr);
		cpgpap(widthPap,aspectPap);
		cpgsch(fontSize);
		cpgask(0);	      
	      }
	    else
	      {
		cpgend();
		if (overlay==1)
		  cpgbeg(0,"?",1,1);
		else
		  cpgbeg(0,"?",2,npsr);
		cpgpap(widthPap,aspectPap);
		cpgsch(fontSize);
		cpgask(0);	      
	      }
	  }
	else if (key=='r') /* Output residuals to file */
	  {
	    FILE *fout;
	    char fname[1000];
	    int ii,jj;

	    for (ii=0;ii<npsr;ii++)
	      {
		sprintf(fname,"%s.res",psr[ii].name);
		fout = fopen(fname,"w");
		/* Print header */
		fprintf(fout,"#PSR %s\n",psr[ii].name);
		ld_fprintf(fout,"#F0  %.14Lf\n",psr[ii].param[param_f].val[0]);
		fprintf(fout,"#RAJ %s\n",psr[ii].rajStrPre);
		fprintf(fout,"#DECJ %s\n",psr[ii].decjStrPre);
		for (jj=0;jj<psr[ii].nobs;jj++)
		  fprintf(fout,"%.5lf %.5lg %.5lg\n",
			  (double)(psr[ii].obsn[jj].bat-psr[0].param[param_pepoch].val[0]),
			  (double)(psr[ii].obsn[jj].residual),(double)(psr[ii].obsn[jj].toaErr)/1.0e6);
		fclose(fout);
	      }
	  }
	else if (key=='x') 
	  {
	    xautoscale*=-1;
	    if (xautoscale==-1)
	      {
		for (k=0;k<npsr;k++)
		  {
		    count=0;
		    for (i=0;i<psr[k].nobs;i++)
		      {
			if (psr[k].obsn[i].deleted==0   &&
			    (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 ||
			     psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) &&
			    (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 ||
			     psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat))

			  {x[count] = (double)(psr[k].obsn[i].bat-psr[0].param[param_pepoch].val[0]); count++;}
		      }
		    minx = findMin(x,psr,k,scale1,count);
		    maxx = findMax(x,psr,k,scale1,count);
		    if (k==0)
		      {
			tmin = minx;
			tmax = maxx;
			printf("Have1 tmin = %f, tmax = %f\n",tmin,tmax);
		      }
		    else
		      {
			if (tmin > minx) tmin = minx;
			if (tmax < maxx) tmax = maxx;
			printf("Have2 tmin = %f, tmax = %f\n",tmin,tmax);

		      }
		  }
	      }
	  }       
	else if (key=='y') 
	  {
	    yautoscale*=-1;
	    if (yautoscale==-1)
	      {
		for (k=0;k<npsr;k++)
		  {
		    count=0;
		    for (i=0;i<psr[k].nobs;i++)
		      {
			if (psr[k].obsn[i].deleted==0   &&
			    (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 ||
			     psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) &&
			    (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 ||
			     psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat))			  
			  {y[count] = (double)psr[k].obsn[i].prefitResidual*1e6; count++;}
		      }
		    miny = findMin(y,psr,k,scale1,count);
		    maxy = findMax(y,psr,k,scale1,count);
		    if (k==0)
		      {
			tminy1 = miny;
			tmaxy1 = maxy;
		      }
		    else
		      {
			if (tminy1 > miny) tminy1 = miny;
			if (tmaxy1 < maxy) tmaxy1 = maxy;
		      }

		    count=0;
		    for (i=0;i<psr[k].nobs;i++)
		      {
			if (psr[k].obsn[i].deleted==0   &&
			    (psr[k].param[param_start].paramSet[0]!=1 || psr[k].param[param_start].fitFlag[0]!=1 ||
			     psr[k].param[param_start].val[0] < psr[k].obsn[i].bat) &&
			    (psr[k].param[param_finish].paramSet[0]!=1 || psr[k].param[param_finish].fitFlag[0]!=1 ||
			     psr[k].param[param_finish].val[0] > psr[k].obsn[i].bat))
			  {y[count] = (double)psr[k].obsn[i].residual*1e6; count++;}
		      }
		    miny = findMin(y,psr,k,scale1,count);
		    maxy = findMax(y,psr,k,scale1,count);
		    if (k==0)
		      {
			tminy2 = miny;
			tmaxy2 = maxy;
		      }
		    else
		      {
			if (tminy2 > miny) tminy2 = miny;
			if (tmaxy2 < maxy) tmaxy2 = maxy;
		      }
		  }
		printf("Have tminy2 = %g %g\n",tminy2,tmaxy2);
	      }
	  }       
	else printf("Unknown key press %c\n",key);
      }
    else
      {
	graphics=1;

	cpgend();
	if (plotpre==-1)
	  {
	    cpgend();
	    if (overlay==1)
	      cpgbeg(0,"/xs",1,1);
	    else
	      cpgbeg(0,"/xs",1,npsr);
	    cpgpap(widthPap,aspectPap);
	    cpgsch(fontSize);
	    cpgask(0);	      
	  }
	else
	  {
	    cpgend();
	    if (overlay==1)
	      cpgbeg(0,"/xs",2,1);
	    else
	      cpgbeg(0,"/xs",2,npsr);
	    cpgpap(widthPap,aspectPap);
	    cpgsch(fontSize);
	    cpgask(0);	      
	  }
      }
  } while (exitFlag==0);
  
  cpgend();
}
Пример #15
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;
}
Пример #16
0
int plot(float ***u, const int nx, const int ny) {

#ifdef PGPLOT
	const int ng=2;
	double xl, xr, yl, yr, dx, dy;
	float  denscontours[NCONTOURS], prescontours[NCONTOURS];
	float *dens, *pres;
	double maxd=-1e19, mind=+1e-19;
	double maxp=-1e19, minp=+1e-19;
	static int called = 0;
	int i, j, count;	
	float tr[6] = {0.,0.,0.,0.,0.,0.};
	
	xl = 0.; xr = nx-2*ng-1;
	yl = 0.; yr = ny-2*ng-1;
    dx = 1.; dy = 1.;

	dens = (float *)malloc((nx-2*ng)*(ny-2*ng)*sizeof(float));
	pres = (float *)malloc((nx-2*ng)*(ny-2*ng)*sizeof(float));
	count = 0;
	for (j=ny-ng; j>ng; j--) {
		for (i=ng; i<nx-ng; i++) {
			dens[count] = u[j][i][IDENS];
            float vx = u[j][i][IMOMX]/dens[count];
            float vy = u[j][i][IMOMY]/dens[count];
			pres[count] = (u[j][i][IENER] - 0.5*(vx*vx+vy*vy)*dens[count]);
			if (dens[count] > maxd) maxd = dens[count];
			if (dens[count] < mind) mind = dens[count];
			if (pres[count] > maxp) maxp = pres[count];
			if (pres[count] < minp) minp = pres[count];
			count++;
		}
	}
	
	tr[0] = xl; tr[3] = yl;
	tr[1] = dx; tr[5] = dy;

	for (i=0; i<NCONTOURS; i++) {
		denscontours[i] = mind + (i+1)*(maxd-mind)/(NCONTOURS+1);
		prescontours[i] = minp + (i+1)*(maxp-minp)/(NCONTOURS+1);
	}


	if (!called) {
		cpgbeg(0, "/XWINDOW", 1, 1);
		called = 1;
		cpgask(0);
	}
	cpgenv(xl, xr, yl, yr, 1, 1);

	cpgsci(2);
	cpgcont(dens, nx-2*ng, ny-2*ng, 1, nx-2*ng, 1, ny-2*ng, denscontours, NCONTOURS, tr);
	if (minp != maxp) {
		cpgsci(3);
	    cpgcont(pres, nx-2*ng, ny-2*ng, 1, nx-2*ng, 1, ny-2*ng, prescontours, NCONTOURS, tr);
	}
	cpgsci(1);
	
	free(dens); free(pres);
#endif
	return 0;
}
Пример #17
0
int main(int argc,char *argv[])
{
  int i;
  char fname[128];
  dSet *data; 
  float freq,bw,chanbw;
  int nchan,npol;
  float bpass[4096];
  float fx[4096];
  float miny,maxy,minx,maxx;
  float ominy,omaxy,ominx,omaxx;
  float mx,my,mx2,my2;
  float binw;
  char key;
  char grDev[128]="/xs";
  int interactive=1;
  int noc1=0;
  int zapChannels[4096];
  int nzap=0;
  int overlay=-1;
  float overlayVal[MAX_OVERLAY];
  char overlayStr[MAX_OVERLAY][128];
  char overlayFile[128];
  int noverlay=0;
  fitsfile *fp;

  data = initialiseDset();
  

  for (i=0;i<argc;i++)
    {
      if (strcmp(argv[i],"-f")==0)
	strcpy(fname,argv[++i]);
      else if (strcmp(argv[i],"-noc1")==0)
	noc1=1;
      else if (strcmp(argv[i],"-g")==0)
	{
	  strcpy(grDev,argv[++i]);
	  interactive=0;
	}
      else if (strcmp(argv[i],"-h")==0)
	help();
      else if (strcmp(argv[i],"-overlay")==0)
	{
	  strcpy(overlayFile,argv[++i]);
	  overlay=1;
	}
    }
  if (overlay==1)
    {
      FILE *fin;
      char line[1024];
      noverlay=0;

      if (!(fin = fopen(overlayFile,"r")))
	  printf("Unable to open overlay file >%s<\n",overlayFile);
      else
	{
	  while (!feof(fin))
	    {
	      fgets(overlayStr[noverlay],1024,fin);
	      if (fscanf(fin,"%f",&overlayVal[noverlay])==1)
		{
		  if (overlayStr[noverlay][strlen(overlayStr[noverlay])-1] == '\n')
		    overlayStr[noverlay][strlen(overlayStr[noverlay])-1]='\0';
		  noverlay++;
		}
	    }
	  fclose(fin);
	}
    }
  fp   = openFitsFile(fname); 
  loadPrimaryHeader(fp,data);
  displayHeaderInfo(data);
  readBandpass(fp,bpass);
  nchan = data->phead.nchan;
  freq  = data->phead.freq;
  bw    = data->phead.bw;
  chanbw = data->phead.chanbw;

  for (i=0;i<nchan;i++)
    {
      fx[i] = freq-bw/2+(i+0.5)*chanbw;
      if (i==noc1)
	{
	  miny = maxy = bpass[i];
	  minx = maxx = fx[i];
	}
      else if (i!=0)
	{
	  if (bpass[i] > maxy) maxy = bpass[i];
	  if (bpass[i] < miny) miny = bpass[i];
	  if (fx[i] > maxx) maxx = fx[i];
	  if (fx[i] < minx) minx = fx[i];
	}
    }
  ominx = minx;
  omaxx = maxx;
  ominy = miny;
  omaxy = maxy;
  binw = fx[1]-fx[0];
  printf("Complete\n");

  cpgbeg(0,grDev,1,1);
  cpgask(0);
  do {
    cpgenv(minx,maxx,miny,maxy,0,1);
    cpglab("Frequency (MHz)","Amplitude (arbitrary)",fname);
    cpgbin(nchan-noc1,fx+noc1,bpass+noc1,0);
    if (overlay==1)
      {
	float tx[2],ty[2];
	cpgsls(4); cpgsci(2); cpgsch(0.8);
	for (i=0;i<noverlay;i++)
	  {
	    tx[0] = tx[1] = overlayVal[i];
	    ty[0] = miny;
	    ty[1] = maxy;
	    if (tx[1] > minx && tx[1] < maxx)
	      {
		cpgline(2,tx,ty);
		//		cpgtext(tx[1],ty[1]-0.05*(maxy-miny),overlayStr[i]);
		cpgptxt(tx[1]-0.004*(maxx-minx),ty[0]+0.05*(maxy-miny),90,0.0,overlayStr[i]);
	      }
	  }
	cpgsci(1); cpgsls(1); cpgsch(1);
      }
    if (interactive==1)
      {
	cpgcurs(&mx,&my,&key);
	if (key=='A')
	  {
	    int cc=-1;
	    int i;
	    for (i=0;i<nchan-1;i++)
	      {
		//		if ((bw > 0 && (mx > fx[i]-binw/2 && mx < fx[i]+binw/2)) ||
		//		    (bw < 0 && (mx > fx[i]+binw/2 && mx < fx[i]-binw/2)))
		if ((bw > 0 && (mx > fx[i] && mx < fx[i]+binw)) ||
		    (bw < 0 && (mx > fx[i] && mx < fx[i]+binw)))
		  {
		    cc = i;
		    break;
		  }
	      }
	    printf("mouse x = %g MHz, mouse y = %g, channel = %d, channel frequency = %g MHz\n",mx,my,cc,fx[cc]);
	  }
	else if (key=='X')
	  {
	    int cc=-1;
	    int i;
	    printf("Deleting %g %g %g\n",mx,fx[10],binw);
	    for (i=0;i<nchan-1;i++)
	      {
		//		if ((bw > 0 && (mx > fx[i]-binw/2 && mx < fx[i]+binw/2)) ||
		//		    (bw < 0 && (mx > fx[i]+binw/2 && mx < fx[i]-binw/2)))
		if ((bw > 0 && (mx > fx[i] && mx < fx[i]+binw)) ||
		    (bw < 0 && (mx > fx[i] && mx < fx[i]+binw)))
		  {
		    cc = i;
		    break;
		  }
	      }
	    printf("Want to delete = %d\n",cc);
	    if (cc != -1)
	      {
		bpass[cc] = 0;
		omaxy = bpass[noc1];
		zapChannels[nzap++] = cc;
		for (i=noc1;i<nchan;i++)
		  {
		    if (omaxy < bpass[i]) omaxy = bpass[i];
		  }
	      }
	  }
	else if (key=='z')
	  {
	    cpgband(2,0,mx,my,&mx2,&my2,&key);
	    if (mx > mx2) {maxx = mx; minx = mx2;}
	    else {maxx = mx2; minx = mx;}
	    
	    if (my > my2) {maxy = my; miny = my2;}
	    else {maxy = my2; miny = my;}	   
	  }
	else if (key=='u')
	  {
	    minx = ominx;
	    maxx = omaxx;
	    miny = ominy;
	    maxy = omaxy;
	  }
	else if (key=='l') // List the channels and frequencies to zap
	  {
	    int i;
	    sortInt(zapChannels,nzap);
	    printf("-------------------------------------------------------\n");
	    printf("Zap channels with first channel = 0\n\n");
	    for (i=0;i<nzap;i++)
	      printf("%d ",zapChannels[i]);
	    printf("\n\n");
	    printf("Zap channels with first channel = 1\n\n");
	    for (i=0;i<nzap;i++)
	      printf("%d ",zapChannels[i]+1);
	    printf("\n\n");
	    printf("Zap channels frequencies:\n\n");
	    for (i=0;i<nzap;i++)
	      printf("%g ",fx[zapChannels[i]]);
	    printf("\n\n");
	    printf("-------------------------------------------------------\n");
	  }
	else if (key=='%') // Enter percentage of the band edges to zap
	  {
	    float percent;
	    int i;

	    printf("Enter band edge percentage to zap ");
	    scanf("%f",&percent);
	    for (i=0;i<nchan;i++)
	      {
		if (i < nchan*percent/100.0 || i > nchan-(nchan*percent/100.0))
		  {
		    bpass[i] = 0;		    
		    zapChannels[nzap++] = i;

		  }
	      }
	    omaxy = bpass[noc1];
	    for (i=noc1;i<nchan;i++)
	      {
		if (omaxy < bpass[i]) omaxy = bpass[i];
	      }

	    // Unzoom
	    minx = ominx;
	    maxx = omaxx;
	    miny = ominy;
	    maxy = omaxy;
	  }

      }
  } while (key != 'q' && interactive==1);
  cpgend();
}
Пример #18
0
/* set window and viewport and draw labeled frame */
static void _pgenv (double *xmin, double *xmax, double *ymin, double *ymax,
                    int *just, int *axis)
{
   cpgenv ((float) *xmin, (float) *xmax, (float) *ymin, (float) *ymax,
           *just, *axis);
}