procedure tsample (imageFile, zinit, zfinal, zstep, reg1, all, reg2, reg3, reg4, outFile) string imageFile {prompt="List of images to be sampled (no @ symbol)"} int zinit {prompt="CS100 z-value for first image"} int zfinal {prompt="CS100 z-value for final image"} int zstep {prompt="Increment of z between images"} string reg1 {prompt="Image region 1 for sampling"} bool all {yes, prompt="Sample one region only?"} string reg2 {prompt="Image region 2 for sampling"} string reg3 {prompt="Image region 3 for sampling"} string reg4 {prompt="Image region 4 for sampling"} string outFile {prompt="Name of output file"} struct *flist # list-directed structure to go thru imageFile begin # Variable Declarations: struct image # image currently being sampled int i # image counter string imageRegion # image region being sampled string list1values # contains list1 values for JOINLINES routine string noteline1 string noteline2 string noteline3 string noteline4 int zcurrent # current z-value flist = imageFile # putting the contents of the list contained in imageFile # to the list-directed structure *flist # Make sure the IMAGES package is loaded: if (! defpac ("images")) { print("IMAGES package not loaded") bye } # Make sure the PROTO package is loaded: if (! defpac ("proto")) { print("PROTO package not loaded") bye } # Looping to form temporary file of sky background samples: i=0 zcurrent = zinit while ( fscan(flist, image) != EOF) { # Getting rid of the ".imh" extension if present: j = strlen(image) if (substr (image, j-3, j) == ".imh") image = substr (image, 1, j-4) i=i+1 print (zcurrent, >> "num.out") print (image," ",zcurrent) # For Region 1: imageRegion=image//reg1 imstat(images=imageRegion,fields="mean",format=no, >> "reg1.out") # For remaining regions (if requested): if (all == no) { imageRegion=image//reg2 imstat(images=imageRegion,fields="mean",format=no, >> "reg2.out") imageRegion=image//reg3 imstat(images=imageRegion,fields="mean",format=no, >> "reg3.out") imageRegion=image//reg4 imstat(images=imageRegion,fields="mean",format=no, >> "reg4.out") } zcurrent = zcurrent+zstep } # Joining lists together: # list1values = imageFile//", num.out, reg1.out" list1values = "num.out, reg1.out" # this is defined so that filename listed under imageFile can be used if (all == yes) { joinlines(list1=list1values,output=outFile,delim=" ") print ("# sliceNum z-value region1", >> outFile) print ("# ", >> outFile) noteline1 = "# Region 1 = "//reg1 print (noteline1, >> outFile) # print (noteline5, >> outFile) } if (all == no) { joinlines(list1=list1values,output="lis1.out",delim=" ") joinlines(list1="lis1.out, reg2.out",output="lis2.out",delim=" ") joinlines(list1="lis2.out, reg3.out",output="lis3.out",delim=" ") joinlines(list1="lis3.out, reg4.out",output=outFile,delim=" ") print ("# sliceNum z-value region1 region2 region3 region4", >> outFile) print ("# ", >> outFile) noteline1 = "# Region 1 = "//reg1 noteline2 = "# Region 2 = "//reg2 noteline3 = "# Region 3 = "//reg3 noteline4 = "# Region 4 = "//reg4 print (noteline1, >> outFile) print (noteline2, >> outFile) print (noteline3, >> outFile) print (noteline4, >> outFile) print ("# ", >> outFile) # print (noteline5, >> outFile) } type (input_file=outFile) zcurrent = zcurrent-zstep if (zcurrent==zfinal) { print("Final value of zcurrent agrees with zfinal...") } else { print("Final value of zcurrent DISAGREES with zfinal...") print(zcurrent) print(zfinal) } # Adding file headings (at end of file): # Deleting temporary files: delete(files="reg?.out",go_ahead=yes,verify=no) delete(files="lis?.out",go_ahead=yes,verify=no) delete(files="num.out",go_ahead=yes,verify=no) end