static void demo3() { #define TWOPI (2.0*3.14159265) #define NPOL 6 int i, j, k; int n1[] = {3, 4, 5, 5, 6, 8}; int n2[] = {1, 1, 1, 2, 1, 3}; float x[10], y[10], y0; char* lab[] = {"Fill style 1 (solid)", "Fill style 2 (outline)", "Fill style 3 (hatched)", "Fill style 4 (cross-hatched)"}; /* Initialize the viewport and window. */ cpgbbuf(); cpgsave(); cpgpage(); cpgsvp(0.0, 1.0, 0.0, 1.0); cpgwnad(0.0, 10.0, 0.0, 10.0); /* Label the graph. */ cpgsci(1); cpgmtxt("T", -2.0, 0.5, 0.5, "PGPLOT fill area: routines cpgpoly(), cpgcirc(), cpgrect()"); /* Draw assorted polygons. */ for (k=1; k<5; k++) { cpgsci(1); y0 = 10.0 -2.0*k; cpgtext(0.2, y0+0.6, lab[k-1]); cpgsfs(k); for (i=0; i<NPOL; i++) { cpgsci(i+1); for (j=0; j<n1[i]; j++) { x[j] = i+1 + 0.5*cos(n2[i]*TWOPI*j/n1[i]); y[j] = y0 + 0.5*sin(n2[i]*TWOPI*j/n1[i]); } cpgpoly(n1[i], x, y); } cpgsci(7); cpgshs(0.0, 1.0, 0.0); cpgcirc(7.0, y0, 0.5); cpgsci(8); cpgshs(-45.0, 1.0, 0.0); cpgrect(7.8, 9.5, y0-0.5, y0+0.5); } cpgunsa(); cpgebuf(); return; }
void plot_image(struct image img,struct transformation t,struct catalog c,char *filename,float mmin) { int i; float tr[]={-0.5,1.0,0.0,-0.5,0.0,1.0}; float heat_l[]={0.0,0.2,0.4,0.6,1.0}; float heat_r[]={0.0,0.5,1.0,1.0,1.0}; float heat_g[]={0.0,0.0,0.5,1.0,1.0}; float heat_b[]={0.0,0.0,0.0,0.3,1.0}; float zmin,zmax,zavg,zstd; for (i=0,zavg=0.0;i<img.naxis1*img.naxis2;i++) zavg+=img.zavg[i]; zavg/=(float) img.naxis1*img.naxis2; for (i=0,zstd=0.0;i<img.naxis1*img.naxis2;i++) zstd+=pow(img.zavg[i]-zavg,2); zstd=sqrt(zstd/(float) (img.naxis1*img.naxis2)); zmin=zavg-2*zstd; zmax=zavg+6*zstd; cpgopen("1/xs"); cpgwnad(0.0,img.naxis1,0.0,img.naxis2); cpgctab (heat_l,heat_r,heat_g,heat_b,5,1.0,0.5); cpgimag(img.zavg,img.naxis1,img.naxis2,1,img.naxis1,1,img.naxis2,zmin,zmax,tr); cpgbox("BCTSNI",0.,0,"BCTSNI",0.,0); cpgsci(3); plot_pixel_catalog(filename); cpgsci(4); plot_astrometric_catalog(t,img,mmin); cpgsci(2); for (i=0;i<c.n;i++) cpgpt1(c.x[i]+t.x0,c.y[i]+t.y0,24); cpgend(); return; }
int main() { char infile[] = "pih.fits"; char devtyp[16], idents[3][80], nlcprm[1], opt[2]; int c0[] = {-1, -1, -1, -1, -1, -1, -1}; int i, ic, gcode[2], naxis[2], nkeyrec, nreject, nwcs, relax, status; float blc[2], trc[2]; double cache[257][4], grid1[1], grid2[1], nldprm[1]; struct wcsprm *wcs; nlfunc_t pgwcsl_; #if defined HAVE_CFITSIO && defined DO_CFITSIO char *header; fitsfile *fptr; #else char keyrec[81], header[28801]; int gotend, j, k; FILE *fptr; #endif /* Set line buffering in case stdout is redirected to a file, otherwise * stdout and stderr messages will be jumbled (stderr is unbuffered). */ setvbuf(stdout, NULL, _IOLBF, 0); printf("Testing WCSLIB parser for FITS image headers (tpih2.c)\n" "------------------------------------------------------\n\n"); /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */ #if defined HAVE_CFITSIO && defined DO_CFITSIO status = 0; if (fits_open_file(&fptr, infile, READONLY, &status)) { fits_report_error(stderr, status); return 1; } if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) { fits_report_error(stderr, status); return 1; } fits_close_file(fptr, &status); #else if ((fptr = fopen(infile, "r")) == 0x0) { printf("ERROR opening %s\n", infile); return 1; } k = 0; nkeyrec = 0; gotend = 0; for (j = 0; j < 10; j++) { for (i = 0; i < 36; i++) { if (fgets(keyrec, 81, fptr) == 0) { break; } if (strncmp(keyrec, " ", 8) == 0) continue; if (strncmp(keyrec, "COMMENT ", 8) == 0) continue; if (strncmp(keyrec, "HISTORY ", 8) == 0) continue; strncpy(header+k, keyrec, 80); k += 80; nkeyrec++; if (strncmp(keyrec, "END ", 8) == 0) { /* An END keyrecord was read, but read the rest of the block. */ gotend = 1; } } if (gotend) break; } fclose(fptr); #endif fprintf(stderr, "Found %d non-comment header keyrecords.\n", nkeyrec); relax = WCSHDR_all; if ((status = wcspih(header, nkeyrec, relax, 2, &nreject, &nwcs, &wcs))) { fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcs_errmsg[status]); } #if defined HAVE_CFITSIO && defined DO_CFITSIO free(header); #endif /* Plot setup. */ naxis[0] = 1024; naxis[1] = 1024; blc[0] = 0.5f; blc[1] = 0.5f; trc[0] = naxis[0] + 0.5f; trc[1] = naxis[1] + 0.5f; strcpy(devtyp, "/XWINDOW"); cpgbeg(0, devtyp, 1, 1); cpgvstd(); cpgwnad(0.0f, 1.0f, 0.0f, 1.0f); cpgask(1); cpgpage(); /* Annotation. */ strcpy(idents[0], "Right ascension"); strcpy(idents[1], "Declination"); opt[0] = 'G'; opt[1] = 'E'; /* Compact lettering. */ cpgsch(0.8f); /* Draw full grid lines. */ cpgsci(1); gcode[0] = 2; gcode[1] = 2; grid1[0] = 0.0; grid2[0] = 0.0; for (i = 0; i < nwcs; i++) { if ((status = wcsset(wcs+i))) { fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]); continue; } /* Get WCSNAME out of the wcsprm struct. */ strcpy(idents[2], (wcs+i)->wcsname); printf("\n%s\n", idents[2]); /* Draw the celestial grid. The grid density is set for each world */ /* coordinate by specifying LABDEN = 1224. */ ic = -1; cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); /* Draw the frame. */ cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0); cpgpage(); } status = wcsvfree(&nwcs, &wcs); return 0; }
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; }
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); }
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; }
int main(int argc, char **argv) { char alt = '\0', *header, idents[3][80], *infile, keyword[16], nlcprm[1], opt[2], pgdev[16]; int c0[] = {-1, -1, -1, -1, -1, -1, -1}; int alts[27], gcode[2], hdunum = 1, hdutype, i, ic, naxes, naxis[2], nkeyrec, nreject, nwcs, stat[NWCSFIX], status; float blc[2], trc[2]; double cache[257][4], grid1[3], grid2[3], nldprm[1]; struct wcsprm *wcs; nlfunc_t pgwcsl_; fitsfile *fptr; /* Parse options. */ strcpy(pgdev, "/XWINDOW"); for (i = 1; i < argc && argv[i][0] == '-'; i++) { if (!argv[i][1]) break; switch (argv[i][1]) { case 'a': alt = toupper(argv[i][2]); break; case 'd': if (argv[i][2] == '?') { cpgldev(); return 0; } if (argv[i][2] == '/') { strncpy(pgdev+1, argv[i]+3, 15); } else { strncpy(pgdev+1, argv[i]+2, 15); } break; case 'h': hdunum = atoi(argv[i]+2); break; default: fprintf(stderr, "%s", usage); return 1; } } if (i < argc) { infile = argv[i++]; if (i < argc) { fprintf(stderr, "%s", usage); return 1; } } else { infile = "-"; } /* Check accessibility of the input file. */ if (strcmp(infile, "-") && access(infile, R_OK) == -1) { printf("wcsgrid: Cannot access %s.\n", infile); return 1; } /* Open the FITS file and move to the required HDU. */ status = 0; if (fits_open_file(&fptr, infile, READONLY, &status)) goto fitserr; if (fits_movabs_hdu(fptr, hdunum, &hdutype, &status)) goto fitserr; if (hdutype != IMAGE_HDU) { fprintf(stderr, "ERROR, HDU number %d does not contain an image array.\n", hdunum); return 1; } /* Check that we have at least two image axes. */ if (fits_read_key(fptr, TINT, "NAXIS", &naxes, NULL, &status)) { goto fitserr; } if (naxes < 2) { fprintf(stderr, "ERROR, HDU number %d does not contain a 2-D image.\n", hdunum); return 1; } else if (naxes > 2) { printf("HDU number %d contains a %d-D image array.\n", hdunum, naxes); } /* Read in the FITS header, excluding COMMENT and HISTORY keyrecords. */ if (fits_hdr2str(fptr, 1, NULL, 0, &header, &nkeyrec, &status)) { goto fitserr; } /* Interpret the WCS keywords. */ if ((status = wcspih(header, nkeyrec, WCSHDR_all, -3, &nreject, &nwcs, &wcs))) { fprintf(stderr, "wcspih ERROR %d: %s.\n", status, wcshdr_errmsg[status]); return 1; } free(header); /* Read -TAB arrays from the binary table extension (if necessary). */ if (fits_read_wcstab(fptr, wcs->nwtb, (wtbarr *)wcs->wtb, &status)) { goto fitserr; } /* Translate non-standard WCS keyvalues. */ if ((status = wcsfix(7, 0, wcs, stat))) { status = 0; for (i = 0; i < NWCSFIX; i++) { if (stat[i] > 0) { fprintf(stderr, "wcsfix ERROR %d: %s.\n", stat[i], wcsfix_errmsg[stat[i]]); /* Ignore problems with CDi_ja and DATE-OBS. */ if (!(i == CDFIX || i == DATFIX)) status = 1; } } if (status) return 1; } /* Sort out alternates. */ if (alt) { wcsidx(nwcs, &wcs, alts); if (alt == ' ') { if (alts[0] == -1) { fprintf(stderr, "WARNING, no primary coordinate representation, " "doing all.\n"); alt = '\0'; } } else if (alt < 'A' || alt > 'Z') { fprintf(stderr, "WARNING, alternate specifier \"%c\" is invalid, " "doing all.\n", alt); alt = '\0'; } else { if (alts[alt - 'A' + 1] == -1) { fprintf(stderr, "WARNING, no alternate coordinate representation " "\"%c\", doing all.\n", alt); alt = '\0'; } } } /* Get image dimensions from the header. */ sprintf(keyword, "NAXIS%d", wcs->lng + 1); fits_read_key(fptr, TINT, "NAXIS1", naxis, NULL, &status); sprintf(keyword, "NAXIS%d", wcs->lat + 1); fits_read_key(fptr, TINT, "NAXIS2", naxis+1, NULL, &status); if ((naxis[0] < 2) || (naxis[1] < 2)) { fprintf(stderr, "ERROR, HDU number %d contains degenerate image axes.\n", hdunum); return 1; } fits_close_file(fptr, &status); /* Plot setup. */ blc[0] = 0.5f; blc[1] = 0.5f; trc[0] = naxis[0] + 0.5f; trc[1] = naxis[1] + 0.5f; if (cpgbeg(0, pgdev, 1, 1) != 1) { fprintf(stderr, "ERROR, failed to open PGPLOT device %s.\n", pgdev); return 1; } cpgvstd(); cpgwnad(blc[0], trc[0], blc[0], trc[1]); cpgask(1); cpgpage(); /* Compact lettering. */ cpgsch(0.8f); /* Draw full grid lines. */ gcode[0] = 2; gcode[1] = 2; grid1[0] = 0.0; grid2[0] = 0.0; /* These are for the projection boundary. */ grid1[1] = -180.0; grid1[2] = 180.0; grid2[1] = -90.0; grid2[2] = 90.0; cpgsci(1); for (i = 0; i < nwcs; i++) { if (alt && (wcs+i)->alt[0] != alt) { continue; } if ((status = wcsset(wcs+i))) { fprintf(stderr, "wcsset ERROR %d: %s.\n", status, wcs_errmsg[status]); continue; } /* Draw the frame. */ cpgbox("BC", 0.0f, 0, "BC", 0.0f, 0); /* Axis labels; use CNAMEia in preference to CTYPEia. */ if ((wcs+i)->cname[0][0]) { strcpy(idents[0], (wcs+i)->cname[0]); } else { strcpy(idents[0], (wcs+i)->ctype[0]); } if ((wcs+i)->cname[1][0]) { strcpy(idents[1], (wcs+i)->cname[1]); } else { strcpy(idents[1], (wcs+i)->ctype[1]); } /* Title; use WCSNAME. */ strcpy(idents[2], (wcs+i)->wcsname); if (strlen(idents[2])) { printf("\n%s\n", idents[2]); } /* Formatting control for celestial coordinates. */ if (strncmp((wcs+i)->ctype[0], "RA", 2) == 0) { /* Right ascension in HMS, declination in DMS. */ opt[0] = 'G'; opt[1] = 'E'; } else { /* Other angles in decimal degrees. */ opt[0] = 'A'; opt[1] = 'B'; } /* Draw the celestial grid. The grid density is set for each world */ /* coordinate by specifying LABDEN = 1224. */ ic = -1; cpgsbox(blc, trc, idents, opt, 0, 1224, c0, gcode, 0.0, 0, grid1, 0, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); /* Delimit the projection boundary. */ if ((wcs+i)->cel.prj.category != ZENITHAL) { /* Reset to the native coordinate graticule. */ (wcs+i)->crval[0] = (wcs+i)->cel.prj.phi0; (wcs+i)->crval[1] = (wcs+i)->cel.prj.theta0; (wcs+i)->lonpole = 999.0; (wcs+i)->latpole = 999.0; status = wcsset(wcs+i); ic = -1; cpgsbox(blc, trc, idents, opt, -1, 0, c0, gcode, 0.0, 2, grid1, 2, grid2, 0, pgwcsl_, 1, WCSLEN, 1, nlcprm, (int *)(wcs+i), nldprm, 256, &ic, cache, &status); } cpgpage(); } status = wcsvfree(&nwcs, &wcs); return 0; fitserr: fits_report_error(stderr, status); fits_close_file(fptr, &status); return 1; }
/* set window and adjust viewport to same aspect ratio */ static void _pgwnad (double *xmin, double *xmax, double *ymin, double *ymax) { cpgwnad ((float) *xmin, (float) *xmax, (float) *ymin, (float) *ymax); }