[ncl-talk] convert grd to nc

Dennis Shea shea at ucar.edu
Wed May 23 15:22:14 MDT 2018


Hi Amy,

The Climate Data Operators (CDO) can be used to convert a binary file to
netCDF. The command is described at:

https://www.ncl.ucar.edu/Applications/grads.shtml

%>  cdo -f nc import_binary ndvip.ctl NDVI.polar_82-17.nc

cdo import_binary: Processed 1 variable ( 1.27s )
----------------------------------------------------------------------
This has a 'minor' problem.

The file contains the following which looks good!

        float ndvi(time, lat, lon) ;
                ndvi:long_name = "normalized difference vegetation index" ;
                ndvi:*_FillValue = -999.f *;
                ndvi:*missing_value = -999.f *;

However, if we observe *the golden rule of data processing: Look at your
data*

%> ncdump -v ndvi  NDVI.polar_82-17.nc | less

You will see the the actual _FillValue and missing_value should be

*-0.0999**ndvi *=
  *-0.0999*, -0.0999, -0.0999, -0.0999, -0.0999, -0.0999, -0.0999, -0.0999,
[SNIP]

>From and NCL perspective, this is readily addressed:

   f = addfile("NDVI.polar_82-17.nc", "r")
   ndvi = f->ndvi
   ndvi at _FillValue = -0.0999   ; change to correct _FillValue
   printVarSummary(ndvi)

You could also use the netCDF Operator's attribute editor:
ncatted <https://linux.die.net/man/1/ncatted>
to change the values on the file.
-----------------------------------------------------------------------
The files [~ 291 MB] created by the CDO [ NDVI.polar_82-17.nc ]  and NCL [
polar_82-17_MaxNDVI3g.grd.NCL.nc ] are at:

ftp ftp.cgd.ucar.edu
anonymous
your_email
cd pub/shea
get NDVI.polar_82-17.nc
get polar_82-17_MaxNDVI3g.grd.NCL.nc
quit
===========================================

They are functionally equivalent
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
============================================
The NCL script you sent had an error or two. The .ctl file had:

[1] the .ctl  pointed to

  DSET ^polar82-*16*_maxndvi_dat.grd

The file you sent was named: polar_82-17_MaxNDVI3g.grd
The .ctl should point to:

  DSET ^polar_82-*17*_MaxNDVI3g.grd

====
The file you sent has size:

299220480 May 22 22:25 polar_82-17_MaxNDVI3g.grd

nlat(=481)*mlon(=4320)*ntim(=36)*nbyte(=4) = 299220480

This means the the file has no 'extra' embedded bytes.
Fortran's sequential binary files have record boundaries. They add to the
size of the file.

This means that you should be using NCL's 'fbindirread' function.

  https://www.ncl.ucar.edu/Document/Functions/Built-in/fbindirread.shtml

and not 'fbinrecread' function.

See attached.

Good Luck




On Tue, May 22, 2018 at 7:05 PM, Amy Hendricks <ashendricks at alaska.edu>
wrote:

> Hell NCL heroes,
>
> I am trying to read in ndvi data in .grd format and convert to netcdf. The
> problem occurs when I go to read in the ndvi data. This script is modified
> from grads_2.ncl (https://www.ncl.ucar.edu/Applications/Scripts/grads_2.
> ncl). Please find attached the script, data, and ctl file. The ctl file
> is an example from my advisor, only the DSET and # of years are different.
>
> Thanks!
>
> Amy​
>  ndvip.ctl
> <https://drive.google.com/a/alaska.edu/file/d/1gfTy4cedHoVucV-YEan0Ph7NES9FfsMM/view?usp=drive_web>
> ​​
>  polar_82-17_MaxNDVI3g.grd
> <https://drive.google.com/a/alaska.edu/file/d/1DNzWno-3WmFqINZBY-ENH7nnMn0lsGvf/view?usp=drive_web>
>>
> --
> Amy Hendricks
> Graduate Research Assistant
> Department of Atmospheric Sciences
> University of Alaska Fairbanks
> IARC 343-R
> 907-388-9893
> ashendricks at alaska.edu
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180523/aee152fd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ndvi2netcdf.ncl
Type: application/octet-stream
Size: 5150 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180523/aee152fd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ndvip.ctl
Type: application/octet-stream
Size: 306 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180523/aee152fd/attachment-0001.obj>


More information about the ncl-talk mailing list