Main Page   Modules   Data Structures   File List   Data Fields   Globals  

C_libs/io/std_io/io_error.c

Go to the documentation of this file.
00001 /* === Doxygen File Comment ============================== */
00009 /* ======================================================= */
00010 
00011 #include <IFU_io.h>
00012 #include <data_io.h>
00013 
00014 extern int TK, ASK;
00015 
00016 /* --- Doxygen Function Comment -------------------------- */
00020                 /* @{ ***** Starting group14 ***** */
00028 /* ------------------------------------------------------- */
00029 
00030 static int *Error_Control_Level = NULL;   /* error control level */
00031 static int Error_Current_Level = -1;
00032 static int Erase_File_Sav = 0;        /* save of file erase flag */
00033 
00034 void 
00035 set_control_level(int level)    
00036 {
00037         Error_Current_Level++;
00038         if (Error_Control_Level == NULL) {
00039                 Error_Control_Level = (int *)malloc(1*sizeof(int));
00040         }
00041         else {
00042                 Error_Control_Level = (int *)realloc((char *)Error_Control_Level,(Error_Current_Level+1)*sizeof(int));
00043         }
00044         Error_Control_Level[Error_Current_Level] = level;
00045 }
00046 /* --- Doxygen Function Comment -------------------------- */
00053 /* ------------------------------------------------------- */
00054 
00055 void 
00056 Handle_Error(char *routine, int status) 
00057 {
00058         char errtext[512];
00059         int level;
00060 
00061         if (Error_Control_Level != NULL) {
00062                 level = Error_Control_Level[Error_Current_Level];
00063         }
00064         else
00065                 level = FATAL;
00066 
00067         switch (level) {  
00068                                         /* What to do when an error occurs ? */
00069         case FATAL :            /* causes program to exit */  
00070         
00071                 sprintf(errtext,"FATAL error from routine %s", routine);
00072                 print_error(errtext);
00073                 strcpy(errtext,"\0");
00074                 get_tiger_errmsg(status,errtext);
00075                 print_error(errtext);
00076                 exit_session(status);
00077                 exit(1);
00078 
00079         case WARNING :          /* display warning */  
00080         
00081                 sprintf(errtext,"WARNING from routine %s", routine);
00082                 print_warning(errtext);
00083                 get_tiger_errmsg(status,errtext);
00084                 print_warning(errtext);
00085                 break;
00086 
00087         case NONE :             /* return status */  
00088                 break;
00089         
00090         default :               /* it's up to the user to handle the error */
00091             break;
00092         }
00093 }
00094 
00095 /* --- Doxygen Function Comment -------------------------- */
00100 /* ------------------------------------------------------- */
00101 void 
00102 disable_user_warnings() 
00103 {
00104         set_control_level(NONE);
00105 }
00106 
00107 /* --- Doxygen Function Comment -------------------------- */
00112 /* ------------------------------------------------------- */
00113 void 
00114 restore_user_warnings() 
00115 {
00116         Error_Current_Level--;
00117 }
00118 /* --- Doxygen Function Comment -------------------------- */
00123 /* ------------------------------------------------------- */
00124 void 
00125 disable_erase_flag()    
00126 {
00127   Erase_File_Sav = ASK;
00128   ASK = 0;
00129 }
00130 /* --- Doxygen Function Comment -------------------------- */
00135 /* ------------------------------------------------------- */
00136 void 
00137 restore_erase_flag()    
00138 {
00139   ASK =  Erase_File_Sav;        
00140 }
00141 
00142 /* --- Doxygen Function Comment -------------------------- */
00149 /* ------------------------------------------------------- */
00150 int 
00151 get_tiger_errcode(short data_format, int stat)
00152 {
00153         switch (data_format) {
00154 
00155         case FITS_A_FORMAT :
00156         case FITS_B_FORMAT :
00157         case EURO3D_FORMAT :
00158                 switch(stat) {
00159              case  101:
00160              case  103:
00161              case  104:
00162                                 return(ERR_OPEN); break;
00163              case  105:   
00164                                 return(ERR_CREAT); break;
00165              case  106: 
00166                                 return(ERR_WRIT); break;
00167              case  107:   
00168              case  108: 
00169                                 return(ERR_READ); break;
00170              case  110:   
00171                                 return(ERR_CLOSE); break;
00172              case  111: 
00173                                 return(ERR_ALLOC); break;
00174              case  112:  
00175                                 return(ERR_ACCESS); break;
00176              case  201:   
00177                                 return(ERR_BAD_HEAD); break;
00178              case  202:   
00179                                 return(ERR_NODESC); break;
00180              case  203:   
00181                                 return(ERR_HEADER_SIZE); break;
00182              case  204:  
00183              case  205:  
00184              case  207: 
00185              case  208: 
00186              case  209: 
00187              case  210: 
00188              case  211:  
00189              case  212: 
00190              case  213:
00191              case  214:
00192              case  215:
00193              case  216:
00194              case  217: 
00195              case  218: 
00196                                 return(ERR_BAD_DESC); break;
00197              case  219:   
00198                                 return(ERR_NOCOL); break;
00199              case  220:  
00200                                 return(ERR_BAD_DESC); break;
00201              case  221: 
00202              case  222: 
00203              case  223: 
00204              case  224: 
00205              case  225: 
00206              case  226:  
00207              case  227: 
00208              case  228: 
00209              case  229: 
00210              case  230: 
00211              case  231: 
00212              case  232: 
00213                                 return(ERR_BAD_HEAD); break;
00214              case  233: 
00215                                 return(ERR_IMA_HEAD); break;
00216              case  234:  
00217                                 return(ERR_BAD_DESC); break;
00218              case  235:  
00219                                 return(ERR_TBL_HEAD); break;
00220              case  236:   
00221                                 return(ERR_HEADER_SIZE); break;
00222              case  237:  
00223                                 return(ERR_NOCOL); break;
00224              case  241:   
00225                                 return(ERR_BAD_DESC); break;
00226              case  251: 
00227              case  252: 
00228              case  253: 
00229              case  261:
00230              case  262:
00231              case  263: 
00232              case  301:  
00233                                 return(ERR_BAD_HEAD); break;
00234              case  302:   
00235                                 return(ERR_COL_NUM); break;
00236              case  304:
00237              case  306:
00238                                 return(ERR_NODATA); break;
00239              case  307:  
00240              case  308: 
00241                                 return(ERR_BAD_PARAM); break;
00242              case  309:
00243              case  310: 
00244              case  311:  
00245              case  312:   
00246                                 return(ERR_BAD_TYPE); break;
00247              case  314:   
00248                                 return(ERR_NODATA); break;
00249              case  317:  
00250              case  320: 
00251              case  321: 
00252                                 return(ERR_BAD_PARAM); break;
00253              case  322:  
00254              case  323: 
00255                                 return(ERR_BAD_DESC); break;
00256              case  401:  
00257              case  402: 
00258              case  403:
00259              case  404:
00260              case  405:
00261              case  406: 
00262              case  407: 
00263              case  408: 
00264              case  409: 
00265              case  410: 
00266                                 return(ERR_BAD_TYPE); break;
00267              case  411:   
00268                                 return(ERR_BAD_PARAM); break;
00269              case  412: 
00270                                 return(ERR_OVERFLOW); break;
00271              case  501: 
00272              case  502:
00273              case  503:
00274                                 return(ERR_BAD_PARAM); break;
00275              case  505:   
00276                                 return(ERR_BAD_DESC); break;
00277                         default : return(stat);
00278                 }
00279                         break;
00280 
00281         case MIDAS_FORMAT :
00282                 switch(stat) {
00283 
00284                         case -4 : return(ERR_NODATA); break;
00285                         case -6 : return(ERR_NODATA); break;
00286                         case  0 : return(OK); break;
00287                         case  1 : return(ERR_NODESC); break;
00288                         case  2 : return(ERR_OVERFLOW); break;
00289                         case  6 : return(ERR_ACCESS); break;
00290                         case  7 : return(ERR_BAD_PARAM); break;
00291                         case  8 : return(ERR_OVERFLOW); break;
00292                         case  9 : return(ERR_BAD_DESC); break;
00293                         case 15 : return(ERR_BAD_CAT); break;
00294                         case 20 : return(ERR_OVERFLOW); break;
00295                         case 21 : return(ERR_ALLOC); break;
00296                         case 22 : return(ERR_ALLOC); break;
00297                         case 23 : return(ERR_OVERFLOW); break;
00298                         case 24 : return(ERR_NOTBL); break;
00299                         case 25 : return(ERR_COL_NUM); break;
00300                         case 26 : return(ERR_ROW_NUM); break;
00301                         case 27 : return(ERR_NOIDENT); break;
00302                         case 28 : return(ERR_BAD_COL); break;
00303                         case 29 : return(ERR_NOIMPL); break;
00304                         case 31 : return(ERR_REN_TBL); break;
00305                         case 32 : return(ERR_NOCOL); break;
00306                         default : return(stat);
00307                 }
00308                 break;
00309         case STSDAS_FORMAT :
00310         case IRAF_FORMAT :
00311                 switch(stat) {
00312                         case -2 : return(ERR_EOF); break;
00313                         case  0 : return(OK); break;
00314                 case  6 : return(ERR_BAD_PARAM); break;
00315                 case  7 : return(ERR_NB_PARAM); break;
00316                 case 10 : return(ERR_OPEN); break;
00317                 case 11 : return(ERR_CREAT); break;
00318                 case 12 : return(ERR_CREAT); break;
00319                 case 13 : return(ERR_NAXIS); break;
00320                 case 14 : return(ERR_NAXIS); break;
00321                 case 15 : return(ERR_BAD_TYPE); break;
00322                 case 16 : return(ERR_OFFSET); break;
00323                 case 17 : return(ERR_ACCESS); break;
00324                 case 18 : return(ERR_CLOSE); break;
00325                 case 19 : return(ERR_BAD_IMA); break;
00326                 case 20 : return(ERR_IMA_BOUND); break;
00327                 case 21 : return(ERR_IMA_EXT); break;
00328                 case 22 : return(ERR_IMA_BOUND); break;
00329                 case 23 : return(ERR_READ); break;
00330                 case 24 : return(ERR_WRIT); break;
00331                 case 25 : return(ERR_NODESC); break;
00332                 case 26 : return(ERR_NODESC); break;
00333                 case 40 : return(ERR_NODESC); break;
00334                 case 41 : return(ERR_BAD_HEAD);break;
00335                 case 42 : return(ERR_HEADER_SIZE); break;
00336                 case 43 : return(ERR_BAD_PARAM); break;
00337                 case 46 : return(ERR_BAD_PARAM); break;
00338                 case 47 : return(ERR_NB_PARAM); break;
00339                 case 48 : return(ERR_DEL_DESC); break;
00340                 case 49 : return(ERR_DEL_DESC); break;
00341                 case 50 : return(ERR_NOIMA); break;
00342                 case 51 : return(ERR_DEL_IMA); break;
00343                 case 52 : return(ERR_REN_IMA); break;
00344                 case 53 : return(ERR_IMA_HEAD); break;
00345                 case 54 : return(ERR_BAD_DESC); break;
00346                 case 70 : return(ERR_GRAPH_DEV); break;
00347                 case 101 : return(ERR_ALLOC); break;
00348                 case 102 : return(ERR_FREE); break;
00349                 case 112 : return(ERR_BAD_SIZE); break;
00350                         default : return(stat); break;
00351                 }
00352                 break;
00353         case TIGER_FORMAT :
00354                 return(stat);
00355                 break;
00356         }
00357         return(ERR_FORMAT);
00358 }
00359 
00360 /* --- Doxygen Function Comment -------------------------- */
00367 /* ------------------------------------------------------- */
00368 void 
00369 get_tiger_errmsg(int stat, char *msg)
00370 {
00371   if(!TK)
00372     {
00373         switch(stat) {
00374         case OK : strcpy(msg,"Successful return\n"); break;
00375         case UNKNOWN : msg=NULL; break;
00376         case ERR_EOF : strcpy(msg,"EOF reached\n"); break;
00377         case ERR_BAD_PARAM : strcpy(msg,"Input element is bad\n"); break;
00378         case ERR_NB_PARAM : strcpy(msg,"Bad input number of elements\n"); break;
00379         case ERR_BAD_TYPE : strcpy(msg,"Invalid data type\n"); break;
00380         case ERR_BAD_SIZE : strcpy(msg,"Field width not wide enough\n"); break;
00381         case ERR_OPEN : strcpy(msg,"Error opening file\n"); break;
00382         case ERR_CREAT : strcpy(msg,"Error opening new file\n"); break;
00383         case ERR_READ : strcpy(msg,"Error reading file\n"); break;
00384         case ERR_WRIT : strcpy(msg,"Error writing to file\n"); break;
00385         case ERR_CLOSE : strcpy(msg,"Error closing file\n"); break;
00386         case ERR_ACCESS : strcpy(msg,"Invalid image access mode\n"); break;
00387         case ERR_NAXIS : strcpy(msg,"Invalid NAXIS parameter\n"); break;
00388         case ERR_NOIDENT : strcpy(msg,"Identifier not found\n"); break;
00389         case ERR_OFFSET : strcpy(msg,"Error returning offset to data\n"); break;
00390         case ERR_NODATA : strcpy(msg,"No data available\n"); break;
00391         case ERR_BAD_IMA : strcpy(msg,"Not an image !\n"); break;
00392         case ERR_IMA_BOUND : strcpy(msg,"Bad section specification for image\n"); break;
00393         case ERR_IMA_EXT : strcpy(msg,"Bad extension for image\n"); break;
00394         case ERR_NOIMA : strcpy(msg,"Image does not exist\n"); break;
00395         case ERR_DEL_IMA : strcpy(msg,"Error deleting image\n"); break;
00396         case ERR_REN_IMA : strcpy(msg,"Error renaming image\n"); break;
00397         case ERR_IMA_HEAD : strcpy(msg,"Illegal image header\n"); break;
00398         case ERR_BAD_TBL : strcpy(msg,"Not a table !\n"); break;
00399         case ERR_TBL_EXT : strcpy(msg,"Bad extension for table\n"); break;
00400         case ERR_NOTBL : strcpy(msg,"Table does not exist\n"); break;
00401         case ERR_DEL_TBL : strcpy(msg,"Error deleting table\n"); break;
00402         case ERR_REN_TBL : strcpy(msg,"Error renaming table\n"); break;
00403         case ERR_TBL_HEAD : strcpy(msg,"Illegal table header\n"); break;
00404         case ERR_BAD_COL : strcpy(msg,"Error in column format\n"); break;
00405         case ERR_NOCOL : strcpy(msg,"Column does not exist\n"); break;
00406         case ERR_COL_NUM : strcpy(msg,"Wrong column number\n"); break;
00407         case ERR_ROW_NUM : strcpy(msg,"Wrong row number\n"); break;
00408         case ERR_NODESC : strcpy(msg,"Header parameter not found\n"); break;
00409         case ERR_BAD_HEAD : strcpy(msg,"Illegal data type for header parameter\n"); break;
00410         case ERR_DEL_DESC : strcpy(msg,"Cannot delete descriptor\n"); break;
00411         case ERR_BAD_DESC : strcpy(msg,"Descriptor bad\n"); break;
00412         case ERR_HEADER_SIZE : strcpy(msg,"Out of space in header\n"); break;
00413         case ERR_BAD_CAT : strcpy(msg,"Not a catalog !\n"); break;
00414         case ERR_GRAPH_DEV : strcpy(msg,"Bad graphics device\n"); break;
00415         case ERR_ALLOC : strcpy(msg,"Error allocating dynamic memory\n"); break;
00416         case ERR_FREE : strcpy(msg,"Error freeing dynamic memory\n"); break;
00417         case ERR_NOIMPL : strcpy(msg,"Not yet implemented\n"); break;
00418         case ERR_OVERFLOW : strcpy(msg,"Overflow (column/frame)\n"); break;
00419         case ERR_FORMAT : strcpy(msg,"Unknown data format\n"); break;
00420         default : msg=NULL; break;
00421         }
00422     } else {
00423         switch(stat) {
00424         case OK : strcpy(msg,"Successful return"); break;
00425         case UNKNOWN : msg=NULL; break;
00426         case ERR_EOF : strcpy(msg,"EOF reached"); break;
00427         case ERR_BAD_PARAM : strcpy(msg,"Input element is bad"); break;
00428         case ERR_NB_PARAM : strcpy(msg,"Bad input number of elements"); break;
00429         case ERR_BAD_TYPE : strcpy(msg,"Invalid data type"); break;
00430         case ERR_BAD_SIZE : strcpy(msg,"Field width not wide enough"); break;
00431         case ERR_OPEN : strcpy(msg,"Error opening file"); break;
00432         case ERR_CREAT : strcpy(msg,"Error opening new file"); break;
00433         case ERR_READ : strcpy(msg,"Error reading file"); break;
00434         case ERR_WRIT : strcpy(msg,"Error writing to file"); break;
00435         case ERR_CLOSE : strcpy(msg,"Error closing file"); break;
00436         case ERR_ACCESS : strcpy(msg,"Invalid image access mode"); break;
00437         case ERR_NAXIS : strcpy(msg,"Invalid NAXIS parameter"); break;
00438         case ERR_NOIDENT : strcpy(msg,"Identifier not found"); break;
00439         case ERR_OFFSET : 
00440                         strcpy(msg,"Error returning offset to data"); break;
00441                 case ERR_NODATA : strcpy(msg,"No data available"); break;
00442         case ERR_BAD_IMA : strcpy(msg,"Not an image !"); break;
00443         case ERR_IMA_BOUND : 
00444                         strcpy(msg,"Bad section specification for image"); break;
00445         case ERR_IMA_EXT : strcpy(msg,"Bad extension for image"); break;
00446         case ERR_NOIMA : strcpy(msg,"Image does not exist"); break;
00447         case ERR_DEL_IMA : strcpy(msg,"Error deleting image"); break;
00448         case ERR_REN_IMA : strcpy(msg,"Error renaming image"); break;
00449         case ERR_IMA_HEAD : strcpy(msg,"Illegal image header"); break;
00450         case ERR_BAD_TBL : strcpy(msg,"Not a table !"); break;
00451         case ERR_TBL_EXT : strcpy(msg,"Bad extension for table"); break;
00452         case ERR_NOTBL : strcpy(msg,"Table does not exist"); break;
00453         case ERR_DEL_TBL : strcpy(msg,"Error deleting table"); break;
00454         case ERR_REN_TBL : strcpy(msg,"Error renaming table"); break;
00455         case ERR_TBL_HEAD : strcpy(msg,"Illegal table header"); break;
00456         case ERR_BAD_COL : strcpy(msg,"Error in column format"); break;
00457         case ERR_NOCOL : strcpy(msg,"Column does not exist"); break;
00458         case ERR_COL_NUM : strcpy(msg,"Wrong column number"); break;
00459         case ERR_ROW_NUM : strcpy(msg,"Wrong row number"); break;
00460         case ERR_NODESC : strcpy(msg,"Header parameter not found"); break;
00461         case ERR_BAD_HEAD : 
00462                         strcpy(msg,"Illegal data type for header parameter"); break;
00463         case ERR_DEL_DESC : strcpy(msg,"Cannot delete descriptor"); break;
00464         case ERR_BAD_DESC : strcpy(msg,"Descriptor bad"); break;
00465         case ERR_HEADER_SIZE : strcpy(msg,"Out of space in header"); break;
00466         case ERR_BAD_CAT : strcpy(msg,"Not a catalog !"); break;
00467         case ERR_GRAPH_DEV : strcpy(msg,"Bad graphics device"); break;
00468         case ERR_ALLOC : strcpy(msg,"Error allocating dynamic memory"); break;
00469         case ERR_FREE : strcpy(msg,"Error freeing dynamic memory"); break;
00470         case ERR_NOIMPL : strcpy(msg,"Not yet implemented"); break;
00471         case ERR_OVERFLOW : strcpy(msg,"Overflow (column/frame)"); break;
00472         case ERR_FORMAT : strcpy(msg,"Unknown data format\n"); break;
00473         default : msg = NULL; break;
00474         }
00475     }
00476 }

Generated on Tue Jul 1 17:35:45 2003 for IFU_C_iolibs by doxygen1.3