c=========================================================== c Demonstration main program and subroutine to c illustrate use of SAVE and DATA statements. c=========================================================== program tsavedata implicit none integer i do i = 1 , 10 call sub1() end do stop end c=========================================================== c Subprogram 'sub1': writes a message to standard c error the FIRST time it is called, and writes c the number of times it has been called so far to c standard output EVERY time it is called. c=========================================================== subroutine sub1() implicit none logical first integer ncall c----------------------------------------------------------- c Strict f77 statement ordering demands that c ANY DATA statements appear after ALL variable c declarations. Note the use of '/' to delimit the c initialization value. c----------------------------------------------------------- data first / .true. / c----------------------------------------------------------- c This 'save' statement guarantees that ALL local c storage is preserved between calls. c----------------------------------------------------------- save if( first ) then ncall = 1 write(0,*) 'First call to sub1' first = .false. end if write(*,*) 'sub1: Call ', ncall ncall = ncall + 1 return end