Re: Problem with my split routine I am not understanding




Jeremy wrote:
I have the following function:

subroutine split(what, by, into)
implicit none

character(len=*), intent(in) :: what, by
character(len=*), dimension(:), intent(out) :: into

integer :: bpos = 1, pos = 1, idx = 1

I have not read your message carefully, but do you realize that the
line above is equivalent to

integer, save :: bpos = 1, pos = 1, idx = 1

and do you know that the SAVE attribute means that the variables are
initialized to 1 only upon the first call of the subroutine and
thereafter preserve their values?

If you do not want the variables to be SAVEd, write instead

integer :: bpos,pos,idx
bpos = 1
pos = 1
idx = 1

Since the Fortran convention is unintuitive to many programmers,
problems with "implicit SAVE" have often come up in this newsgroup --
you can search the archives.

.



Relevant Pages

  • Terminator 2.0 Fortran Source Code
    ... SUBROUTINE TailHookm ... implicit real*8 ... common/constm2/xm, gmmars, radM,rm,soiM,omm,phM,rpM ...
    (comp.lang.fortran)
  • Re: calculating the julian day
    ... SUBROUTINE calend ... Implicit None Statement .. ... TYPE, INTENT:: x ... Intrinsic Functions .. ...
    (comp.lang.fortran)
  • Re: memory leak help!
    ... a loop from the main program. ... REPLACE THE NEW COMPLEX INTO ORIGINAL ARRAY x ... END OF SUBROUTINE SCEUA ... IMPLICIT NONE ...
    (comp.lang.fortran)
  • Re: Pointers to procedures in Intel Fortran
    ... implicit none ... subroutine fooint ... end interface genfoo ...
    (comp.lang.fortran)
  • Re: Fortran templates
    ... implicit none ... end subroutine _READFILE_DATA_NAME ... myvalue % classname = classname ... subroutine printdata (myvalue) ...
    (comp.lang.fortran)