Exemplo n.º 1
0
void doPlot(pulsar *psr,int npsr,float *scale,int nScale,char *grDev,int plotUs,float fontSize,float centreMJD,int ptStyle,float ptSize,int error,float minyv,float maxyv,float minxv,float maxxv,int nOverlay,float labelsize,float fracX)
{
  int i,j,fitFlag=2,exitFlag=0,scale1=0,scale2,count[MAX_PSR],p,xautoscale=0,k,graphics=1;
  int yautoscale=0,plotpre=1;
  int ps,pe,pi;
  int time=0;
  char xstr[1000],ystr[1000];
  float px[2],py[2],pye1[2],pye2[2];
  float x[MAX_PSR][MAX_OBSN],y[MAX_PSR][MAX_OBSN],yerr1[MAX_PSR][MAX_OBSN],yerr2[MAX_PSR][MAX_OBSN],tmax,tmin,tmaxy1,tminy1,tmaxy2,tminy2;
  float sminy[MAX_PSR],smaxy[MAX_PSR];
  float minx[MAX_PSR],maxx[MAX_PSR],miny[MAX_PSR],maxy[MAX_PSR],plotx1,plotx2,ploty1,ploty2,mean;
  float fx[2],fy[2];
  float mouseX,mouseY;
  char key;
  //  float widthPap=0.0,aspectPap=0.618;
  float widthPap=0.0,aspectPap=1;
  float xx[MAX_OBSN],yy[MAX_OBSN],yyerr1[MAX_OBSN],yyerr2[MAX_OBSN];
  int num=0,colour;

  /* Obtain a graphical PGPLOT window */
  cpgbeg(0,grDev,1,1);
  //    cpgpap(widthPap,aspectPap);
  cpgsch(fontSize);
  cpgscf(2);
  cpgslw(2);
  cpgask(0);

  for (p=0;p<npsr;p++)
    {
      scale2 = psr[p].nobs;
      
      /*      sprintf(xstr,"MJD-%.1Lf",psr[0].param[param_pepoch].val[0]); */
      if (centreMJD == -1)
	sprintf(xstr,"Year"); 
      else
	sprintf(xstr,"MJD-%.1f",centreMJD); 

      sprintf(ystr,"Residual (\\gmsec)");
      
      count[p]=0;
      printf("points = %d\n",psr[p].nobs);
      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))
	    {
	      /* x[p][count[p]] = (double)(psr[p].obsn[i].bat-psr[0].param[param_pepoch].val[0]);	     	       */
	      if (centreMJD == -1)
		x[p][count[p]] = calcYr(psr[p].obsn[i].bat);
	      else
		x[p][count[p]] = (double)(psr[p].obsn[i].bat-centreMJD); 
	      y[p][count[p]] = (double)psr[p].obsn[i].residual*1.0e6;
	      if (nScale>0)
		y[p][count[p]] *= scale[p];
	      count[p]++;
	    }
	}
      /* Remove mean from the residuals and calculate error bars */
      mean = findMean(y[p],psr,p,scale1,count[p]);
      count[p]=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[p][count[p]]-=mean;
	      yerr1[p][count[p]] = y[p][count[p]]-(float)psr[p].obsn[i].toaErr;
	      yerr2[p][count[p]] = y[p][count[p]]+(float)psr[p].obsn[i].toaErr;
	      count[p]++;
	    }
	}
    	  
      /* Get scaling for graph */
      if (minxv == maxxv) {
	minx[p] = findMin(x[p],psr,p,scale1,count[p]);
	maxx[p] = findMax(x[p],psr,p,scale1,count[p]);
      }
      else {
	minx[p] = minxv;
	maxx[p] = maxxv;
      }
      if (minyv == maxyv){
	miny[p] = findMin(y[p],psr,p,scale1,count[p]);
	maxy[p] = findMax(y[p],psr,p,scale1,count[p]);
      }
      else {
	miny[p] = minyv;
	maxy[p] = maxyv;
      }
      sminy[p] = miny[p]/1e6;
      smaxy[p] = maxy[p]/1e6;
    }
  for (p=0;p<npsr;p++)
    {
      for (i=0;i<count[p];i++)
	{
	  y[p][i] = (y[p][i]-miny[p])/(maxy[p]-miny[p]);
	  yerr1[p][i] = (yerr1[p][i]-miny[p])/(maxy[p]-miny[p]);
	  yerr2[p][i] = (yerr2[p][i]-miny[p])/(maxy[p]-miny[p]);
	}
      //      maxy[p] = 1.0;
      //      miny[p] = 0.0;
    }
  

  tmin = findMinVal(minx,npsr);
  tmax = findMaxVal(maxx,npsr);

  tminy2 = 0.0; //findMinVal(miny,npsr);
  tmaxy2 = 1.0; //findMaxVal(maxy,npsr);

  plotx1 = tmin-(tmax-tmin)*0.1;
  plotx2 = tmax+(tmax-tmin)*0.1;
  
  //  ploty1 = tminy2-(tmaxy2-tminy2)*0.1;
  //  ploty2 = tmaxy2+(tmaxy2-tminy2)*0.1;
	
  ploty1 = 0.1;
  ploty2 = 0.9;

  for (p=0;p<npsr;p++)
    {
      for (i=0;i<count[p];i++)
	{
	  y[p][i]=(p)+ploty1+y[p][i]*(ploty2-ploty1);
	  yerr1[p][i]=(p)+ploty1+yerr1[p][i]*(ploty2-ploty1);
	  yerr2[p][i]=(p)+ploty1+yerr2[p][i]*(ploty2-ploty1);
	}
    } 
  
  printf("ytick = %g\n",ploty2-ploty1);
      /*  cpgenv(plotx1,plotx2,ploty1,ploty2+(ploty2-ploty1)*(npsr-1),0,0); */
  //  cpgenv(plotx1,plotx2,0,npsr+1,0,-1);

  if (labelsize!=-1)
    cpgsch(labelsize);
  cpgsvp(fracX,1.0,0.1,1.0);
  cpgswin(0,1,0,npsr);
  cpgbox("ABC",0.0,0,"C",0.0,0);
  cpgsch(fontSize);
  char str[1000];
  for (p=0;p<npsr;p++)
    {
      cpgsch(fontSize);
      //      cpgtext(tmax+(tmax-tmin)*0.05,p+1.5-0.5,psr[p].name);
      cpgtext(0,p+0.6,psr[p].name);
      //      cpgsch(fontSize);
      if (plotUs==0)
	{
	  sprintf(str,"%.2f",(double)((smaxy[p]-sminy[p])*psr[p].param[param_f].val[0]));
	  cpgtext(0,p+0.4,str);
	  //	  cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str);
	}
      else
	{
	  sprintf(str,"%.2f\\gms",(double)((smaxy[p]-sminy[p])/1e-6));
	  //	  cpgtext(tmax+(tmax-tmin)*0.05,p+1.1-0.5,str);
	  cpgtext(0,p+0.1,str);
	}
      cpgsch(1);
      px[0] = 0;
      //      px[1] = tmax; //+(tmax-tmin)*0.03;
	px[1] = 1;
      py[0] = p;
      py[1] = p;
      cpgline(2,px,py);
      
    }
  if (labelsize!=-1)
    cpgsch(labelsize);

  cpgsvp(0.1,fracX,0.1,1.0);
  cpgswin(plotx1,plotx2,0,npsr);
  cpgbox("ATNSBC",0.0,0,"B",0.0,0);
  cpglab(xstr,"","");	    
  cpgsch(fontSize);

  for (p=0;p<npsr;p++)
    {
      cpgsls(1);
      px[0] = plotx1;
      //      px[1] = tmax; //+(tmax-tmin)*0.03;
      px[1] = plotx2;
      py[0] = p;
      py[1] = p;
      cpgline(2,px,py);
      cpgsls(4);
      px[0] = tmin;
      px[1] = tmax+(tmax-tmin)*0.03;

      py[0]=py[1] =(p)+ploty1+(-miny[p]/(maxy[p]-miny[p]))*(ploty2-ploty1);
      //      py[0]=py[1] = (p)+ploty1;
      //      py[0] = py[1] = (0-miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1)+p;
      cpgline(2,px,py);

      px[0] = plotx1+0.005*(plotx2-plotx1);
      py[0] = p;
      pye1[0] = p + 5/(ploty2-ploty1);
      pye2[0] = p - 5/(ploty2-ploty1);
      cpgsls(1);
      cpgsch(3);
      //      cpgerry(1,px,pye1,pye2,1); 
      cpgsch(1);

      for (colour=0;colour<5;colour++)
	{
	  num=0;
	  for (i=0;i<count[p];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[p][i];
		  yy[num]=y[p][i];
		  yyerr1[num]=yerr1[p][i];
		  yyerr2[num]=yerr2[p][i];
		  //		  printf("plotting: %g\n",yy[num]);

		  num++;
		}
	    }
	  cpgsci(colour+1);
	  cpgsch(ptSize);
	  cpgpt(num,xx,yy,ptStyle);
	  if (error==1)
	    cpgerry(num,xx,yyerr1,yyerr2,1);
	  cpgsch(fontSize);
	  // Plot arrow giving one period
	  fx[0] = fx[1] = tmin-(tmax-tmin)*0.05;
	  //	  fy[0] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1);
	  //	  fy[1] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(ploty2-ploty1);

	  //	  fy[0] = (-(float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5;
	  //	  fy[1] = ((float)(1.0/psr[p].param[param_f].val[0])/2.0/1.0e6 - miny[p])/(maxy[p]-miny[p])/(ploty2-ploty1) + (p+1)+0.5;
	  fy[0] = (p+1)+0.5+(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6;
	  fy[1] = (p+1)+0.5-(float)(1.0/psr[p].param[param_f].val[0])/2.0/(maxy[p]-miny[p])*1e6;
	  if (fy[0] > (p+1)+1) fy[0] = (p+1)+1;
	  if (fy[1] < (p+1)) fy[1] = (p+1);
	  
	  //	  cpgsls(1); cpgline(2,fx,fy); cpgsls(1);
	}
      cpgsci(1);
    }

  
  cpgend();
}
Exemplo n.º 2
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.º 3
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.º 4
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;
}
Exemplo n.º 5
0
main(int argc, char *argv[])
{
  FILE *output;
  int numerate,i,j,k,l,nsperdmp,nsamps,indexing,plot,indexnow;
  int ifchan[16],frchan[4096],ifnum,chnum,ns,sample,ntotal;
  float time_of_pulse, width_of_pulse, time, time_start, time_end;
  float series_amp[100000],series_time[100000],ampmin,ampmax;
  char message[80],outfile[80],filename[80],timestring[80],pgdev[80];
  unsigned char c;
  unsigned short s;
  float f[8];

    if (argc<2) {
    puts("");
    puts("getpulse - make and/or plot a time series from dedispersed file\n"); 
    puts("usage: getpulse {filename} -{options}\n");
    puts("filename is the dedispersed data file\n");
    puts("options:\n");
    puts("-t time - time (in seconds) on which to center time series (REQUIRED)\n");
    puts("-w width - width (in seconds) of time series to plot (def=1)\n");
    puts("-c fchan - to only output frequency channel fchan (def=all)\n");
    puts("-i ifchan - to only output IF channel ifchan (def=all)\n");
    puts("-p pgdev - pgplot device (def=/xs)\n");
    puts("-numerate - to precede each dump with sample number (def=time)\n");
    puts("-noindex - do not precede each dump with time/number\n");
    puts("-plot - PGPLOT the results\n");
    puts("");
    exit(0);
   }

  /* zero IF and frequency channel arrays */
  for (i=0;i<16;i++)   ifchan[i]=0;
  for (i=0;i<4096;i++) frchan[i]=0;

  /* default case is to read from standard input */
  input=stdin;
  numerate=0;
  ampmin = 1.e6;
  ampmax = -1.e6;
  plot=0;
  indexnow=0;
  indexing=1;
  strcpy(pgdev,"/xs");

  /* parse command line if arguments were given */
  if (argc>1) {
    i=1;
    while (i<argc) {
        if (strings_equal(argv[i],"-i")) {
	i++;
	ifchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-c")) {
	i++;
	frchan[atoi(argv[i])-1]=1;
      } else if (strings_equal(argv[i],"-t")) {
        i++;
	time_of_pulse = atof(argv[i]);
        strcpy(timestring,argv[i]);
	fprintf(stderr,"centering on time %f s\n",time_of_pulse); 
      } else if (strings_equal(argv[i],"-w")) {
        i++;
        width_of_pulse = atof(argv[i]);
        fprintf(stderr,"with width %f s\n",width_of_pulse);
      } else if (strings_equal(argv[i],"-p")) {
        i++;
        strcpy(pgdev,argv[i]); 
      } else if (strings_equal(argv[i],"-numerate")) {
	numerate=1;
      } else if (strings_equal(argv[i],"-noindex")) {
	indexing=0;
      } else if (strings_equal(argv[i],"-plot")) {
	plot=1;
      } else if (file_exists(argv[i])) {
	input=open_file(argv[i],"rb");
        strcpy(filename,argv[i]);
      } else {
	sprintf(message,"unknown argument (%s) passed to getpulse",argv[i]);
	error_message(message);
      }
      i++;
    }
  }

  strcat(filename,".pulse.");
  strcat(filename,timestring);
  strcpy(outfile,filename);
  output=fopen(outfile,"w");
  time_start = time_of_pulse - width_of_pulse/2.;
  time_end = time_of_pulse + width_of_pulse/2.;
  sample = 0;
  /* try to read the header */
  if (!read_header(input)) error_message("error reading header\n");

  /* check what IF and frequency channels (if any the user has selected) */
  j=0;
  for (i=0; i<nifs; i++) if (ifchan[i]) j++;
  if (j==0) for (i=0; i<nifs; i++) ifchan[i]=1;
  j=0;
  for (i=0; i<nchans; i++) if (frchan[i]) j++;
  if (j==0) for (i=0; i<nchans; i++) frchan[i]=1;

  /* number of samples to read per dump */
  nsperdmp=nifs*nchans;
  /* initialize loop counters and flags */
  ifnum=chnum=nsamps=l=0;

  while (!feof(input)) {

    /* unpack the sample(s) if necessary */
    switch (nbits) {
    case 1:
      fread(&c,1,1,input);
      for (i=0;i<8;i++) {
	f[i]=c&1;
	c>>=1;
      }
      ns=8;
      break;
    case 4:
      fread(&c,1,1,input);
      char2ints(c,&j,&k);
      f[0]=(float) j;
      f[1]=(float) k;
      ns=2;
      break;
    case 8:
      fread(&c,nbits/8,1,input);
      f[0]=(float) c;
      ns=1;
      break;
    case 16:
      fread(&s,nbits/8,1,input);
      f[0]=(float) s;
      ns=1;
      break;
    case 32:
      fread(&f[0],nbits/8,1,input);
      ns=1;
      break;
    default:
      sprintf(message,"cannot read %d bits per sample...\n",nbits);
      error_message(message);
      break;
    }

    if (plot) {
       ntotal = (time_end-time_start)/tsamp;
       if (ntotal > 100000) {
	  fprintf(stderr,"Too many samples to plot!\n");
	  plot=0;
	}
    }
    for (i=0; i<ns; i++) {
      /* time stamp or index the data */
      time = (double) tsamp * (double) l;
      if (time > time_end) {
         if (plot) {
	       indexnow=indexnow-1;
	       cpgbeg(0,pgdev,1,1);
               cpgsvp(0.1,0.9,0.1,0.9);
               cpgswin(series_time[0],series_time[indexnow],ampmin-0.1*ampmax,ampmax+0.1*ampmax);
               cpgbox("bcnst",0.0,0,"bcnst",0,0.0);
               cpgline(indexnow,series_time,series_amp);
               cpgscf(2);
	       cpgmtxt("B",2.5,0.5,0.5,"Time (s)");
	       cpgmtxt("L",1.8,0.5,0.5,"Amplitude");
               cpgend();}
	    exit(0);
      }
      /* print sample if it is one of the ones selected */
      if (ifchan[ifnum] && frchan[chnum] && time >= time_start && time <= time_end) {
	if (indexing) {
           if (numerate) fprintf(output,"%d %f\n",l,f[i]);
           else fprintf(output,"%f %f\n",time,f[i]);
        }	
	else {
	   fprintf(output,"%f\n",f[i]);
	}
	if (plot) {
	   series_amp[indexnow]=f[i];
	   series_time[indexnow]=time;
           if (f[i] < ampmin) ampmin = f[i];
           if (f[i] > ampmax) ampmax = f[i];
           indexnow++;
	}
      } 
      nsamps++;
      chnum++;
      if (chnum==nchans) {
	chnum=0;
	ifnum++;
	if (ifnum==nifs) ifnum=0;
      }
      if ((nsamps%nsperdmp)==0) {
	nsamps=0;
	l++;
      }
      }
	}
    fclose(output);

}
Exemplo n.º 6
0
int main()

