[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #ITH-188331]: netcdf data append in f90



Rama,

> I tried your suggestions in the following way:
> 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> INTEGER, INTENT(IN) :: netcdffileid
> INTEGER :: status, recID, nRecs, start, count
> 
> ! Before we start writing the data into an existing file
> ! We need to tell where to start append the data
> ! and the count of records
> 
> status=nf90_inquire(netcdffileid,unlimitedDimID=recID)
> print*, 'recID=',recID
> 
> status=nf90_inquire_dimension(netcdffileid,recID, len=nRecs)
> print*, 'nRecs=', nRecs
> 
> print*, 'successfully came up to put var routine'
> print*, 'scaled data=', scaled_orbitdata( Ch1OrbitMeanSpCount_ghrr, &
> Ch1OrbitMinSpCount_ghrr, &
> Ch1OrbitMaxSpCount_ghrr )
> print*, 'netcdffileid=',netcdffileid
> print*, 'Ch1OrbitMeanSpCount_ghrr_id=',Ch1OrbitMeanSpCount_ghrr_id
> 
> call check (nf90_put_var(netcdffileid,Ch1OrbitMeanSpCount_ghrr_id,
> scaled_orbitdata( Ch1OrbitMeanSpCount_ghrr, &
> Ch1OrbitMinSpCount_ghrr, &
> Ch1OrbitMaxSpCount_ghrr ), start=nRecs+1,
> count= 1) )
> print*, 'successfully wrote the Ch1 data'
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
> +
> 
> I get the following error:
> ******************************************************************************
> In file ghrr_orbitstat_netcdf_update_module.f90:494
> 
> call check (nf90_put_var(netcdffileid,Ch1OrbitMeanSpCount_ghrr_id,
> scaled_or
> 1
> Error: Generic function 'nf90_put_var' at (1) is not consistent with a
> specific intrinsic interface
> *****************************************************************************************
> 
> If I don't use the start, count options, then no error pops up and it
> overwrites. Instead of update, overwrite happens and I understand
> why it is from your previous e-mail reply.
> 
> Please note that the "scaled_orbitdata()" is a local function for
> scaling the data into integer.
> 
> If you know why this error pops-up please let me know.

Yes, it turns out when you are only appending a simple scalar value to
a record variable, no "count" argument should be used, although I was
providing it as "1" in the example I sentt you.  Also, due to
Fortran-90 overloading rules, in order to match the voerloaded
functions in the F90 interface you actually have to make the "start"
parameter a 1-dimensional array, rather than a scalar value, to match
the 1-dimensional array you are writing to.

So when I wrote:

> 5. nf90_put_var(ncid, varid, data, start = nRecs + 1, count = 1)
>    Writes a single data value at the end of the array, assuming the
>    netCDF variable you are writing is one-dimensional.

it should have actually been

5. nf90_put_var(ncid, varid, data, start = (/ nRecs + 1 /))
   Writes a single data value at the end of the array, assuming the
   netCDF variable you are writing is one-dimensional.

or you could store the start value in a 1-dimensional array and give
that array as the value of the optional starts parameter, as in

     integer :: starts(1)
     st(1) = nRecs + 1
     nf90_put_var(ncid, varid, data, start = st)

Sory about the bad advice, I should have tried compiling my example
and would have seen that including the count parameter when appending
jusrt a scalar wouldn't match any of the overloaded function
signatures for nf90_put_var() so would give a compile error.  We
should make this clearer in the documentation or in an example.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: ITH-188331
Department: Support netCDF
Priority: Normal
Status: Closed