Convert Multiple NetCDF files into CSVs

Jun 3, 2011 at 4:30 PM

Hi,

I have multiple NetCDF files that I want to convert to CSV files.  Is it possible to do this from C#?  I'd like to simply specify the source file folder and the destination file folders.

Thanks much...

 

Marilyn

Developer
Jun 3, 2011 at 6:34 PM

Hi Marilyn,

The simplest way to do that is to do the following:

1. Open command window from the folder containing NetCDF files (if you need instructions, take a look here).

2. Type the command:

 

forfiles /m *.nc /c "cmd /c sds copy @file c:\temp\outdir\\@fname.csv?openMode=create"

You can replace c:\temp\outdir with the real path to folder where you want to collect CSV files (note that there must two slashes before @fname to be parsed properly, otherwise one slash ('\@') would escape the reserved symbol '@').

More information about forfiles command is here.

 

 

Regards,

Dmitry.

Developer
Jun 3, 2011 at 6:42 PM

Sorry, just noticed that you need to convert files from C#. 

That's very simple, too. Just use foreach statement to enumerate files from the given folder; use System.IO.Directory class for that:

Directory.EnumerateFiles(@"c:\temp\library\", "*.nc")

And for each file use such code:

DataSet.Open(filePath).Clone(Path.Combine(outputDir, Path.GetFileName(filePath) + ".csv") + "?openMode=create").Dispose();

Jun 3, 2011 at 6:44 PM

Thank you very much for your reply.  I'll work on this and let you know if I encounter anything.

Marilyn

Jun 3, 2011 at 6:51 PM

Hi,

Works perfectly!!!  Thank you so much,

 

Marilyn