reading in data using matlab
suppose you have a large data file containing elements of a matrix.
The original matrix has dimensions
uzy(1:orng,1:grn)
Then it is likely that the program dumps the matrix using nested loops:
do a=1,orng
do b=1,grn
write(*,*) uzy(a,b)
enddo
enddo
To read the data back in vectorally,
for a=1:orng
%disp([1+grn*(a-1) grn*a size(1+grn*(a-1):grn*a)])
uzy(1:grn,a)=uzy_raw(1+grn*(a-1):grn*a);
end
If the original matrix had dimensions
A(1:orng,1:grn,1:blu)
Then it is likely that the program dumps the matrix using nested for loops:
for a=1:orng
for b=1:grn
for c=1:blu
write(*,*) A(a,b,c)
end
end
end
[Note: normally, it would be more efficient to vectorize the inner most loop, but their may be other constraints (like complex-valued elements, or matrix dimensions are large)]
Now we want to re-construct the matrix in matlab from the output file. First, load the data:
raw_data = load('outputfile.dat');
[Note: this will not be useable if outputfile.dat exceeds 100 Mb. Then you'd need to read in line by line?]
now raw_data is of size orng*grn*blu and we need to convert to a matrix of the form A(1:orng,1:grn,1:blu)
for a=1:orng
for b=1:grn
disp([(blu*grn*(a-1)+(b-1)*blu+1) (blu*grn*(a-1)+(b-1)*blu+blu)])
A=raw_data((blu*grn*(a-1)+(b-1)*blu+1):(blu*grn*(a-1)+(b-1)*blu+blu));
end
end
for c = 1:num_freq
for a = 1:num_gain
for b = 1:n_open
f = b+n_open*(a-1) + num_gain*n_open*(c-1);
trans_complex(b,:,a,c)=trans_raw(f,1:n_open)+i*trans_raw(f,n_open+1:2*n_open);
end
end
end
Fortran write:
do q=1,nopen
do p=1,nmax
do a=1,nz
write(*,*) jflux(q,p,a)
enddo
enddo
enddo
Matlab read
for a=1:n_open % input channels
for b = 1:nmax % interior channels
indx = b+nmax*(a-1)
disp([1+nz*(indx-1) nz*indx])
% jflux(a,b,(1:nz)) = jraw(,1);
end
end
Fortran write:
do d=1,nmax
do a=1,nz
write(*,*) wdist(a,d)
enddo
enddo
Matlab read:
for intrior=1:nmax
disp([((intrior-1)*siz+1) (intrior*siz)])
%w=wraw(((intrior-1)*siz+1):(intrior*siz));
end