Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!nisca.ircc.ohio-state.edu!hpuxa.ircc.ohio-state.edu!jliu From: jliu@hpuxa.ircc.ohio-state.edu (Joe Liu) Newsgroups: comp.lang.fortran Subject: Fortran OPEN and WRITE Message-ID: <962@nisca.ircc.ohio-state.edu> Date: 8 Apr 90 00:50:34 GMT Sender: news@nisca.ircc.ohio-state.edu Distribution: na Organization: Ohio State Univ IRCC Lines: 65 I have been troubled by maybe a very simple problem, what I want to do is: to write a collection of data into a binary file, each of my data is normalized to 128 ( 1-128), so it's possible to represent it with a BYTE on VAX or INTEGER*1 on a Stellar UNIX machine. Now I must write the data byte by byte successively, because that's how another program will look for data. Suppose I have 5 data points as ( 1,2,3,4,5), the binary file I want must be 5 bytes. However, it seems Fortran on the Unix takes 1+8 bytes to write each one byte data, thus the following will result in a 45 bytes file. OPEN (7, FILE='test.dat', FORM='UNFORMATTED') DO 10 I=1,5 10 WRITE (7) I CLOSE (7) if I have a 5 bytes array and write the array as one record, I will get a 5+8= 13 bytes file on the Unix machine. BYTE N(5) DO 10 I=1,5 10 N(I)=I OPEN (7,FILE='test.dat, FORM='UNFORMATTED') WRITE (7) N CLOSE (7) I can look at the 45 bytes or ( 13 bytes) file byte by byte, and I can see the first 4 bytes and the last 4 bytes contain some kind of information. (the size of that record ? ) while the 5th byte contain the right data. that is, in the 45 bytes files, the 45 bytes are, 0,0,0,1, 1 ,0,0,0,1 0,0,0,1, 2, 0,0,0,1 0,0,0,1, 3, 0,0,0,1 0,0,0,1, 4, 0,0,0,1 0,0,0,1, 5, 0,0,0,1 in the 13 bytes file, they are 0,0,0,5, 1,2,3,4,5, 0,0,0,5 Although Fortran has no problem to get the right data back when I read them out, The file is not what I must have, ie, only 1,2,3,4,5 in it. On the VAX machine, the bahavior is similar, only difference is that it has a 4 bytes extra for each record writen instead of 8. If I compile the above two on the VAX I will get a 25 bytes and a 9 bytes file respectively instead the 45 bytes and 13 bytes. I did try to play with possible options in the OPEN statements but did not achieve what I wanted. As I said the FORTRAN itself has no problem to read back the right data. What's behind this ? Some one told me this will not happen on an IBM machine but I did not get the chance to try it on IBM yet. The same purpose can be very easily achieved in C. That's what I am doing now, use a C program to pick out the right bytes from a FORTRAN output and write it into the byte by byte form, to input this into anthoer graphics application. It will be nice if I can slightly modify the FORTRAN program to have the compatible output for the application. There must be a lot FORTRAN experts on this group. Please enlighten me. I have sought help from as close as my next door to as far as DEC technical assitance. But I still do not know how. Thanks. Joe