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 Paul, > I am obviously missing a point here, but this is my problem: We have > read/write routines that accept a float array and a nc_type. The routines > use a switch (nc_type) to copy w/truncation to an appropriate temp array of > the correct type, and then call the appropriate nc_put_vara_<type> function. > This works fine for all except nc_put_vara_scar which returns the error > "Attempt to convert between text and numbers". I am thinking of scar as > 1-byte numbers from -127/+127 as opposed to the uchar version which is > 1-byte numbers in 0-255 range. What is my misunderstanding? I'm not sure, because the appended small test program works here by using nc_put_vara_schar to write signed 1-byte numbers into a float array, as verified by using ncdump on the netCDF file it creates. If this fails on your platform, please provide more details about your compiler/machine and we'll see if we can reproduce the problem. --Russ #include <stdio.h> #include <stdlib.h> #include <netcdf.h> void check_err(const int stat, const int line, const char *file) { if (stat != NC_NOERR) { (void) fprintf(stderr, "line %d of %s: %s\n", line, file, nc_strerror(stat)); exit(1); } } int main() { /* create test-schar.nc, testing nc_put_var_schar() */ int ncid; int n_dim; size_t n_len = 4; int a_id; # define RANK_a 1 int a_dims[RANK_a]; int stat = nc_create("test-schar.nc", NC_CLOBBER, &ncid); check_err(stat,__LINE__,__FILE__); stat = nc_def_dim(ncid, "n", n_len, &n_dim); check_err(stat,__LINE__,__FILE__); a_dims[0] = n_dim; stat = nc_def_var(ncid, "a", NC_FLOAT, RANK_a, a_dims, &a_id); check_err(stat,__LINE__,__FILE__); stat = nc_enddef (ncid); check_err(stat,__LINE__,__FILE__); { static signed char a[] = {-2, -1, 0, 1}; stat = nc_put_var_schar(ncid, a_id, a); check_err(stat,__LINE__,__FILE__); } stat = nc_close(ncid); check_err(stat,__LINE__,__FILE__); return 0; }