void psOutput(int *hist, char *psFile) /* Output histogram in postscript format. */ { double labelSize = 72.0/2; double psInnerSize = psSize - labelSize; double tickSize = labelSize/4; double textSize = labelSize - tickSize; struct psGfx *ps = psOpen(psFile, psSize, psSize, psSize, psSize, margin); double val, maxVal = findMaxVal(hist); int x, y, both; double grayScale; double xPos, yPos, xMid; double xBinPts = psInnerSize/xBins; double yBinPts = psInnerSize/yBins; grayScale = 1.0 / maxVal * postScale; for (y=0; y<yBins; ++y) { int yg = yBins-1-y; yPos = yg*yBinPts; for (x=0; x<xBins; ++x) { xPos = x * xBinPts + labelSize; both = y*xBins + x; val = mightLog(hist[both]) * grayScale; if (val > 1.0) val = 1.0; if (val < 0.0) val = 0.0; psSetGray(ps, 1.0 - val); boxOut(ps, xPos, yPos, xBinPts, yBinPts); } } /* Draw ticks and labels. */ psSetGray(ps, 0); yPos = psInnerSize; for (x=labelStep; x<xBins; x += labelStep) { char buf[16]; sprintf(buf, "%d", x*xBinSize+xMin); xPos = x * xBinPts + labelSize; xMid = xPos; psDrawBox(ps, xPos, yPos, 1, tickSize); psTextDown(ps, xPos, yPos+tickSize+2, buf); } for (y=labelStep; y<yBins; y += labelStep) { char buf[16]; int yg = yBins-y; sprintf(buf, "%d", y*yBinSize+yMin); yPos = yg*yBinPts; psDrawBox(ps, textSize, yPos, tickSize, 1); psTextAt(ps, 0, yPos, buf); } psClose(&ps); }
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(); }