/********************************/ /* fltr.c */ /* filter subroutines */ /********************************/ #include "focas1.h" #include "match1.h" #define END -1 #define PASS 1 #define FAIL 0 #define AFLAG 010000 #define BFLAG 01 #define CFLAG 020 #define DFLAG 02 #define EFLAG 04 #define HFLAG 0100 #define MFLAG 0200 #define PFLAG 020000 #define RFLAG 0400 #define SFLAG 01000 #define TFLAG 02000 #define WFLAG 010 #define YFLAG 040 #define ZFLAG 04000 static char *flthelp[] = { /* instructions */ " Options - Objects of particular classes are selected by strings", " beginning with a lower case character. The object class", " must match one of the strings exactly unless there is a", " trailing '-' in which case only the initial preceeding", " characters must match. Absence of class selections selects", " all classes and is equivalent to '-'.", " The upper case options must all be matched by the object.", "", " A min max - select objects with min < area <= max", " B - select split objects", " C - select split objects and parents", " D - select originally detected objects", " E - select objects without B flag and never split", " F [ABCDEFLPRS] - select objects with flags", " G [ABCDEFLPRS] - select objects without flags", " H - reject multiple objects", " I - reverse the sense of the filter, objects not selected", " by the other options are passed", " K k1 ... kn - select objects with entnum k1 ... kn", " M min max - select objects with magnitudes in range min - max", " N first last - select objects with numbers between first and last", " Rn min max - select objects with intensity moment radius irn", " (n = 1, 2, 3, 4) between min and max", " P pmin pmax - select objects with prob in range pmin to pmax", " S smin smax - select objects with scales in range smin - smax", " T tmin tmax - template fraction in range tmin - tmax", " W xl yl xh yh - select objects in window of scan coordinates", " Y xl yl xh yh - select objects in window of ra and dec", " Z min max - select objects with asymmetry between min and max", 0 }; static char *mflthelp[] = { /* instructions */ "Matched catalog filter options:", " w \"wmin wmax\" - select in given matching weight range", " c \"n1 n2 type cmin cmax\" - select by color where n1 and n2", " are the two entries to form color m1-m2, the magnitude", " type is one of (c a i t), and cmin and cmax are the", " color range (may be repeated for several colors).", " The color filter options must be quoted as a string!", " in include only entries with objects in catalog n", " en exclude entries with objects in catalog n", " fn \"filter options\" - filter objects from catalog n", " (if an entry does not contain an object from catalog n", " the filter fails). The filter options must be quoted as", " a string!", " Fn \"filter options\" - filter objects from catalog n", " (if an entry does not contain an object from catalog n", " the filter passes). The filter options must be quoted as", " a string!", " mn select objects with at least n components", " z remove all entries with class 'ignre'", " I complement the selections (pass objects failing the other", " options", 0 }; static int pass = PASS, fail = FAIL; static float hmag = -1000.0, lmag = 50.0; static float pmin = -10000., pmax = 10000.; static float smin = -1., smax = 10000.; static float tmin = 0., tmax = 10000.; static float rmin = 0., rmax = 1000.; static float zmin = 0., zmax = 1000.; static float armin = 0., armax = MXSZ; static int first = -100000, last = 100000; static int kflag = 0; static int flag = 0; static int eflgs = 0, neflgs = 0; static float skbr = -1e+30; static int ntypes = 0; static int modu = 1; static int mmnt = 0; static int wxl, wyl, wxh, wyh; static float yxl, yyl, yxh, yyh; static int klist[1000]; static char types[30][5]; static int zflag, Iflag, wtmin, wtmax, match; static int nclr, nclr1[MAXMATCH], nclr2[MAXMATCH]; static float clrmin[MAXMATCH], clrmax[MAXMATCH]; static char magtype[10]; static char imask, emask; static char mfltstr[MAXMATCH][80]; static short binary[] = {1, 2, 4, 8, 16, 32, 64, 128, 0, 0}; stflt (options) char *options; { int i, fltwds; char *fltptr[25], fltwd[25][10]; if (strlen (options)) { fltwds = sscanf (options, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", fltwd[0], fltwd[1], fltwd[2], fltwd[3], fltwd[4], fltwd[5], fltwd[6], fltwd[7], fltwd[8], fltwd[9], fltwd[10], fltwd[11], fltwd[12], fltwd[13], fltwd[14], fltwd[15], fltwd[16], fltwd[17], fltwd[18], fltwd[19], fltwd[20], fltwd[21], fltwd[22], fltwd[23], fltwd[24]); for (i = 0; i < fltwds; i++) fltptr[i] = fltwd[i]; } else fltwds = 0; return (setflt (fltwds, fltptr)); } setflt (argc, argv) int argc; char *argv[]; { int i, j, k; pass = PASS; fail = FAIL; hmag = -1000.0; lmag = 50.0; pmin = -10000.; pmax = 10000.; smin = -1.; smax = 10000.; tmin = 0.; tmax = 10000.; rmin = 0.; rmax = 1000.; zmin = 0.; zmax = 1000.; armin = 0.; armax = MXSZ; first = -100000; last = 100000; kflag = 0; flag = 0; eflgs = 0; neflgs = 0; skbr = -1e+30; ntypes = 0; modu = 1; mmnt = 0; if (argc < 1) return (0); if (argv[0][0] == '^') { for (i = 0; flthelp[i] != 0; i++) fprintf (stderr, "%s\n", flthelp[i]); return (1); } for (i = 0; i < argc; i++) switch (argv[i][0]) { case 'A': sscanf (argv[++i], "%hf", &armin); sscanf (argv[++i], "%hf", &armax); flag |= AFLAG; break; case 'B': flag |= BFLAG; break; case 'C': flag |= CFLAG; break; case 'D': flag |= DFLAG; break; case 'E': flag |= EFLAG; break; case 'F': k = strlen (argv[++i]); for (j = 0; j < k; j++) switch (argv[i][j]) { case 'F': eflgs |= FRCD; break; case 'L': eflgs |= SIZE; break; case 'C': eflgs |= CLSF; break; case 'A': eflgs |= ATTN; break; case 'S': eflgs |= SNGL; break; case 'B': eflgs |= EDGE; break; case 'P': eflgs |= PEAK; break; case 'D': eflgs |= DARK; break; case 'E': eflgs |= EVAL; break; case 'R': eflgs |= REFP; break; } break; case 'G': k = strlen (argv[++i]); for (j = 0; j < k; j++) switch (argv[i][j]) { case 'F': neflgs |= FRCD; break; case 'L': neflgs |= SIZE; break; case 'C': neflgs |= CLSF; break; case 'A': neflgs |= ATTN; break; case 'S': neflgs |= SNGL; break; case 'B': neflgs |= EDGE; break; case 'P': neflgs |= PEAK; break; case 'D': neflgs |= DARK; break; case 'E': neflgs |= EVAL; break; case 'R': neflgs |= REFP; break; } break; case 'H': flag |= HFLAG; break; case 'I': pass = FAIL; fail = PASS; case 'K': for (i++; i < argc; i++) { if ((argv[i][0] < '0') || (argv[i][0] > '9')) break; sscanf (argv[i], "%d", &klist[kflag++]); } i--; break; case 'M': sscanf (argv[++i], "%hf", &hmag); sscanf (argv[++i], "%hf", &lmag); eflgs |= EVAL; flag |= MFLAG; break; case 'N': sscanf (argv[++i], "%d", &first); sscanf (argv[++i], "%d", &last); break; case 'R': sscanf (argv[i], "R%d", &mmnt); sscanf (argv[++i], "%hf", &rmin); sscanf (argv[++i], "%hf", &rmax); eflgs |= EVAL; flag |= RFLAG; break; case 'P': sscanf (argv[++i], "%hf", &pmin); sscanf (argv[++i], "%hf", &pmax); flag |= PFLAG; break; case 'S': sscanf (argv[++i], "%hf", &smin); sscanf (argv[++i], "%hf", &smax); flag |= SFLAG; break; case 'T': sscanf (argv[++i], "%hf", &tmin); sscanf (argv[++i], "%hf", &tmax); flag |= TFLAG; break; case 'W': sscanf (argv[++i], "%d", &wxl); sscanf (argv[++i], "%d", &wyl); sscanf (argv[++i], "%d", &wxh); sscanf (argv[++i], "%d", &wyh); flag |= WFLAG; break; case 'Y': sscanf (argv[++i], "%hf", &yxl); sscanf (argv[++i], "%hf", &yyl); sscanf (argv[++i], "%hf", &yxh); sscanf (argv[++i], "%hf", &yyh); flag |= YFLAG; break; case 'Z': sscanf (argv[++i], "%hf", &zmin); sscanf (argv[++i], "%hf", &zmax); eflgs |= EVAL; flag |= ZFLAG; break; default: strcpy (types[ntypes++], argv[i]); break; } return (0); } ffilter (ob) struct objrec *ob; { int i, j, k; float v; if (ntypes > 0) { for (i = 0; i < ntypes; i++) { j = strlen (types[i]) - 1; for (k = 0; k <= j; k++) if (types[i][k] != '-') break; if (types[i][j] != '-') j = 5; if (strncmp (&ob->class[k], &types[i][k], j - k) == 0) break; } if (i == ntypes) return (fail); } if ((ob->entnum < first) || (ob->entnum > last)) return (fail); if (!((eflgs & ob->eflgs) == eflgs)) return (fail); if ((neflgs & ob->eflgs) != 0) return (fail); if ((flag & HFLAG) && (ob->class[0] == 'm')) return (fail); if ((flag & BFLAG) && ((ob->subent == 0) || (ob->class[0] == 'm'))) return (fail); if ((flag & CFLAG) && ((ob->subent == 0) && (ob->class[0] != 'm'))) return (fail); if ((flag & DFLAG) && (ob->subent != 0)) return (fail); if ((flag & EFLAG) && ((ob->subent != 0) || (ob->class[0] == 'm') || (ob->eflgs & EDGE))) return (fail); if ((flag & WFLAG) && ((ob->xc < wxl) || (ob->yc < wyl) || (ob->xc > wxh) || (ob->yc > wyh))) return (fail); if ((flag & YFLAG) && ((ob->ra < yxl) || (ob->dec < yyl) || (ob->ra > yxh) || (ob->dec > yyh))) return (fail); if ((flag & AFLAG) && ((ob->area < armin) || (ob->area > armax))) return (fail); if ((flag & MFLAG) && ((ob->mag >= lmag) || (ob->mag < hmag))) return (fail); if ((flag & PFLAG) && ((ob->prob < pmin) || (ob->prob > pmax))) return (fail); if ((flag & SFLAG) && ((ob->scale < smin) || (ob->scale > smax))) return (fail); if ((flag & TFLAG) & ((ob->frac < tmin) || (ob->frac > tmax))) return (fail); if ((flag & RFLAG) && mmnt) { switch (mmnt) { case 1: v = ob->ir1; break; case 2: v = ob->ixx + ob->iyy; v = v > 0. ? v : 0.; v = sqrt (v); break; case 3: v = pow (ob->ir3, 1./ 3.); break; case 4: v = ob->ir4; v = v > 0. ? v : 0.; v = sqrt (sqrt (v)); break; } if ((v < rmin) || (v > rmax)) return (fail); } if (flag & ZFLAG) { v = (ob->ixx - ob->iyy) * (ob->ixx - ob->iyy) + 4 * ob->ixy * ob->ixy; v = v > 0. ? v : 0.; v = sqrt (v) / (ob->ixx + ob->iyy); if ((v < zmin) || (v > zmax)) return (fail); } if (kflag) { for (k = 0; k < kflag; k++) if (ob->entnum == klist[k]) return (pass); return (fail); } return (pass); } mstflt (options) char *options; { int i, fltwds; char *fltptr[25], fltwd[25][10]; if (strlen (options)) { fltwds = sscanf (options, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", fltwd[0], fltwd[1], fltwd[2], fltwd[3], fltwd[4], fltwd[5], fltwd[6], fltwd[7], fltwd[8], fltwd[9], fltwd[10], fltwd[11], fltwd[12], fltwd[13], fltwd[14], fltwd[15], fltwd[16], fltwd[17], fltwd[18], fltwd[19], fltwd[20], fltwd[21], fltwd[22], fltwd[23], fltwd[24]); for (i = 0; i < fltwds; i++) fltptr[i] = fltwd[i]; } else fltwds = 0; return (msetflt (fltwds, fltptr)); } msetflt (argc, argv) int argc; char *argv[]; { int i, j, n, zflag = 0; Iflag = 0; imask = 0; emask = 0; wtmin = 0; wtmax = 255; nclr = 0; match = 0; for (i = 0; i < MAXMATCH; i++) mfltstr[i][0] = 0; if (argc < 1) return (0); if (argv[0][0] == '^') { for (i = 0; mflthelp[i] != 0; i++) fprintf (stderr, "%s\n", mflthelp[i]); return (1); } for (i = 0; i < argc; i++) switch (argv[i][0]) { case 'i': sscanf (argv[i], "i%d", &n); n--; imask |= binary[n]; break; case 'e': sscanf (argv[i], "e%d", &n); n--; emask |= binary[n]; break; case 'w': fprintf (stderr, "Select minimum and maximum weights: "); sscanf (argv[++i], "%d", &wtmin); sscanf (argv[++i], "%d", &wtmax); break; case 'c': if (nclr == MAXMATCH) { fprintf (stderr, "Too many colors\n"); break; } sscanf (argv[++i], "%d %d %s %hf %hf", &n, &j, magtype, &clrmin[nclr], &clrmax[nclr]); n--; j--; imask |= binary[n] | binary[j]; nclr1[nclr] = n; nclr2[nclr] = j; nclr++; break; case 'f': sscanf (argv[i], "f%d", &n); n--; imask |= binary[n]; strcpy (mfltstr[n], argv[++i]); break; case 'F': sscanf (argv[i], "F%d", &n); n--; strcpy (mfltstr[n], argv[++i]); break; case 'm': sscanf (argv[i], "m%d", &match); break; case 'z': zflag = 1; break; case 'I': Iflag = 1; break; } return (0); } mfilter (msp, mentry, mob) struct sgparm *msp; struct mentry *mentry; struct objrec *mob; { int i, flag, wt; float color, magselect (); flag = PASS; if (~(mentry->entries | (~imask))) flag = FAIL; if (mentry->entries & emask) flag = FAIL; wt = mentry->wt & 0377; if (wt < wtmin) flag = FAIL; if (wt > wtmax) flag = FAIL; if (charbits (mentry->entries) < match) flag = FAIL; for (i = 0; i < ncats; i++) { if (mob[i].entnum < 0) continue; if (zflag && (strcmp (mob[i].class, "ignre") == 0)) flag = FAIL; stflt (mfltstr[i]); if (ffilter (&mob[i]) == 0) flag = FAIL; } if (flag != FAIL) { for (i = 0; i < nclr; i++) { color = magselect (&msp[nclr1[i]], &mob[nclr1[i]], magtype) - magselect (&msp[nclr2[i]], &mob[nclr2[i]], magtype); if ((color < clrmin[i]) || (color > clrmax[i])) flag = FAIL; } } return ((!Iflag && (flag!=FAIL)) || (Iflag && (flag==FAIL))); } float magselect (sp, ob, type) struct sgparm *sp; struct objrec *ob; char *type; { switch (type[0]) { case 'i': return (ob->mag); case 'a': if (ob->Lfca > 0.) return (sp->magfst - 2.5 * log10 (ob->Lfca)); else return (0.); case 't': if (ob->Ltotal > 0.) return (sp->magfst - 2.5 * log10 (ob->Ltotal)); else return (0.); case 'c': if (ob->Lc > 0.) return (sp->magfst - 2.5 * log10 (ob->Lc)); else return (0.); } }