This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Matthew, > I need some help with doing index mapping in NetCDF v. 3.5.0 using VB > 6. I just want to transpose two indices in a NetCDF variable but it > won't work. > I have spent a whole day of crashing VB and I haven't got anywhere. My > netcdf api hasn't failed me until now. I am trying to use the function > > Public Declare Function nc_get_varm_double Lib "netcdf.dll" (ByVal ncid > As Long, ByVal varid As Long, ByRef startp As Long, ByRef countp As > Long, ByRef stridep As Long, ByRef imapp As Long, ByRef ip As Double) As > Long > > Firstly, I am hoping the above is correct. It is based on all my other > netcdf api conversions but to date I have only done read/write of netcdf > files with single value, array and subarray functions. I have never > tried anything like this before. > > My netcdf file has dimensions for lon, lat, and time. I have coordinate > variables for each as well. I also have a data variable declared as: > short water_u(time, lat, lon) ; > water_u:long_name = "Eastward Water Velocity" ; > water_u:units = "meters/second" ; > water_u:_FillValue = -10000s ; > water_u:scale_factor = 0.01f ; > water_u:add_offset = 0.f ; > > I need to read this into a VB variable declared as: > Dim WaterU(1 To lNumLat, 1 To lNumLon) As Double > > If it wasn't for the fact that the array indices must be in this order I > would be fine. I could just transpose after read the > NetCDF variable but it very ineligent and rather slow in VB so I prefer > using the NetCDF api. This is what I am trying to do now: > > Dim dims(1 To 3) As Long, count(1 To 3) As Long, stride(1 To 3) As > Long, imap(1 To 3) As Long > > dims(1) = lCurrentTime - 1 'VB arrays are base 1 for me so I > must subtract 1 to get NetCDF array index > dims(2) = 0 > dims(3) = 0 > > count(1) = 1 'Only 1 time step > count(2) = lNumLat 'All the latitudes and > longitudes please > count(3) = lNumLon > > stride(1) = 1 > stride(2) = 1 > stride(3) = 1 > > imap(1) = 1 '** I am guessing my > problem is here but no combination of numbers has worked for me > imap(2) = nLon > imap(3) = CLng(nLat * nLon) > > NcErr = nc_get_varm_double(fHandle, var_id, dims(1), count(1), > stride(1), imap(1), dblArray(1, 1)) > If NcErr <> 0 Then GoTo NcErrOut It doesn't look like you've gotten any answers yet to your question, so I'll try an answer, although I don't have a VB installation and don't know much about VB. I assume from your question that VB arrays are similar to Fortran arrays, in that the first dimension varies fastest (also called column major order). Try imap(1) = NumLat*NumLon imap(2) = 1 imap(3) = NumLat although it may not matter what value imap(1) is set to in this case, since I don't think it will be used. imap(2)=1 means that the distance between two different lat indices in your internal array is just 1 value, and imap(3)=NumLat means that the distance between successive lon values is NumLat values. --Russ