Opening dat files

Opening dat files

Hello,

I normally use microsoft visual studio on Microsoft. However, I will have to use xcode on mac osx from now on. I am not able to read data from a .dat file. I normally use the following code:

    filename='input.dat'
    write(*,1000) filename

    1000 format(' ','The input file name is: ',A)
    open(unit=3, file=filename, status='old', action='read',&
         iostat=status)

    if(status.eq.0) then
    do
    read(3,'(F25.16)',iostat=st1) TolSSSA
    if (st1.eq.0) exit
    end do

When I use the code above, it gives me the following error:

Error opening file: IOSTAT =     29

I don't think .dat files are compatible with MAC. What should I use then? I have so much data in the input file. It might be difficult to read it all if I change the extension of my input file.

Thank you,

Emre

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

IOSTAT 29 is "file not found".  Make sure input.dat is in your current working directory or specify a full path name in your open() call. You may also be running into case sensitivity issues you wouldnt see in windows.  Make sure the file is actually called "input.dat" and not "Input.dat" or "INPUT.DAT" or some other mixed-case name.

By the way, the extension ".dat" has no bearing on the contents of the file and changing that will not have an effect (aside from making sure the correct filename is listed in code).  The only compatibility issues with fortran data files would be endianness (you are using intel chips on both systems in question, so that is not the issue) and fortran record cruft (this would only be an issue reading the file with something other than fortran).  You should not have a problem reading the file in OSX, just doublecheck your paths and name.  

And since you ask for alternatives to fortran data files, if your data is scientific in nature you could look into formats like hdf5 or netcdf.  Do note that while working with these files can be quite a bit more involved than standard fortran OPEN/READ/WRITE to work with initially, they are more flexible and can handle metadata.  These formats are very well suited to gridded data (or n-dimensional arrays in general).  The resulting files are portable across platform and language.

Hello,

Thank you very much for your reply. Both my code File.f90 and the input file input.dat are in the same folder. I tried to simplify the problem and attached the file. This time, it doesn't give error but it never comes to the end of the file. It just doesn't let me attach the dat file.

Attachments: 

AttachmentSize
Downloadapplication/octet-stream file.f903.06 KB

Just above the "Start Upload" button, there is a list of accepted file extensions. Since .dat is not one of those, either add .txt to the file name or zip (or use tar -zcf {filename}.tgz {list of files} ) all the files together before uploading.

I am not sure what is the default folder in Xcode when running a program - try putting in the full path to the file as a start.  Or you could as a test change the STATUS='OLD' to STATUS='UNKNOWN' and then use INQUIRE to find out what the full path is, giving you a clue as to where it put the file.

This has nothing to do with the data file itself.

Steve - Intel Developer Support

Hello,

Thank you very much. I don't think it is about the pathfile because it is able to open the file sometimes. I am attaching the file as txt. you can find the f90 file attached at the previous comments.

Thank you,

Emre

Attachments: 

AttachmentSize
Downloadtext/plain input.txt1.93 KB

Print out the value of status immediately after the file is opened, and you should be able to see which branch of the IF block is executed, and why the file is not read as intended. 

Leave a Comment

Please sign in to add a comment. Not a member? Join today