3D array in MAT file ->DAT file to read in FORTRAN
Alright, so I have been trying to resolve this issue for awhile, but now feel like help is very necessary.
I have a 128(by)128(by)128 array in a MAT file, and am using the following MATLAB script to convert it to a DAT file: load C_42.mat fid=fopen('C_42.dat','wt') fwrite(fid,Nu) fclose(fid) With it in the DAT format I am hoping to read it with a FORTRAN code, at which point I will be able to manipulate the array values and output it to a binary file. Below is the read command in the FORTRAN code: fn1='/home/C_42.dat' open(11,file=fn1,form='FORMATTED') read(11,'(4ES10.9)') u1,v1,w1 close(11) Currently, I am getting a runtime error: Bad value during floating point read (I am using gfortran) I guess I am mainly lost on formatting, should I have used some sort of formatting in the MATLAB script in order to match the format in the FORTRAN code? (When I open the MAT file in MATLAB it loads in the workspace as just a 3D matrix, Nu) Thanks ahead for any possible help. -B.P. |
Welcome to LinuxQuestions.
A DAT file is a generic term which really does not define a file format. Just because you write to a file called something.dat does not mean it will automatically be converted. I'm not a MatLab script person but what you posted is only coping the file and it is still in a mat format. You will have to use an export function i.e. to CSV for example and then your FORTRAN program will have to read and process the data accordingly. |
Quote:
Anyway, the only thing you have to pay attention is to create a binary file with access "direct" or "sequential". Your code creates the first one. In that case you have to specify access=direct in the open statement in Fortran. If you want to create a binary with sequential access, you have to add a signed 32-bit integer at the beginning and at the end of each record, containing the number of bytes to read. For example: Code:
>> nbytes = 128*128*128*4; Code:
program test |
All times are GMT -5. The time now is 08:05 AM. |