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

Combining Arrays of different shape?? 1

Status
Not open for further replies.

econ2008

Programmer
Jul 26, 2010
9
Hello!

I have a question concerning the combination of scalars and arrays. In the code i am working with the following is defined (in parentheses of what dimension i think those are):

REAL(WP), DIMENSION:)), INTENT(IN) :: a (vector)
INTEGER, ALLOCATABLE, DIMENSION:),:) :: hmax (2D matrix)
REAL(WP), ALLOCATABLE, DIMENSION:)) :: b (vector)
REAL(WP), ALLOCATABLE, DIMENSION:),:) :: f,pv (2D matrix)
INTEGER :: hmin, imax(1)
REAL :: MU
Later in the code it is set: hmin=1 and hmax(j,i)=count(a<f(j,i) then the following is used with i=1,n and j=1,m.

b(hmin:hmax(j,i))=(f(j,i)-a(hmin:hmax(j,i)))**(1-MU)/(1-MU)+pv(j,hmin:hmax(j,i))

As far as i understood, when i use count(), the result is a scalar of type integer. But hmax(j,i) is a matrix, isn't it? So do I understand right that hmax() becomes a matrix filled with the same scalar in every row and coloummn? But then I do not understand of what size b is (vector or matrix)?

I am still a new to fortran, although i have learned a lot in the last months, this one really confuses me. I hope someone can help me!
Thanks in advance.

econ

 
hmax is a matrix but hmax(i,j) is just one element of the matrix, i.e. a scalar value

b is a vector and b(hmin:hmax(j,i)) is a "sub-vector" going from the index hmin to the index hmax(j,i).

François Jacq
 
Ok thanks so far, but am I right that hmax is then a matrix filled with the same number because of the "count"?
 
No.

You wrote that :

Code:
hmax(i,j)=count(a<f(j,i))

which means that the integer scalar value hmax(i,j) is equal to the number of elements of the vector "a" which are less that the value f(j,i).

So hmax may contain many different values which depend together on the values within the matrix f and the values within the vector a. This only thing which is sure is that the values of hmax are in the range 0..SIZE(a)



François Jacq
 
Hey,

just another problem occured now. In the code the following is defined:

INTEGER :: dpi(2)
REAL(WP), DIMENSION:),:) :: ap,ap1

the following operation is done:

dpi=maxloc(abs(ap1-ap))
dp=ap1(dpi(1),dpi(2))-ap(dpi(1),dpi(2))

Do I understand it right, that dpi(1) is the row where abs(ap1-ap) is maximal and dpi(2) is the respective column? I was searching for this in books and google, but I do not know for what keywords i have to look for. I first thought that this is a co-array topic, but I did not found an answer that fits.

If anyone can help with this?

econ
 
YES : this is exactly the role of MAXLOC (locating the maximum value) which exists for a long time (since Fortran90)

And NO : this has nothing to do with co-arrays which is a Fortran2008 feature for // processing.

François Jacq
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top