procedure tbias (imageFile, trimoversc, imageDimen, createList, keepStats) string imageFile {prompt="List of images to be bias-subtracted"} bool trimoversc {yes, prompt="Remove overscan region?"} string imageDimen {"[1:1024,1:1024]", prompt="Image dimensions (excluding overscan)"} bool createList {yes, prompt="Create list (biass.lis) of output filenames?"} bool keepStats {no, prompt="Keep file (statsb.out) of overscan region statistics?"} struct *flist # list-directed structure to go thru imageFile begin # Variable Declarations: struct image # image currently being bias-subtracted string subArray # sub-array of image being bias-subtracted string newImage # bias-subtracted image int i, j # counters real meanBias # mean of overscan sampling 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 } # Reporting on status: if (createList == yes) { print("Writing output filenames to biass.lis...") } if (trimoversc == yes) { print("Trimming overscan...") } # Looping to form temporary file of sky background samples: i=0 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 newImage=image//"b" # Filename of bias-subtracted image # Performing image statistics on two overscan sub-arrays: subArray=image//"[1036:1047,201:250]" # print(subArray) imstat(images=subArray,fields="mean",format=no, >> "statsb.out") subArray=image//"[1036:1047,601:650]" # print(subArray) imstat(images=subArray,fields="mean",format=no, >> "statsb.out") average (option="new_sample", < "statsb.out", >> "statsb.out") meanBias=average.mean # Deleting the file containing overscan sample(s) if requested if (keepStats == no) { delete(files="statsb.out",go_ahead=yes,verify=no) } # print(image) # print(meanBias) # print(newImage) # Removing overscan region if requested: if (trimoversc == yes) { image = image//imageDimen print(image) } imarith (operand1=image,op="-",operand2=meanBias, result=newImage,verbose=no,noact=no) # Writing output filenames to a biass.lis: if (createList == yes) { print(newImage, >> "biass.lis") } # print("----------") } # print (i) # i.e. number of images de-biased end