Re: The concept of a record



On Wed, 30 Jan 2008, qsc wrote:

I found it hard to understand the concept of a record in Fortran I/O.

I do not find anything strange with the concept of record, but I'm used to things like telemetry files, images or binary tables (one record = one row). And I was used to operating systems where the concept of record was native.

1. one record is equivalent to one line?

Fortran traditionally allowed 4 ways to produce output given by the 4 combinations of ACCESS= SEQUENTIAL or DIRECT and FORM = FORMATTED or UNFORMATTED.

The concept of "line" is natural with SEQUENTIAL FORMATTED i/o in which
you transfer line by line what is presumably text (i.e. a sequence of characters, nowadays almost invariable ASCII). In this case the line or record can have variable length. This is the default i/o when you specify a format or use "free format" (list directed, i.e. a * format).

The way the actual record is written to disk (if you aren't writing to stdout) may depend on the operating systems. Nowadays on Unix like systems there is a newline (a byte with decimal value 10 in ASCII) as record terminator. But other OS use carriage return, or newline AND carriage return. Other OS used other ways like a binary length word in front (or after, or both) of the record text. Some OS, like VMS, even supported several record organizations which could be selected at OPEN time !

The concept of record is natural for DIRECT UNFORMATTED access. In this case records are transferred in the same binary form as in memory, and are assumed to be all of the same length RECL. This is extremely convenient for a lot of data analysis applications. On some OS of the past the record length was a native file attribute which could be accessed by the INQUIRE statement. On modern OS this is no longer the case, INQUIRE will just return the RECL used in OPEN. DIRECT access allows to read/write records at random positions in the file.

In my opinion these two combinations are the only ones to use, or at least the ones to be used in the vast majority of cases, unless there are really compelling reasons to do otherwise.

SEQUENTIAL FORMATTED (which is default in OPEN) for stdin and stdout,
for log files, for printout listings, and small files intended to be
human readable

DIRECT UNFORMATTED (which should be the default if one OPENs for
DIRECT access) for big data files, or when one wants to preserve
full binary precision and/or save space

The other two combinations are of more rare use, less useful and sometimes troublesome.

DIRECT FORMATTED is possible if you want to output readable text
files, but be able to access records at random. But one could also
read unformatted into a string, and use internal i/o

SEQUENTIAL UNFORMATTED according to me should be avoided, because
the way the variable record length is coded may be OS and language
dependent, and therefore not portable or interoperable ... it means
looking for troubles ! I believe I used it only in very few special
cases when writing over named pipes.

2. Each read, write or print statement deal transfer one record?

Yes for unformatted. If formatted you can use the slash format element to break in several lines. You can also include newlines in your output list. Or you can use a list longer than the format, and have the output automatically broken in several lines.

3. What if in one write statement I want output several values?

It is up to you. The objects listed in the output list will be output, and is your responsibility to make sure they fill the record length (for DIRECT access) or list as many elements as in the format statement (or consider what happens in this [somewhat contrived] case

REAL U(4,5,6)
WRITE(*,1)' A string, two numbers and an array',1,23.5,U
1 FORMAT(A / I3.3,1X,F5.2 / 12(10(F12.5,1X,/)) )

This will write on the first line the text
' A string, two numbers and an array'
On the second line the two values 001 23.50
On the next 10 lines the elements of U, 10 on each line
--
----------------------------------------------------------------------
nospam@xxxxxxxxxxxxxx is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
.



Relevant Pages

  • Re: Removing password-protected
    ... by saving it as you said to the 2000-2003 format .mpp, however, a ... "JulieS" wrote: ... I've stepped through creating and removing passwords in MS ...
    (microsoft.public.project)
  • Re: Document not opening though Word is
    ... then it suggests "Rich Text Format ". ... I searched on some key words from the template and the content is in there, ... It should prompt you to indicate the file type. ... All produce the same result (Word opens, ...
    (microsoft.public.word.application.errors)
  • Re: Write position
    ... But it's surprisingly hard to do in Fortran. ... the format correct to fill the record (including the newline sequence). ... NCOUNT = NCOUNT + 1 ...
    (comp.lang.fortran)
  • Re: F2k8+/- : Direct Access File Record Locking
    ... > Fortran direct access records mapped directly into a record supported by ... This could simply be a slightly modified format ... It is available for rewrite as a "new" record. ... Is a format specifier. ...
    (comp.lang.fortran)
  • Re: open CSV.file
    ... "Dave Peterson" wrote: ... after this iam able to change the format manually in format ... below code but the file still opens in a US format. ... Dim TempWkbk As Workbook ...
    (microsoft.public.excel.programming)