Common variable....help me



Hi all,

I am not much experienced about FORTRAN.I am writing a program to
simulate about the spreading of a chemical in water. Here is my
question.

All my variables and arrays are "double precision" type. All common
variables are specified in the header file "common.fi" . Program reads
many values into double precision variables in the Main Program. These
values do not change anywhere else in the main program or subprograms.
Those values are going to be used in the many subroutines. Therefore I
made them common in order that I can use them at any place. Note that
my subroutines are placed in separate souce files. Each source file
contains several subroutines. I call "commmon.fi" header file at the
beginning of each subroutine. Debugging shows no problem. However,
relevant variables in the subroutines receive different values than
those in the main program.

For example:
Shown below is a part in the main program
---
Program Main

USE DFLIB

include 'Common.fi'

double precision rho_oil, miu, int_ten_OW, cont_ang, rho_w, cont_ang

call Disch_crack(ix,jy,Q_crack)
------
Shown next is my subroutine
-----

subroutine Disch_crack(i,j,Q)

USE DFLIB

include 'Common.fi'

double precision Q, diam_crit, ang_rad

ang_rad=cont_ang*PI/180.0

diam_crit=4.0*int_ten_OW*dcos(ang_rad)*grav_accn/(thick_oil(i,j)*(rho_w-rho_oil))

if (diam(i,j).ge.diam_crit) then
Q=(rho_w-rho_oil)*grav_accn*thick_oil(i,j)*(0.25*PI*diam(i,j)*diam(i,j))
+ *NBCUA(i,j)/(32.0*delta_ice(i,j)*miu) ! Number of Brine
Channels per Unit Area
else
Q=0.0
endif
return
end
----------------
Shown next is my "Common.fi" file
-----------------

USE DFLIB

Double precision, parameter ::
omega=(2*3.14159265358979/23.93446959/3600)

Double precision, parameter :: grav_accn=9.81, PI=3.14159265358979

CHARACTER($MAXPATH) dir


character*3 fns(999)

Double precision, POINTER :: thick_oil(:,:), diam(:,:), NBCUA(i,j),
delta_ice(i,j)


common /para/ thick_oil, diam, NBCUA, delta_ice, rho_oil, miu,
int_ten_OW, cont_ang, rho_w, cont_ang

--------------------------------------
Now, for example the value read in the main program for "miu" is 31.
However, when the value for "miu" is viewed at the subroutine, it is
seen as -7964582102. I want it to be seen as 30 in these subroutines as
well as throughout the program. I am totally confused in this issue.

I am wondering if calling "Common.fi" at the beginning of subroutine
was wrong.

Could someone please help me to fix this?

Thank you very much,

Kith

.


Quantcast