Using it in C#

Jul 20, 2007 at 3:42 PM
I have downloaded the netcdf assembly and added as a reference to my project. I now want to create a similar CreateNETCDF app in C# just like the J# one.
Any help on that one?

Osei
Aug 23, 2007 at 11:31 AM
Edited Aug 23, 2007 at 1:36 PM

Osei wrote:
I have downloaded the netcdf assembly and added as a reference to my project. I now want to create a similar CreateNETCDF app in C# just like the J# one.
Any help on that one?

Osei

Sorry. Been away for a while...
Using this library in C# is a bit tricky. You still need some of vjslib.dll, so you'll have to reference it in your project as well. The code will look like this:

NetcdfFileWriteable ncfile = new NetcdfFileWriteable();
ncfile.setName("C:\\testncfile.nc");
Dimension latDim = ncfile.addDimension("lat", 3);
Dimension lonDim = ncfile.addDimension("lon", 4);
Dimension timeDim = ncfile.addDimension("time", -1);
Dimension[] dim3 = new Dimension[3];
dim3[0] = timeDim;
dim3[1] = latDim;
dim3[2] = lonDim;
ncfile.addVariable("rh", java.lang.Integer.TYPE, dim3);
ncfile.addVariableAttribute("rh", "long_name", "relative humidity");
ncfile.addVariableAttribute("rh", "units", "percent");
ncfile.addVariable("T", java.lang.Double.TYPE, dim3);
ncfile.addVariableAttribute("T", "long_name", "surface temperature");
ncfile.addVariableAttribute("T", "units", "degC");
ncfile.addVariable("lat", java.lang.Float.TYPE, new Dimension[] { latDim });
ncfile.addVariableAttribute("lat", "units", "degrees_north");
ncfile.addVariable("lon", java.lang.Float.TYPE, new Dimension[] { lonDim });
ncfile.addVariableAttribute("lon", "units", "degrees_east");
ncfile.addVariable("time", java.lang.Integer.TYPE, new Dimension[] { timeDim });
ncfile.addVariableAttribute("time", "units", "hours");
ncfile.addGlobalAttribute("title", "Example Data");
ncfile.create();

Console.WriteLine("ncfile = " + ncfile);
int[, ,] rhData = {{{ 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12}},
{{21, 22, 23, 24}, {25, 26, 27, 28}, {29, 30, 31, 32}}};
ArrayInt rhA = new ArrayInt.D3(2, latDim.getLength(), lonDim.getLength());
int i, j, k;
Index ima = rhA.getIndex();
for (i = 0; i < 2; i++)
for (j = 0; j < latDim.getLength(); j++)
for (k = 0; k < lonDim.getLength(); k++)
rhA.setInt(ima.set(i, j, k), rhData[i, j, k]);
ncfile.write("rh", rhA);

double[, ,] tData = {{{ 1, 2, 3, 4}, {2, 4, 6, 8}, { 3, 6, 9, 12}},
{{2.5, 5, 7.5, 10}, {5, 10, 15, 20}, {7.5, 15, 22.5, 30}}};
ArrayDouble tA = new ArrayDouble.D3(2, latDim.getLength(), lonDim.getLength());
ima = tA.getIndex();
for (i = 0; i < 2; i++)
for (j = 0; j < latDim.getLength(); j++)
for (k = 0; k < lonDim.getLength(); k++)
tA.setDouble(ima.set(i, j, k), tData[i, j, k]);

ncfile.write("T", tA);
ncfile.write("lat", ArrayAbstract.factory(new float[] { 41, 40, 39 }));
ncfile.write("lon", ArrayAbstract.factory(new float[] { -109, -107, -105, -103 }));
ncfile.write("time", ArrayAbstract.factory(new int[] { 6, 18 }));
ncfile.close();
Jul 20, 2010 at 4:13 AM

I don't know if you are still working about this project but...

I have try to build the code in c#, but I have a many errors with the "java.lang.Integer.TYPE" argument.

I generated the project with c# and I added the reference "netcdf.dll".

Any help about this.

Thank you very much!

Jul 20, 2010 at 11:40 AM

Most likely, you get this error because you are trying to use a J# version from 1.0 release. You should download the C# wrapper in C.1.0 release. You can use it with netcdf.dll C library provided by Unidata.

From: isamaima [mailto:notifications@codeplex.com]
Sent: Tuesday, July 20, 2010 7:14 AM
To: dmedv@wdcb.ru
Subject: Re: Using it in C# [netcdf:12833]

From: isamaima

I don't know if you are still working about this project but...

I have try to build the code in c#, but I have a many errors with the "java.lang.Integer.TYPE" argument.

I generated the project with c# and I added the reference "netcdf.dll".

Any help about this.

Thank you very much!

Read the full discussion online.

To add a post to this discussion, reply to this email (netcdf@discussions.codeplex.com)

To start a new discussion for this project, email netcdf@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



__________ Information from ESET NOD32 Antivirus, version of virus signature database 5294 (20100720) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru/.ml
Jul 20, 2010 at 4:33 PM

Thank you very much for your answer. I will try to do your recomendation!

 

Nov 17, 2010 at 8:42 PM

dmedv,

 

I appologize up front for not knowing the answer to this question. Seems as though it should be something very easy. I've downloaded the DotNetCdf.cs and tried to compile. What do I need to do for the compiler to recognize NcType and CreateMode? Are these classes that are defined in another library? Any help is greatly appreciated!

 

Thanks!

 

Nov 18, 2010 at 9:37 AM

The types are declared in Constants.cs. I've just added the file to the download section. Sorry for the inconvenience.

P.S. We no longer actively support this project, but you might also want to check sds.codeplex.com, which offers a higher level interface for different data sources, including NetCDF.

From: keitheweber [mailto:notifications@codeplex.com]
Sent: Wednesday, November 17, 2010 11:43 PM
To: dmedv@wdcb.ru
Subject: Re: Using it in C# [netcdf:12833]

From: keitheweber

dmedv,

I appologize up front for not knowing the answer to this question. Seems as though it should be something very easy. I've downloaded the DotNetCdf.cs and tried to compile. What do I need to do for the compiler to recognize NcType and CreateMode? Are these classes that are defined in another library? Any help is greatly appreciated!

Thanks!

Read the full discussion online.

To add a post to this discussion, reply to this email (netcdf@discussions.codeplex.com@discussions.codeplex.com)

To start a new discussion for this project, email netcdf@discussions.codeplex.com@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