You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sswapf.f 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. subroutine sswapf (n,sx,incx,sy,incy)
  2. c
  3. c interchanges two vectors.
  4. c uses unrolled loops for increments equal to 1.
  5. c jack dongarra, linpack, 3/11/78.
  6. c modified 12/3/93, array(1) declarations changed to array(*)
  7. c
  8. real sx(*),sy(*),stemp
  9. integer i,incx,incy,ix,iy,m,mp1,n
  10. c
  11. if(n.le.0)return
  12. if(incx.eq.1.and.incy.eq.1)go to 20
  13. c
  14. c code for unequal increments or equal increments not equal
  15. c to 1
  16. c
  17. ix = 1
  18. iy = 1
  19. if(incx.lt.0)ix = (-n+1)*incx + 1
  20. if(incy.lt.0)iy = (-n+1)*incy + 1
  21. do 10 i = 1,n
  22. stemp = sx(ix)
  23. sx(ix) = sy(iy)
  24. sy(iy) = stemp
  25. ix = ix + incx
  26. iy = iy + incy
  27. 10 continue
  28. return
  29. c
  30. c code for both increments equal to 1
  31. c
  32. c
  33. c clean-up loop
  34. c
  35. 20 m = mod(n,3)
  36. if( m .eq. 0 ) go to 40
  37. do 30 i = 1,m
  38. stemp = sx(i)
  39. sx(i) = sy(i)
  40. sy(i) = stemp
  41. 30 continue
  42. if( n .lt. 3 ) return
  43. 40 mp1 = m + 1
  44. do 50 i = mp1,n,3
  45. stemp = sx(i)
  46. sx(i) = sy(i)
  47. sy(i) = stemp
  48. stemp = sx(i + 1)
  49. sx(i + 1) = sy(i + 1)
  50. sy(i + 1) = stemp
  51. stemp = sx(i + 2)
  52. sx(i + 2) = sy(i + 2)
  53. sy(i + 2) = stemp
  54. 50 continue
  55. return
  56. end