null character without reason in written files

Steve Kargl sgk@troutmask.apl.washington.edu
Thu Oct 31 15:20:00 GMT 2013


On Thu, Oct 31, 2013 at 03:49:54PM +0100, unomas wrote:
> 
> >> #define OTHER_SPECIE 0
> >> #define MAIN_SPECIE 2
> >> #define BOUNDARY 4
> >> #define LIMIT 5
> >
> > This doesn't look like Fortran.
> 
> It is the language of the C preprocessor, and I think it is always 
> available in a fortran compiler.

Yes, I know and ...

> > What is the exact command
> > line that you use to compile the code.

this is the reason why I asked about the command line.
Are you doing something like 

gfortran -DEBUG -DSOMETHING -o z -O2 file.F90

> I use a Makefile. However, for compiling it is used the code of a RNG 
> in fortran 70, which was given to me by a teacher, but this hasn't any 
> note about a license (I suppose that it was copied from some text book). 
> Maybe the rules of the mailing lists don't allow me to post that code. I 
> didn't find any well-known RNG written in fortran with a clear license 
> browsing the internet.

Posting code of unknown origin to the mailing list is probably not
a good idea.  However, as you are using a Fortran95 compiler, it
comes with a PRNG.  See the manual for RANDOM_NUMBER intrinsic
subroutine.

> (By the way, I had an idea. The code is implementing a look-up table of 
> 10000*10000 for a matrix, accessed by an integer index. Normally, only 
> indexes between 1 and a not so big number are used. But occasionally 
> they could be bigger. Maybe there is some kind of overflow. However, I 
> would not understand why a bunch of null's appear when writting float 
> values.)

One of the checks -fcheck=all performs is for an out-of-bounds
array index.  The nulls you are seeing may be a result of writing
out invalid array elements.

If you have access to a system with valgrind, you can also run
compiled code under it.  This will quickly tell you if you have
invalid memory accesses.

-- 
Steve



More information about the Fortran mailing list