Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
error.c
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "ncconfig.h"
00009 #include <stdio.h>
00010 #include <stdarg.h>
00011 #include <stdlib.h>
00012 #include "netcdf.h"
00013 
00014 
00015 #ifndef NO_STRERROR
00016 #include <string.h> 
00017 #else
00018 
00019 static char *
00020 strerror(int errnum)
00021 {
00022 #ifdef  __cplusplus
00023     static char *noname = "**I don't know!**" ;
00024     return noname ;
00025 #else
00026     extern int sys_nerr;
00027     extern char *sys_errlist[];
00028 
00029     if(errnum < 0 || errnum >= sys_nerr) return NULL;
00030     
00031     return sys_errlist[errnum];
00032 #endif
00033 }
00034 #endif 
00035 
00036 
00037 #ifdef vms
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 #include <errno.h>
00048 #include <descrip.h>
00049 #include <ssdef.h>
00050 
00051 static const char *
00052 vms_strerror( int status )
00053 {
00054         short msglen;
00055         static char msgbuf[256];
00056         $DESCRIPTOR(message, msgbuf);
00057         register ret;
00058 
00059         msgbuf[0] = 0;
00060         ret = SYS$GETMSG(status, &msglen, &message, 15, 0);
00061         
00062         if(ret != SS$_BUFFEROVF && ret != SS$_NORMAL) {
00063                 (void) strcpy(msgbuf, "EVMSERR");
00064         }
00065         return(msgbuf);
00066 }
00067 #endif 
00068 
00069 
00070 static char unknown[] = "Unknown Error";
00071 
00072 
00073 const char *
00074 nc_strerror(int err)
00075 {
00076 
00077 #ifdef vms 
00078         if(err == EVMSERR)
00079         {
00080                 return vms_strerror(err);
00081         }       
00082         
00083 #endif 
00084 
00085         if(NC_ISSYSERR(err))
00086         {
00087                 const char *cp = (const char *) strerror(err);
00088                 if(cp == NULL)
00089                         return unknown;
00090                 
00091                 return cp;
00092         }
00093         
00094 
00095         switch (err) {
00096         case NC_NOERR:
00097             return "No error";
00098         case NC_EBADID:
00099             return "Not a netCDF id";
00100         case NC_ENFILE:
00101             return "Too many netCDF files open";
00102         case NC_EEXIST:
00103             return "netCDF file exists && NC_NOCLOBBER";
00104         case NC_EINVAL:
00105             return "Invalid argument";
00106         case NC_EPERM:
00107             return "Write to read only";
00108         case NC_ENOTINDEFINE:
00109             return "Operation not allowed in data mode";
00110         case NC_EINDEFINE:
00111             return "Operation not allowed in define mode";
00112         case NC_EINVALCOORDS:
00113             return "Index exceeds dimension bound";
00114         case NC_EMAXDIMS:
00115             return "NC_MAX_DIMS exceeded";
00116         case NC_ENAMEINUSE:
00117             return "String match to name in use";
00118         case NC_ENOTATT:
00119             return "Attribute not found";
00120         case NC_EMAXATTS:
00121             return "NC_MAX_ATTRS exceeded";
00122         case NC_EBADTYPE:
00123             return "Not a netCDF data type or _FillValue type mismatch";
00124         case NC_EBADDIM:
00125             return "Invalid dimension id or name";
00126         case NC_EUNLIMPOS:
00127             return "NC_UNLIMITED in the wrong index";
00128         case NC_EMAXVARS:
00129             return "NC_MAX_VARS exceeded";
00130         case NC_ENOTVAR:
00131             return "Variable not found";
00132         case NC_EGLOBAL:
00133             return "Action prohibited on NC_GLOBAL varid";
00134         case NC_ENOTNC:
00135             return "Not a netCDF file";
00136         case NC_ESTS:
00137             return "In Fortran, string too short";
00138         case NC_EMAXNAME:
00139             return "NC_MAX_NAME exceeded";
00140         case NC_EUNLIMIT:
00141             return "NC_UNLIMITED size already in use";
00142         case NC_ENORECVARS:
00143             return "nc_rec op when there are no record vars";
00144         case NC_ECHAR:
00145             return "Attempt to convert between text & numbers";
00146         case NC_EEDGE:
00147             return "Edge+start exceeds dimension bound";
00148         case NC_ESTRIDE:
00149             return "Illegal stride";
00150         case NC_EBADNAME:
00151             return "Attribute or variable name contains illegal characters";
00152         case NC_ERANGE:
00153             return "Numeric conversion not representable";
00154         case NC_ENOMEM:
00155             return "Memory allocation (malloc) failure";
00156         }
00157         
00158         return unknown;
00159 }