include include include define NOCHECK 1 define P_CHECK 2 define C_CHECK 3 # For checking coordinates, the ratio (cdelt1 / cdelt2) must be within # these limits; otherwise, we will refuse to dezoom. define LOW_RATIO 1.8 define HIGH_RATIO 2.3 # T_DEZOOMX -- dezoom FOC image by splitting pixels into 2 equal parts # # Dave Giaretta wrote the original. # Small change, Richard Hook, ST-ECF, Dec 88, force dezoom # even if problem with world coordinates # Phil Hodge, 11-Mar-1992 Set pxlcorr = COMPLETE after dezooming. # Phil Hodge, 29-Oct-1992 Use imastr instead of impstr for pxlcorr; # in dezlabel change coordinate handling; move # check to dezcheck, dezlabel updates coord param.; # if we're not dezooming, don't copy either. # Phil Hodge, 22-Jan-1993 !IS_INDEFR (Change) to !IS_INDEF. procedure t_dezoomx () char image1[SZ_FNAME], image2[SZ_FNAME] int clgwrd() char key_check[SZ_LINE] bool verbose char list[SZ_LINE] int inlist # Input image list int outlist # Output image list pointer in, out pointer outbuf, inbuf, imgl2r(), impl2r() pointer immap() long line, inpix, outpix, npts real temp int imtopen(), imtgetim() int pixtype, check bool clgetb(), dezcheck() char dtype[SZ_LINE] errchk immap, clgetb, clgwrd, imgl2r, impl2r begin # Get task parameters. call clgstr ("input", list, SZ_LINE) inlist = imtopen (list) call clgstr ("output", list, SZ_LINE) outlist = imtopen (list) check = clgwrd( "check", key_check, SZ_LINE, ",none,pxformt,cd") switch ( clgwrd( "pixtype", dtype, SZ_LINE, ",real,long,short,int,double") ) { case 1: pixtype = TY_REAL case 2: pixtype = TY_LONG case 3: pixtype = TY_SHORT case 4: pixtype = TY_INT case 5: pixtype = TY_DOUBLE } verbose = clgetb("verbose") # Loop through input images. while ((imtgetim (inlist, image1, SZ_FNAME) != EOF) && (imtgetim (outlist, image2, SZ_FNAME) != EOF)) { # check we can open input and output, and that input has # dimension 2 iferr (in = immap (image1, READ_ONLY, 0)) { call erract (EA_WARN) next } if (IM_NDIM(in) != 2) { call eprintf ("image %s has dimension %d; cannot dezoom \n") call pargstr( image1 ) call pargi( IM_NDIM(in) ) call imunmap(in) next } # Check whether we should dezoom this image. if ( ! dezcheck (in, check)) { call eprintf ("Skipping %s because it's not in zoom format.\n") call pargstr (image1) call imunmap (in) next } iferr (out = immap (image2, NEW_COPY, in)) { call imunmap (in) call erract (EA_WARN) next } IM_PIXTYPE (out) = pixtype # Dezoom the CD matrix and CRPIX1. call dezlabel (in, out) if (verbose) { call printf ("dezooming %s ---> %s\n") call pargstr( image1 ) call pargstr( image2 ) call flush( STDOUT) } # set the axis length IM_LEN(out, 1) = IM_LEN(in, 1)*2 # Do it. npts = IM_LEN(in, 1) do line = 1, IM_LEN(in, 2) { inbuf = imgl2r( in, line) outbuf = impl2r( out, line) do inpix = 0, npts-1 { temp = Memr[inbuf + inpix] if ( !IS_INDEFR (temp) ) temp = temp/2.0 outpix = 2*inpix Memr[outbuf+outpix] = temp Memr[outbuf+outpix+1] = temp } } # Set pxlcorr to "COMPLETE" so we can tell from the header # that the image has been dezoomed. call imastr (out, "pxlcorr", "COMPLETE") # close files call imunmap (out) call imunmap (in) } call imtclose (inlist) call imtclose (outlist) end bool procedure dezcheck (in, check) pointer in # i: input image int check # i: what should we check for zoom? #-- bool unzoom # true if we should dezoom; this is returned char pxformt[SZ_LINE] real cd[2,2] # CD matrix real cdelt[2] # pixel spacing for each axis real ratio # cdelt1 / cdelt2 bool cd_found # true if CD matrix found in input bool coords_ok # true if either CD matrix or CDELT found real imgetr() int imaccf() bool streq() begin unzoom = true # Get CD matrix. cd_found = true # initial values coords_ok = true cd[1,1] = 1. cd[2,2] = 1. if (imaccf (in, "cd1_1") == YES) cd[1,1] = imgetr (in, "cd1_1") else cd_found = false if (imaccf (in, "cd2_1") == YES) cd[2,1] = imgetr (in, "cd2_1") else cd[2,1] = 0. if (imaccf (in, "cd1_2") == YES) cd[1,2] = imgetr (in, "cd1_2") else cd[1,2] = 0. if (imaccf (in, "cd2_2") == YES) cd[2,2] = imgetr (in, "cd2_2") else cd_found = false if (!cd_found) { # See if we can find cdelt1 & cdelt2 instead of the CD matrix. if (imaccf (in, "cdelt1") == YES && imaccf (in, "cdelt2") == YES) { cdelt[1] = abs (imgetr (in, "cdelt1")) cdelt[2] = abs (imgetr (in, "cdelt2")) } else { coords_ok = false } } # check if required for PXFORMT = zoom, or CDELT1 twice CDELT2 switch ( check ) { case NOCHECK: unzoom = true case P_CHECK: if (imaccf (in, "PXFORMT") == YES) call imgstr (in, "PXFORMT", pxformt, SZ_LINE) else call strcpy( EOS, pxformt, SZ_LINE) if ( streq( pxformt, "ZOOM") ) unzoom = true else unzoom = false case C_CHECK: if (coords_ok) { if (cd_found) { cdelt[1] = sqrt (cd[1,1]**2 + cd[2,1]**2) cdelt[2] = sqrt (cd[1,2]**2 + cd[2,2]**2) } if (cdelt[1] == 0. || cdelt[2] == 0.) { call eprintf ("Warning: CD matrix is singular.\n") } else { ratio = cdelt[1] / cdelt[2] unzoom = (ratio > LOW_RATIO && ratio < HIGH_RATIO) } } else { call eprintf ( "You specified check=cd, but this image doesn't have coordinate parameters.\n") } } return ( unzoom ) end procedure dezlabel (in, out) pointer in # i: input image pointer out # i: output image #-- real crpix1 # reference pixel in first axis real cd1_1, cd2_1 # first column of CD matrix real cdelt1 # pixel spacing for first axis real imgetr() int imaccf() begin # Get the first column of the CD matrix, divide by two, # and put into the output image. if (imaccf (in, "cd1_1") == YES) { cd1_1 = imgetr (in, "cd1_1") / 2. call imaddr (out, "cd1_1", cd1_1) if (imaccf (in, "cd2_1") == YES) { cd2_1 = imgetr (in, "cd2_1") / 2. call imaddr (out, "cd2_1", cd2_1) } } else if (imaccf (in, "cdelt1") == YES) { # See if we can find cdelt1 instead of the CD matrix. cdelt1 = imgetr (in, "cdelt1") / 2. call imaddr (out, "cdelt1", cdelt1) } # Reference pixel for first axis. if (imaccf (in, "crpix1") == YES) { crpix1 = imgetr (in, "crpix1") crpix1 = crpix1 * 2. - 0.5 call imaddr (out, "crpix1", crpix1) } end