title: How to extract data from NetCDF file using C# and Microsoft Scientific Data Set?
body: <p>I am trying to extract data from a NetCDF file using <a href="https://www.microsoft.com/en-us/download/details.aspx?id=52412" rel="nofollow noreferrer">Microsoft's Scientific Data Set libraries (SDS)</a>. I'm restricted to using MS SDS and C#. I'm not a programmer by trade so I'm struggling to get the basics working. To begin with I'd like to write a simple script to extract data and write it to a .csv file.
  Using the <a href="https://www.codeplex.com/Download?ProjectName=sds&amp;DownloadId=127282" rel="nofollow noreferrer">introduction doc</a> and codeplex tutorials. I've tried to write a simple C# console app which just reads the file and writes it out to the console or ideally to a .csv file. </p>
  
  <p>using SDS 1.3 command line I can view the contents of my test file: </p>
  
  <pre><code>D:\NetCDF&gt;sds list test.nc
  [2] ACPR of type Single (Time:85) (south_north:213) (west_east:165)
  [1] Times of type SByte (Time:85) (DateStrLen:19)
  D:\NetCDF&gt;
  </code></pre>
  
  <p>My script looks like this: </p>
  
  <pre><code>using System;
  using System.IO;
  using sds = Microsoft.Research.Science.Data;
  using Microsoft.Research.Science.Data.Imperative;
  
  
  namespace NetCDFConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              /// Gets the path to the NetCDF file to be used as a data source.
              var dataset = sds.DataSet.Open("D:\\NetCDF\\test.nc?openMode=readOnly");
  
              SByte[,] times = dataset.GetData&lt;SByte[,]&gt;("Times");
              //Int32[,] times = dataset.GetData&lt;Int32[,]&gt;("Times");
  
              //Single[] longitudes = dataset.GetData&lt;Single[]&gt;("west_east");
              //var latitudes = dataset.GetData&lt;Single[]&gt;("south_north");
              Single[,,] dataValues = dataset.GetData&lt;Single[,,]&gt;("ACPR");
  
              for (int iTime = 50; iTime &lt; 60; iTime++)
              {
                  for (int iLongitude = 130; iLongitude &lt; 150; iLongitude++)
                   {
                      for (int iLatitude = 130; iLatitude &lt; 140; iLatitude++)
                      {
                          // write output data
                          float thisValue = dataValues[iTime,iLatitude,iLongitude];
  
                          Console.WriteLine(iTime);
                          Console.WriteLine(iLatitude);
                          Console.WriteLine(iLongitude);
                          Console.WriteLine(thisValue);
  
                      }
                   }
              }
          }
      }
  } 
  </code></pre>
  
  <p>If I comment out the var Times... line it runs. But I'm struggling to get SDS to read Time Dimension. If I use SByte it complains that the variable doesn't exist. If I use Int32 it complains about converting to string.  </p>
  
  <pre><code>System.InvalidOperationException was unhandled
    HResult=-2146233079
    Message=Requested variable does not exist in the data set
    Source=ScientificDataSet
    StackTrace:
         at Microsoft.Research.Science.Data.Imperative.DataSetExtensions.FindVariable(DataSet dataset, Func`2 predicate)
         at Microsoft.Research.Science.Data.Imperative.DataSetExtensions.GetData[D](DataSet dataset, String variableName)
         at NetCDFConsoleApp.Program.Main(String[] args) in \\gdc-fs01\user$\prm\Visual Studio 2015\projects\NetCDFConsoleApp\Program.cs:line 16
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: 
  </code></pre>
  
  <p>What am I missing? </p>