NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hello! Referring to: "If the error is suppressed (with "OnError Resume Next") then I can read some simple data from the *.cdf file. But if string variables or array variables are involved, the program fails or even crashes." for this case, I want to right away say that you need to keep an eye on how you pass your arrays. You have to pass them by referencing the first element of the array. For example, I want to load a longitude variable into an array: 'ncFile is the handle to a NetCDF file from nc_open 'lon_id is the longitude variable id from nc_inq_varid 'lon_length is the size of the longitude dimension Redim lon_array!(1 To lon_length&) NcErr& = nc_get_var_float(ncFile&, lon_id&, lon_array!(1)) Same thing for a 2D array: Redim lon_array2!(1 To cellx_length&, 1 To celly_length&) NcErr& = nc_get_var_float(ncFile&, lon_id&, lon_array2!(1, 1)) For strings, you must make sure the string variable you are passing in has space already allocated for it by using Space or String. VB takes care of passing it your function properly as long as your string parameter is declared to be ByVal in the nc_get_att_text declaration. You can determine the size of the string by looking at the dimensions of the variable. For attributes you would use nc_inq_attlen or nc_inq_att. Once you have the string length you must create a string of the right size to contain the string data. For example, I want to get the units for the longitude variable above: NcErr& = nc_inq_attlen(ncFile&, lon_id&, "units", units_len&) units$ = String(units_len& + 1, Chr$(0)) NcErr& = nc_get_att_text(ncFile&, lon_id&, "units", units$) 'Can precede units$ with ByVal I got the string length for the attribute, created a string of Null characters of the appropriate length (I like to include an extra character just in case), and then I retrieved the string from the attribute. In summary, make sure you have memory room in your arrays and strings since the NetCDF API doesn't allocate those for you. Make sure you specify the first indices of the array when you are retrieving a variable into an array. And, finally, make sure your declarations are correct. Where the C API says byte use integer, short use integer, int use long, float use single, and double use double. Be sure your declaration uses ByVal when passing strings. Good Luck! Matthew Hanna ncdigest wrote:
ncdigest Thursday, December 9 2004 Volume 01 : Number 828 Today's Topics: netcdf.dll and Visual Basic 6 ---------------------------------------------------------------------- Date: Thu, 9 Dec 2004 19:27:08 +0100 (MET) From: =?ISO-8859-1?Q?=22Hans-J=FCrgen_Rieger=22?= <H.Rieger@xxxxxx> Subject: netcdf.dll and Visual Basic 6 Hi, I´ve got some problems using the netcdf.dll (prebuilt dll from the netcdf-3.5.1 download) with Visual Basic 6. In a new module I wrote the declaration: Declare Function nc_open Lib "netcdf.dll" (ByVal path As String, ByVal cmode As Long, ByRef ncidp As Long) As Long Then I used it in a procedure: Sub main Dim path As String, ncidp As Long, res As Long path = "c:\test.cdf" res = nc_open(path, 0, ncidp) End Sub Running the program, I get the error message "Bad dll calling convention" If the error is suppressed (with "OnError Resume Next") then I can read some simple data from the *.cdf file. But if string variables or array variables are involved, the program fails or even crashes. I´ve got the impression from other netcdfgroup members that it is possible to use the netcdf.dll in the way outlined above. Does anybody know what I am doing wrong? What calling convention does the netcdf.dll uses? With best regards H.J. Rieger- -- GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++ ------------------------------ End of ncdigest V1 #828 ***********************
From owner-netcdfgroup@xxxxxxxxxxxxxxxx 10 2004 Dec -0700 09:23:17
Message-ID: <wrxr7lydswa.fsf@xxxxxxxxxxxxxxxxxxxxxxx> Date: 10 Dec 2004 09:23:17 -0700 From: Ed Hartnett <ed@xxxxxxxxxxxxxxxx> In-Reply-To: <417432E2.1010500@xxxxxxxxxx> To: Mark Hadfield <m.hadfield@xxxxxxxxxx>, Harald.Anlauf@xxxxxx, Subject: Re: netCDF 3.6.0-beta6 (almost) success on cygwin+g95 Received: (from majordo@localhost) by unidata.ucar.edu (UCAR/Unidata) id iBAGNT0g015598 for netcdfgroup-out; Fri, 10 Dec 2004 09:23:29 -0700 (MST) Organization: UCAR/Unidata Keywords: 200412101623.iBAGNIlI015586 netcdfgroup@xxxxxxxxxxxxxxxx CC: russ@xxxxxxxxxxxxxxxx References: <52704F189EF3D811910900055DE6449E4A604D@ofexc0> <417432E2.1010500@xxxxxxxxxx> Lines: 42 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-netcdfgroup@xxxxxxxxxxxxxxxx Precedence: bulk Reply-To: Ed Hartnett <ed@xxxxxxxxxxxxxxxx> Mark Hadfield <m.hadfield@xxxxxxxxxx> writes:
Anlauf Harald wrote: >first of all: Congratulations! Building and testing this beta went >very smooth on my cygwin system with a self-built g95 compiler from >www.g95.org . > >The only problem I encountered was due to a bug in the install script >that did not expect that the ncdump and ncgen executables have an >.exe ending on cygwin: > >... >A possible solution for Windows/Cygwin systems: define a variable >EXEEXT in the top-level Makefile which is set to EXEEXT by configure >(and left empty for real Unix systems), and fix the Makefiles in the >ncgen and ncdump directories accordingly. > A better solution: use the "install" command. On Cygwin this command copes with the .exe extension automatically. Is there any reason not to modify the standard netCDF makefiles to use "install" in place of "cp"? I am willing to submit a patch. -- Mark Hadfield "Ka puwaha te tai nei, Hoea tatou" m.hadfield@xxxxxxxxxx National Institute for Water and Atmospheric Research (NIWA)
Mark and Anlauf, Thanks for pointing out the problem installing under cygwin. I have switched to using install instead of cp, and this change will be included in the 3.6.0 release. If you have any other suggestions to make, I would be very happy to learn of them. Thanks again, Ed Hartnett Unidata
netcdfgroup
archives: