subroutine exchange (a, old, new) character*(*) a, old, new c Exchanges occurrences of 'OLD' for 'NEW' within 'A' c NOTE: This will not work on PC or SUN if LEN(NEW) > LEN(OLD) c in order to get around this problem temporarily c a restriction has been introduced such that len(new) must c be less than or equal len(old) character*6 chival if (len(new) .gt. len(old)) 2 call abort ('Exchange: len(new)'//chival(len(new)) 2 //' may not exceed len(old)'//chival(len(old))) in = index (a, old) if (in .eq. 1) then if (in+len(old) .eq. len(a)+1) then a = new else a = new//a(in+len(old):len(a)) end if in = index (a, old) end if c now 'in' can no longer have the value 1 do while (in .ne. 0) if (in+len(old) .eq. len(a)+1) then a = a(1:in-1)//new else a = a(1:in-1)//new//a(in+len(old):len(a)) end if in = index (a, old) end do return end