00001
00005 #ifndef _das_h_
00006
00007 #include <stdbool.h>
00008 #include <stdint.h>
00009 #include <stdlib.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef __linux
00023
00024 #include <endian.h>
00025 #if __BYTE_ORDER == __LITTLE_ENDIAN
00026 #define HOST_IS_LSB_FIRST
00027 #else
00028 #undef HOST_IS_LSB_FIRST
00029 #endif
00030
00031 #else
00032
00033 #ifdef __sun
00034
00035 #include <sys/isa_defs.h>
00036 #ifdef _LITTLE_ENDIAN
00037 #define HOST_IS_LSB_FIRST
00038 #else
00039 #undef HOST_IS_LSB_FIRST
00040 #endif
00041
00042 #else
00043
00044 #ifdef WIN32
00045
00049 #define HOST_IS_LSB_FIRST
00050
00051 #else
00052
00053 #error "unknown byte order!"
00054
00055 #endif
00056 #endif
00057 #endif
00058
00059
00060 #ifdef HOST_IS_LSB_FIRST
00061
00063 #define swapBufIfHostLE(p, s, n) _swapBufInPlace(p, s, n)
00064
00066 #define swapFloatIfHostLE(x) _swapFloat(x)
00067
00068 #else
00069
00070 #define swapBufIfHostLE(p, s, n)
00071
00072 #define swapFloatIfHostLE(x) x
00073
00074 #endif
00075
00077 void _swapBufInPlace(void* pMem, size_t szEach, size_t numItems);
00078
00079
00080 inline float _swapFloat(float rIn){
00081 const uint8_t* pIn = (const uint8_t*)(&rIn);
00082
00083 float rOut;
00084 uint8_t* pOut = (uint8_t*)(&rOut);
00085
00086 pIn += 3; *pOut = *pIn;
00087 pIn--; pOut++; *pOut = *pIn;
00088 pIn--; pOut++; *pOut = *pIn;
00089 pIn--; pOut++; *pOut = *pIn;
00090
00091 return rOut;
00092 }
00093
00094
00095 #define DAS1ERR 11
00096
00103 typedef struct das_time{
00104
00106 int year;
00107
00109 int month;
00110
00112 int mday;
00113
00117 int yday;
00118
00120 int hour;
00121
00123 int minute;
00124
00129 double second;
00130
00131 } das_time_t;
00132
00136 int parsetime (const char *string,
00137 int *year, int *month, int *mday, int *yday,
00138 int *hour, int *minute, double *second);
00139
00140
00149 bool dt_parsetime(const char* string, das_time_t* dt);
00150
00155 void dt_from_1958(
00156 unsigned short int daysSince1958, unsigned int msOfDay, das_time_t* dt
00157 );
00158
00160 int past_1958 (int year, int day);
00161
00172 bool dt_in_range(
00173 const das_time_t* begin, const das_time_t* end, const das_time_t* test
00174 );
00175
00180 void dt_copy(das_time_t* pDest, const das_time_t* pSrc);
00181
00189 void dt_set(
00190 das_time_t* pDt, int year, int month, int mday, int yday, int hour,
00191 int minute, double second
00192 );
00193
00206 int dt_compare(const das_time_t* pA, const das_time_t* pB);
00207
00208
00222 double dt_diff(const das_time_t* pA, const das_time_t* pB);
00223
00241 char* dt_isoc(char* sBuf, size_t nLen, const das_time_t* pDt, int nFracSec);
00242
00260 char* dt_isod(char* sBuf, size_t nLen, const das_time_t* pDt, int nFracSec);
00261
00262
00280 char* dt_dual_str(char* sBuf, size_t nLen, const das_time_t* pDt, int nFracSec);
00281
00282
00283
00284 #define EPOCH 2436205
00285
00286
00309 double ttime (
00310 int *year, int *month, int *mday, int *yday, int *hour, int *minute,
00311 double *second
00312 );
00313
00331 double dt_ttime(const das_time_t* dt);
00332
00333
00339 void emitt (double tt, int *year, int *month, int *mday, int *yday,
00340 int *hour, int *minute, double *second);
00341
00348 void dt_emitt (double tt, das_time_t* dt);
00349
00350
00355 void tnorm (int *year, int *month, int *mday, int *yday,
00356 int *hour, int *minute, double *second);
00357
00369 void dt_tnorm(das_time_t* dt);
00370
00383 void yrdy1958(int* pYear, int* pDoy, int days_since_1958);
00384
00399 void ms2hms(int* pHour, int* pMin, float* pSec, double ms_of_day);
00400
00401
00402
00403 int jday (int year, int month, int day);
00404
00405
00406 void fail (const char *message);
00407
00408
00409
00410
00411 int getpkt (char *ph, void *data, int max);
00412
00413
00414
00415
00416 int putpkt (const char *ph, const void *data, int bytes);
00417
00418 #define _das_h_
00419 #endif