procedure chkimg (images,action) string images ="" {prompt="IRAF image name"} string action ="access" {prompt="check for", enum="access|noaccess"} bool ok =no {prompt="result of I/O action?"} string imroot ="" {prompt="image root name"} int imglen =0 {prompt="length of image root name"} string imtype ="" {prompt="image file format"} string imrpstr ="" {prompt="image region/plane"} int iostat =0 {prompt="integer I/O status"} bool verbose =yes {prompt="verbose error message?"} # @(#) task chkimg Author: R.A. Jansen -- Feb 4 1998 # @(#) # @(#) task to check the I/O status of an IRAF image, return the image # @(#) root name and character length thereof. The 'action' switch con- # @(#) trols whether the tasks tests for existence or non-existence of # @(#) the image. If 'imtype' is non-empty upon invokation of this task, # @(#) only images of type 'imtype' will be searched, otherwise the cur- # @(#) rent image type is returned. The 'iostat' parameter returns the # @(#) I/O status of the image regardless of 'action', where iostat=0,1 # @(#) means that the image does not exist or exists, respectively. The # @(#) verbose switch allows for an error message to be returned to the # @(#) standard output, the value of which depends on 'action'. # @(#) # @(#) Jun 14 2000 -- Added support for multi-extension / N-dim. images. begin string img, type, cmode, ctyp, cpln int i, j, ilen, tlen bool bok img = images cmode = action bok = no ilen = 0 iostat = 0 type = imtype ctyp = "Image \"" # Get image format type... if ( type == "" ) { type = "."//envget("imtype") } else { if ( substr(type,1,1) != "." ) { type = "."//type } if ( type == ".file" ) { type = "" ctyp = "File \"" } } # Check whether a plane in a N-dimensional image was specified # and/or an image section... i = stridx("[",img) j = stridx(" ",img) if ( j == 0 ) { j = strlen(img) + 1 } if ( i > 0 ) { cpln = substr(img,i,j-1) img = substr(img,1,i-1) imrpstr = cpln # Check whether region string conforms to valid format... rpparse (cpln, verbose=yes) } # Get image root name... tlen = strlen(type) ilen = strlen(img) if ( substr(img,ilen-tlen+1,ilen) == type ) { img = substr(img,1,ilen-tlen) #if ( type == ".fits" || type == ".imh" ) { ilen = ilen - tlen } ilen = ilen - tlen } # Get I/O status... if ( access(img//type) ) { if ( cmode == "access") { bok = yes iostat = 1 } else { bok = no iostat = 0 } } else { if ( cmode == "noaccess" ) { bok = yes } } # Verbose output on error... if ( !bok && verbose ) { if ( cmode == "access" ) { print ("ERROR: "//ctyp//img//type//"\" not found!") } else { print ("ERROR: "//ctyp//img//type//"\" already exists!") } } # Update task parameters... imroot = img ok = bok imtype = type imglen = ilen end