# T_COPYMASK -- Copy a mask to a bad pixel list (or vice versa) # # The input images are given by an image template list. The output # is either a matching list of images or a directory. If the number # of dimensions (ndim) is zero, the output mask will have the same # number of groups as the input image. If the number of dimensions # is positive, but less than the number of dimensions in the input # image, extra dimensions will be converted into groups. # # B.Simon 16-Jan-91 Original procedure t_copymask () #-- pointer input # Input image list pointer output # Output image list int ndim # Number of dimensions in output mask bool verbose # Print operations? int rootlen pointer sp, inmask, outmask, indir, outdir, temp, inlist, outlist string mismatch "Number of input and output images not the same" int clgeti(), imtopen(), imtgetim(), imtlen() int fnldir(), isdirectory() bool clgetb() begin # Allocate dynamic memory for strings call smark (sp) call salloc (input, SZ_FNAME, TY_CHAR) call salloc (output, SZ_FNAME, TY_CHAR) call salloc (inmask, SZ_PATHNAME, TY_CHAR) call salloc (outmask, SZ_PATHNAME, TY_CHAR) call salloc (indir, SZ_PATHNAME, TY_CHAR) call salloc (outdir, SZ_PATHNAME, TY_CHAR) call salloc (temp, SZ_PATHNAME, TY_CHAR) # Get task parameters call clgstr ("input", Memc[input], SZ_FNAME) call clgstr ("output", Memc[output], SZ_FNAME) ndim = clgeti ("ndim") verbose = clgetb ("verbose") # Check if the output string is a directory. if (isdirectory (Memc[output], Memc[outdir], SZ_PATHNAME) > 0) { inlist = imtopen (Memc[input]) while (imtgetim (inlist, Memc[inmask], SZ_PATHNAME) != EOF) { # Strip the image section first because fnldir recognizes it # as part of a directory. Place the input image name # without a directory or image section in string indir. call imgcluster (Memc[inmask], Memc[temp], SZ_PATHNAME) rootlen = fnldir (Memc[temp], Memc[indir], SZ_PATHNAME) call strcpy (Memc[outdir], Memc[outmask], SZ_PATHNAME) call strcat (Memc[temp+rootlen], Memc[outmask], SZ_PATHNAME) call copymask (Memc[inmask], Memc[outmask], ndim, verbose) } call imtclose (inlist) } else { # Expand the input and output image lists. inlist = imtopen (Memc[input]) outlist = imtopen (Memc[output]) if (imtlen (inlist) != imtlen (outlist)) { call imtclose (inlist) call imtclose (outlist) call error (1, mismatch) } # Do each set of input/output images. while ((imtgetim (inlist, Memc[inmask], SZ_PATHNAME) != EOF) && (imtgetim (outlist, Memc[outmask], SZ_PATHNAME) != EOF)) { call copymask (Memc[inmask], Memc[outmask], ndim, verbose) } call imtclose (inlist) call imtclose (outlist) } call sfree (sp) end