[netcdfgroup] problems writing to file

Hi,

I'm trying to write a series of arrays to a single netcdf file that will be about 1/2 Gb when done. The datasets are 1D, 2D, and 3D arrays of packed data. I'm having trouble writing the data correctly using the examples given in the manual and the netcdf example directory.

My problem is that when I check the data before writing, everything looks fine but when I check the data written to netcdf file the arrays are all screwed up with the max and mins for each level being incorrect and some slices of the 3D array being garbled.

any help would be greatly appreciated!

/Marston

Here's how I setup the file for writing:


// create netCDF dataset with perfomance options: enter define mode
  status = nc_create(outfile,NC_64BIT_OFFSET,&ncid);
  if(status != NC_NOERR) handle_error(status);

  // Define a title for the file
  status = nc_put_att_text(ncid,NC_GLOBAL,"Title",strlen(title),title);

  // define dimensions: from name and length
  status = nc_def_dim(ncid,"Lat",latlen,&lat_dimid);
  if (status != NC_NOERR) handle_error(status);

  status = nc_def_dim(ncid,"Lon",lonlen,&lon_dimid);
  if (status != NC_NOERR) handle_error(status);

  status = nc_def_dim(ncid,"Lev",levlen,&lev_dimid);
  if (status != NC_NOERR) handle_error(status);

  dim[0]   = lev_dimid;

  dim2d[0] = lat_dimid;
  dim2d[1] = lon_dimid;

  dim3d[0] = lev_dimid;
  dim3d[1] = lat_dimid;
  dim3d[2] = lon_dimid;

  Print("Define variables: from name, type");
  status = nc_def_var(ncid,"Latitude",NC_FLOAT,2,dim2d,&laid);
  if(status != NC_NOERR) handle_error(status);
  status = nc_def_var(ncid,"Longitude",NC_FLOAT,2,dim2d,&loid);
  if(status != NC_NOERR) handle_error(status);

  status = nc_def_var(ncid,"Levels",NC_SHORT,1,dim,&leid);
  if(status != NC_NOERR) handle_error(status);

        
// Setting up the temperature variable

  status = nc_def_var(ncid,"Temperature",NC_SHORT,3,dim3d,&tid);
  if(status != NC_NOERR) handle_error(status);
status = nc_put_att_text(ncid,tid,"Units",strlen(TEMP_UNITS),TEMP_UNITS);
  if (status != NC_NOERR) handle_error(status);
  pos = RetPos(sptr,130);
status = nc_put_att_double(ncid,tid,"scale",NC_DOUBLE,1,&sptr[pos]- >scale);
  if (status != NC_NOERR) handle_error(status);
status = nc_put_att_double(ncid,tid,"offset",NC_DOUBLE,1,&sptr[pos]- >offset);
  if (status != NC_NOERR) handle_error(status);


// Fetching the data, packing it, checking it before writing to file

  pos = RetPos(sptr,130);
swd->t = GetNlevsP(f,wk->array_size,sptr[pos]->nlev,sptr[pos]- >pnum,sptr[pos]->scale,sptr[pos]->offset);

 // Checking the Maxs and mins for each level
  int lev;
 for(lev = 0; lev < wk->nlev; lev++) {
    printf("Lev: %d\t",lev);
MMSI(swd->t[lev],wk->nlat,wk->nlon,sptr[pos]->scale,sptr[pos]- >offset);
  }

  status = nc_put_var_short(ncid,tid,&swd->t[0][0][0]);
  if(status != NC_NOERR) handle_error(status);






Marston Johnston, PhD Student
Radio and Space Science
Chalmers University of Technology
Gothenburg Sweden
marston at chalmers.se
cell: +46 736 637 909
Skype ID: marston.johnston



  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: