<nul> Characters in Fortran 77

Dear all:

I am working with a large scientific parallel code which uses unit 7 for formatted output. However, at some point the code writes one very long line with binary charachters to unit 7 which is supposed to contain only ascii data.

The error is hard to debug since some debugging output to
unit 7 seems to be missing. Instead there are these characters.
The code has hundred’s of FORMAT and WRITE and statements to unit 7.

I am running the code on a Cray XD1 system with Portland pgf77
compiler using the version mpich-pgi601.

Please give me a hint how to find the IO command which produces
the characters.

Best regards,


Hi Andreas,

Does your program call any C routines or system libraries which have a character array as an argument? C character arrays are NULL terminated, meaning that the ASCII Character 0 (NULL) denotes the end of the string. When passing Fortran character arrays to C functions, the NULL character must be appended, for example ‘string’//char(0). Try searching your code for “char(0)” to see if this is the case here. Also, if you return a character array from a C function, the array will most likely contain a NULL terminator.

Hope this helps,

Dear Mat:

No C routines are called. char(0) is never used in the code.

I found another astonishing fact about this bug: It seems that the fort.7 file is written for some time, then it is deleted and created new. Then some output is written in the file and, after a short time, the characters.

The beginning of the fort.7 output file is missing as if it has been deleted.

When I use

tail -f fort.7

there comes the message:

tail: file truncated

I have no idea what is going on here.


Hi Andreas,

I saw your post on comp.lang.fortran and I though some of the suggestions seemed like good ideas. The binary search method would help narrow down where the NULL is being printed.

Is the source available that I could take a look?

  • Mat