ascii weird behaviour

Hi all,

I’m trying to make MM5 works on my PC with Debian distro.
It would be nice if someone could give me some hint about this error I got when running PREGRID after a succesful compilation:


-I execute the pregrid.csh script that starts ‘pregrid_on84.exe’
-‘pregrid_on84.exe’ make a call to ‘rd_on84()’ fortran routine.
-From there, a call is made to ‘ron84_record()’ fortran routine.
-From there, a last call is made to COPEN() which resides in a C code.

Erroneous result:

-The name of file to be opened arrives bad to COPEN().
-There are many garbage chars appended to real file name.

Original file name (sent by fortran code): ON84FILE
File name when arrives cio.c: “ON84FILE ÐUnknown nk: NULLrd_on84.fNot using field number PRESSUREPSFC`ê”

I compile the codes as following (default package settings):


compile cio.c:
cc -DDEC -DBIT32 -I. -c cio.c

create library:
ar ru ./libpgu.a  [...several objects...] cio.o

Compile codes:
/lib/cpp -I. -c -P -DDEC -DBIT32 -traditional ron84_record.F > ron84_record.f
pgf90 -c Mfreeform -byteswapio -I. ron84_record.f

/lib/cpp -I. -c -P -DDEC -DBIT32 -traditional rd_on84.F > rd_on84.f
pgf90 -c Mfreeform -byteswapio -I. rd_on84.f

Link and creation of executable:
pgf90 -o pregrid_on84.exe rd_on84.o ron_record.o libpgu.a


I guess it must be someting dealing with null termination of strings and the way it differs between fortran and C

Thanks for your suggestions


Hi Jean,

It looks like a program error to me. The Fortran character string ‘on84flnm’ has length of 9 and does not end with a blank or NULL. This is fine except that the copen routine in cio.c does expect a blank or NULL to end the string. I think the best solution is to append a ‘\0’ to the end of ‘on84flnm’ when COPEN is called. Also, if you look at other pregridder directories, such as grib.misc’s rd_grib.F at line 134, you’ll see that this is exactly what is done.

To fix, change line 31 to ron84_record.F

call COPEN(iunit, ifd, trim(on84flnm)//char(0), 1, ierr, -1)

Hope this helps,

Hi Mat,

thank you very much for your fast reply.
It is exactly as you explained and now it works fine.