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.
Jennifer, Actually, the UDUNITS-2 package supports the UDUNITS-1 API -- so you might not have to modify any code. Otherwise, the following mappings should work: #include <udunits.h> -> #include <udunits2.h> utInit() -> ut_read_xml(NULL) utScan() -> ut_parse() utConvert(utUnit* from, utUnit* to, double* slope, double* intercept) -> cv_converter* converter = ut_get_converter(ut_unit* from, ut_unit* to); *intercept = cv_convert_double(converter, 0.0); *slope = cv_convert_double(converter, 1.0) - *intercept; Alternatively, instead of computing the slope and intercept, use the converter functions cv_convert_*() to convert the values and then call cv_free() on the converter. utCalendar() is a bit more complicated because you have to know, a priori, that the encoding of the temporal offset is in seconds since 2001-01-01T00:00:00Z. I suggest you look at the utCalendar() function in the file "lib/udunits-2.c". Please feel free to contact us further. > GrADS uses just a few routines in the udunits library to parse the metadata > in a netcdf file: > > utInit() to initialize and load udunits.dat > utScan() to convert a unit string into udunits format > utCalendar() to convert a time unit string to integer values for yr, mo, dy, > hr, mn > utConvert() to compare a parsed to a known/accepted unit string > > We have been statically linking our executables with udunits-1.11.7. I don’t > know how old this library is, but there’s been no need to upgrade because it > works perfectly and the interface in GrADS hasn’t changed in a very long time. > > It’s become a bit of a challenge to build the old library on newer operating > systems with newer compilers. The issue is further complicated because we are > moving to linking dynamically with all the dependent libraries. I would like > to use udunits2, since that seems to be what gets installed on unix systems > these days, and I want GrADS to be able to use a version of the library that > can be installed easily with yum or rpm. I have found RPM packages for > verison 2.2.20. > > I’d be very grateful if you could help me to migrate our use of the udunits > library to the new API syntax. Are there equivalents for the four routines we > currently use? If not, what would be the closest approximation? Regards, Steve Emmerson Ticket Details =================== Ticket ID: XIP-166037 Department: Support UDUNITS Priority: Critical Status: Closed =================== NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.