00001 #ifndef UTIL_H
00002 #define UTIL_H
00003
00004 #include <math.h>
00005
00006 typedef enum
00007 {
00008 kExact = 0,
00009 kInexact
00010 } FltCnvDisp_t;
00011
00012 struct BASE_Cleanup_struct
00013 {
00014 void *item;
00015 void (*free)(void *);
00016 };
00017
00018 typedef struct BASE_Cleanup_struct BASE_Cleanup_t;
00019
00020
00021 char *ns(const char *name);
00022 void strtolower(char *str);
00023 void strtoupper(char *str);
00024 void copy_string(char **dst, char *src);
00025 size_t base_strlcat(char *dst, const char *src, size_t size);
00026 void *base_strcatalloc(char *dst, const char *src, size_t *sizedst);
00027 char *base_strreplace(const char *text, const char *orig, const char *repl);
00028 char *base_strcasereplace(const char *text, const char *orig, const char *repl);
00029 int convert_int_field(char *field, int len);
00030 long convert_long_field(char *field, int len);
00031 float convert_float_field(char *field, int len);
00032 double convert_double_field(char *field, int len);
00033 void convert_string_field(char *field, int len, char *output, int maxlen);
00034 int copyfile(const char *inputfile, const char *outputfile);
00035 #undef likely
00036 #undef unlikely
00037 #define unlikely(a) __builtin_expect((a), 0)
00038 #define likely(a) __builtin_expect((a), 1)
00039
00040 int GenerateDRMSKeyName(const char *fitsName, char *drmsName, int size);
00041 int GenerateFitsKeyName(const char *drmsName, char *fitsName, int size);
00042 int RemoveDir(const char *pathname, int maxrec);
00043 size_t CopyFile(const char *src, const char *dst, int *ioerr);
00044
00045
00046 void base_cleanup_init();
00047 int base_cleanup_register(const char *key, BASE_Cleanup_t *cu);
00048 int base_cleanup_go(const char *explicit);
00049 void base_cleanup_term();
00050 void base_term();
00051 int base_drmskeycheck(const char *drmsName);
00052 int base_isvers(const char *vers, const char *minvers);
00053
00054 #ifdef ICCCOMP
00055 #pragma warning (disable : 1572)
00056 #endif
00057
00058 static inline long long FloatToLongLong(float f, int *stat)
00059 {
00060 long long result = (long long)(f + 0.5);
00061
00062 if (f == (float)result)
00063 {
00064 *stat = kExact;
00065 }
00066 else
00067 {
00068 *stat = kInexact;
00069 }
00070
00071 return result;
00072 }
00073
00074 static inline long long DoubleToLongLong(double d, int *stat)
00075 {
00076 long long result = (long long)(d + 0.5);
00077
00078 if (d == (double)result)
00079 {
00080 *stat = kExact;
00081 }
00082 else
00083 {
00084 *stat = kInexact;
00085 }
00086
00087 return result;
00088 }
00089
00090 static inline int IsZeroF(float f)
00091 {
00092 return f == (float)0.0;
00093 }
00094
00095 static inline int IsZero(double d)
00096 {
00097 return d == (double)0.0;
00098 }
00099
00100 static inline int IsPosHugeValF(float f)
00101 {
00102 return f == HUGE_VALF;
00103 }
00104
00105 static inline int IsNegHugeValF(float f)
00106 {
00107 return f == -HUGE_VALF;
00108 }
00109
00110 static inline int IsPosHugeVal(double d)
00111 {
00112 return d == HUGE_VAL;
00113 }
00114
00115 static inline int IsNegHugeVal(double d)
00116 {
00117 return d == -HUGE_VAL;
00118 }
00119
00120 int base_floatIsEqual(const float val1, const float val2);
00121 int base_doubleIsEqual(const double val1, const double val2);
00122
00123 #ifdef ICCCOMP
00124 #pragma warning (default : 1572)
00125 #endif
00126
00127
00128 #endif