procedure texpand (onlyOne,singleDir,dirFile,contoIraf,delFits) 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 contoIraf {no, prompt="Convert expanded fits to IRAF format?"} bool delFits {no, prompt="Delete fits files if 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: !ls *.fits.Z > temp_fullnames.out # Generating other lists with appropriate extensions etc: flist = "temp_fullnames.out" while ( fscan(flist, dummy) != EOF) { k = strlen(dummy) dummy2 = substr(dummy, 1, (k-7)) 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 shellLine = "uncompress "//dummy2//".fits.Z" print (shellLine, >> "temp_script.out") shellLine = "/bin/rm "//dummy2//".fits" print (shellLine, >> "temp_delscript.out") } # Uncompressing: print (" ") print (" Uncompressing fits images ...") ! chmod 777 temp_script.out ! temp_script.out # Convert to IRAF if need be: if (contoIraf==yes) { print(" ") print (" Converting fits to IRAF format images ...") rfits(fits_fil="@temp_fits.out",file_lis="-", iraf_fil="@temp_noextns.out",make_im+,long_he-,short_h+,dataty="",blank=0., scale+,oldiraf-,offset=0,flpar-) } # Delete fits versions if requested: if ((delFits==yes)&&(contoIraf==yes)) { # i.e. images were originally in fits format so converting # them to IRAF has generated a second set. Deleting fits ones: print (" ") print (" Deleting uncompressed fits images ..") ! chmod 777 temp_delscript.out ! temp_delscript.out # **N.B: running a script such as this allows us to leave other # fits files in the same directory (that were *not* compressed # originally) untouched } 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