0
votes

I have a program, written in fortran90, that is writing an array to a file, but for some reason is using an asterix to represent multiple columns:

8*9,  4,  2*9,  4

later on reading from the file I am getting I/O errors:

lib-4190 : UNRECOVERABLE library error

A numeric input field contains an invalid character.

Encountered during a list-directed READ from unit 10 Fortran unit 10 is connected to a sequential formatted text file:

Does anyone have any idea why this is happening, and if there is a flag to feed to the compiler to prevent it. I'm using the cray fortran compiler, and the write statement looks like this:

write (lun,*) nsf_species(bundle%species(1:bundle%n_prim))

Update:

The line reading in the data file looks like:

read (lun,*) Info(ifile)%alpha_i(1:size)

I have checked to ensure that it is this line that is causing the problem.

3
Please show the corresponding read statement. - francescalus
* is not unformatted unformatted essentially means binary, the raw representation. - Vladimir F
have you looked at the compiler docs? I'd be surprised if there is not an option to disable the repeat count. - agentp
Hi guys, thanks for having a look. The read statement has been added, and I have looked through the compiler docs and couldn't find anything to disable this formatting. - user5151524
Půease do NOT edit your question with "Problem solved", accept the answer tat helped you instead. - Vladimir F

3 Answers

2
votes

This compression of list-directed output is a very useful feature of the Cray Compilation Environment when writing out large amounts of data. This compressed output will, however, not be read in correctly, as you point out (which is less useful).

You can modify this behaviour, not using a compiler flag but by using the "assign" command.

Consider this sample code:

PROGRAM test
IMPLICIT NONE

INTEGER :: u

OPEN(UNIT=u,FILE="f1",FORM="FORMATTED",STATUS="UNKNOWN")
WRITE(u,*) 0,0,0
CLOSE(u)

OPEN(UNIT=u,FILE="f2",FORM="FORMATTED",STATUS="UNKNOWN")
WRITE(u,*) 0,0,0
CLOSE(u)

END PROGRAM test

We first build with CCE and execute. Files f1 and f2 both contain the compressed output form:

$ ftn -o test.x test.F90 
$ ./test.x 
$ cat f1
 3*0
$ cat f2
 3*0

Now we will use "assign" to modify the format in file f2. First we need to define a filename to hold the assign information:

$ export FILENV=my_filenenv

Now we use assign to switch off the compressed output for file f2:

$ assign -y on f:f2

Now we rerun the experiment (without needing to recompile):

$ ./test.x 
$ cat f1
 3*0
$ cat f2
 0,  0,  0

There are options to do this for all files, for certain filename patterns or many other cases.

There are other things that assign can do. See "man assign" with PrgEnv-cray loaded for more details.

1
votes

The write statement is using list directed formatting (it is still a formatted output statement - "formatted" means "formatted such that a human can read it")- as specified by the * inside the parenthesised part of the statement. The rules for list directed output give a great deal of freedom to the compiler. Typically, if you actually care about the details of the output, you should provide an explicit format.

One of the rules that does apply is that the resulting output should generally be suitable for list directed input. But there are some rather surprising rules for what is permitted as input for list directed formatting. One such feature is that you can specify in the input text a repeat count for an input values using the syntax repeat*value.

The compiler has noticed that there are repeat values in the output, so it has used this repeat count feature.

I don't know why you get an error message when reading the file under list directed input - as the line you show is a valid input line for list directed input. Make sure that the line causing the error is actually the line that you show.

1
votes

A simple workaround solution would be to change the write statement so that it does not use the compressed format. e.g. change to:

write (lun,'(*(I5))') nsf_species(bundle%species(1:bundle%n_prim))

The '*' allows an arbitrary number of repeats of the specified format and should suppress the compressed output format.

However, if the compiler outputs in compressed format than it should be able to read back in in the same compressed format. Hopefully the helpdesk will be able to get to the root of why that does not work.