include include define NC 3 # number of columns for output table define MASK_GOOD 0 # anything else is bad # flmakev -- make a vmask table procedure flmakev() pointer inmask # scratch for name of input mask image pointer outtable # scratch for name of output mask table #-- pointer sp pointer im # imhdr pointer for input mask pointer mask # pointer to mask data pointer tp # pointer to table structure pointer cp[NC] # pointers to column descriptors char cname[SZ_COLNAME,NC] # column names char cunits[SZ_COLUNITS,NC] # units for columns char cfmt[SZ_COLFMT,NC] # print formats for columns int dtype[NC] # data type of each column int lendat[NC] # length of array (1) int naxis1, naxis2 # size of image int k pointer immap(), imgs2s(), tbtopn() begin call smark (sp) call salloc (inmask, SZ_FNAME, TY_CHAR) call salloc (outtable, SZ_FNAME, TY_CHAR) call clgstr ("inmask", Memc[inmask], SZ_FNAME) call clgstr ("outtable", Memc[outtable], SZ_FNAME) # Open input mask image. im = immap (Memc[inmask], READ_ONLY, NULL) naxis1 = IM_LEN(im,1) naxis2 = IM_LEN(im,2) # Initialize output table. tp = tbtopn (Memc[outtable], NEW_FILE, NULL) # Define columns in output table. call strcpy ("x", cname[1,1], SZ_COLNAME) call strcpy ("ylow", cname[1,2], SZ_COLNAME) call strcpy ("yhigh", cname[1,3], SZ_COLNAME) do k = 1, NC { call strcpy ("pixel", cunits[1,k], SZ_COLUNITS) call strcpy ("%5d", cfmt[1,k], SZ_COLFMT) dtype[k] = TY_INT lendat[k] = 1 } call tbcdef (tp, cp, cname, cunits, cfmt, dtype, lendat, NC) # Create the output table. call tbtcre (tp) # Get the mask into memory. mask = imgs2s (im, 1, naxis1, 1, naxis2) # Read mask and put data into table. call fl_mask_tab (tp, cp, Mems[mask], naxis1, naxis2) call sfree (sp) call tbtclo (tp) call imunmap (im) end procedure fl_mask_tab (tp, cp, mask, naxis1, naxis2) pointer tp # i: pointer to table structure pointer cp[NC] # i: pointer to column descriptors short mask[naxis1,naxis2] # i: mask int naxis1, naxis2 # i: size of mask #-- int x, y # x coordinates of a pixel int ylow, yhigh # range of y within which mask indicates bad int row # row number begin row = 0 # initial value # Loop through the image in the "wrong" order. do x = 1, naxis1 { ylow = naxis2 + 1 # indicates no masked region found yet yhigh = -1 do y = 1, naxis2 { if (mask[x,y] == MASK_GOOD) { if (ylow <= yhigh) { # We have a masked region. Write it to the table. row = row + 1 call tbepti (tp, cp[1], row, x) call tbepti (tp, cp[2], row, ylow) call tbepti (tp, cp[3], row, yhigh) ylow = naxis2 + 1 yhigh = -1 } } else { # Current pixel is masked out; update ylow, yhigh. if (ylow > y) # else it's already set ylow = y yhigh = y } } if (ylow <= yhigh) { # We have a masked region. Write it to the table. row = row + 1 call tbepti (tp, cp[1], row, x) call tbepti (tp, cp[2], row, ylow) call tbepti (tp, cp[3], row, yhigh) } } end