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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Variables in FORTRAN

Status
Not open for further replies.

shalinibasu82

Programmer
Mar 20, 2008
4
US
Hello,

I am new to FORTRAN and just getting hang of it. I have a global variable say counter which I need to pass to a subroutine and do some processing.

FIRST.f90
integer counter
common /coun/counter
counter = 1000
call second

In SECOND.f90
subroutine second
common /coun/counter

print *,'counter is ',counter

counter = counter - 1

print *,'counter is', counter
end


Current I am getting a garbage value. Please let me know if I am missing something. Thanks.

Shalini
 
You must declare identical types for all common block elements in every item. By default you have real counter var in the second subroutine but it is declared (and initialized) as an integer in the main program. Integer value 1000 is a garbage data when treated as a real (floating point) in the subroutine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top