procedure tshrink (onlyOne,singleDir,dirFile,alreadyFits,delIraf) bool onlyOne {yes, prompt="Only the one directory to search?"} string singleDir {".", prompt="Name of that directory"} string dirFile {prompt="Otherwise, file listing multiple directories"} bool alreadyFits {no, prompt="Are files already in fits format?"} bool delIraf {no, prompt="Delete IRAF format files once converted?"} struct *flist # list-directed structure to go thru dirFile begin # Variable Declarations: struct currentDir # current directory from dirFile string shellLine # shell command line int exLength # character length of image extension int k # character length of file name dummy string dummy # filename in list string dummy2 # same as dummy except without extension # Make sure the IMAGES package is loaded: if (! defpac ("images")) { print("IMAGES package not loaded") bye } if (! defpac ("dataio")) { print("DATAIO package not loaded") bye } # Clearing any files to be used: delete (files="temp_*.out",verify=no,default=yes,go_ahead=yes) # Checking if just the one directory: if (onlyOne==yes) { print (singleDir, >> "temp_dirfile.out") dirFile = "temp_dirfile.out" } # Main loop: flist = dirFile while ( fscan(flist, currentDir) != EOF) { chdir (currentDir) delete (files="temp_*.out",verify=no,default=yes,go_ahead=yes) print (" ") print (" Directory to work on:") ! pwd print (" ") # Generate list of files to work on: if (alreadyFits==no) { !ls *.pix > temp_fullnames.out exLength = 3 } if (alreadyFits==yes) { !ls *.fits > temp_fullnames.out exLength = 4 } # Generating other lists with appropriate extensions etc: flist = "temp_fullnames.out" while ( fscan(flist, dummy) != EOF) { k = strlen(dummy) dummy2 = substr(dummy, 1, (k-exLength-1)) print (dummy2, >> "temp_noextns.out") # i.e. list file minus the image extensions print (dummy2//".fits", >> "temp_fits.out") # i.e. list file with .fits extensions (created even # if original images *were* fits images; in this case, # temp_fits.out == temp_fullnames.out . shellLine = "compress "//dummy2//".fits" print (shellLine, >> "temp_script.out") } # Convert to fits if need be: if (alreadyFits==no) { print(" ") print (" Converting IRAF format images to fits ...") wfits(iraf_fil="@temp_noextns.out",fits_fil="@temp_fits.out", make_im+,long_he-,short_h+,bitpix=0,blockin=0,scale+,autosca+, bscale=1.,bzero=0.,flpar-) } # Compress: print (" ") print (" Compressing fits images ...") ! chmod 777 temp_script.out ! temp_script.out # Delete iraf versions if need be: if ((delIraf==yes)&&(alreadyFits==no)) { # i.e. images were originally in IRAF format so converting # them to fits has generated a second set. Deleting that: print (" ") print (" Deleting IRAF version of images ..") imdelete(images="@temp_noextns.out",verify-,default+,go_ahead+) } delete (files="temp_*.out",verify=no,default=yes,go_ahead=yes) if (currentDir!=".") { chdir("..") # i.e. only go back up a level if specified dir is not "." } } # Cleaning up stray list files: delete (files="temp_*.out",verify=no,default=yes,go_ahead=yes) if (onlyOne==yes) { dirFile = "" } # resetting dirFile back to nothing if it was empty originally print (" ") print (" Done.") end