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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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/py3_attempt2/esysUtils/src/error.c:3871-3891 /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 /branches/symbolic_from_3470/esysUtils/src/error.c:3471-3974 /branches/symbolic_from_3470/ripley/test/python/esysUtils/src/error.c:3517-3974 /release/3.0/paso/src/Paso.c:2591-2601 /trunk/ripley/test/python/esysUtils/src/error.c:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26