Converting VBA to Fortran

  • Fortran
  • Thread starter zakynthos
  • Start date
  • #1
2
0
Hi, I've no knowledge of Fortran but am researching its (theoretical) use to perform a 'cross- referencing' function on data in a four column array of one million rows. The program matches data in column A to Column D by referencing the matching values in columns B and C.

Here's the program I'm using - could anyone convert this to Fortran and could this in, in practice, run on Fujitsu's K (10 teraflops) computer. If so, how long would it take the K to perform this task - I've calculated 12.93 hrs from tests on a typical office PC? With thanks.

Sub AddCodes()

Dim x As Long, LastRow As Long, UB As Long, BList As Variant

Const StartRow As Long = 1
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

BList = Join(WorksheetFunction.Transpose(Cells(StartRow, "B").Resize(LastRow - StartRow + 1)), "/")
' Application.ScreenUpdating = False

For x = StartRow To LastRow
UB = UBound(Split(Split(BList, Cells(x, "C").Value)(0), "/"))
If UB >= 0 Then
With Cells(x, "D")
.Value = .Value & "," & Range("A1").Offset(UB).Value
If Left(.Value, 1) = "," Then .Value = Mid(.Value, 2)
.Interior.ColorIndex = 6
.Font.Bold = True
End With
End If
Next

Application.ScreenUpdating = True

End With

End Sub
 

Answers and Replies

  • #2
AlephZero
Science Advisor
Homework Helper
6,994
292
If it takes 12 hours on a PC your algorithm is hopelessly inefficient.

If you first sorted the table on the relevant columns and then did the matching, I would expect the run time to be of the order of 1 second not 12 hours.

Relational database operations are a good way to describe what you want to do, but they are often a bad way to actually do it.
 
  • #3
2
0
Many thanks for your answer - your advice made me re-think the code and I've processed the array with vlookup instead and yes, you're right of course, about a second!

However, I'm still interested to knnow how my original code qwould translate into Fortran.

Thanks once again!
 

Related Threads on Converting VBA to Fortran

Replies
4
Views
5K
Replies
1
Views
3K
Replies
3
Views
14K
  • Last Post
Replies
18
Views
4K
  • Last Post
Replies
2
Views
7K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
2
Views
4K
Top