error4.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. This file is part of netcdf-4, a netCDF-like interface for HDF5, or a
  3. HDF5 backend for netCDF, depending on your point of view.
  4. This file contains functions relating to logging errors. Also it
  5. contains the functions nc_malloc, nc_calloc, and nc_free.
  6. Copyright 2003, University Corporation for Atmospheric Research. See
  7. netcdf-4/docs/COPYRIGHT file for copying and redistribution
  8. conditions.
  9. $Id: error4.c,v 1.4 2010/06/01 17:48:55 ed Exp $
  10. */
  11. #include <config.h>
  12. #include <stdarg.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <assert.h>
  16. #include <hdf5.h>
  17. /* This contents of this file get skipped if LOGGING is not defined
  18. * during compile. */
  19. #ifdef LOGGING
  20. extern int nc_log_level;
  21. /* This function prints out a message, if the severity of the message
  22. is lower than the global nc_log_level. To use it, do something like
  23. this:
  24. nc_log(0, "this computer will explode in %d seconds", i);
  25. After the first arg (the severity), use the rest like a normal
  26. printf statement. Output will appear on stdout.
  27. This function is heavily based on the function in section 15.5 of
  28. the C FAQ. */
  29. void
  30. nc_log(int severity, const char *fmt, ...)
  31. {
  32. va_list argp;
  33. int t;
  34. /* If the severity is greater than the log level, we don' care to
  35. print this message. */
  36. if (severity > nc_log_level)
  37. return;
  38. /* If the severity is zero, this is an error. Otherwise insert that
  39. many tabs before the message. */
  40. if (!severity)
  41. fprintf(stdout, "ERROR: ");
  42. for (t=0; t<severity; t++)
  43. fprintf(stdout, "\t");
  44. /* Print out the variable list of args with vprintf. */
  45. va_start(argp, fmt);
  46. vfprintf(stdout, fmt, argp);
  47. va_end(argp);
  48. /* Put on a final linefeed. */
  49. fprintf(stdout, "\n");
  50. fflush(stdout);
  51. }
  52. void
  53. nc_log_hdf5(void)
  54. {
  55. H5Eprint(NULL);
  56. }
  57. #endif /* ifdef LOGGING */