######################################################################### # This is a procedure to dissect an input string which is presumed # # to be an image section into its component start/end pixels in each # # dimension. The results are obtained by querying the task parameters. # # # # The first thing to query after running is the numdim parameter. # # If this is <=0, the input string was not parseable as a section. # # # # This is a very early cut at a task like this. There are many # # problems. # # # # This will bomb badly if the string looks like [1:2,3,4:5] or # # if there are any wildcards like [1:2,*,4:5] # # # # Steve Allen (sla@lick.ucsc.edu) 1993 August 22 # # # # This IRAF cl script is Copyright (c) 1993 Steven L. Allen # ######################################################################### procedure parsec (secstr) string secstr {prompt = 'Input image section string'} int numdim=0 {prompt = "return: # of dimensions",mode="h"} int sp[7]=7(0) {prompt = "return: Start pixels",mode="h"} int ep[7]=7(0) {prompt = "return: End pixels",mode="h"} begin string thisdim # "sp:ep" strings from each dimension string remainder # the unparsed remainder of the input string spaced # eachdim with space replacing colon int bc, len # index position of boundary, length real s, e # foo int i # loop # prompt the user for the query parameters remainder = secstr s = 0 e = 0 # find the opening bracket bc = stridx("[", remainder) len = strlen(remainder) # strip it off remainder = substr(remainder, bc+1, len) len = strlen(remainder) # loop thru all remaining parts of the string, parsing as we go for ( i=1; i<=7; i += 1) { # look for the end of this set of dimension limits bc = stridx(",]", remainder) if (bc <= 1) { # we appear to be done with the string, get out of the loop break } else { # pick out the piece representing the next dimension thisdim = substr(remainder, 1, bc-1) # set the remainder for the next pass thru the loop remainder = substr(remainder, bc+1, len) # try to split the string in half bc = stridx(":", thisdim) if (bc <= 1) { # if no colon in middle, we are badly confused numdim = 0 bye } len = strlen(thisdim) spaced = substr(thisdim,1,bc-1)//" "//substr(thisdim,bc+1,len) # We have to read into real variables because "a:b" would # be parsed correctly as the ASCII character values if s and e # were integer variables. len = fscan(spaced, s, e) if (len != 2) { numdim = 0 bye } sp[i] = int(s) ep[i] = int(e) # set up length of remainder for next pass thru the loop len = strlen(remainder) } } numdim = i - 1 end