Re: Common variable....help me





kithsiri@xxxxxxxxx wrote:
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

This is unrelated to your problems, but is a frequent mistake. The constants in these lines are SINGLE precision. The values of all constants in Fortran are determined by the form of the constant, not how it is used. You need to do something like ....PI=3.14159265358979D0 ^^ to indicate that the constant is a double precision constant. What you have is roughly equivalent to

....PI = convert_single_precision_to_double(3.14159)

If you want the result to have double precision accuracy,
you have to make ALL of the constants in the expression be
double precision.  Adding a D0 to each is good enough.

You'd be better off to learn about the KIND parameters
for constants.  But, that's probably a later step.

*** Hendrickson

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