Hi,
some time ago, I reported a problem I´ve experienced using the VB.NET class
of NetCDF. The NetCDF files I am working with contain a 2-dimensional string
(or char) variable of the type
char peak_name(peak_number, _32_byte_string)
with the two dimensions peak_number=7 and _32_byte_string=32
The data of the variable peak_name are therefore 7 strings (the peak names).
Using the code
vartext = New StringBuilder(dimlen - 1)
res = NetCDF.nc_get_var_text(ncid, varid, vartext)
which was used by Ed Hartnett in a sample application he provided together
with the VB.NET wrapper class, I could read only one (the first) string
(peak name) from the 2-dimensional variable.
I now found a solution to read all string data (all peak names) from the
variable.
The data can all be read using the NetCDF function
Declare Ansi Function nc_get_var1_text Lib "netcdf.dll" (ByVal ncid As
Int32, _
ByVal varid As Int32, <[In](), Out()> ByVal indexp() As Int32, _
ByVal ip As StringBuilder) As Int32
As I understand, the first index value of the indexp() variable
(indexp(0))points to the data of the first dimension, the second index value
(indexp(1)) to the second dimension. A definite set of values points to a
definite character (for example indexp(0)=0 and indexp(1) =1 points to the
second character in the first string). The function stores that char in the
StringBuilder ip.
Now one can loop through both dimensions and read each caracter at a time.
The way I implement this in my code is as follows:
Me.listview.items.clear
res=NetCDF.nc_inq_varid (ncid, "peak_name", varid)
For k= 0 To number_of_peaks-1
dimname = New StringBuilder(32)
For i= 0 To 31
indexp(0)=k
indexp(1)=i
Try
res = NetCDF.nc_get_var1_text(ncid, varid,indexp,
varname)
If (res <> 0) Then exit for ' GoTo err
dimname.append(varname(0))
Catch ex as IndexOutOfRangeException
Exit For
End Try
Next i
Me.listView.Items.Add(dimname.tostring)
Next k
The error handling is necessary, because an IndexOutOfRangeException always
occurs when the variable i exceeds the length of a string (a peak name). The
second dimension (_32_byte_string) only specifies the maximum number of
characters of a peak name, but they can have a smaller length.
With best regards
H.J. Rieger
--
"Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
Jetzt aktivieren unter http://www.gmx.net/info