Fortran How to Merge and Sort Two Fortran Arrays?

  • Thread starter Thread starter hobmarcus
  • Start date Start date
  • Tags Tags
    Arrays Fortran
AI Thread 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
6
Views
1K
Replies
25
Views
3K
Replies
2
Views
1K
Replies
13
Views
3K
Replies
2
Views
1K
Replies
5
Views
3K
Back
Top