|
From: qsc on 31 Jan 2008 12:32 I found it hard to understand the concept of a record in Fortran I/O. Here are some of the questions I have about it. 1. one record is equivalent to one line? 2. Each read, write or print statement deal transfer one record? 3. What if in one write statement I want output several values? Will they be treated as one record, or splitted into several? For example: write(12) U(:) Notice that I want binary output, and the array U have many components. So now, will U be written in one record, or many? Will the output be on one line, or many? Thanks in advance!
From: Gordon Sande on 31 Jan 2008 13:22 On 2008-01-30 13:32:26 -0400, qsc <qingshan.chen(a)gmail.com> said: > I found it hard to understand the concept of a record in Fortran I/O. It is a very old concept that can be thought of as the formalization of punch cards. You can look at the beginning of a punch card and get the next card without bothering to look at the end of the previous one. > Here are some of the questions I have about it. > 1. one record is equivalent to one line? Yes, for the simple cases. Assuming some reasonable meaning for line. See below for one possible trouble even with that. > 2. Each read, write or print statement deal transfer one record? Yes, for the simple cases. Some fancy formats or advance="no" are not simple cases. There is "new record" format item and advance="no" stays on the same record. Both are useful once you get beyond the common simple cases. > 3. What if in one write statement I want output several values? Will > they be treated as one record, Yes, A record can have many values in in it. > or splitted into several? For example: > write(12) U(:) No. Unless you do something quite strange. No easy examples of what that might be. > Notice that I want binary output, and the array U have many > components. So now, will U be written in one record, or many? Will the > output be on one line, or many? Unformatted output (what you probably mean by binary as every thing on a binary computer is in binary) and lines are probaly a symptom of some confusion. What you see in a text editor is often not a record as "line wrapping" will turn a long line (often a record) into many lines on the display. Using a text editor with unformatted records is typically not useful except when the data is characters. Formatted output is when you convert the internal values into a form that is suitable for people to read. It may use either an explicit format (what many folks call formatted output) or allow the system to choose a format when you ask for list directed (a "*" usually) output. Both are formatted within the meanings established for Fortran. This technical usage is often used incorrectly and leads to repeated confusion. > Thanks in advance!
From: Klaus Wacker on 31 Jan 2008 13:30 qsc <qingshan.chen(a)gmail.com> wrote: > I found it hard to understand the concept of a record in Fortran I/O. > > Here are some of the questions I have about it. The answers to your questions depend on whether you have formatted or unformatted I/O. > 1. one record is equivalent to one line? In formatted I/O, yes. In un formatted I/O the concept of a line doesn't exist. > > 2. Each read, write or print statement deal transfer one record? In unformatted I/O, yes (unless you use "advance=no", then you only get part of a record). In formatted I/O, one I/O statement can deal with several records. E.g., a "/" format item starts a new record. If you run off of the end of the format string and you have still items left in the I/O list, a new record will be started. > > 3. What if in one write statement I want output several values? Will > they be treated as one record, or splitted into several? For example: > write(12) U(:) > Notice that I want binary output, and the array U have many > components. So now, will U be written in one record, or many? One record. Will the > output be on one line, or many? There is no line, write(12) U(:) is unformatted I/O. You may be confusing this with write(12,*) U(:). This is formatted, list-directed I/O. Here, the compiler or run time system is free to produce several records or lines. It will usually do so if the line gets too long otherwise. > > Thanks in advance! -- Klaus Wacker klaus.wacker(a)udo.edu Experimentelle Physik V http://www.physik.uni-dortmund.de/~wacker Universitaet Dortmund Tel.: +49 231 755 3587 D-44221 Dortmund Fax: +49 231 755 4547
From: qsc on 31 Jan 2008 14:37 After reading Gordon and Klaus's replies, I came to the conclusion that write(12) U(:) will write all the values in U(:) as one record. But the concept of "line" doesn't apply here. If I am correct in the statement above, then what will be the structure of the data file? Or put in another way, after writing the array into an external data file, I load the data file using fread of matlab. The function fread will produce a data matrix. What will be the shape of the matrix? Is it (1,N), or is it (N, 1), or something else? I will soon find it out by experiments. But if someone can shed light on it beforehand, it is greatly appreciated. Thank you!
From: glen herrmannsfeldt on 31 Jan 2008 14:57 qsc wrote: > After reading Gordon and Klaus's replies, I came to the > conclusion that write(12) U(:) will write all the values > in U(:) as one record. But the concept of "line" doesn't > apply here. > If I am correct in the statement above, then what will be > the structure of the data file? Or put in another way, after > writing the array into an external data file, I load the > data file using fread of matlab. The function fread will > produce a data matrix. What will be the shape of the matrix? > Is it (1,N), or is it (N, 1), or something else? All the data from one UNFORMATTED WRITE statement goes into one record. The shape, if any, does not. REAL A,B,C,D,X(4) DATA A,B,C,D/1.,2.,3.,4./ WRITE(1) A,B,C,D WRITE(1) A,B,C,D REWIND 1 READ(1) X(1:4) WRITE(*,*) X READ(1) X(3:4),X(1:2) You can read or write with separate scalar variables, arrays, array elements, implied DO over any of the above, all goes into one record. Systems may have a record length limit, and even if they don't it might require a buffer the size of the record to be written. Small records may have excess overhead, very large ones might have other types of overhead. -- glen
|
Next
|
Last
Pages: 1 2 3 Prev: Allocatable Arrays As Outputs Next: Did anyone manage to get MATRAN compiled with g95? |