Fortran Merging arrays in fortran 90/95

  • Thread starter Thread starter seneika
  • Start date Start date
  • Tags Tags
    Arrays Fortran
Click For Summary
SUMMARY

This discussion focuses on merging multiple 1D arrays into a 2D array using Fortran 90/95. Participants clarify that there is no intrinsic function for this operation, but it can be accomplished through manual array manipulation. A practical example is provided where two 1D arrays, numbersA and numbersB, are merged into a 2D array named merged using a simple loop. Additionally, the use of array sections is demonstrated for a more concise approach.

PREREQUISITES
  • Understanding of Fortran 90/95 syntax
  • Familiarity with array manipulation in Fortran
  • Knowledge of pointers in Fortran
  • Basic programming concepts such as loops and indexing
NEXT STEPS
  • Research how to use array sections in Fortran 90/95
  • Learn about pointer arrays and their applications in Fortran
  • Explore intrinsic functions available in Fortran for array operations
  • Investigate best practices for memory management with pointers in Fortran
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with numerical computing and array data structures, as well as educators teaching Fortran programming concepts.

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
 
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
2K
  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K