Fortran Merging arrays in fortran 90/95

  • Thread starter Thread starter seneika
  • Start date Start date
  • Tags Tags
    Arrays Fortran
AI Thread Summary
The discussion centers around merging multiple 1D arrays into a single 2D array in Fortran 90/95. The original poster inquires about intrinsic routines for this task and explores the use of pointers to create a 2D pointer array that references different 1D arrays. However, the attempt to assign 1D arrays to specific columns of a pointer array fails. A solution is suggested, demonstrating how to manually merge arrays by iterating through them and assigning values to a 2D array. Additionally, an alternative method using array sections is proposed, allowing direct assignment of 1D arrays to rows of a 2D array. This highlights practical approaches for effectively merging arrays in Fortran.
seneika
Messages
4
Reaction score
0
Hi,

can someone help me with this one?

I'm trying to merge several 1d-arrays into one 2d-array. Is there any intrinsic routine/function in fortran 90/95 to do so?

I also thought of pointers. Can I assign a 2d-pointer to more than one object so I have
a pointer array whose columns point to different 1d-target arrays?

I naively tried to do

...
double precision,dimension(:,:),pointer :: ptr_array
...

ptr_array(*,1)=>x(*)
ptr_array(*,2)=>y(*)
...

what didn't work. Can I do something like this?

Thanks!
 
Technology news on Phys.org
seneika said:
Hi,

can someone help me with this one?

I'm trying to merge several 1d-arrays into one 2d-array. Is there any intrinsic routine/function in fortran 90/95 to do so?
As far as I know, there isn't, but it isn't that hard to do.
seneika said:
I also thought of pointers. Can I assign a 2d-pointer to more than one object so I have
a pointer array whose columns point to different 1d-target arrays?

I naively tried to do

...
double precision,dimension(:,:),pointer :: ptr_array
...

ptr_array(*,1)=>x(*)
ptr_array(*,2)=>y(*)
...

what didn't work. Can I do something like this?

Thanks!
I think something like this would work...
Fortran:
real :: numbersA(5) 
real :: numbersB(5)
real :: merged(2,5)
integer::i
numbersA = (/1.5, 3.2, 4.5, 0.9, 7.2 /)
numbersB = (/2.5, 2.2, 3.5,1.9, 6.2 /)
do i = 1, 5
   merged(1, i) = numbersA(i)
   merged (2, j) = numbersB(i)
end do
 
  • Like
Likes jedishrfu
Alternatively, one can do it with array sections:

Fortran:
real :: A(2), B(2), C(2, 2)

A = (/ 1.0, 2.0 /)
B = (/ 3.0, 4.0 /)
C(1, :) = A
C(2, :) = B
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...

Similar threads

Replies
20
Views
4K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
19
Views
6K
Replies
13
Views
2K
Replies
5
Views
4K
Back
Top