0

I have a .bin file on my hard drive. It's recl is nx*ny*4. Its dimensions are (241,121). 241 in x dimension. 121 in y dimension. How would I convert it using fortran to an ascii file that I can open and read numbers off of?

So, far I have tried

real :: g1(241,121) 
open(unit=1,file=gaugemax2010.bin',status='old',
form='unformatted',access='direct',recl=nx*ny*4) 


open(unit=5,file='g2010.txt',status='unknown', 
form='unformatted',access='direct',recl=1) 

read(1, rec=1) ((g1(i,j,),i=1,nx,j=1,ny)
write(5, rec=1) (g1(i,j,),i=1,241),h=1,121) 
end

and it has not worked

2
  • What language wrote it? Do you have that code? Do you know that the file contains single-precision reals? Why do you say that it doesn't work ... that the values output are wrong? Commented Jun 9, 2014 at 18:39
  • 1
    fixing simple syntax errors, stray comma and unbalanced parenthesis: read(1, rec=1) ((g1(i,j),i=1,nx),j=1,ny) . Obvioulsy h should be j in the second case... Of course since your array is dimensioned exactly right you could just do read(1,rec=1)g1 Commented Jun 9, 2014 at 19:02

1 Answer 1

1

FORM='UNFORMATTED' opens a file for binary content. For pure text you have to specify FORM='FORMATTED'.

For more details on the OPEN statement see here: Opening Binary Files in Fortran: Status, Form, Access

Sign up to request clarification or add additional context in comments.

3 Comments

I generally use form='binary'. Is there any difference?
software.intel.com/sites/products/documentation/doclib/stdxe/… unformatted appears to still retain some record structure?
@bdforbes This seems to be some vendor extension. The standard (ch. 9.5.6.11) specifies that the "FORM= specifier in the OPEN statement [...] shall evaluate to FORMATTED or UNFORMATTED."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.