[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #HEV-388573]: NetCDF C library question



Good question. Is it possible to create a .cdl file to show what you are 
doing?

On 5/19/2017 9:39 AM, James Gallagher wrote:
> New Client Reply: NetCDF C library question
> 
> Dennis,
> 
> I probably should have replied directly to you…
> 
> However I was thinking about this and here’s my question/thought: Could it be 
> that the attribute is ‘text’ (a 1D array of chars) while the variable is a 2d 
> array of char? That is, the variable in question _is_ a 2d array of char - 
> it’s an array of strings, but in netcdf3 (or netcdf4 classic) that’s a 2d 
> array of char, correct? So maybe that’s the nature of the type mismatch?
> 
> If so, how do I handle this? The data are originally in/from a HDF4 file (or 
> maybe HDF5).
> 
> Thanks,
> James
> 
>> On May 17, 2017, at 17:06, James Gallagher <address@hidden> wrote:
>>
>>>
>>> On May 17, 2017, at 15:57, Unidata netCDF Support <address@hidden 
>>> <mailto:address@hidden>> wrote:
>>>
>>> nc_put_att_text should work. s/uchar fails because they
>>> are in effect conversions from int8/uint8 respectively.
>>> and number->char conversions are disallowed.
>>> I am surprised that nc_put_att_text failed.
>>> Any hope of providing a small fragment of code showing the failure?
>>
>> OK. When I sent my first message I was trying to use nc_put_att_uchar(). 
>> I’ve switched back to nc_put_att_text() and now I get different error 
>> messages for nc3 and nc4:
>>
>> nc3: NetCDF: Not a valid data type or _FillValue type mismatch
>>
>> nc4: NetCDF: Invalid argument
>>
>> Here’s the code (it’s somewhat tortured at this point because I’m hacking it 
>> and running it in the debugger, …):
>>
>>          if (new_name == "_FillValue") {
>>              nc_type xtype;
>>              stax = nc_inq_vartype(ncid, varid, &xtype);
>>              if (stax != NC_NOERR) {
>>                  FONcUtils::handle_error(stax,
>>                      string("File out netcdf, failed to get variable type 
>> while processing attribute ").append(new_name),
>>                      __FILE__, __LINE__);
>>              }
>>              cerr << "Variable type: " << xtype << endl;
>>              // NC_CHAR is 2
>>              // NC_STRING is 12
>>
>>              stax = nc_put_att_text(ncid, varid, new_name.c_str(), 
>> val.length(), val.c_str());
>>          }
>>
>> The output to cerr is ‘2’.
>>
>> The variable is made using:
>>
>> int stax = nc_def_var(ncid, _varname.c_str(), d_array_type, d_ndims, 
>> &d_dim_ids[0], &_varid);
>>
>> where, in this case, d_array_type is NC_CHAR and d_ndims is 2.
>>
>> The variable in question is an array of strings, so the code makes a 2D 
>> array of char.
>>
>> Note that for nc4 I’m testing the case where the file is created using the 
>> ‘classic’ model.
>>
>> Thanks,
>> James
>>
>> PS. I think Ted H told me that you were using THG’s hdf5 (and hdf4?) C 
>> libraries. Is that true?
>>
>>> =Dennis Heimbigner
>>>   Unidata
>>>
>>>
>>> Ticket Details
>>> ===================
>>> Ticket ID: HEV-388573
>>> Department: Support netCDF
>>> Priority: Normal
>>> Status: Open
>>> ===================
>>> 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.
>>>
>>>
>>
>> --
>> James Gallagher
>> address@hidden <mailto:address@hidden>
> --
> James Gallagher
> address@hidden
> 
> 
> 
> 
> 
> 
> 
> Ticket Details
> ===================
> Ticket ID: HEV-388573
> Department: Support netCDF
> Priority: Normal
> Status: Open
> Link:  
> https://andy.unidata.ucar.edu/esupport/staff/index.php?_m=tickets&_a=viewticket&ticketid=28290
> 



Ticket Details
===================
Ticket ID: HEV-388573
Department: Support netCDF
Priority: Normal
Status: Open
===================
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.