c=========================================================== c Demonstration main program and subroutine c to illustrate use of COMMON blocks for creating c 'global' storage. Common blocks should always c be labelled (named) and should be used sparingly. c=========================================================== program tcommon implicit none c----------------------------------------------------------- c Declare variables to be placed in common block c----------------------------------------------------------- character*16 string real*8 v(3), & x, y, z integer i c----------------------------------------------------------- c Variables are stored in a common block in the c order in which they are specified in the 'common' c statement. ALWAYS order variables from longest to c shortest to avoid "alignment problems". Don't c try to put a variable in more than one common block c and note that entire arrays (such as 'v') are placed c in the common block by simply specifying the name c of the array. Finally, note that variables in a c common block CAN NOT be initialized with a 'data' c statement. c----------------------------------------------------------- common / coma / & string, & v, & x, y, z, & i string = 'foo' v(1) = 1.0d0 v(2) = 2.0d0 v(3) = 3.0d0 x = 10.0d0 y = 20.0d0 z = 30.0d0 i = 314 call subcom() stop end c=========================================================== c This subroutine dumps information passed to it in c a common block. c=========================================================== subroutine subcom() c----------------------------------------------------------- c Overall layout of common block should be identical c in all program units which use the common block. c----------------------------------------------------------- character*16 string real*8 v(3), & x, y, z integer i common / coma / & string, & v, & x, y, z, & i write(0,*) 'In subcom:' write(0,*) 'string = ', string write(0,*) 'v = ', v write(0,*) 'x = ', x, ' y = ', y, ' z = ', z write(0,*) 'i = ', i return end