On 04/25/2016 12:34 PM, Thompson, Matt (GSFC-610.1)[SCIENCE SYSTEMS AND
APPLICATIONS INC] wrote:
On 04/22/2016 10:37 AM, Arlindo Arriaga wrote:
Dear all
NASA has decided to change formats of MODIS data files with ocean biology
products from hdf4 to netcdf-4, and my software turned useless. I was
asked
to change my Fortran executables from hdf4 to netcdf-4. After training
myself to get control on using netcdf-4 library functions of Fortran
interface, I hit on a road bloc: the function NF90_GET_VAR to read
datasets
works well for arrays of single types (integers or reals) but NOT for
compound user defined types, like the structure sstdata
TYPE binSST
real(kind=4) :: sum
real(kind=4) :: sum2
end TYPE binSST
TYPE(binSST), allocatable, dimension(:) :: sstdata
In case someone has hit on a similar problem or has a suggestion, I would
kindly appreciate the help.
I work in Linux (Ubuntu) 64 bits, and the Fortran compiler is gfortran.
Arlindo,
Are you trying to use compound variables using nf90_def_compound, a la:
http://stackoverflow.com/questions/6924073/netcdf-and-fortran-structures
I've used these before and they seem to work well. If not, what does
your code look like?
Arlindo,
I'm beginning to think you are right. I grabbed a file that contains
compound data (in a group, so even more fun), and I've been trying to
figure out how to NF90_GET_VAR the data and I'm not sure I can.
The nc4 file has:
group: level-3_binned_data {
types:
compound binListType {
uint bin_num ;
short nobs ;
short nscenes ;
float weights ;
float time_rec ;
}; // binListType
compound binDataType {
float sum ;
float sum_squared ;
}; // binDataType
compound binIndexType {
uint start_num ;
uint begin ;
uint extent ;
uint max ;
}; // binIndexType
dimensions:
binListDim = UNLIMITED ; // (4433821 currently)
binDataDim = UNLIMITED ; // (4433821 currently)
qualityDim = UNLIMITED ; // (4433821 currently)
binIndexDim = UNLIMITED ; // (4320 currently)
variables:
binListType BinList(binListDim) ;
binDataType sst(binDataDim) ;
byte qual_l3(qualityDim) ;
binIndexType BinIndex(binIndexDim) ;
For simplicities sake, I decided to focus on binDataType because that is
easy and I don't have to mess with int(int16) and the like. I defined my
own as:
type binDataType
sequence
real(real32) :: sum
real(real32) :: sum_squared
end type binDataType
type(binDataType), allocatable, dimension(:) :: sst
I don't think sequence is needed, but couldn't hurt I guess.
Now I am definitely sure that "sst" is varids(2) thanks to a
nf90_inq_varids on the group, but when I try to compile:
retval = nf90_get_var(grpid(1), varids(2), sst)
you get:
example_reader.F90(87): error #6284: There is no matching specific function for
this generic function reference. [NF90_GET_VAR]
retval = nf90_get_var(grpid(1), varids(2), sst)
---------------^
compilation aborted for example_reader.F90 (code 1)
And, since I don't think the netcdf interfaces have a type(*) or
class(*) variant, there is no interface that seems to work according to
the compiler. But, the documentation says in 5.1: "Read data of
user-defined type with NF90_GET_VAR (see NF90_GET_VAR)."
Does anyone know how to do this other than through the C or Python
interfaces?
Matt
--
Matt Thompson, SSAI, Sr Scientific Programmer/Analyst
NASA GSFC, Global Modeling and Assimilation Office
Code 610.1, 8800 Greenbelt Rd, Greenbelt, MD 20771
Phone: 301-614-6712 Fax: 301-614-6246
http://science.gsfc.nasa.gov/sed/bio/matthew.thompson