Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

help with too many open files

After calling the write_histogram function below a couple of dozen
times, I get the message:

  ncredef: filename "hcaa8842": Too many open files

Why?  I'm believe that I'm calling ncendef and ncclose in the
appropriate places.  None of the assertions fail.  Any help would be
appreciated.

Thanks,
Charles

----------------------------------------------------------------------
static int write_histogram(char *filename, long *values, long duration_max)
{
  int ncid;
  int status;
  int dur_max_dim;
  int dimids[1], dur_hist_id;
  static long start[] = {0};    /* start writing at index 0 */
  static long count[1];

  ncid = ncopen(filename, NC_WRITE);
  assert(ncid >= 0);

  status = ncredef(ncid);
  assert(status >= 0);
  dur_max_dim = ncdimdef(ncid, "duration_max_frame", duration_max);
  assert(dur_max_dim >= 0);
  dimids[0] = dur_max_dim;
  dur_hist_id = ncvardef(ncid, "duration_histogram", NC_LONG, 1, dimids);
  status = ncendef(ncid);

  count[0] = duration_max;
  status = ncvarput(ncid, dur_hist_id, start, count, values);
  assert(status >= 0);

  status = ncclose(ncid);
  assert(status >= 0);

  return 0;
}


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690