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!

Dynamic array names

Status
Not open for further replies.

redrighthand

Programmer
Jan 15, 2008
3
US
Hi all

My question is that, is there a way to use a character as a name of a real array? In the following example "dir" is a character. According to the value of "idir", "dir" becomes, x, y or z. In the last statement, I am calculating "hgt" using the real arrays(x,y, or z arrays). x, y, and z real arrays are already defined in the code. Is there a way out for this problem.all I want to do is to use a dynamic name for the real arrays.

idir=2 ! 1=x, 2=y, 3=z
if (idir ==1) then
istart=istep
iend=istep2
write(dir,'(a)')'x'
elseif (idir == 2) then
istart=jstep
iend=jstep2
write(dir,'(a)')'y'
else
istart=kstep
iend=kstep2
write(dir,'(a)')'z'
endif

hgt = dir(iend)-dir(istart)
 
Are x, y and z the same size? If they are, you could use a 2D array. Say they have 20 items each
Code:
real, dimension(3,20):: dir
integer, parameter:: x = 1, y = 2, z = 3

... some code to set up istart and iend

hgt = dir(idir,iend) - dir(idir,istart)
 
xwb,

My arrays are not the same size, but i can't foresee a bad thing about setting them equal. . Your suggestion can really be helpful, thanks a lot. However, if somebody still has the solution for dynamic array names and share it, I would really appreciate it.

Thanks
 
Thanks ArkM
I followed your suggestion about pointer/target, and it worked so easy and great for me.
Thanks again

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top