{
  char text[80];
  int  naxisj, nFail = 0, status;
  double cdeltX, crpixj, crvalX, restfrq, restwav, x1, x2;


  printf(
    "Testing closure of WCSLIB spectral transformation routines (tspc.c)\n"
    "-------------------------------------------------------------------\n");

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


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

  naxisj = NSPEC;
  crpixj = naxisj/2 + 1;

  restfrq = 1420.40595e6;
  restwav = C/restfrq;
  x1 = 1.0e9;
  x2 = 2.0e9;
  cdeltX = (x2 - x1)/(naxisj - 1);
  crvalX = x1 + (crpixj - 1.0)*cdeltX;
  printf("\nLinear frequency axis, span: %.1f to %.1f (GHz), step: %.3f "
         "(kHz)\n---------------------------------------------------------"
         "-----------------\n", x1*1e-9, x2*1e-9, cdeltX*1e-3);
  nFail += closure("WAVE-F2W",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VOPT-F2W",     0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ZOPT-F2W",     0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AWAV-F2A",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VELO-F2V", restfrq,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("BETA-F2V", restfrq,     0.0, naxisj, crpixj, cdeltX, crvalX);

  restwav = 700.0e-9;
  restfrq = C/restwav;
  x1 = 300.0e-9;
  x2 = 900.0e-9;
  cdeltX = (x2 - x1)/(naxisj - 1);
  crvalX = x1 + (crpixj - 1.0)*cdeltX;
  printf("\nLinear vacuum wavelength axis, span: %.0f to %.0f (nm), "
         "step: %f (nm)\n---------------------------------------------"
         "-----------------------------\n", x1*1e9, x2*1e9, cdeltX*1e9);
  nFail += closure("FREQ-W2F",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AFRQ-W2F",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ENER-W2F",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVN-W2F",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VRAD-W2F", restfrq,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AWAV-W2A",     0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VELO-W2V",     0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("BETA-W2V",     0.0, restwav, naxisj, crpixj, cdeltX, crvalX);


  printf("\nLinear air wavelength axis, span: %.0f to %.0f (nm), "
         "step: %f (nm)\n------------------------------------------"
         "--------------------------------\n", x1*1e9, x2*1e9, cdeltX*1e9);
  nFail += closure("FREQ-A2F", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AFRQ-A2F", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ENER-A2F", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVN-A2F", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VRAD-A2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVE-A2W", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VOPT-A2W", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ZOPT-A2W", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VELO-A2V", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("BETA-A2V", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);


  restfrq = 1420.40595e6;
  restwav = C/restfrq;
  x1 = -0.96*C;
  x2 =  0.96*C;
  cdeltX = (x2 - x1)/(naxisj - 1);
  crvalX = x1 + (crpixj - 1.0)*cdeltX;
  printf("\nLinear velocity axis, span: %.0f to %.0f m/s, step: %.0f "
         "(m/s)\n------------------------------------------------------"
         "--------------------\n", x1, x2, cdeltX);
  nFail += closure("FREQ-V2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AFRQ-V2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ENER-V2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVN-V2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VRAD-V2F", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVE-V2W", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VOPT-V2W", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ZOPT-V2W", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AWAV-V2A", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);


  restwav = 650.0e-9;
  restfrq = C/restwav;
  x1 =  300e-9;
  x2 = 1000e-9;
  cdeltX = (x2 - x1)/(naxisj - 1);
  crvalX = x1 + (crpixj - 1.0)*cdeltX;
  printf("\nVacuum wavelength grism axis, span: %.0f to %.0f (nm), "
         "step: %f (nm)\n--------------------------------------------"
         "------------------------------\n", x1*1e9, x2*1e9, cdeltX*1e9);
  nFail += closure("FREQ-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AFRQ-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ENER-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVN-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VRAD-GRI", restfrq, 0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("WAVE-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VOPT-GRI", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("ZOPT-GRI", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("AWAV-GRI", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VELO-GRI", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("BETA-GRI", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);


  /* Reproduce Fig. 5 of Paper III. */
  naxisj = 1700;
  crpixj = 719.8;
  crvalX = 7245.2e-10;
  cdeltX = 2.956e-10;
  restwav = 8500.0e-10;
  restfrq = C/restwav;
  x1 = crvalX + (1 - crpixj)*cdeltX;
  x2 = crvalX + (naxisj - crpixj)*cdeltX;
  mars[5] = 0.0;
  mars[6] = 0.0;
  printf("\nAir wavelength grism axis, span: %.0f to %.0f (nm), "
         "step: %f (nm)\n--------------------------------------------"
         "------------------------------\n", x1*1e9, x2*1e9, cdeltX*1e9);
  nFail += closure("AWAV-GRA", 0.0,     0.0, naxisj, crpixj, cdeltX, crvalX);
  nFail += closure("VELO-GRA", 0.0, restwav, naxisj, crpixj, cdeltX, crvalX);

  cpgask(0);
  cpgend();

  if (nFail) {
    printf("\nFAIL: %d closure residuals exceed reporting tolerance.\n",
      nFail);
  } else {
    printf("\nPASS: All closure residuals are within reporting tolerance.\n");
  }

  return nFail;
}
Exemplo n.º 7
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();
}
Exemplo n.º 8
0
int main()

{
  char   text[80];
  register int status;


  printf("Testing WCSLIB wcsmix() routine (twcsmix.c)\n"
         "-------------------------------------------\n");

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


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

  /* Define pen colours. */
  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);
  cpgscr(9, 1.00f, 0.75f, 0.00f);


  /*----------------------------------------------------------*/
  /* Set the PVi_m keyvalues for the longitude axis so that   */
  /* the fiducial native coordinates are at the native pole,  */
  /* i.e. (phi0,theta0) = (0,90), but without any fiducial    */
  /* offset.  We do this as a test, and also so that all      */
  /* projections will be exercised with the same obliquity    */
  /* parameters.                                              */
  /*----------------------------------------------------------*/
  PV[0].i = 4;			/* Longitude is on axis 4.     */
  PV[0].m = 1;			/* Parameter number 1.         */
  PV[0].value =  0.0;		/* Fiducial native longitude.  */

  PV[1].i = 4;			/* Longitude is on axis 4.     */
  PV[1].m = 2;			/* Parameter number 2.         */
  PV[1].value = 90.0;		/* Fiducial native latitude.   */

  /* Set the PVi_m keyvalues for the latitude axis.           */
  PV[2].i = 2;			/* Latitude is on axis 2.      */
  PV[2].m = 1;			/* Parameter number 1.         */
  PV[2].value = 0.0;		/* PVi_1 (set below).          */

  PV[3].i = 2;			/* Latitude is on axis 2.      */
  PV[3].m = 2;			/* Parameter number 2.         */
  PV[3].value = 0.0;		/* PVi_2 (set below).          */

  /* ARC: zenithal/azimuthal equidistant. */
  strncpy(&CTYPE[1][5], "ARC", 3);
  strncpy(&CTYPE[3][5], "ARC", 3);
  NPV = 2;
  mixex(-190.0, 190.0, -190.0, 190.0);

  /* ZEA: zenithal/azimuthal equal area. */
  strncpy(&CTYPE[1][5], "ZEA", 3);
  strncpy(&CTYPE[3][5], "ZEA", 3);
  NPV = 2;
  mixex(-120.0, 120.0, -120.0, 120.0);

  /* CYP: cylindrical perspective. */
  strncpy(&CTYPE[1][5], "CYP", 3);
  strncpy(&CTYPE[3][5], "CYP", 3);
  NPV = 4;
  PV[2].value = 3.0;
  PV[3].value = 0.8;
  mixex(-170.0, 170.0, -170.0, 170.0);

  /* CEA: cylindrical equal area. */
  strncpy(&CTYPE[1][5], "CEA", 3);
  strncpy(&CTYPE[3][5], "CEA", 3);
  NPV = 3;
  PV[2].value = 0.75;
  mixex(-200.0, 200.0, -200.0, 200.0);

  /* CAR: plate carree. */
  strncpy(&CTYPE[1][5], "CAR", 3);
  strncpy(&CTYPE[3][5], "CAR", 3);
  NPV = 2;
  mixex(-210.0, 210.0, -210.0, 210.0);

  /* SFL: Sanson-Flamsteed. */
  strncpy(&CTYPE[1][5], "SFL", 3);
  strncpy(&CTYPE[3][5], "SFL", 3);
  NPV = 2;
  mixex(-190.0, 190.0, -190.0, 190.0);

  /* PAR: parabolic. */
  strncpy(&CTYPE[1][5], "PAR", 3);
  strncpy(&CTYPE[3][5], "PAR", 3);
  NPV = 2;
  mixex(-190.0, 190.0, -190.0, 190.0);

  /* MOL: Mollweide's projection. */
  strncpy(&CTYPE[1][5], "MOL", 3);
  strncpy(&CTYPE[3][5], "MOL", 3);
  NPV = 2;
  mixex(-170.0, 170.0, -170.0, 170.0);

  /* AIT: Hammer-Aitoff. */
  strncpy(&CTYPE[1][5], "AIT", 3);
  strncpy(&CTYPE[3][5], "AIT", 3);
  NPV = 2;
  mixex(-170.0, 170.0, -170.0, 170.0);

  /* COE: conic equal area. */
  strncpy(&CTYPE[1][5], "COE", 3);
  strncpy(&CTYPE[3][5], "COE", 3);
  NPV = 4;
  PV[2].value = 60.0;
  PV[3].value = 15.0;
  mixex(-140.0, 140.0, -120.0, 160.0);

  /* COD: conic equidistant. */
  strncpy(&CTYPE[1][5], "COD", 3);
  strncpy(&CTYPE[3][5], "COD", 3);
  NPV = 4;
  PV[2].value = 60.0;
  PV[3].value = 15.0;
  mixex(-200.0, 200.0, -180.0, 220.0);

  /* BON: Bonne's projection. */
  strncpy(&CTYPE[1][5], "BON", 3);
  strncpy(&CTYPE[3][5], "BON", 3);
  NPV = 3;
  PV[2].value = 30.0;
  mixex(-160.0, 160.0, -160.0, 160.0);

  /* PCO: polyconic. */
  strncpy(&CTYPE[1][5], "PCO", 3);
  strncpy(&CTYPE[3][5], "PCO", 3);
  NPV = 2;
  mixex(-190.0, 190.0, -190.0, 190.0);

  /* TSC: tangential spherical cube. */
  strncpy(&CTYPE[1][5], "TSC", 3);
  strncpy(&CTYPE[3][5], "TSC", 3);
  NPV = 2;
  mixex(-340.0, 80.0, -210.0, 210.0);

  /* QSC: quadrilateralized spherical cube. */
  strncpy(&CTYPE[1][5], "QSC", 3);
  strncpy(&CTYPE[3][5], "QSC", 3);
  NPV = 2;
  mixex(-340.0, 80.0, -210.0, 210.0);

  cpgend();

  return 0;
}
Exemplo n.º 9
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.º 10
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;
}
Exemplo n.º 11
0
int main()

{
  void prjplt();
  int  status;
  char text[80], text1[80], text2[80];
  struct prjprm prj;


  printf("Testing WCSLIB spherical projection routines (tprj2.c)\n"
         "------------------------------------------------------\n");

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

  printf("\n");


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

  /* Define pen colours. */
  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);

  strcpy(text1, "\n%s projection\n");
  strcpy(text2, "\n%s projection\nParameters:");

  prjini(&prj);

  /* AZP: zenithal/azimuthal perspective. */
  prj.pv[1] =   2.0;
  prj.pv[2] =  30.0;
  printf(text2, "Zenithal/azimuthal perspective");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("AZP", 90, -90, &prj);

  /* SZP: slant zenithal perspective. */
  prj.pv[1] =   2.0;
  prj.pv[2] = 210.0;
  prj.pv[3] =  60.0;
  printf(text2, "Slant zenithal perspective");
  printf("%12.5f%12.5f%12.5f\n", prj.pv[1], prj.pv[2], prj.pv[3]);
  prjplt("SZP", 90, -90, &prj);

  /* TAN: gnomonic. */
  printf(text1, "Gnomonic");
  prjplt("TAN", 90,   5, &prj);

  /* STG: stereographic. */
  printf(text1, "Stereographic");
  prjplt("STG", 90, -85, &prj);

  /* SIN: orthographic. */
  prj.pv[1] = -0.3;
  prj.pv[2] =  0.5;
  printf(text2, "Orthographic/synthesis");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("SIN", 90, -90, &prj);

  /* ARC: zenithal/azimuthal equidistant. */
  printf(text1, "Zenithal/azimuthal equidistant");
  prjplt("ARC", 90, -90, &prj);

  /* ZPN: zenithal/azimuthal polynomial. */
  prj.pv[0] =  0.05000;
  prj.pv[1] =  0.95000;
  prj.pv[2] = -0.02500;
  prj.pv[3] = -0.15833;
  prj.pv[4] =  0.00208;
  prj.pv[5] =  0.00792;
  prj.pv[6] = -0.00007;
  prj.pv[7] = -0.00019;
  prj.pv[8] =  0.00000;
  prj.pv[9] =  0.00000;
  printf(text2, "Zenithal/azimuthal polynomial");
  printf("%12.5f%12.5f%12.5f%12.5f%12.5f\n",
    prj.pv[0], prj.pv[1], prj.pv[2], prj.pv[3], prj.pv[4]);
  printf("           %12.5f%12.5f%12.5f%12.5f%12.5f\n",
    prj.pv[5], prj.pv[6], prj.pv[7], prj.pv[8], prj.pv[9]);
  prjplt("ZPN", 90,  10, &prj);

  /* ZEA: zenithal/azimuthal equal area. */
  printf(text1, "Zenithal/azimuthal equal area");
  prjplt("ZEA", 90, -90, &prj);

  /* AIR: Airy's zenithal projection. */
  prj.pv[1] = 45.0;
  printf(text2, "Airy's zenithal");
  printf("%12.5f\n", prj.pv[1]);
  prjplt("AIR", 90, -85, &prj);

  /* CYP: cylindrical perspective. */
  prj.pv[1] = 3.0;
  prj.pv[2] = 0.8;
  printf(text2, "Cylindrical perspective");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("CYP", 90, -90, &prj);

  /* CEA: cylindrical equal area. */
  prj.pv[1] = 0.75;
  printf(text2, "Cylindrical equal area");
  printf("%12.5f\n", prj.pv[1]);
  prjplt("CEA", 90, -90, &prj);

  /* CAR: plate carree. */
  printf(text1, "Plate carree");
  prjplt("CAR", 90, -90, &prj);

  /* MER: Mercator's. */
  printf(text1, "Mercator's");
  prjplt("MER", 85, -85, &prj);

  /* SFL: Sanson-Flamsteed. */
  printf(text1, "Sanson-Flamsteed (global sinusoid)");
  prjplt("SFL", 90, -90, &prj);

  /* PAR: parabolic. */
  printf(text1, "Parabolic");
  prjplt("PAR", 90, -90, &prj);

  /* MOL: Mollweide's projection. */
  printf(text1, "Mollweide's");
  prjplt("MOL", 90, -90, &prj);

  /* AIT: Hammer-Aitoff. */
  printf(text1, "Hammer-Aitoff");
  prjplt("AIT", 90, -90, &prj);

  /* COP: conic perspective. */
  prj.pv[1] =  60.0;
  prj.pv[2] =  15.0;
  printf(text2, "Conic perspective");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("COP", 90, -25, &prj);

  /* COE: conic equal area. */
  prj.pv[1] =  60.0;
  prj.pv[2] = -15.0;
  printf(text2, "Conic equal area");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("COE", 90, -90, &prj);

  /* COD: conic equidistant. */
  prj.pv[1] = -60.0;
  prj.pv[2] =  15.0;
  printf(text2, "Conic equidistant");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("COD", 90, -90, &prj);

  /* COO: conic orthomorphic. */
  prj.pv[1] = -60.0;
  prj.pv[2] = -15.0;
  printf(text2, "Conic orthomorphic");
  printf("%12.5f%12.5f\n", prj.pv[1], prj.pv[2]);
  prjplt("COO", 85, -90, &prj);

  /* BON: Bonne's projection. */
  prj.pv[1] = 30.0;
  printf(text2, "Bonne's");
  printf("%12.5f\n", prj.pv[1]);
  prjplt("BON", 90, -90, &prj);

  /* PCO: polyconic. */
  printf(text1, "Polyconic");
  prjplt("PCO", 90, -90, &prj);

  /* TSC: tangential spherical cube. */
  printf(text1, "Tangential spherical cube");
  prjplt("TSC", 90, -90, &prj);

  /* CSC: COBE quadrilateralized spherical cube. */
  printf(text1, "COBE quadrilateralized spherical cube");
  prjplt("CSC", 90, -90, &prj);

  /* QSC: quadrilateralized spherical cube. */
  printf(text1, "Quadrilateralized spherical cube");
  prjplt("QSC", 90, -90, &prj);

  /* HPX: HEALPix projection. */
  prj.pv[1] = 4.0;
  prj.pv[2] = 3.0;
  printf(text1, "HEALPix");
  prjplt("HPX", 90, -90, &prj);

  /* XPH: HEALPix polar, aka "butterfly" projection. */
  printf(text1, "Butterfly");
  prjplt("XPH", 90, -90, &prj);

  cpgask(0);
  cpgend();

  return 0;
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
   FILE *fftfile, *candfile = NULL, *psfile = NULL;
   char filenm[100], candnm[100], psfilenm[120];
   float locpow, norm, powargr, powargi;
   float *powr, *spreadpow, *minizoompow, *freqs;
   fcomplex *data, *minifft, *minizoom, *spread;
   fcomplex *resp, *kernel;
   double T, dr, ftobinp;
   int ii, nbins, ncands, candnum, lofreq = 0, nzoom, numsumpow = 1;
   int numbetween, numkern, kern_half_width;
   binaryprops binprops;
   infodata idata;

   if (argc < 3 || argc > 6) {
      usage();
      exit(1);
   }
   printf("\n\n");
   printf("         Binary Candidate Display Routine\n");
   printf("              by Scott M. Ransom\n");
   printf("                3 January, 1998\n\n");

   /* Initialize the filenames: */

   sprintf(filenm, "%s.fft", argv[1]);
   sprintf(candnm, "%s_bin.cand", argv[1]);

   /* Read the info file */

   readinf(&idata, argv[1]);
   if (idata.object) {
      printf("Plotting a %s candidate from '%s'.\n", idata.object, filenm);
   } else {
      printf("Plotting a candidate from '%s'.\n", filenm);
   }
   T = idata.N * idata.dt;

   /* Open the FFT file and get its length */

   fftfile = chkfopen(filenm, "rb");
   nbins = chkfilelen(candfile, sizeof(fcomplex));

   /* Open the candidate file and get its length */

   candfile = chkfopen(candnm, "rb");
   ncands = chkfilelen(candfile, sizeof(binaryprops));

   /* The candidate number to examine */

   candnum = atoi(argv[2]);

   /* Check that candnum is in range */

   if ((candnum < 1) || (candnum > ncands)) {
      printf("\nThe candidate number is out of range.\n\n");
      exit(1);
   }
   /* The lowest freq present in the FFT file */

   if (argc >= 4) {
      lofreq = atoi(argv[3]);
      if ((lofreq < 0) || (lofreq > nbins - 1)) {
         printf("\n'lofreq' is out of range.\n\n");
         exit(1);
      }
   }
   /* Is the original FFT a sum of other FFTs with the amplitudes added */
   /* in quadrature?  (i.e. an incoherent sum)                          */

   if (argc >= 5) {
      numsumpow = atoi(argv[4]);
      if (numsumpow < 1) {
         printf("\nNumber of summed powers must be at least one.\n\n");
         exit(1);
      }
   }
   /* Initialize PGPLOT using Postscript if requested  */

   if ((argc == 6) && (!strcmp(argv[5], "ps"))) {
      sprintf(psfilenm, "%s_bin_cand_%d.ps", argv[1], candnum);
      cpgstart_ps(psfilenm, "landscape");
   } else {
      cpgstart_x("landscape");
   }

   /* Read the binary candidate */

   chkfileseek(candfile, (long) (candnum - 1), sizeof(binaryprops), SEEK_SET);
   chkfread(&binprops, sizeof(binaryprops), 1, candfile);
   fclose(candfile);

   /* Output the binary candidate */

   print_bin_candidate(&binprops, 2);

   /* Allocate some memory */

   powr = gen_fvect(binprops.nfftbins);
   minifft = gen_cvect(binprops.nfftbins / 2);
   spread = gen_cvect(binprops.nfftbins);
   spreadpow = gen_fvect(binprops.nfftbins);
   nzoom = 2 * ZOOMFACT * ZOOMNEIGHBORS;
   minizoom = gen_cvect(nzoom);
   minizoompow = gen_fvect(nzoom);

   /* Allocate and initialize our interpolation kernel */

   numbetween = 2;
   kern_half_width = r_resp_halfwidth(LOWACC);
   numkern = 2 * numbetween * kern_half_width;
   resp = gen_r_response(0.0, numbetween, numkern);
   kernel = gen_cvect(binprops.nfftbins);
   place_complex_kernel(resp, numkern, kernel, binprops.nfftbins);
   COMPLEXFFT(kernel, binprops.nfftbins, -1);

   /* Read the data from the FFT file */

   data = read_fcomplex_file(fftfile, binprops.lowbin - lofreq, binprops.nfftbins);

   /* Turn the Fourier amplitudes into powers */

   for (ii = 0; ii < binprops.nfftbins; ii++)
      powr[ii] = POWER(data[ii].r, data[ii].i);

   /* Chop the powers that are way above the median level */

   prune_powers(powr, binprops.nfftbins, numsumpow);

   /* Perform the minifft */

   memcpy((float *) minifft, powr, sizeof(float) * binprops.nfftbins);
   realfft((float *) minifft, binprops.nfftbins, -1);

   /* Calculate the normalization constant */

   norm = sqrt((double) binprops.nfftbins * (double) numsumpow) / minifft[0].r;
   locpow = minifft[0].r / binprops.nfftbins;

   /* Divide the original power spectrum by the local power level */

   for (ii = 0; ii < binprops.nfftbins; ii++)
      powr[ii] /= locpow;

   /* Now normalize the miniFFT */

   minifft[0].r = 1.0;
   minifft[0].i = 1.0;
   for (ii = 1; ii < binprops.nfftbins / 2; ii++) {
      minifft[ii].r *= norm;
      minifft[ii].i *= norm;
   }

   /* Interpolate the minifft and convert to power spectrum */

   corr_complex(minifft, binprops.nfftbins / 2, RAW,
                kernel, binprops.nfftbins, FFT,
                spread, binprops.nfftbins, kern_half_width,
                numbetween, kern_half_width, CORR);
   for (ii = 0; ii < binprops.nfftbins; ii++)
      spreadpow[ii] = POWER(spread[ii].r, spread[ii].i);

   /* Plot the initial data set */

   freqs = gen_freqs(binprops.nfftbins, binprops.lowbin / T, 1.0 / T);
   xyline(binprops.nfftbins, freqs, powr, "Pulsar Frequency (hz)",
          "Power / Local Power", 1);
   free(freqs);
   printf("The initial data set (with high power outliers removed):\n\n");

   /* Plot the miniFFT */

   freqs = gen_freqs(binprops.nfftbins, 0.0, T / (2 * binprops.nfftbins));
   xyline(binprops.nfftbins, freqs, spreadpow, "Binary Period (sec)",
          "Normalized Power", 1);
   free(freqs);
   printf("The miniFFT:\n\n");

   /* Interpolate and plot the actual candidate peak */

   ftobinp = T / binprops.nfftbins;
   freqs = gen_freqs(nzoom, (binprops.rdetect - ZOOMNEIGHBORS) *
                     ftobinp, ftobinp / (double) ZOOMFACT);
   for (ii = 0; ii < nzoom; ii++) {
      dr = -ZOOMNEIGHBORS + (double) ii / ZOOMFACT;
      rz_interp(minifft, binprops.nfftbins / 2, binprops.rdetect + dr,
                0.0, kern_half_width, &minizoom[ii]);
      minizoompow[ii] = POWER(minizoom[ii].r, minizoom[ii].i);
   }
   xyline(nzoom, freqs, minizoompow, "Binary Period (sec)", "Normalized Power", 1);
   free(freqs);
   printf("The candidate itself:\n\n");
   printf("Done.\n\n");

   /* Cleanup */

   cpgend();
   free(data);
   free(powr);
   free(resp);
   free(kernel);
   free(minifft);
   free(spread);
   free(spreadpow);
   free(minizoom);
   free(minizoompow);
   fclose(fftfile);
   if ((argc == 6) && (!strcmp(argv[5], "ps"))) {
      fclose(psfile);
   }
   return (0);
}
Exemplo n.º 13
0
static void _pgend (void)
{
   cpgend ();
}
Exemplo n.º 14
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();
}
Exemplo n.º 15
0
void main()
{
   
   float RES = (XMAX - XMIN)/N;                          //resolution
   
   int i,j,p;
   
    
   
   //************************* PGPLOT CODE ***************************
  
  cpgbeg(0,"?",1,1);
  cpgpage();
  
  cpgsci(1);                                           // axis color
  
  cpgpap(0,1);
  
                                                      //axis limits
  cpgswin(XMIN,XMAX,YMIN,YMAX);
  
  cpgbox("BCN",1, 0, "BCN", 1, 0);                  // draw the axes
  
  cpgsci(1);                                          //data color

  cpgsch(0.00000000000001);                        //data point size
  
  
  
  //******************* GRID ALGORITHM AND PLOTTING *******************
  
  
  struct cnum z;                      //complex variables z and c introduced
  struct cnum c;
  
  for(i=0;i<N;i++)                    //look at every point on grid
  {
    for(j=0;j<N;j++)                       
    {
       z.cx = XMIN + i*RES;           // z = current point
       z.cy = YMIN + j*RES;         
       
       CPRINT(z);                     
       
       c.cx = z.cx;                   // keep z, feed c=z in to iteration
       c.cy = z.cy;
          
       for(p=0;p<MNI;p++)                  //apply MNI iterations to c
       {                                     
	 c = FJULIA(c);
	 
	 if ( c.cx*c.cx + c.cy*c.cy > R)    // if iteration "blows up"... 
	 {
	   z.cx = 0;
	   z.cy = 0;
	   c.cx = 0;
	   c.cy = 0;
	 }
	   
       }                                  
           
           
       if (c.cx*c.cx + c.cy*c.cy < R)      //if iteration hasn't blown up...
       {
	 float X[1], Y[1];
	 X[0] = z.cx;
	 Y[0] = z.cy;
	 cpgpt(1,X,Y,17);                  // plot point z
       }
       
       
    }
    
  }
   
  printf("\n\n");                             
 
  cpgend();                       
  
  
   
}
Exemplo n.º 16
0
int main(int argc, char *argv[])
{
    FILE *infile;
    int numchan, numtodisplay = 0, numprofs = 0;
    long i, j, proflen, offset;
    double *profs, *sumprof, nc, pl, tt, bt, p, f, df;
    float rotate = 0.0;
    char device[200], output[200];

    if (argc == 1) {
        printf("usage:  showmulti filename [rotate] [numtodisplay] [device]\n");
        printf("   'filename'     (required) is the multi-profile save file.\n");
        printf("   'rotate'       (optional) is the number of bins to rotate\n");
        printf("                             each profile to the left.\n");
        printf("                             Can be fractional. Default is 0.\n");
        printf("   'numtodisplay' (optional) is the number of profiles to\n");
        printf("                             display at once.  Defaults to\n");
        printf("                             the number of channels.\n");
        printf("   'device'       (optional) is the pgplot device to use ('x' or\n");
        printf("                             'ps').  Defaults to 'x'\n");
        exit(1);
    }

    infile = chkfopen(argv[1], "rb");
    sprintf(output, "%s.ps", argv[1]);
    chkfread(&nc, sizeof(double), 1, infile);
    chkfread(&pl, sizeof(double), 1, infile);
    chkfread(&p, sizeof(double), 1, infile);
    chkfread(&tt, sizeof(double), 1, infile);
    chkfread(&bt, sizeof(double), 1, infile);
    chkfread(&f, sizeof(double), 1, infile);
    chkfread(&df, sizeof(double), 1, infile);
    numchan = nc;
    proflen = pl;

    if (argc == 2) {
        rotate = 0.0;
        numtodisplay = numchan;
        strcpy(device, "x");
    } else if (argc == 3) {
        rotate = strtod(argv[2], NULL);
        numtodisplay = numchan;
        strcpy(device, "x");
    } else if (argc == 4) {
        rotate = strtod(argv[2], NULL);
        numtodisplay = (int) strtol(argv[3], NULL, 10);
        strcpy(device, "x");
    } else if (argc == 5) {
        rotate = strtod(argv[2], NULL);
        numtodisplay = (int) strtol(argv[3], NULL, 10);
        strcpy(device, argv[4]);
    }

    printf("\n      Multi-Profile Display Program\n");
    printf("              Scott M. Ransom\n");
    printf("               18 July 1998\n");
    printf("\nProfile properties:\n");
    printf("Initial folding period (s)  =  %-15.13f\n", p);
    printf("Topocentric time   (start)  =  %-15.10f\n", tt);
    printf("Barycentric time   (start)  =  %-15.10f\n", bt);
    printf("Profile length      (bins)  =  %-ld\n", proflen);
    printf("Number of channels          =  %-d\n", numchan);
    printf("Channel 1 frequency  (MHz)  =  %-10.5f\n", f);
    printf("Channel freq width   (MHz)  =  %-10.5f\n\n", df);

    /* Read the profiles. */

    profs = gen_dvect(proflen * numchan);
    chkfread(profs, sizeof(double), (unsigned long) (numchan * proflen), infile);
    fclose(infile);

    /* Create a Summed-Profile vector */

    sumprof = gen_dvect(proflen);
    for (i = 0; i < proflen; i++) {
        sumprof[i] = 0.0;
    }

    /* Rotate the vectors and summ the profiles */

    for (i = 0; i < numchan; i++) {
        if (rotate)
            drotate(&profs[i * proflen], proflen, rotate);
        for (j = 0; j < proflen; j++) {
            sumprof[j] += profs[i * proflen + j];
        }
    }

    /* Plot the profiles */

    if (0 == strcmp("x", device))
        cpgstart_x("portrait");
    else
        cpgstart_ps(output, "portrait");
    for (i = 0; i <= numchan / numtodisplay; i++) {
        offset = i * numtodisplay;
        numprofs =
            (numchan - offset) > numtodisplay ? numtodisplay : numchan - offset;
        if (numprofs > 0) {
            cpgpage();
            multi_prof_plot(proflen, numprofs, profs + offset * proflen,
                            sumprof, "Pulse Phase (Periods)",
                            (double) (1 + offset), 1.0, "Channel Number",
                            f + offset * df, df, "Frequency (MHz)");
        }
    }
    cpgend();

    /* Cleanup */

    vect_free(profs);
    vect_free(sumprof);

    return 0;
}
Exemplo n.º 17
0
void getTOA_alg1(ptime_observation *obs,pheader *header,tmplStruct *tmpl,toaStruct *toa,FILE *fout_log)
{
  int i,j,k;
  int nbin = header->nbin;
  int nchan = header->nchan;
  int npol = header->npol;
  double chisq;
  double diffVals[nbin];
  double phiRot = 0;
  double step1 = 1.0/nbin/2.0;
  double step = step1;
  double baseline = 0;
  double scale = 1;
  double tmplEval;
  int chan = 0;
  int pol = 0;
  double phi,bestPhi;
  double phi0,phi1,bestChisq;
  int it;
  double chisqVals[nbin*2];
  double phiVals[nbin*2];
  int nChisqVals,ibest;
  int iterateAgain;
  int maxIterations = 10;
  int plotOutput=0;
  double error;
  double *fitX;
  double *fitY;
  double *fitE;
  int    *fitI,*fitJ,*fitK;
  int nfit = npol+1; // Up to 4 baselines per profile + 1 scaling factor
  double outputParams_v[nfit];
  double outputParams_e[nfit];
  double results_v[npol*nchan+nchan];
  double results_e[npol*nchan+nchan];
  int weight = 1;
  double bestParameters[npol*nchan+nchan];
  double chisqTot;

  // Covariance matrix
  double **cvm;
  cvm = (double **)malloc(sizeof(double*)*nfit);
  for (i=0;i<nfit;i++)
    cvm[i] = (double *)malloc(sizeof(double)*nfit);
  if (!(fitX = (double *)malloc(sizeof(double)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitX\n");
    exit(1);
  }
  if (!(fitY = (double *)malloc(sizeof(double)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitY\n");
    exit(1);
  }
  if (!(fitE = (double *)malloc(sizeof(double)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitE\n");
    exit(1);
  }
  if (!(fitI = (int *)malloc(sizeof(int)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitI\n");
    exit(1);
  }
  if (!(fitJ = (int *)malloc(sizeof(int)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitJ\n");
    exit(1);
  }
  if (!(fitK = (int *)malloc(sizeof(int)*npol*nchan*nbin))){
    printf("Unable to allocate enough memory for fitK\n");
    exit(1);
  }

  printf("Baseline sdev = %g, mean = %g\n",obs->chan[0].pol[0].sdev,obs->chan[0].pol[0].baselineVal);
  printf("On the next line\n");
  printf("npol = %d \n",npol);
  printf("Doing fit\n");
  it = 0;
  do {
    printf("Iteration %d\n",it+1);
    if (it == 0) {
      phi0 = -0.5;
      phi1 = 0.5;
    } else {
      phi0 = bestPhi - step;
      phi1 = bestPhi + step;
      step/=(double)10.0;
    }
    nChisqVals = 0;
    for (phiRot = phi0;phiRot < phi1;phiRot += step)
      {
	printf("Complete: %.1f percent\n",(phiRot-phi0)/(phi1-phi0)*100);
	//	phiRot = 0.0;
	// Least squares fit for baseline and amplitude at given phiRot
	//	printf("Doing fit\n");
	chisqTot=0;
	for (j=0;j<nchan;j++){
	  for (i=0;i<npol;i++){
	    for (k=0;k<nbin;k++){
	      //	printf("Setting %d %d %d %d %d\n",i,j,k,npol*nchan*nbin,i*(nchan*nbin)+j*nbin+k);
	      fitI[i*nbin+k] = i;
	      fitJ[i*nbin+k] = j;
	      fitK[i*nbin+k] = k;
	      fitX[i*nbin+k] = (double)k/(double)nbin; 
	      //	printf("This far\n");
	      //	printf("Searching for %g\n",obs->chan[j].pol[i].val[k]);
	      fitY[i*nbin+k] = obs->chan[j].pol[i].val[k];
	      fitE[i*nbin+k] = obs->chan[j].pol[i].sdev; 
	    }
	  }

	  TKleastSquares_svd(fitX,fitY,fitE,fitI,fitJ,fitK,npol*nbin,outputParams_v,outputParams_e,nfit,cvm, &chisq, fitFunc, tmpl, weight,phiRot);
	  chisqTot += chisq;
	  for (i=0;i<npol+1;i++)
	    {
	      results_v[(npol+1)*j + i] = outputParams_v[i];
	      results_e[(npol+1)*j + i] = outputParams_e[i];
	    }
	  //	  for (i=0;i<npol*nbin;i++)
	  //	    {
	  //	      printf("FitVals = %g %g %g\n",fitX[i],fitY[i],fitE[i]);
	  //	    }
	  //	  for (i=0;i<nbin;i++)
	  //	    printf("Best %g %g\n",fitX[i],outputParams_v[4]*evaluateTemplateChannel(tmpl,fitX[i],j,0,phiRot)+outputParams_v[0]);
	  //	  for (i=0;i<nbin;i++)
	  //	    printf("Best %g %g\n",fitX[i],outputParams_v[4]*evaluateTemplateChannel(tmpl,fitX[i],j,1,phiRot)+outputParams_v[1]);
	  //	  for (i=0;i<nbin;i++)
	  //	    printf("Best %g %g\n",fitX[i],outputParams_v[4]*evaluateTemplateChannel(tmpl,fitX[i],j,2,phiRot)+outputParams_v[2]);
	  //	  for (i=0;i<nbin;i++)
	  //	    printf("Best %g %g\n",fitX[i],outputParams_v[4]*evaluateTemplateChannel(tmpl,fitX[i],j,3,phiRot)+outputParams_v[3]);

	  //	for (i=0;i<nfit;i++){
	  //	  printf("%d %g %g\n",i,outputParams_v[i],outputParams_e[i]);


	}

	//	printf("Done fit\n");
	//	baseline = outputParams_v[0];
	//	scale = outputParams_v[1];
	//	for (i=0;i<nfit;i++){
	//	  printf("%d %g %g\n",i,outputParams_v[i],outputParams_e[i]);
	//	}
	//	exit(1);	
	chisqVals[nChisqVals] = chisqTot;
	phiVals[nChisqVals] = phiRot;
	if (nChisqVals==0){
	  bestPhi = phiRot;
	  bestChisq = chisqTot;
	  for (i=0;i<nchan*npol+nchan;i++){
	    bestParameters[i] = outputParams_v[i];
	  }
	  ibest = nChisqVals;
	} else {
	  if (bestChisq > chisqTot){
	    bestChisq = chisqTot;
	    bestPhi = phiRot;
	    ibest = nChisqVals;
	    for (i=0;i<nchan*npol+nchan;i++){
	      bestParameters[i] = outputParams_v[i];
	    }
	  }
	}
	//	printf("Chisq = %g\n",chisq);
	//	exit(1);
	nChisqVals++;
      }
    printf("nvals =%d\n",nChisqVals);
    // Should check if we need to iterate again - do check based on how chisq is changing - i.e, must get a good measure of the chisq increasing by 1
    iterateAgain = 1;
    for (i=ibest+1;i<nChisqVals;i++)
      {
	if (chisqVals[i] < bestChisq + 1){
	  iterateAgain = 0;
	  break;
	}
      }
    it++;
  } while (iterateAgain == 1 && it < maxIterations);
  printf("ibest = %d, nChisqVals = %d, bestPhi = %g\n",ibest,nChisqVals,bestPhi);
  //  exit(1);
  {
    int foundStart = 0;
    double start,end;

    // Should think how to improve this method
    for (i=0;i<nChisqVals;i++)
      {
	fprintf(fout_log,"chisqVals %g %g\n",phiVals[i],chisqVals[i]);
	if (foundStart==0 && chisqVals[i] <= bestChisq + 1) 
	  {
	    foundStart = 1;
	    start = phiVals[i]; 
	  }
	else if (foundStart == 1 && chisqVals[i] >= bestChisq + 1)
	  {
	    end = phiVals[i];
	    break;
	  }
      }
    error = (end-start)/2.0;
  }
    
  printf("Number of iterations = %d\n",it);
  printf("bestPhi = %g\n",bestPhi);
  printf("bestChisq = %g\n",bestChisq);
  for (i=0;i<nchan*npol+nchan;i++){
    printf("Best parameter: %d %g\n",i,bestParameters[i]);
  }

  fprintf(fout_log,"Number of iterations = %d\n",it);
  fprintf(fout_log,"bestPhi = %g\n",bestPhi);
  fprintf(fout_log,"bestChisq = %g\n",bestChisq);
  for (i=0;i<nchan*npol+nchan;i++){
    fprintf(fout_log,"Best parameter: %d %g\n",i,bestParameters[i]);
  }

  if (plotOutput == 1){
    float fx[nbin*2],fy[nbin*2],ft[nbin*2],dy[nbin*2];
    float miny,maxy;
    float miny2,maxy2;

    for (i=0;i<nbin;i++)
      {
	fx[i] = (float)i/(float)nbin;
	fx[i+nbin] = fx[i]+1;
	//	tmplEval = bestScale*evaluateTemplateChannel(tmpl,fx[i],chan,pol,bestPhi)+bestBaseline;
	
	fy[i] = obs->chan[chan].pol[pol].val[i];
	fy[i+nbin] = fy[i];
	ft[i] = tmplEval;
	ft[i+nbin] = ft[i];
	dy[i] = fy[i]-ft[i];
	dy[i+nbin] = dy[i];
      }
    findMinMax(nbin,fy,&miny,&maxy);
    findMinMax(nbin,dy,&miny2,&maxy2);

    cpgbeg(0,"/xs",1,1);
    cpgsvp(0.1,0.9,0.5,0.9);
    cpgeras();
    cpgswin(0,2,miny,maxy);
    cpgbox("BCTS",0.0,0,"BCTSN",0.0,0);


    cpgbin(nbin*2,fx,fy,1);
    cpgsci(2); cpgline(nbin*2,fx,ft); cpgsci(1);

    cpgsvp(0.1,0.9,0.15,0.5);
    cpgswin(0,2,miny2,maxy2);
    cpgbox("BCTSN",0.0,0,"BCTSN",0.0,0);
    cpglab("Phase","prof-tmpl","");
    cpgbin(nbin*2,fx,dy,1);



    cpgend();
  }
  toa->dphi = bestPhi;
  toa->dphiErr = error;

  for (i=0;i<nfit;i++)
    free(cvm[i]);
  free(cvm);
  free(fitX); free(fitY); free(fitE); free(fitI); free(fitJ); free(fitK);
  return;
}