include include define SZ_KEYWRD 8 # IMAGREE -- Modify image header keywords to agree with the file name # # This task expands a file name template into a list of images. It opens # each image and modifies the value of the designated keywords so that # they agree with the image header and data file names. # # B.Simon 02-Dec-88 Original procedure t_imagree () #-- pointer ilist # Input image template pointer hkey # Name of parameter containing header file name pointer dkey # Name of parameter containing data file name bool verbose # Print file names as they are changed bool hasdat, noerr int ic pointer sp, hfile, hroot, droot, hval, dval, im string nokeywrd "Warning: Keyword `%s' not found in %s\n" bool clgetb(), isblank() int imtgetim(), fnldir() pointer immap(), imtopenp() begin # Set flush on newline for output call fseti (STDOUT, F_FLUSHNL, YES) # Allocate dynamic memory used to hold strings call smark (sp) call salloc (hfile, SZ_FNAME, TY_CHAR) call salloc (hroot, SZ_FNAME, TY_CHAR) call salloc (droot, SZ_FNAME, TY_CHAR) call salloc (hval, SZ_FNAME, TY_CHAR) call salloc (dval, SZ_FNAME, TY_CHAR) call salloc (hkey, SZ_KEYWRD, TY_CHAR) call salloc (dkey, SZ_KEYWRD, TY_CHAR) # Read task parameters ilist = imtopenp ("image") call clgstr ("header", Memc[hkey], SZ_KEYWRD) call clgstr ("data", Memc[dkey], SZ_KEYWRD) verbose = clgetb ("verbose") # See if the data keyword needs to be changed hasdat = ! isblank (Memc[dkey]) # Loop over all images named in template while (imtgetim (ilist, Memc[hfile], SZ_FNAME) != EOF) { im = immap (Memc[hfile], READ_WRITE, NULL) # Create the file name strings ic = fnldir (Memc[hfile], Memc[hval], SZ_FNAME) call strcpy (Memc[hfile+ic], Memc[hroot], SZ_FNAME) call sprintf (Memc[hval], SZ_FNAME, "%s%19t") call pargstr (Memc[hroot]) call strupr (Memc[hval]) if (hasdat) { call imdfile (Memc[hroot], Memc[droot], SZ_FNAME) call sprintf (Memc[dval], SZ_FNAME, "%s%19t") call pargstr (Memc[droot]) call strupr (Memc[dval]) } # Modify header and data keywords in image noerr = true iferr { call impstr (im, Memc[hkey], Memc[hval]) } then { noerr = false call eprintf (nokeywrd) call pargstr (Memc[hkey]) call pargstr (Memc[hroot]) } if (hasdat) { iferr { call impstr (im, Memc[dkey], Memc[dval]) } then { noerr = false call eprintf (nokeywrd) call pargstr (Memc[dkey]) call pargstr (Memc[hroot]) } } call imunmap (im) # Print diagnostic message if (verbose && noerr) { if (hasdat) call printf ("Keywords modified in %s\n") else call printf ("Keyword modified in %s\n") call pargstr (Memc[hfile]) } } # Task cleanup call imtclose (ilist) call sfree (sp) end