How to Merge and Sort Two Fortran Arrays?

  • Context: Fortran 
  • Thread starter Thread starter hobmarcus
  • Start date Start date
  • Tags Tags
    Arrays Fortran
Click For Summary

Discussion Overview

The discussion revolves around merging and sorting two arrays in Fortran, as well as finding the intersection of these arrays. Participants share their approaches to merging the arrays and express challenges related to dynamically handling the size of the intersection array.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes the need to merge two arrays and sort them in ascending order, indicating familiarity with sorting but uncertainty about merging.
  • Another participant provides pseudo code suggesting the creation of a new array to hold all data, followed by loops to populate this new array with elements from both original arrays.
  • A later post reiterates the pseudo code and expresses gratitude for the previous help, while also requesting assistance for a new subroutine to find the intersection of the two arrays.
  • Some participants emphasize the need for the original poster to share their attempts in code form rather than just describing their efforts.
  • One participant mentions using a do loop to compare values in both arrays to find intersection values but struggles with dynamically sizing the intersection array.

Areas of Agreement / Disagreement

Participants generally agree on the need to merge and sort the arrays, but there is disagreement regarding the requirement for the original poster to provide their code attempts. The discussion remains unresolved regarding the best approach to dynamically handle the intersection array size.

Contextual Notes

There are limitations regarding the assumptions about the data structure and the specific requirements for the intersection array, which are not fully explored in the discussion.

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.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 25 ·
Replies
25
Views
4K
  • · 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