C @(#)exchange.f 1.2 03/25/98 C subroutine exchange (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) character*(*) a, old, new if(len(new).gt.len(old)) call abort('exchange: new longer than 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