procedure rpparse(imrpstr) string imrpstr ="" {prompt="image region/plane string"} bool ok =no {prompt="is string a valid section/plane?"} int xlo =0 {prompt="x_start"} int xhi =0 {prompt="x_end"} int ylo =0 {prompt="y_start"} int yhi =0 {prompt="y_end"} real xcen =0. {prompt="x_center"} real ycen =0. {prompt="y_center"} int pln =0 {prompt="image plane (N-dim images)"} bool verbose =yes {prompt="verbose error message?"} # @(#) task rpparse Author: R.A. Jansen -- August 25 2000 # @(#) # @(#) task to test and parse an image region/plane string of generic # @(#) format [pln][xlo:xhi,ylo:yhi], where the image plane is optional. # @(#) Xlo, xhi, ylo, yhi, as well as xcen, ycen and pln are returned as # @(#) task parameters (int). This task generalizes task 'gprst48' in # @(#) the 'CCD48' package. # @(#) Jul 18 2002 -- # of image planes no longer restricted to 7. RAJ. begin string cstr, csav, cpln int i, j, ierr, llen, comm, col1, col2 cstr = imrpstr csav = cstr cpln = "0" ierr = 0 # Check whether a string was given. Note that an empty string is a # valid regions/plane string as it would mean the whole 2-D image ... llen = strlen(cstr) if ( llen == 0 ) { ierr = -1 } # Check whether 'imrpstr' conforms to a valid format... # image sections must start with a '[' i = stridx("[",cstr) if ( ierr == 0 && i != 1 ) { ierr = 2 } # image sections must end with a ']' if ( ierr == 0 && substr(cstr,llen,llen) != ']' ) { ierr = 3 } # check whether a plane identifier [0](HST!),[1]--[19] is included j = stridx("]",cstr) if ( j == 3 ) { cpln = substr(cstr,2,2) if ( ierr == 0 && cpln != "0" && cpln != "1" && cpln != "2" && cpln != "3" && cpln != "4" && cpln != "5" && cpln != "6" && cpln != "7" && cpln != "8" && cpln != "9" ) { ierr = 4 } cstr = substr(cstr,4,llen) llen = strlen(cstr) } else if ( j == 4 ) { cpln = substr(cstr,2,3) if ( ierr == 0 && cpln != "10" && cpln != "11" && cpln != "12" && cpln != "13" && cpln != "14" && cpln != "15" && cpln != "16" && cpln != "17" && cpln != "18" && cpln != "19" ) { ierr = 4 } cstr = substr(cstr,5,llen) llen = strlen(cstr) } if ( ierr == 0 && j == 5 ) { ierr = 4 } # no more than at most two '[' can be present i = stridx("[",cstr) if ( ierr == 0 && i != 1 && llen > 0 ) { ierr = 5 } if ( ierr == 0 && stridx("[",substr(cstr,i+1,llen)) != 0 ) { ierr = 5 } if ( ierr == 5 && substr(cstr,llen-2,llen-2) == "[" && substr(cstr,llen-3,llen-3) == "]" ) { ierr = 8 } # no more than at most two ']' can be present j = stridx("]",cstr) if ( ierr == 0 && j != llen ) { ierr = 6 } if ( ierr == 6 && substr(cstr,llen-2,llen-2) == "[" && substr(cstr,llen-3,llen-3) == "]" ) { ierr = 8 } # check whether a image section is included col1 = stridx (":", cstr) comm = stridx(",",cstr) col2 = stridx (":", substr(cstr,comm,llen)) if ( ierr == 0 && comm < col1 && comm != 0 ) { ierr = 9 } if ( ierr == 0 && ( col1 == 0 || comm == 0 || col2 == 0 ) && llen > 0 ) { ierr = 7 } if ( ierr == 7 && comm == 0 ) { j = stridx (":", substr(cstr,col1+1,llen)) if ( j == 0 && col1 != 0 ) { ierr = 0 } } # Verbose output on error... if ( ierr != 0 && verbose ) { if ( ierr == -1 ) { #print ("WARNING: empty image region/plane string \"\"!") ierr = 0 } if ( ierr == 2 ) { print ("ERROR: \""//imrpstr//"\" must start with a \"[\"!") } if ( ierr == 3 ) { print ("ERROR: \""//imrpstr//"\" must end with a \"]\"!") } if ( ierr == 4 ) { print ("ERROR: image plane id must be an integer in range (0)1..19!") } if ( ierr == 5 ) { print ("ERROR: \""//imrpstr//"\" contains more than two \"[\"'s!") } if ( ierr == 6 ) { print ("ERROR: \""//imrpstr//"\" contains more than two \"]\"'s!") } if ( ierr == 7 ) { print ("ERROR: \""//imrpstr//"\" invalid image section!") } if ( ierr == 8 ) { print ("ERROR: \""//imrpstr//"\" plane identifier must precede section!") } if ( ierr == 9 ) { print ("ERROR: \""//imrpstr//"\" incorrect order of comma and colon!") } } # Update task parameters... imrpstr = csav ok = no xlo = 0 xhi = 0 ylo = 0 yhi = 0 xcen = 0. ycen = 0. pln = 0 if ( ierr == 0 ) { # String 'imrpstr' conforms to a valid format... ok = yes pln = int(cpln) if ( llen > 0 && comm != 0 ) { xlo = int(substr(cstr,2,col1-1)) xhi = int(substr(cstr,col1+1,comm-1)) ylo = int(substr(cstr,comm+1,comm+col2-2)) yhi = int(substr(cstr,comm+col2,llen-1)) xcen = 0.5*(xhi-xlo)+xlo ycen = 0.5*(yhi-ylo)+ylo } if ( llen > 0 && comm == 0 ) { xlo = int(substr(cstr,2,col1-1)) xhi = int(substr(cstr,col1+1,llen-1)) xcen = 0.5*(xhi-xlo)+xlo } } end