Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMMON BLOCK

Status
Not open for further replies.

FZK

Technical User
Joined
Sep 14, 2010
Messages
4
Location
DE
Is there anybody who can suggest me how i can transfer two dimensional array to another subroutine using common block technique????

Please suggest me in details as i am not able to transfer the array element perfectly...
 
Hi FZK
The code below is a simple one that uses a COMMON BLOCK which is a two dimensional array. Pay attention that a COMMOB BLOCK can be neither ALLOCATABE nor AUTOMATIC. An AUTOMATIC Array is the one that its bound is a variable inside the SUBROUTINE of FUNCTION like "BIC_automatic(e,e)".
Code:
program COMMBLO
 implicit none
 Integer::i,a
 Real::AIC(10,10)
 COMMON /TwoDimArray/ AIC
 a=5
 Call Calling2DimArray(a)
 a=1
 Call CallingCommBlock(a)
end program COMMBLO
!=================================
Subroutine Calling2DimArray(E)
 implicit none
 Integer::i,j,e,bound
 Real::BIC(10,10) , BIC_automatic(e,e)
 COMMON /TwoDimArray/ BIC

  Open(Unit=3,File="BIC.TXT",status="old",Action="read")
  Do i=1,10
	read (Unit=3,fmt=*) (BIC(i,j),j=1,10)
  End Do
 print*, BIC(e,e)
End Subroutine Calling2DimArray
!=================================
Subroutine CallingCommBlock(ee)
 implicit none
 Integer::ee
 Real::CIC(10,10)
 COMMON /TwoDimArray/ CIC
 print*, CIC(ee,ee)
End Subroutine CallingCommBlock






 
An alternative to eSAFARI's example is to put the common block and everything associated with it in an include file

Code:
 Real::CIC(10,10)
 COMMON /TwoDimArray/ CIC
Unlike that technique, in this one, the 2D array always retains the same name
Code:
program COMMBLO
 implicit none
 Integer::i,a
 include 'twodimarray.inc'
 a=5
 Call Calling2DimArray(a)
 a=1
 Call CallingCommBlock(a)
end program COMMBLO
!=================================
Subroutine Calling2DimArray(E)
 implicit none
 Integer::i,j,e,bound
 Real::BIC_automatic(e,e)
 include 'twodimarray.inc'

  Open(Unit=3,File="BIC.TXT",status="old",Action="read")
  Do i=1,10
    read (Unit=3,fmt=*) (CIC(i,j),j=1,10)
  End Do
 print*, CIC(e,e)
End Subroutine Calling2DimArray
!=================================
Subroutine CallingCommBlock(ee)
 implicit none
 Integer::ee
 include 'twodimarray.inc'
 print*, CIC(ee,ee)
End Subroutine CallingCommBlock
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top