Fortran How to Merge and Sort Two Fortran Arrays?

  • Thread starter Thread starter hobmarcus
  • Start date Start date
  • Tags Tags
    Arrays Fortran
Click For Summary
To merge two arrays and sort them in ascending order, a new array should be created with sufficient size to hold all elements from both arrays. A loop can be used to transfer elements from the first array into the new array, followed by another loop to add elements from the second array, starting at the index where the first loop ended. For finding the intersection of the two arrays, a separate subroutine is required. This involves comparing each value in both arrays and storing the intersecting values in a new array, which may vary in size based on the data. It is important to provide code examples of what has been attempted for effective assistance. Additionally, posting in the appropriate forum section is recommended for homework-related queries.
hobmarcus
Messages
10
Reaction score
0
I have 2 set of data (from different files) and I allocate each set of data to array in my main program. But now I want to merge those 2 array and sort them in ascending orders in my sub program. What should I do? I know how to sort array in ascending orders, but i don't know how to merge those 2 array together... Any suggestion or help?
 
Technology news on Phys.org
hobmarcus said:
I have 2 set of data (from different files) and I allocate each set of data to array in my main program. But now I want to merge those 2 array and sort them in ascending orders in my sub program. What should I do? I know how to sort array in ascending orders, but i don't know how to merge those 2 array together... Any suggestion or help?
pseudo code:
create new array big enough to hold all the data
create a loop that puts all of the first array's elements into the new array
create a loop that puts all of the second array's elements into the new array (starting at the index left at the end of the first loop)
 
phinds said:
pseudo code:
create new array big enough to hold all the data
create a loop that puts all of the first array's elements into the new array
create a loop that puts all of the second array's elements into the new array (starting at the index left at the end of the first loop)
thanks you for answering my question. It helps a lot. However, Another subroutine is required to find the intersection of them and combined it into 1 array. Any suggestion or help please
 
Last edited:
hobmarcus said:
thanks you for answering my question. It helps a lot. However, Another subroutine is required to find the intersection of them and combined it into 1 array. Any suggestion or help please
You need to show us what you have tried. We are not going to write this code for you.

Your question should be posted in the Engineering & Comp. Sci. subsection under Homework & Coursework. I am closing this thread.
 
Last edited:
Mark44 said:
You need to show us what you have tried. We are not going to write this code for you.
First, I tried to use do loop to compare each value in both array and the write out each intersect value. But I do not know how to put them together into an array since the size of this intersect array varies if the data change.
 
hobmarcus said:
First, I tried to use do loop to compare each value in both array and the write out each intersect value. But I do not know how to put them together into an array since the size of this intersect array varies if the data change.

Again, you need to show us (in code) what you have tried, not explain to us what you have tried. As already noted, please start a new thread in the Homework & Coursework section.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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