include include define SZ_KEYWRD 8 # CHGKEYWRD -- Change the names of selected keywords in an image header # # This task reads a text file which is in free format and contains two # identfiers on each line. The first identifier is the name of an existing # keyword in an image header and the second is a new name for that keyword. # Each line of the file is read, and if the keyword is found in the header # or the group parameter block, the old name is replaced by the new name. # # B.Simon 01-Jun-87 Original procedure chgkeywrd () #-- pointer image # Name of the image whose keywords are renamed pointer keyfile # Name of file containing the keywords int ic, nc pointer oldfield, newfield, oldkey, newkey pointer sp, im, fd, rp string badformat "WARNING: Line in keyword file ignored: incorrect format\n" string keytoolong "WARNING: Keyword too long: truncated to 8 characters\n" int fscan(), nscan(), strlen(), idb_findrecord(), can_replace() pointer immap(), open() begin call smark (sp) call salloc (image, SZ_FNAME, TY_CHAR) call salloc (keyfile, SZ_FNAME, TY_CHAR) call salloc (oldfield, SZ_LINE, TY_CHAR) call salloc (newfield, SZ_LINE, TY_CHAR) call salloc (oldkey, SZ_KEYWRD, TY_CHAR) call salloc (newkey, SZ_KEYWRD, TY_CHAR) call clgstr ("image", Memc[image], SZ_FNAME) call clgstr ("keyfile", Memc[keyfile], SZ_FNAME) # Open the image and keyword file im = immap (Memc[image], READ_WRITE, NULL) fd = open (Memc[keyfile], READ_ONLY, TEXT_FILE) # Read each line from the keyword file, replacing keywords while (fscan (fd) != EOF) { call gargwrd (Memc[oldfield], SZ_LINE) call gargwrd (Memc[newfield], SZ_LINE) if (nscan() != 2) call eprintf (badformat) else { if (strlen (Memc[oldfield]) > SZ_KEYWRD) call eprintf (keytoolong) if (strlen (Memc[newfield]) > SZ_KEYWRD) call eprintf (keytoolong) call strcpy (Memc[oldfield], Memc[oldkey], SZ_KEYWRD) call strupr (Memc[oldkey]) call strcpy (Memc[newfield], Memc[newkey], SZ_KEYWRD) call strupr (Memc[newkey]) if (idb_findrecord (im, Memc[oldkey], rp) != 0 && can_replace (Memc[oldkey]) == YES ) { # Blank out the old keyword and replace with the new do ic = 0, 7 Memc[rp+ic] = ' ' nc = min (strlen (Memc[newkey]), SZ_KEYWRD) do ic = 0, nc - 1 Memc[rp+ic] = Memc[newkey+ic] } } } call imunmap (im) call close (fd) call sfree (sp) end