How to create and fill very large netcdf files?

Feb 18, 2013 at 2:52 AM

I'm trying to build a 3D (lon,lat,time) netcdf temperature variable as part of a netcdf file. The variables I want to include in the netcdf file are lon, lat, time, and temperature. Time is 1D, temperature is 3D, and lat/lon are 2D. I'm not a c# programmer and am only a beginning vb programmer (going from IDL or Matlab to .Net is no fun!). So, it's very difficult for me to follow the example code. Thank you very much!

Here's my code:

Imports Microsoft.Research.Science.Data.Imperative
Imports Microsoft.Research.Science.Data.Utilities
Imports Microsoft.Research.Science.Data
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnStart.Click
    Dim hrValue As String
    Dim file As NetCDF4.NetCDFDataSet
    Dim temp(,) As Single
    Dim precip(,) As Single
    Dim pet(,) As Single
    Dim tempstr As String = "TMP_110_HTGL"
    Dim precipstr As String = "A_PCP_110_SFC_acc1h"
    Dim petstr As String = "PEVAP_110_SFC_acc1h"

    'I don't know if these statements are correct or complete or just plain wrong
    Dim Hourly1979NLDASTemps As NetCDF4.NetCDFDataSet = DataSet.Open("L:\NLDAS2\1979\")
    Dim lat As Variable(Of Single) = Hourly1979NLDASTemps.AddVariable(Of Single)("lat", "x", "y") 'I would like to add this as a 2D variable (grid)
    Dim lon As Variable(Of Single) = Hourly1979NLDASTemps.AddVariable(Of Single)("lon", "x", "y") 'I would like to add this as a 2D variable as well (another grid)
    Dim time As Variable(Of DateTime) = Hourly1979NLDASTemps.AddVariable(Of DateTime)("time", "z")
    Dim hourlyTemps As Variable(Of Single) = Hourly1979NLDASTemps.AddVariable(Of Single)("hourlytemps", "x", "y", "z")

    For hr = 1 To 8760
        hrValue = Format(hr, "0000")
        file = DataSet.Open("L:\NLDAS2\1979\NLDAS1979." & hrValue & ".nc?openMode=open")
        temp = file.GetData(Of Single(,))(tempstr)
        precip = file.GetData(Of Single(,))(precipstr)
        pet = file.GetData(Of Single(,))(petstr)

        'temp is a 2D array (1 for each hour of the year) - how do I add them to the 'hourlyTemps' variable?
End Sub
End Class