Re: [netcdfgroup] add_offset and scale_factor

Pooran,

It looks like your user function cf90_get_att is ignoring the netCDF
function status code.  You need to add some code to check for the existence
of scale_factor and add_offset attributes.  An easy way to do this is to
call nf90_get_att and check the returned netCDF status code.  There is a
specific error code for "attribute does not exist".  See documentation for
that function.

Use the status information to automatically decide how to handle scale and
offset corrections, as Daniel described.

--Dave


On Mon, Apr 15, 2019 at 9:15 AM Daniel Neumann <
daniel.neumann@xxxxxxxxxxxxxxxxx> wrote:

> Dear Pooran,
>
> the scale_factor and add_offset attributes are optional. They are used for
> packing data (search for "netcdf packing data" for details) and for similar
> purposes. If they do not exist, you can consider scale_factor to be 1.0 and
> add_offset 0.0 (or you just ignore them and use the data as they are).
>
> Cheers,
> Daniel
>
>
> On 15.04.19 07:02, Pooran khedri wrote:
>
> Hi everybody,
> I have a piece of a code to read meteorological forcing  from ECMWF
> database   in a NetCDF format, Here is some of my piece code to read this
> file
>
>   !reading atmospheric pressure
>
>    CALL cf90_get_att(iunit, atmpID, "scale_factor", scale_factor)
>      CALL cf90_get_att(iunit, atmpID, "add_offset", offset)
>      CALL cf90_get_var(iunit, atmpID, atmpindat(:,:), filepars%timerec)
>      atmpindat = atmpindat*scale_factor + offset
>
> but I have downloaded the new meteorological file from another database in
> a NetCDF format , this new file is different from ECMWF file and it does
> not have    add_offset and scale_factor  in its attribute and my code does
> not read it and I have got many errors.
> I think I have to   add the add_offset and scale_factor to  the  new
> NetCDF file  or I have to  modify the FORTRAN code  that scaling is not
> used for this variable, but I do not know how to do them☺ ,I am new to
> using the NetCDF files and FORTRAN .
> I would be grateful if you could explain to me How to solve my problem.
>
> Pooran
>
>
  • 2019 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: