source: CIVL/mods/dev.civl.abc/examples/fortran/f77_standard/save.f

main
Last change on this file was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5664 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.1 KB
Line 
1c F77 Sec. 8.9: SAVE statement
2c The value of a SAVE variable is preserved across calls to a subroutine
3c or function.
4 subroutine sub(t,b)
5 integer a,b
6 logical t
7 save a
8 if(t) then
9 a = 2
10 else
11 a = a + 1
12 end if
13c$ civl assert(a .eq. b)
14 end subroutine
15
16 subroutine sub2(t,b)
17 integer a,b
18 logical t
19c SAVE without a variable name preserves all variables in that subroutine
20 save
21 if(t) then
22 a = 2
23 else
24 a = a + 1
25 end if
26c$ civl assert(a .eq. b)
27 end subroutine
28
29 subroutine sub3(t,b)
30 integer :: b
31 logical :: t
32c Initialising a variable in the same line in which it is declared
33c implicitly activates the SAVE attribute for this variable.
34 integer :: a = 2
35 if(.not. t) then
36 a = a + 1
37 end if
38c$ civl assert(a .eq. b)
39 end subroutine
40
41 program p
42 call sub(.true.,2)
43 call sub(.false.,3)
44 call sub(.false.,4)
45 call sub2(.true.,2)
46 call sub2(.false.,3)
47 call sub2(.false.,4)
48 call sub3(.true.,2)
49 call sub3(.false.,3)
50 call sub3(.false.,4)
51 end program
Note: See TracBrowser for help on using the repository browser.