I have a code written in Fortran which outputs a large block-diagonal matrix, which is then written into a file in blocks. I want to know how best to import these matrices into Mathematica (I don't necessarily need to reconstruct the full block-diagonal matrix). The Import
function seems to be very unhelpful when it comes to importing .dat files. Using Import["filename.dat","Table"]
places a comma every time there is a space, enclosing each line in brackets. This is fine for a single matrix, but I have multiple matrices all in the same file separated by blank spaces. For example if I had a file
a b
c d
A B
C D
After importing I get
{{a,b},{c,d},{},{A,B},{C,D}}
I can write a routine to break these apart using the {}
as a separator but there must be some simpler way of doing this. Note that with Fortran it is very hard to control the number of spaces, so I cannot write complex expressions like {i,j}->a
because generally each number is printed with a fixed number of digits, leaving extra white spaces which Mathematica will convert into extra commas.