sort_to_sort.f90

I suggest you either typed  this as it appears into the compiler, or as an easier way, just copy and paste it!

Note: I do not claim the program will 100% work, but I give it my best. If it doesn't, try tweaking it yourself, or email me about it, and I'll modify and post the improved version later. Good luck!

 

PROGRAM sort_to_sort
IMPLICIT NONE

INTEGER :: n1, n2 

PRINT*, "Welcome to ADCY Number Sorter Program"
PRINT*, "Please tell me how long will the first list to be sorted."
PRINT*, "(i.e: how many numbers must it contain?)"
WRITE (UNIT=*, FMT=10, ADVANCE="NO") "It is "
READ*, n1
PRINT*

PRINT*, "Now, can you tell me how long the second list should be?"
WRITE (UNIT=*, FMT=10, ADVANCE="NO") "It will be "
READ*, n2
PRINT*

10 FORMAT (A)

CALL construct_array_N_sorter(n1, n2)

PRINT*
PRINT*, "Thank you for using ADCY Sorting Program"
PRINT*, "Have a nice day:)"
PRINT*

END PROGRAM sort_to_sort
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%***SUBROUTINE PART***%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%!

SUBROUTINE construct_array_N_sorter(n1, n2)
IMPLICIT NONE

INTEGER, INTENT(IN) :: n1, n2
INTEGER :: n3
REAL, DIMENSION(1:n1) :: lister1
REAL, DIMENSION(1:n2) :: lister2
REAL, DIMENSION(1:n1+n2):: combined_array
INTEGER :: i, j, k, l, first_num

PRINT*, "Tell me the numbers now for the first list:"
READ*, lister1
PRINT*

PRINT*, "I think that you know the numbers for the second list? What is it?"
READ*, lister2
PRINT*


!Sorts lister1
i=1
DO WHILE (i<=n1-1)
first_num=lister1(i)
k=i
j=i+1
DO WHILE (j<=n1)
IF (lister1(j)<first_num) THEN
first_num=lister1(j)
k=j
END IF
j=j+1
END DO

IF (k/=i) THEN
l=lister1(i)
lister1(i)=lister1(k)
lister1(k)=l
END IF

i=i+1
END DO

PRINT*, "This is the sorted list for the first series of numbers:"
PRINT*, lister1 

!Sorts lister2
i=1
DO WHILE (i<=n2-1)
first_num=lister2(i)
k=i
j=i+1
DO WHILE (j<=n2)
IF (lister2(j)<first_num) THEN
first_num=lister2(j)
k=j
END IF
j=j+1
END DO

IF (k/=i) THEN
l=lister2(i)
lister2(i)=lister2(k)
lister2(k)=l
END IF

i=i+1
END DO

PRINT*
PRINT*, "This is the sorted list for the second series of numbers:"
PRINT*, lister2 

!Creates a composite of both lists
i=1
DO WHILE (i<=n1)
combined_array(i:n1)=lister1(i)
i=i+1
END DO

j=1
DO WHILE (j<=n2)
combined_array(n1+j)=lister2(j)
j=j+1
END DO

!Sorts the composite list
n3=n1+n2
i=1
DO WHILE (i<=n3-1)
first_num=combined_array(i)
k=i
j=i+1
DO WHILE (j<=n3)
IF (combined_array(j)<first_num) THEN
first_num=combined_array(j)
k=j
END IF
j=j+1
END DO

IF (k/=i) THEN
l=combined_array(i)
combined_array(i)=combined_array(k)
combined_array(k)=l
END IF

i=i+1
END DO
PRINT*
PRINT*, "This is the final, composite list of the two:"
PRINT*, combined_array

RETURN
END SUBROUTINE construct_array_N_sorter
!*****%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*****!