ncdf4a13/nc_test/error.c

Go to the documentation of this file.
00001 /*********************************************************************
00002  *   Copyright 1996, UCAR/Unidata
00003  *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
00004  *   $Id: error.c,v 1.6 2004/11/16 21:51:17 russ Exp $
00005  *********************************************************************/
00006 
00007 #include <stddef.h>     /* because gcc 2.7.2.2 doesn't define size_t */
00008                         /* in <stdio.h> and it cannot hurt */
00009 #include <stdio.h>
00010 #include <stdarg.h>
00011 
00012 #include "error.h"
00013 #include "tests.h"
00014 
00015 /*
00016  * Use for logging error conditions
00017  */
00018 void
00019 error(const char *fmt, ...)
00020 {
00021     va_list args ;
00022 
00023     va_start(args, fmt) ;
00024     if (nfails <= max_nmpt)
00025         (void) vfprintf(stderr,fmt,args) ;
00026     va_end(args) ;
00027 }
00028 
00029 /*
00030  * Use for general printing (other than error conditions)
00031  * This also currently goes to stderr, but this could change
00032  */
00033 void
00034 print(const char *fmt, ...)
00035 {
00036     va_list args ;
00037 
00038     va_start(args, fmt) ;
00039     (void) vfprintf(stderr,fmt,args) ;
00040     va_end(args) ;
00041 }
00042 
00043 /*
00044  * Called by macro IF
00045  */
00046 int
00047 ifFail(const int expr, const int line, const char *file)
00048 {
00049     if (expr) {
00050         ++nfails;
00051         error("\n\tFAILURE at line %d of %s: ", line, file);
00052     }
00053     return expr;
00054 }
00055 
00056 /* TODO:
00057  * This diagnostic doesn't fit very well with the diagnostic message 
00058  * "architecture" of this program.
00059  */
00060 void
00061 print_n_size_t(size_t nelems, const size_t *array)
00062 {
00063         fprintf(stderr, "[");
00064         while(nelems-- > 0)
00065         {
00066                 fprintf(stderr, "%ld", (long)*array++);
00067                 if(nelems > 0)
00068                         fprintf(stderr, " ");
00069         }
00070         fprintf(stderr, "]");
00071 }

Generated on Thu Mar 16 18:10:09 2006 for nco by  doxygen 1.4.4