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 >From: Naveenta Anand <address@hidden> >Subject: Re: 20020618: netCDF: Problem displaying array of values >Organization: . >Keywords: Hi Naveenta, > On June 20, 2002 1:05 PM, Russ Rew [SMTP:address@hidden] wrote: > ... > > The reason ncdump does not show any of the other variables, is because > > they are record variables (use the unlimited dimension) and you have > > not written any records yet: > > > > PRIMARY_DIMENSION = UNLIMITED ; // (0 currently) > > > > The (0 currently) says there are currently no records. Only the > > LATITUDE and LONGITUDE variables are not record variables, so they > > appear in the ncdump output, each having a single fill value: > > > > data: > > > > LATITUDE = _ ; > > > > LONGITUDE = _ ; > > > > The reason you aren't writing any records (or any data) is because you > > are specifying a 0 count for how much data to write: > > > > size_t count[] = {primary_dimension_len}; > > ------------> Ok! I agree to this point. I changed the count now but > there is no change and thus no display in netcdf file. Why would > that be? And also how do UNLIMITED dimensions actually work? I > cannot specify the unlimited_dimesnion_length, right? But I do want > the length to grow with my # of records and then how does the length > reflect in definition in netcdf file [PRIMARY_DIMENSION = UNLIMITED > ; // (0 currently)].And there is something else not right that I > cannot figure out!! I am attaching my function along (ascii file) so > you can take a look at the program (function for Russ) as a whole. You don't specify the unlimited dimension length, but it is stored in the file as the number of records written, and it automatically gets increased when you write new records. So for example, if you write the 100th record of a variable without having written records 0 to 99, all the records get written with fill values before record 100 is written. Then later if you write record 50, that overwrites the fill values, but the file still has 100 records. The length of the unlimited dimension is the greatest number of records written for any record variable so far. You could write the records backward if you want, starting with record 100, record 99, record 0, and then later write record 101. The record number is just the value of the first index (index[0]) of a record variable. You write records just like you would write other slices of data, specifying the corner where to start the write with the "index" array and specifying how far along each dimension to write with the "count" array. So if you are writing 2 records starting at record 50, you would have index[0] = 49 and count[0] = 2. > I am also attaching the current netcdf output (again ascii file called > temp.netcdf) I'm not sure I see how you changed the count or whether it is right. You have the statements size_t index[] = {0}; size_t count[] = {1}; size_t index1[] = {0}; size_t count1[] = {1}; ... count[0] = records; indicating you want to write "records" records, but what is the value of "records"? It looks like it should be the number of input records you read above: int records = 0; printf("Entered the function \n"); while(read_twl_station(infile)!=1) { records++; ... } printf(" %d records have been read \n",records); but you didn't send the output from running the program, so I don't know from looking at the code what the value of "records" is. Also from the structure of your code, it looks like you are trying to read all the ASCII data in initially in the above while loop, and then trying to write all the data to the netCDF file. At least that's what I think setting count[0] = records; means. But then you only give the address of a single value, stat = nc_put_vara_float(ncid,sea_level_id,index,count,&fill); so if count[0] was anything except 1, this would not work. For example if records was 2, count[0] would be 2, and you would have to provide the address of an array of two values instead of just &fill. Maybe the structure you want is to just write a single record of data after you read a record of data from the input. In that case, your program would look something like: // create the netCDF file, defining dimensions, variable, and attributes ... // Leave define mode ... // read in each record and write it to the netCDF file while(read_twl_station(infile)!=1) { // read in a record of data ... // write the record of data to the netCDF file size_t index[] = {0}; size_t count[] = {1}; size_t index1[] = {0}; size_t count1[] = {1}; // call nc_put_var_... for all the record variables } where you write each record out after you read it in, instead of reading in all the data and then writing it all out. In this case, you would definitely want to just leave count[0] set to 1 to indicate you are writing one record's worth of data and increment index[0] for each record in the loop to indicate that you are adding a record. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu