#include "focas1.h" #include "setjmp.h" #include "review.h" /* REVIEW -- Review FOCAS catalogs */ #define IISDEV 3 /* Display: 1=IISM70, 2=IISM75, 3=IMTOOL*/ #define NEXT 1 #define CONT 2 #define LAST 3 #define PREV 4 #define NEAR 5 #define SAME 6 static char *cmds[] = { "# catalog [1-4]", ". cursor select", "a set class", "b set flags", "c continue", "d set display", "e evaluate", "f set filter", "g aperture mag", "h locate objects", "i remove", "j field display", "k object display", "l last", "m move cursor", "n next", "o set overlays", "p previous", "q quit", "r resolution", "u set ref point", "v set view size", "w redisplay", "x cursor on/off", "y redraw terminal", "z zoom", ": shell command", "T write text", "", 0 }; jmp_buf env; struct objrec ob[ARMAX]; struct areas area[ARMAX]; static nextob = 0; static struct image q; static int rmflag = 0, chflag = 0; static int vdx = 0, vdy = 0; review (argc, argv) int *argc; char *argv[]; { struct objrec *o; struct areas *ar; char orient; float size; long bkcat (); int i, j, k, n, ns, res, curs[2]; short entnum; long subent; int diag; char ca[120], str[120]; float grow, ap, dmin, dmax; float ref1 = 0, ref2 = 0; int ftype = 1, center = 0, fldflg = 0; setr (); nreview = *argc; if (nreview > NWNDW) nreview = NWNDW; k = nreview; if (k == NWNDW) k = nreview - 1; p[k].pic = NULL; initrev (IISDEV); for (i = 0; i < nreview; i++) { printf ("Review %s: Copy files and read catalog\n", argv[i]); fflush (stdout); sprintf (cfile[i], "review%-d.tmp", i + 1); c_delete (cfile[i]); c_copy (argv[i], cfile[i]); cfd = catopen (cfile[i], 2); cffd[i] = cfd; sprintf (afile[i], "revareas%-d.tmp", i + 1); c_delete (afile[i]); c_copy (sp.arfl, afile[i]); afd = fndar (afile[i], 2); arfd[i] = afd; nobs[i] = getpos (i); sptflag[i] = 0; iobs[i] = 0; cathdr[i] = sp; printf ("Review %s: Display %s", argv[i], sp.ptfl); fflush (stdout); iferr (pfd = fndfld (sp.ptfl, 2)) { dmin = (0.- pthdr.dzero) / pthdr.dscale; dmax = (255.- pthdr.dzero) / pthdr.dscale; printf (" - display range (%.4g %.4g) = ", dmin, dmax); fflush (stdout); if (strlen (gets (str))) { sscanf (str, "%hf%hf", &dmin, &dmax); pthdr.dscale = 255./ (dmax - dmin); pthdr.dzero = -pthdr.dscale * dmin; } } else { dmin = (0.- pthdr.dzero) / pthdr.dscale; dmax = (255.- pthdr.dzero) / pthdr.dscale; printf (" - display range (%.4g %.4g) = ", dmin, dmax); fflush (stdout); if (strlen (gets (str))) { sscanf (str, "%hf%hf", &dmin, &dmax); pthdr.dscale = 255./ (dmax - dmin); pthdr.dzero = -pthdr.dscale * dmin; wtimhdr (pfd, &pthdr); } } pffd[i] = pfd; imhdr[i] = pthdr; window[i] = i; p[i].pic = NULL; getfld (i, 0, window[i], 0); } terminit (); mvaddstr (0, 20, "FOCAS IMAGE REVIEW"); refresh (); curcat = 0; chcat (curcat); iiswdw (window[curcat]); werase (win0); mvwaddstr (win0, 0, 0, argv[curcat]); mvwaddstr (win0, 1, 0, sp.pltnm); wrefresh (win0); fillwin (win1, cmds); chwin (win5, "Filter: "); fseek (cfd, offset[curcat][iobs[curcat]], 0); for (j = SAME;;) { chwin (win6, ""); if (getnext (j, &ob[1]) == 0) chwin (win6, "Object not found"); else ob[0] = ob[1]; o = &ob[0]; ar = &area[0]; rdarea (afd, o->entnum, o->subent, o->arpos, ar); VIEW: if (fldflg) { if (ca[0] != '.') fdisplay (curcat, window[curcat], o, ar, vdx, vdy, 1); switch (iisdev) { case 1: case 2: curs[0] = lpcoords (o->xc,1,2) - p[window[curcat]].x0 + 0.5; curs[1] = lpcoords (o->yc,2,2) - p[window[curcat]].y0 + 0.5; break; case 3: /* res = 4; */ res = 1; curs[0] = res * (lpcoords (o->xc,1,2) - p[window[curcat]].x0) + 0.5; curs[1] = res * (lpcoords (o->yc,2,2) - p[window[curcat]].y0) + 0.5; break; } } else { if (fldflag[window[curcat]]) { pfd = pffd[curcat]; pthdr = imhdr[curcat]; sp = cathdr[curcat]; getfld (curcat, 0, window[curcat], 0); } curs[0] = lpcoords (o->xc, 1, 2) / red[curcat] + 0.5; curs[1] = lpcoords (o->yc, 2, 2) / red[curcat] + 0.5; } iiscrm (window[curcat], 1, curs); drwovrlys (curcat, window[curcat], o, ar); reviewsig (2); setjmp (env); for (j = 0; j == 0;) { putstatus (win2, o); chwin (win3, "Command: "); ca[0] = wgetch (win3); switch (ca[0]) { case 'u': sprintf (str, "\nReference coordinates (%g %g): ", ref1, ref2); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (strlen (ca)) sscanf (ca, "%hf%hf", &ref1, &ref2); o->ra = ref1; o->dec = ref2; o->eflgs |= REFP; break; case '1': chflag = 1; j = SAME; break; case '2': chflag = 2; j = SAME; break; case '3': chflag = 3; j = SAME; break; case '4': chflag = 4; j = SAME; break; case 'j': fldflg = 0; for (i = 0; i < nreview; i++) window[i] = i; iiswdw (window[curcat]); goto VIEW; break; case 'k': fldflg = 1; if (window[curcat] == k) { if (window[curcat] == NWNDW - 1) k = k - 1; else k = k + 1; } for (i = 0; i < nreview; i++) window[i] = k; iiswdw (window[curcat]); goto VIEW; break; case 'a': sprintf (str, "\nClass: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if ((o->class[0] == 'm') && (ca[0] != 'm')) rmflag = 1; else if (ca[0] == 'm') rmflag = 0; o->eflgs |= FRCD | SNGL; strcpy (o->class, ca); break; case 'b': setflgs (o); fillwin (win1, cmds); break; case 'c': j = CONT; break; case 'e': chwin (win6, ""); if ((nreview == 1) || (sp.pflags & LNR)) { if (o->subent == 0) o->sbr = 0.; if (evlobj (o, ar, 1, stdout)) sprintf (str, "Evaluation unsuccessful"); waddstr (win6, str); wrefresh (win6); } else /* There is a problem with the film curve */ chwin (win6, "Option not available"); break; case 'f': chflt (); j = SAME; break; case 'l': j = LAST; break; case 'n': j = NEXT; break; case 'p': j = PREV; break; case 'd': dtrack (window[curcat]); fillwin (win1, cmds); break; case 'h': locate (o, ar); break; case 'o': setovrlys (curcat, window[curcat], o, ar, vdx, vdy); fillwin (win1, cmds); break; case '.': j = NEAR; break; case 'q': reviewsig (1); fseek (cfd, offset[curcat][iobs[curcat]], 0); wtcat (o, cfd); chwin (win1, ""); chwin (win3, ""); for (i = 0; i < nreview; i++) { fclose (cffd[i]); fclose (arfd[i]); imclose (pffd[i]); sprintf (str, "Save changes for %s? ", argv[i]); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (ca[0] != 'y') { c_delete (cfile[i]); c_delete (afile[i]); } else { /* if (sptflag[i]) sprintf (str, "<%s ffilter I ignre|catsort n>%s;rm %s;mv -f %s %s", cfile[i], argv[i], cfile[i], afile[i], cathdr[i].arfl); else sprintf (str, "<%s ffilter I ignre>%s;rm %s;mv -f %s %s", cfile[i], argv[i], cfile[i], afile[i], cathdr[i].arfl); */ c_delete (argv[i]); c_rename (cfile[i], argv[i]); c_delete (cathdr[i].arfl); c_rename (afile[i], cathdr[i].arfl); } } termclose (); reviewsig (0); return; case 'i': j = SAME; strcpy (o->class, "ignre"); rmflag = 1; break; case 'v': sprintf (str, "\nMinimum display size: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (strlen (ca)) sscanf (ca, "%d%d", &vdx, &vdy); rdarea (afd, o->entnum, o->subent, o->arpos, ar); j = SAME; break; case 'g': chwin (win6, ""); if ((nreview == 1) || (sp.pflags & LNR)) { chwin (win3, ""); sprintf (str, "\nAperture radius in pixels: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); sscanf (ca, "%hf", &ap); if (aplum (o, ar, ap, stdout)) sprintf (str, "Evaluation unsuccessful"); waddstr (win6, str); wrefresh (win6); } else /* There is a problem with the film curve */ chwin (win6, "Option not available"); break; /* case 's': chwin (win6, ""); if ((nreview == 1) || (sp.pflags & LNR)) { chwin (win1, ""); sprintf (str, "\nSignificance for detection: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (strlen (ca)) sscanf (ca, "%hf", &sp.sig); sprintf (str, "Display splitting? "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (ca[0] == 'y') { diag = 1; iiswdw (nreview); iiserase (nreview, "f"); iiserase (nreview, "F"); } else diag = 0; n = msplit (o, ar, diag); if (n > 0) { chwin (win6, ""); sprintf (str, "Multiple object split into %d objects", n); waddstr (win6, str); wrefresh (win6); fseek (cfd, 0L, 2); for (ns = 1; ns <= n; ns++) { if (nobs[curcat] < MAXOBJ) { offset[curcat][nobs[curcat]] = fseek (cfd, 0L, 2); pos[curcat][nobs[curcat]][0] = ob[ns].xc; pos[curcat][nobs[curcat]][1] = ob[ns].yc; nobs[curcat]++; } ob[ns].arpos = wrarea (afd, &ob[ns], &area[ns]); wtcat (&ob[ns], cfd); } sptflag[curcat] = 1; if (nobs[curcat] < MAXOBJ) nextob = (nobs[curcat] - n); } else chwin (win6, "Failed to split object"); if (diag) iiswdw (window[curcat]); fillwin (win1, cmds); } else chwin (win6, "Option not available"); break; */ case 'r': chwin (win6, ""); if ((nreview == 1) || (sp.pflags & LNR)) { fit (o, ar, ftype, center, 0., 1.); classes (o); } else /* There is a problem with the film curve */ chwin (win6, "Option not available"); break; case 'x': iiswitch (window[curcat], 1); j = SAME; break; case 'z': iiszmsc (window[curcat]); break; case 'y': clear (); mvaddstr (0, 20, "FOCAS IMAGE REVIEW"); refresh (); werase (win0); mvwaddstr (win0, 0, 0, argv[curcat]); mvwaddstr (win0, 1, 0, sp.pltnm); wrefresh (win0); fillwin (win1, cmds); chwin (win5, "Filter: "); break; case 'w': imclose (pfd); pfd = fndfld (sp.ptfl, 0); pffd[curcat] = pfd; imhdr[curcat] = pthdr; getfld (curcat, 0, window[curcat], 0); cathdr[curcat] = sp; break; case ':': chwin (win3, ""); sprintf (str, "Shell command?: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (strlen (ca)) { system (ca); sprintf (str, "[Hit return to continue] "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); wrefresh (curscr); } chwin (win3, ""); break; case 'm': chwin (win3, ""); sprintf (str, "\nEnter x y position: "); waddstr (win3, str); wrefresh (win3); wgetstr (win3, ca); if (strlen (ca)) { sscanf (ca, "%d %d", &curs[0], &curs[1]); curs[0] = lpcoords ((float)curs[0], 1, 2); curs[1] = lpcoords ((float)curs[1], 2, 2); iiscrm (window[curcat], 1, curs); } chwin (win3, ""); break; case 'T': graphics_on = 'y'; chwin (win1, ""); sprintf (str, "Put cursor where text is to go and hit return: "); waddstr (win1, str); wrefresh (win1); wgetstr (win1, ca); iiscrm (window[curcat], 0, curs); sprintf (str, "Enter string: "); waddstr (win1, str); wrefresh (win1); wgetstr (win1, ca); sprintf (str, "Size (10): "); waddstr (win1, str); wrefresh (win1); wgetstr (win1, str); if (strlen (str)) sscanf (str, "%hf", &size); else size = 10; sprintf (str, "Orientation (h/v/u/d) (h): "); waddstr (win1, str); wrefresh (win1); wgetstr (win1, str); if (strlen (str)) sscanf (str, "%c", &orient); else orient = 'h'; nfont (ca, size, curs[0], curs[1], orient, window[curcat]); fillwin (win1, cmds); graphics_on = 'n'; break; default: sprintf (str, "\nUnknown command %c", ca[0]); waddstr (win3, str); wrefresh (win3); } } fseek (cfd, offset[curcat][iobs[curcat]], 0); wtcat (o, cfd); if (rmflag) { entnum = o->entnum; subent = o->subent; for (;;) { if (getnext (NEXT, o) == 0) chwin (win6, "Object not found"); if (entnum != o->entnum) break; if (subentry (entnum, subent, o->entnum, o->subent) == 1) { strcpy (o->class, "ignre"); fseek (cfd, offset[curcat][iobs[curcat]], 0); wtcat (o, cfd); } } fseek (cfd, offset[curcat][iobs[curcat]], 0); rdcatob (cfd, 0L, o); rmflag = 0; } if (chflag) { if (chflag <= nreview) chflag -= 1; else chflag = curcat; chcat (chflag); werase (win0); sprintf (str, "%s\n%s", argv[curcat], sp.pltnm); waddstr (win0, str); wrefresh (win0); chwin (win5, "Filter: "); sprintf (str, "%s", fltstr[curcat]); waddstr (win5, str); wrefresh (win5); stflt (fltstr[curcat]); iiswdw (window[curcat]); chflag = 0; } } } getnext (mode, o) int mode; struct objrec *o; { int i, iob, start; iob = start = iobs[curcat]; if (nextob >= 0) { iob = nextob - 1; fseek (cfd, offset[curcat][nextob], 0); } switch (mode) { case NEXT: iob++; if (iob > nobs[curcat] - 1) { iob = 0; fseek (cfd, offset[curcat][iob], 0); } rdcatob (cfd, 0L, o); break; case SAME: fseek (cfd, offset[curcat][iob], 0); iob--; start--; if (iob < 0) iob = start = nobs[curcat] - 1; case CONT: do { iob++; if (iob > nobs[curcat] - 1) { iob = 0; fseek (cfd, offset[curcat][iob], 0); } rdcatob (cfd, 0L, o); if (iob == start) return (0); } while (ffilter (o) == 0); break; case PREV: do { iob--; if (iob < 0) iob = nobs[curcat] - 1; fseek (cfd, offset[curcat][iob], 0); rdcatob (cfd, 0L, o); if (iob == start) return (0); } while (ffilter (o) == 0); break; case LAST: iob--; if (iob < 0) iob = nobs[curcat] - 1; fseek (cfd, offset[curcat][iob], 0); rdcatob (cfd, 0L, o); if (iob == start) return (0); break; case NEAR: iob = nearcr (curcat, window[curcat]); fseek (cfd, offset[curcat][iob], 0); rdcatob (cfd, 0L, o); break; } if (iob < MAXOBJ) iobs[curcat] = iob; nextob = -1; return (1); } locate (o, ar) struct objrec *o; struct areas *ar; { struct imiso imiso; struct liso *liso; char *calloc(), *malloc(), *realloc(); short i, j, k, l, n, nbytes, *tmp; int res, start, color, revcolor(); if (nisphts[window[curcat]] > 0) { switch (iisdev) { case 1: case 2: iiserase (window[curcat], "F"); break; case 3: res = 1; if (fldflag[window[curcat]]) fdisplay (curcat, window[curcat], o, ar, vdx, vdy, 1); } nisphts[window[curcat]] = 0; } if (fldflag[window[curcat]]) { getnext (SAME, o); start = iobs[curcat]; for (;;) { if (o->class[0] != 'm') { rdarea (afd, o->entnum, o->subent, o->arpos, ar); if (fldflag[window[curcat]]) iisispht (window[curcat], &p[window[curcat]], o, ar, res, revcolor (window[curcat], o->class)); else iisispht (window[curcat], &p[window[curcat]], o, ar, red[curcat], revcolor (window[curcat], o->class)); nisphts[window[curcat]]++; } getnext (CONT, o); if (iobs[curcat] == start) break; } } else { imiso.x0 = 0; imiso.y0 = 0; imiso.nx = pthdr.naxis1; imiso.ny = pthdr.naxis2; imiso.liso = (struct liso *) calloc (imiso.ny, sizeof (struct liso)); if (imiso.liso == 0) focaserr (1, "Memory allocation error", ""); getnext (SAME, o); start = iobs[curcat]; for (;;) { if (o->class[0] != 'm') { rdarea (afd, o->entnum, o->subent, o->arpos, ar); color = revcolor (window[curcat], o->class); for (i=0, j=ar->i.ychst, k=0; i < ar->i.nlines; i++, j--) { liso = &imiso.liso[j]; if (liso->nalloc < liso->nused + ar->i.nx[i]) { liso->nalloc = liso->nused + ar->i.nx[i] + 20; nbytes = liso->nalloc * sizeof (short); if (liso->xla == 0) { liso->xla = (short *) malloc (nbytes); liso->xra = (short *) malloc (nbytes); liso->color = (short *) malloc (nbytes); } else { /* liso->xla = (short *) realloc (liso->xla, nbytes); liso->xra = (short *) realloc (liso->xra, nbytes); liso->color = (short *) realloc (liso->color, nbytes); */ tmp = (short *) malloc (nbytes); for (l=0; lnused; l++) tmp[l] = liso->xla[l]; free (liso->xla); liso->xla = tmp; tmp = (short *) malloc (nbytes); for (l=0; lnused; l++) tmp[l] = liso->xra[l]; free (liso->xra); liso->xra = tmp; tmp = (short *) malloc (nbytes); for (l=0; lnused; l++) tmp[l] = liso->color[l]; free (liso->color); liso->color = tmp; } if (liso->xla==0 || liso->xra==0 || liso->color==0) focaserr (1, "Memory allocation error", ""); } n = liso->nused; for (; k < ar->i.nx[i]; k++) { liso->xla[n] = ar->i.xla[k]; liso->xra[n] = ar->i.xra[k]; liso->color[n] = color; n++; } liso->nused = n; } nisphts[window[curcat]]++; } getnext (CONT, o); if (iobs[curcat] == start) break; } getfld (curcat, &imiso, window[curcat], 0); for (i=0; i