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.
>To: "'address@hidden'" <address@hidden> >From: "Yoon, Hoon (CICG - NY Program Trading)" <address@hidden> >Subject: Inquiry about netCDF >Organization: . >Keywords: 199806111528.JAA12217 Hi Hoon, > I am interested in netCDF. I have questions that I want to address prior > to spending resources. I promise they are simple. > > 1. How does one represent null or NA values? If you want a variable to have null or NA values, create a netCDF attribute for that variable that specifies the special value you will use for such values. A predefined attribute you can use is "_FillValue", so for example if you want to specify "-99" as the null value for integers stored in a variable named foo, just define foo:_FillValue = -99 Then if you try to read foo data that hasn't been written yet, it will return this value. If you have multiple kinds of null values, you can define additional variable attributes, for example foo:missing_value, etc. The "_FillValue" attribute is treated specially by the netCDF library: it is used for reading data that wasn't written. More information on missing values is available in the User's Guide http://www.unidata.ucar.edu/packages/netcdf/guidec/guidec-12.html#HEADING12-1398 and http://www.unidata.ucar.edu/packages/netcdf/guidec/guidec-13.html#MARKER-2-175 > 2. Can I mix char and numeric in an array? No. An array is defined to be a set of values of the same type. If you want to store associated character and numeric values, you will need to store them in two different arrays. If the two arrays are of the same shape, you can associate the numeric value in one with the character value in the other array at the same index. If you want to store a string associated with each value, you will need to add an extra dimension to the character array for the maximum string length. > 3. If I had 2 or 3 dimentional array, do I need to redimention it every > time if I need to get it to increase on the other (non-planned side)? > Example: > IBM, AAPL, BORL > 19980101 100, 23, 8 > 19980102 101, 24, 7 > If I need additional date and that was the planned add dimention, I > guess that won't be problem; however, if I need to increase number of > stocks, do I have to create a new storage array and copy over? Could you > tell me what this really takes to get it done? Yes, to change the shape of an array in any way other than increasing the size of the unlimited dimension requires creating a new array of the desired shape and copying the old data into the new array. The best way to do this would probably be to just create a new netCDF file with the desired shape of variables and copy the old data into it. This is clearly not something you would want to do very often; it's similar to redefining the schema of a database, which is usually costly. You can choose to avoid this at the expense of preallocating variables at the maximum size you anticipate using, or some strategy that doubles the dimension size whenever a dimension grows beyond the current maximum ... If you need to do this frequently, netCDF might not be the right choice for storing your data in a platform-independent way. It's not a database system, but an interface for array-oriented data that can be represented as named variables with named attributes and dimensions. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu