include include define SZ_KEYWRD 8 # IMKEYNAME -- Rename an image with one of its header keywords # # This task expands a file name template into a list of images. It opens # each image and reads the value of the designated keyword. It converts the # keyword to lower case and concatenates it to the directory name. It then # renames the image. # # Written by B.Simon on 31 March 88 procedure imkeyname () #-- bool verbose # Print file names as they are changed pointer dirname # Directory name used in new image name pointer keyword # Header keyword containing new image name pointer ilist # Input image template pointer sp, old, new, im string nokeywrd "Warning: Keyword not found in %s\n" bool clgetb() int imtgetim() pointer immap() pointer imtopenp() begin # Allocate dynamic memory used to hold strings call smark (sp) call salloc (old, SZ_FNAME, TY_CHAR) call salloc (new, SZ_FNAME, TY_CHAR) call salloc (keyword, SZ_FNAME, TY_CHAR) call salloc (dirname, SZ_FNAME, TY_CHAR) # Read task parameters ilist = imtopenp ("image") call clgstr ("keyword", Memc[keyword], SZ_KEYWRD) call clgstr ("dirname", Memc[dirname], SZ_FNAME) verbose = clgetb ("verbose") # Loop over all images named in template while (imtgetim (ilist, Memc[old], SZ_FNAME) != EOF) { # Read header keyword from image im = immap (Memc[old], READ_ONLY, NULL) ifnoerr { call imgstr (im, Memc[keyword], Memc[new], SZ_FNAME) } then { # Change image name call imunmap (im) call strlwr (Memc[new]) call imnewname (Memc[old], Memc[dirname], Memc[new], verbose) } else { # Print warning message call imunmap (im) call fprintf (STDERR, nokeywrd) call pargstr (Memc[old]) call flush (STDERR) } } # Task cleanup call imtclose (ilist) call sfree (sp) end