Is there a way to pass NULL in PGI Fortran?

I’m experiencing an error with the use of a NetCDF function that PGI’s compiler doesn’t like (yet Intel’s ifort just passes by with no complaint). Namely, it’s the NF_DEF_VAR_FILL NetCDF FORTRAN 77 function.

In our code, we call this by:

STATUS = NF_DEF_VAR_FILL    (UNIT, varid, NF_NOFILL, )

where we are passing a ‘NULL’ to the command by passing nothing to FILL_VALUE:

FILL_VALUE
    A value which will be used as the fill value for the variable. Must be the same type as the variable. This will be written to a _FillValue attribute, created for this purpose. If NULL, this argument will be ignored.

As I said, Intel compiles this call just fine, but PGI says:

PGF90-S-0034-Syntax error at or near )

I imagine this is because it’s seeing a trailing comma. Is there a compile-time flag I can use to emulate the Intel behavior (a la -fno-ugly-comma, I guess)? Or is there a standard way to pass a ‘NULL’ to a Fortran interface like this?

Hi Matt,

I needed to do some research on this since to me it’s obviously a syntax error. It turns out that it’s an old VAX Fortran extension that the g77 documentation calls a “distensions: extensions that just plain look ugly in the harsh light of day.” Full docs HERE.

While we do support most VAX extensions, we don’t support this one. Instead, you may want to try another VAX Fortran extension “%VAL(0_8)” to passing in a 64-bit zero by value. The C “fill_value” is a void pointer so passing it a 64-bit 0 is equivalent to a C NULL pointer.

STATUS = NF_DEF_VAR_FILL    (UNIT, varid, NF_NOFILL, %VAL(0_8))

Though, probably the most “correct” solution would be to use F2003 standard ISO_C_BINDING and not use extension at all.

  • Mat

Another developer here came up with a clever solution. We used C_NULL_PTR from ISO_C_BINDING:

STATUS = NF_DEF_VAR_FILL    (UNIT, varid, NF_NOFILL, C_NULL_PTR)

PGI didn’t mind compiling this (though I’m not sure if it works since I don’t use that code path), and it worked with Intel and was successful there.

Thanks again for the help,
Matt