Need help reading NetCDF data using C#

Jun 1, 2011 at 6:47 PM

Hi,

I'd like to read NetCDF data into a DataGridView using C#.  I tested a NetCDF file from National Weather Service and from the command line, I got the following schema:

[9] hrap_yor of type Single
[8] hrap_xor of type Single
[7] timeofcreation of type SByte (dates:11)
[6] timeofdata of type SByte (dates:11)
[5] true_lon of type Single
[4] true_lat of type Single
[3] lon of type Single (latlong:4)
[2} lat of type Single (latlong:4)
[1] amountofprecip of type Int16 (hrapy:813) (hrapx:1051)

My code snippet is as follows: (using Windows Form):

private void  btnOK_Click(object sender, EventArgs e)
{
    try
    {
      var dataset = sds.Dataset.Open("nws_precip_conus_20110531.nc?openMode=readOnly");

      //Get data of variables
      Single hrap_yor = dataset.GetData<Single>("hrap_yor");
      Single hrap_xor = dataset.GetData<Single>("hrap_xor");
      SByte[] timeofcreation = dataset.GetData<SByte[]>("timeofcreation");
      SByte[] timeofdata = dataset.GetData<SByte[]>("timeofdata");
      Single true_lon = dataset.GetData<Single>("true_lon");
      Single true_lat = dataset.GetData<Single>("true_lat");
      Single lon = dataset.GetData<Single>("lon");
      Single lat = dataset.GetData<Single>("lat");
      Int16[] amountofprecip = dataset.GetData<Int16[]>("amountofprecip");
    }

With the above, I'm getting an error:  "Cannot unambiguously identify a variable in the dataset."

Can anyone help?  Thanks in advance...

Marilyn

Jun 1, 2011 at 10:12 PM

Hi,

Sorry...I can't really make use of this approach.  Will try some other approach...

Jun 2, 2011 at 6:15 AM

Hi Marilyn,

The reason of the error is the wrong dimensionality of type you have specified for lon, lat, and amountofprecip. So instead of 

Single lon = dataset.GetData<Single>("lon");
Single lat = dataset.GetData<Single>("lat");
Int16[] amountofprecip = dataset.GetData<Int16[]>("amountofprecip");

you should have written

Single[] lon = dataset.GetData<Single[]>("lon");
Single[] lat = dataset.GetData<Single[]>("lat");
Int16[,] amountofprecip = dataset.GetData<Int16[,]>("amountofprecip");

Rank of a variable is seen from the schema: lon and lat depends on a single dimension latlong, and amountofprecip depends on 2 dimensions hrapy and hrapx.

 

Regards,

Dmitry.

Jun 3, 2011 at 4:50 PM
Hi,

Thanks. That helps.

Marilyn


From: [email removed]
To: [email removed]
Date: Wed, 1 Jun 2011 22:15:45 -0700
Subject: Re: Need help reading NetCDF data using C# [sds:259817]

From: dvoits
Hi Marilyn,
The reason of the error is the wrong dimensionality of type you have specified for lon, lat, and amountofprecip. So instead of
Single lon = dataset.GetData<Single>("lon");
Single lat = dataset.GetData<Single>("lat");
Int16[] amountofprecip = dataset.GetData<Int16[]>("amountofprecip");


you should have written

Single[] lon = dataset.GetData<Single[]>("lon");
Single[] lat = dataset.GetData<Single[]>("lat");
Int16[,] amountofprecip = dataset.GetData<Int16[,]>("amountofprecip");


Rank of a variable is seen from the schema: lon and lat depends on a single dimension latlong, and amountofprecip depends on 2 dimensions hrapy and hrapx.

Regards,
Dmitry.

Read the full discussion online.
To add a post to this discussion, reply to this email (sds@discussions.codeplex.com)
To start a new discussion for this project, email sds@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com