[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 20000320: Getting attributes with the netCDF F90 interface
- Subject: Re: 20000320: Getting attributes with the netCDF F90 interface
- Date: Tue, 21 Mar 2000 10:00:36 -0700
Robert and Bill,
> I used Bill's program and monkied about a bit with the netcdf-f90
> interface. The F90 function that gets called
> (nf90_get_att_one_FourByteReal ) is simply:
>
> nf90_get_att_one_FourByteReal = &
> nf_get_att_real(ncid, varid, name, nf90_real4, 1, values)
>
> Printing out "values" before and after the call to nf_get_att_real
> shows that it doesn't get changed by the Fortran 77 call. It looks
> like the problem is below the F90 interface, and should be
> reproducable in the F77 interface.
>
> Russ, is there anything problematic about the order in which Bill is
> re-syncing the file before or after the attribute read?
No, but there should always be a call to nf90_close(ncid) before exiting
in any program that writes to a netCDF file.
Also, the calls to nf90_redef(ncid) and nf90_enddef(ncid) around the
call to nf90_put_att(...) are unnecessary, since the program is only
writing the value of an existing attribute, not creating a new
attribute.
Nevertheless, I tried to reproduce the problem with the appended f77
program, but it seemed to work as expected on a Sun Sparc/Solaris 7
platform and an SGI IRIX64 6.5 platform, even without the nf90_close()
call. I didn't remake the netCDF library to use 64 bit objects first,
but just used the default 32-bit library we have made for netCDF 3.5:
$ /bin/f90 ex.F -mips4 -r10000 -32 -O3 -r8 -mp -o ex ../libsrc/libnetcdf.a
$ cp eof-test.nc eof.nc # so attribute mean:scale_factor = .01
$ ./ex
scale used in nf_put_att_real call is 3.05810407699999998E-3
before nf_get_att_real, scale is 1.
after nf_get_att_real, scale is 3.05810384452342987E-3
Then I built the 64-bit netCDF library and tried the above using a
"-64" flag when compiling, with exactly the same results.
Bill, it would be helpful if you could compile the ex.F program I've
appended for the Fortran 77 interface and see if it works as expected
or shows the problem, because I can't make it occur in the f77
interface. Maybe there is some problem involving the "mean" array,
which I removed from this example to try to isolate the problem ...
--Russ
----- ex.F, to test netCDF f77 interface for possible nf_get_att_real() problem
program ex
implicit none
#include "/upc/netcdf/include/netcdf.inc"
integer ncid,varid
real scale
call nccall( nf_open('eof.nc',NF_WRITE,ncid) )
call nccall( nf_inq_varid(ncid,'mean',varid) )
call nccall( nf_redef(ncid) )
scale = 3.058104077E-3
print*,'scale used in nf_put_att_real call is',scale
call nccall( nf_put_att_real(ncid,varid,'scale_factor',NF_FLOAT,
* 1,scale) )
call nccall( nf_enddef(ncid) )
scale = 1.
print*,'before nf_get_att_real, scale is',scale
call nccall( nf_get_att_real(ncid,varid,'scale_factor',scale) )
print*,'after nf_get_att_real, scale is',scale
call nccall( nf_sync(ncid) )
* nf_close should always be called before exiting, when writing to a file.
call nccall( nf_close(ncid) )
end
*------------------------------------------------------------------------
* nccall
* This subroutine checks if a netCDF error occured
* and quits the program if it did.
*
* ierr: Return value from a netCDF function call
*
*------------------------------------------------------------------------
subroutine nccall(ierr)
integer ierr
#include "/upc/netcdf/include/netcdf.inc"
if( ierr.ne.NF_NOERR ) then
print*,nf_strerror(ierr)
stop 'Stopped due to error associated with netCDF.'
endif
return
end