/[escript]/trunk/esysUtils/src/error.c
ViewVC logotype

Contents of /trunk/esysUtils/src/error.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3792 - (show annotations)
Wed Feb 1 06:16:25 2012 UTC (6 years, 11 months ago) by caltinay
File MIME type: text/plain
File size: 2464 byte(s)
Merged ripley rectangular domain into trunk.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include <string.h>
16 #include "error.h"
17
18 #ifdef _OPENMP
19 #include <omp.h>
20 #endif
21
22 #ifdef ESYS_MPI
23 #include "mpi_C.h"
24 #else
25 #include <time.h>
26 #endif
27
28
29
30 #define MIN(X,Y) ((X)<(Y)?(X):(Y))
31
32
33
34 Esys_ErrorCodeType Esys_ErrorCode_=NO_ERROR;
35 char Esys_ErrorMsg_[LenErrorMsg_MAX]={'\0'};
36
37 /* reset the error to NO_ERROR */
38 void Esys_resetError(void) {
39 Esys_ErrorCode_=NO_ERROR;
40 }
41
42 /* sets an error */
43 void Esys_setError(Esys_ErrorCodeType err,__const char* msg) {
44 size_t lenMsg=strlen(msg);
45 if (Esys_noError()) {
46 /* printf("error set = %d %s\n",err,msg); */
47 Esys_ErrorCode_=err;
48 strncpy(Esys_ErrorMsg_,msg,MIN(LenErrorMsg_MAX,lenMsg));
49 Esys_ErrorMsg_[MIN(LenErrorMsg_MAX,lenMsg)]='\0';
50 }
51 }
52
53 /* checks if there is no error */
54 bool_t Esys_noError(void) {
55 Esys_ErrorCodeType err=Esys_getErrorType();
56 /* return (err==NO_ERROR || err==WARNING);*/
57 return (err==NO_ERROR);
58 }
59 /* This function checks if the pointer ptr has a target. If not an
60 error is raised and TRUE is returned. */
61
62 bool_t Esys_checkPtr(void* ptr) {
63 if (ptr==NULL) {
64 Esys_setError(MEMORY_ERROR,"Out of memory.");
65 return TRUE;
66 } else {
67 return FALSE;
68 }
69 }
70
71 /* This function returns a timer */
72 double Esys_timer(void) {
73 double out;
74
75 #ifdef ESYS_MPI
76 out = MPI_Wtime();
77 #else
78 #ifdef _OPENMP
79 out=omp_get_wtime();
80 #else
81 out=((double) clock())/CLOCKS_PER_SEC;
82 #endif
83 #endif
84 return out;
85 }
86
87
88
89 /* return the error code */
90 Esys_ErrorCodeType Esys_getErrorType(void) {
91 return Esys_ErrorCode_;
92 }
93
94 /* return the error message */
95 char* Esys_getErrorMessage(void) {
96 return Esys_ErrorMsg_;
97 }
98 /**************************************************************/

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/paso/src/Paso.c:2682-2741 /branches/pasowrap/esysUtils/src/error.c:3661-3674 /branches/restext/paso/src/Paso.c:2610-2624 /branches/ripleygmg_from_3668/esysUtils/src/error.c:3669-3791 /branches/stage3.0/paso/src/Paso.c:2569-2590 /release/3.0/paso/src/Paso.c:2591-2601

  ViewVC Help
Powered by ViewVC 1.1.26