00001
00004 #ifndef _DRMS_TYPES_H
00005 #define _DRMS_TYPES_H
00006
00007 #include <math.h>
00008 #include <float.h>
00009 #include <limits.h>
00010 #include <stdint.h>
00011 #include "db.h"
00012 #include "hcontainer.h"
00013 #include "list.h"
00014 #include "util.h"
00015 #include "tagfifo.h"
00016 #include "SUM.h"
00017 #include "sum_rpc.h"
00018
00019
00020 #define DRMS_MAXNAMELEN (32)
00021 #define DRMS_MAXSERIESNAMELEN (64)
00022 #define DRMS_MAXOWNERLEN DRMS_MAXNAMELEN
00023 #define DRMS_MAXSERIESVERSION (64)
00024 #define DRMS_MAXKEYNAMELEN DRMS_MAXNAMELEN
00025 #define DRMS_MAXLINKNAMELEN DRMS_MAXNAMELEN
00026 #define DRMS_MAXSEGNAMELEN DRMS_MAXNAMELEN
00027 #define DRMS_MAXCURSORNAMELEN (64)
00028
00029 #define DRMS_MAXHASHKEYLEN (DRMS_MAXSERIESNAMELEN+22)
00030
00031 #define DRMS_MAXUNITLEN (32)
00032 #define DRMS_MAXQUERYLEN (8192)
00033 #define DRMS_MAXBIGQUERYLEN (16384)
00034 #define DRMS_MAXPATHLEN (512)
00035 #define DRMS_MAXFORMATLEN (20)
00036
00037 #define DRMS_MAXRANK (16)
00038
00039 #define DRMS_MAXSEGMENTS (255)
00040
00041 #define DRMS_MAXCOMMENTLEN (255)
00042
00043 #define DRMS_MAXSEGFILENAME (256)
00044
00045 #define DRMS_MAXCPARMS (256)
00046
00047 #define DRMS_MAXPRIMIDX (15)
00048
00049 #define DRMS_MAXDBIDX (10)
00050
00051 #define DRMS_DEFVAL_MAXLEN (1000)
00052
00055 #define DRMS_MAXLINKDEPTH (20)
00056 #define DRMS_MAXHOSTNAME (128)
00057
00059 #define DRMS_MAXCHUNKSIZE (16777216)
00060
00061 #include "drms_protocol.h"
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00075 typedef enum {
00077 DRMS_TYPE_CHAR,
00079 DRMS_TYPE_SHORT,
00081 DRMS_TYPE_INT,
00083 DRMS_TYPE_LONGLONG,
00085 DRMS_TYPE_FLOAT,
00087 DRMS_TYPE_DOUBLE,
00089 DRMS_TYPE_TIME,
00091 DRMS_TYPE_STRING,
00093 DRMS_TYPE_RAW
00094 } DRMS_Type_t;
00095
00096 #ifndef DRMS_TYPES_C
00097 extern char *drms_type_names[];
00098 #else
00099
00103 char *drms_type_names[] = {"char", "short", "int", "longlong",
00104 "float", "double", "time", "string", "raw"};
00105 #endif
00106
00108 union DRMS_Type_Value
00109 {
00110 char char_val;
00111 short short_val;
00112 int int_val;
00113 long long longlong_val;
00114 float float_val;
00115 double double_val;
00116 double time_val;
00117 char *string_val;
00118 };
00119
00121 typedef union DRMS_Type_Value DRMS_Type_Value_t;
00122
00123
00124
00125
00126
00127 typedef struct DRMS_Value
00128 {
00129 DRMS_Type_t type;
00130 DRMS_Type_Value_t value;
00131 } DRMS_Value_t;
00132
00133
00135 #define DRMS_MISSING_CHAR (SCHAR_MIN)
00136
00137 #define DRMS_MISSING_SHORT (SHRT_MIN)
00138
00139 #define DRMS_MISSING_INT (INT_MIN)
00140
00141 #define DRMS_MISSING_LONGLONG (LLONG_MIN)
00142
00143 #define DRMS_MISSING_FLOAT (F_NAN)
00144 #define _DRMS_IS_F_MISSING(v) (isnan(v))
00145
00146 #define DRMS_MISSING_DOUBLE (D_NAN)
00147 #define _DRMS_IS_D_MISSING(v) (isnan(v))
00148
00149 #define DRMS_MISSING_STRING ("")
00150
00151 #define DRMS_MISSING_TIME (-211087684832.184)
00152
00153
00154
00155
00156 #define _DRMS_IS_T_MISSING(v) (isnan(v) || ((long long)v < (long long)DRMS_MISSING_TIME + 10.0e-5 && (long long)v > (long long)DRMS_MISSING_TIME - 10.0e-5))
00157
00158 #define TSEQ_EPOCH_S MDI_EPOCH_S
00159 #define TSEQ_EPOCH_F MDI_EPOCH_F
00160 #define TSEQ_EPOCH MDI_EPOCH
00161 #define SDO_EPOCH_S "1958.01.01_00:00:00_TAI"
00162 #define SDO_EPOCH_F (sscan_time (SDO_EPOCH_S))
00163 #define SDO_EPOCH (-599616000.000)
00164
00165 #define DRMS_MAXTYPENAMELEN (9)
00166
00167
00168
00169 #ifdef ICCCOMP
00170 #pragma warning (disable : 1572)
00171 #endif
00172 static inline int drms_ismissing_char(char value)
00173 {
00174 return (DRMS_MISSING_CHAR == value);
00175 }
00176
00177 static inline int drms_ismissing_short(short value)
00178 {
00179 return (DRMS_MISSING_SHORT == value);
00180 }
00181
00182 static inline int drms_ismissing_int(int value)
00183 {
00184 return (DRMS_MISSING_INT == value);
00185 }
00186
00187 static inline int drms_ismissing_longlong(long long value)
00188 {
00189 return (DRMS_MISSING_LONGLONG == value);
00190 }
00191
00192 static inline int drms_ismissing_float(float value)
00193 {
00194 return (_DRMS_IS_F_MISSING(value));
00195 }
00196
00197 static inline int drms_ismissing_double(double value)
00198 {
00199 return (_DRMS_IS_D_MISSING(value));
00200 }
00201
00202 static inline int drms_ismissing_time(TIME value)
00203 {
00204 return (_DRMS_IS_T_MISSING(value));
00205 }
00206
00207 static inline int drms_ismissing_string(char *value)
00208 {
00209 return (!value || *value == '\0');
00210 }
00211
00212 static inline int drms_ismissing(DRMS_Value_t *val)
00213 {
00214 int ans = -1;
00215
00216 switch(val->type)
00217 {
00218 case DRMS_TYPE_CHAR:
00219 ans = drms_ismissing_char(val->value.char_val);
00220 break;
00221 case DRMS_TYPE_SHORT:
00222 ans = drms_ismissing_short(val->value.short_val);
00223 break;
00224 case DRMS_TYPE_INT:
00225 ans = drms_ismissing_int(val->value.int_val);
00226 break;
00227 case DRMS_TYPE_LONGLONG:
00228 ans = drms_ismissing_longlong(val->value.longlong_val);
00229 break;
00230 case DRMS_TYPE_FLOAT:
00231 ans = drms_ismissing_float(val->value.float_val);
00232 break;
00233 case DRMS_TYPE_TIME:
00234 ans = drms_ismissing_time(val->value.time_val);
00235 break;
00236 case DRMS_TYPE_DOUBLE:
00237 ans = drms_ismissing_double(val->value.double_val);
00238 break;
00239 case DRMS_TYPE_STRING:
00240 ans = drms_ismissing_string(val->value.string_val);
00241 break;
00242 default:
00243 fprintf(stderr, "Unsupported data type %d.\n", (int)val->type);
00244 }
00245
00246 return ans;
00247 }
00248
00249 #ifdef ICCCOMP
00250 #pragma warning (default : 1572)
00251 #endif
00252
00253
00254
00255
00256
00257
00258
00259
00261 struct DRMS_Session_struct
00262 {
00263 int db_direct;
00264
00265
00266
00267 DB_Handle_t *db_handle;
00268
00269
00270 DB_Handle_t *stat_conn;
00271
00272
00273
00274
00275 long long sessionid;
00276
00277 char *sessionns;
00278
00279
00280
00281 long long sunum;
00282 char *sudir;
00283
00284
00285
00286 int clientid;
00287
00288
00289 char hostname[DRMS_MAXHOSTNAME];
00290 unsigned short port;
00291 int sockfd;
00292 int readonly;
00293
00294 char startTime[32];
00295
00296
00297
00298 char dbhost[DRMS_MAXHOSTNAME];
00299 int dbport;
00300 char dbname[64];
00301 char dbuser[64];
00302 };
00303
00305 typedef struct DRMS_Session_struct DRMS_Session_t;
00306
00307
00308
00309 typedef struct DS_node_struct
00310 {
00311 char *series;
00312 int n,nmax;
00313 long long *recnums;
00314 struct DS_node_struct *next;
00315 } DS_node_t;
00316
00317 enum DRMS_Shutdown_State_enum
00318 {
00319 kSHUTDOWN_UNINITIATED = 0,
00320 kSHUTDOWN_COMMITINITIATED = 1,
00321 kSHUTDOWN_ABORTINITIATED = 2,
00322 kSHUTDOWN_COMMIT = 3,
00323 kSHUTDOWN_ABORT = 4,
00324 kSHUTDOWN_BYMAIN = 5
00325 };
00326
00327 typedef enum DRMS_Shutdown_State_enum DRMS_Shutdown_State_t;
00328
00329 typedef int (*pFn_Cleaner_t)(void *);
00330
00331 struct CleanerData_struct
00332 {
00333 pFn_Cleaner_t cb;
00334 void *data;
00335 };
00336
00337 typedef struct CleanerData_struct CleanerData_t;
00338
00340 struct DRMS_Env_struct
00341 {
00342 DRMS_Session_t *session;
00343
00344 HContainer_t series_cache;
00345 HContainer_t record_cache;
00346 HContainer_t storageunit_cache;
00347 DS_node_t *templist;
00348
00349
00350 int16_t retention;
00351
00352
00353 int query_mem;
00354
00355
00356 int archive;
00357 int server_wait;
00358
00359
00360
00361
00362
00363
00364
00365 int verbose;
00366
00367 char *dbpasswd;
00368 char *user;
00369 const char *logfile_prefix;
00370 int dolog;
00371 int quiet;
00372
00373 int clientcounter;
00374 pid_t tee_pid;
00375
00376 pthread_mutex_t *drms_lock;
00377
00378 pthread_mutex_t *clientlock;
00379
00380
00381
00382
00383 pthread_t sum_thread;
00384
00385 tqueue_t *sum_inbox;
00386 tqueue_t *sum_outbox;
00387 long sum_tag;
00388
00389
00390 pthread_t signal_thread;
00391 sigset_t signal_mask;
00392 sigset_t old_signal_mask;
00393
00394
00395 pthread_t main_thread;
00396 int selfstart;
00397 int transinit;
00398
00399 LinkedList_t *cleaners;
00400
00401
00402
00403 int transrunning;
00404
00405 int sessionrunning;
00406
00407 int loopconn;
00408 int dbtimeout;
00409
00410 int16_t newsuretention;
00411 int sumssafe;
00412 int createshadows;
00413 int dbutf8clientencoding;
00414 };
00415
00417 typedef struct DRMS_Env_struct DRMS_Env_t;
00418
00419 typedef struct DRMS_ThreadInfo_struct
00420 {
00421 DRMS_Env_t *env;
00422 int noshare;
00423
00424
00425
00426
00427 int threadnum;
00428 int sockfd;
00429 } DRMS_ThreadInfo_t;
00430
00431
00432
00433
00434 #define DRMS_SUMALLOC 0
00435 #define DRMS_SUMGET 1
00436 #define DRMS_SUMPUT 2
00437 #define DRMS_SUMCLOSE 3
00438 #define DRMS_SUMDELETESERIES 4
00439 #define DRMS_SUMALLOC2 5
00440 #define DRMS_SUMEXPORT 6
00441 #define DRMS_SUMINFO 7
00442 #define DRMS_SUMOPEN 8
00443 #define DRMS_SUMABORT 99
00444 #define DRMS_MAX_REQCNT MAXSUMREQCNT
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 typedef struct DRMS_SumRequest_struct
00458 {
00459 int opcode;
00460
00461 int reqcnt;
00462 double bytes;
00463 char *dsname;
00464 int mode;
00465 int group;
00466 int tdays;
00467 char *comment;
00468
00469 char *sudir[DRMS_MAX_REQCNT];
00470 uint64_t sunum[DRMS_MAX_REQCNT];
00471
00472 int dontwait;
00473 } DRMS_SumRequest_t;
00474
00475 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
00476
00477
00478 typedef struct DRMS_MtSumsRequest_struct
00479 {
00480 int opcode;
00481
00482 int reqcnt;
00483 double bytes;
00484 char *dsname;
00485 int mode;
00486 int group;
00487 int tdays;
00488 char *comment;
00489
00490 char **sudir;
00491 uint64_t *sunum;
00492
00493 int dontwait;
00494 } DRMS_MtSumsRequest_t;
00495 #endif
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 typedef enum {DRMS_PERMANENT, DRMS_TRANSIENT} DRMS_RecLifetime_t;
00508
00510 enum DRMS_RecSetCursorSeek_enum
00511 {
00512 kRSChunk_First = 0,
00513 kRSChunk_Last,
00514 kRSChunk_Abs,
00515 kRSChunk_Next,
00516 kRSChunk_Prev
00517 };
00518
00519 typedef enum DRMS_RecSetCursorSeek_enum DRMS_RecSetCursorSeek_t;
00520
00522 struct DRMS_RecSetCursor_struct
00523 {
00525 struct DRMS_RecordSet_struct *parent;
00527 char **names;
00529 DRMS_Env_t *env;
00531 int chunksize;
00533
00534 int currentchunk;
00537 int lastrec;
00539 int currentrec;
00541 int *allvers;
00543 int staging_needed;
00545 int retrieve;
00547 int dontwait;
00548
00549 int infoneeded;
00551 HContainer_t *suinfo;
00552 };
00553
00555 typedef struct DRMS_RecSetCursor_struct DRMS_RecSetCursor_t;
00556
00557 typedef enum DRMS_RecordSetType_struct
00558 {
00559 kRecordSetType_DRMS = 0,
00560 kRecordSetType_DSDS,
00561 kRecordSetType_VOT,
00562 kRecordSetType_PlainFile,
00563 kRecordSetType_DSDSPort
00564 } DRMS_RecordSetType_t;
00565
00566 #ifndef DRMS_TYPES_C
00567 extern char *drms_type_recsetnames[];
00568 #else
00569 char *drms_type_recsetnames[] =
00570 {
00571 "drms",
00572 "dsds",
00573 "vot",
00574 "plainfile",
00575 "dsdsport"
00576 };
00577 #endif
00578
00580 struct DRMS_RecordSet_struct
00581 {
00583 int n;
00585 struct DRMS_Record_struct **records;
00587 int ss_n;
00589 char **ss_queries;
00591 DRMS_RecordSetType_t *ss_types;
00593 int *ss_starts;
00595 int *ss_currentrecs;
00597
00598 DRMS_RecSetCursor_t *cursor;
00600 DRMS_Env_t *env;
00601 };
00602
00604 typedef struct DRMS_RecordSet_struct DRMS_RecordSet_t;
00605
00606 struct DRMS_SeriesVersion_struct
00607 {
00608 char first[DRMS_MAXSERIESVERSION];
00609 char last[DRMS_MAXSERIESVERSION];
00610 };
00611
00612 typedef struct DRMS_SeriesVersion_struct DRMS_SeriesVersion_t;
00613
00614
00615 typedef struct DRMS_SeriesInfo_struct
00616 {
00617 char seriesname[DRMS_MAXSERIESNAMELEN];
00618 char description[DRMS_MAXCOMMENTLEN];
00619 char author[DRMS_MAXCOMMENTLEN];
00620 char owner[DRMS_MAXOWNERLEN];
00621
00622
00623
00624
00625 int unitsize;
00626 int archive;
00627 int retention;
00628 int retention_perm;
00629 int tapegroup;
00630
00631
00632 int pidx_num;
00633 struct DRMS_Keyword_struct *pidx_keywords[DRMS_MAXPRIMIDX];
00634
00635
00636
00637 int dbidx_num;
00638 struct DRMS_Keyword_struct *dbidx_keywords[DRMS_MAXDBIDX];
00639 char version[DRMS_MAXSERIESVERSION];
00640 int createshadow;
00641
00642 int hasshadow;
00643 } DRMS_SeriesInfo_t;
00644
00645
00646
00647
00649 struct DRMS_Record_struct
00650 {
00651 struct DRMS_Env_struct *env;
00652
00653 long long recnum;
00654 long long sunum;
00655
00656
00657 int init;
00658 int readonly;
00659 DRMS_RecLifetime_t lifetime;
00660
00661 struct DRMS_StorageUnit_struct *su;
00662
00663
00664
00665 int slotnum;
00666
00667 long long sessionid;
00668 char *sessionns;
00669
00670 DRMS_SeriesInfo_t *seriesinfo;
00671 HContainer_t keywords;
00672 HContainer_t links;
00673 HContainer_t segments;
00674 SUM_info_t *suinfo;
00675
00676
00677
00678 int refcount;
00679
00680 };
00681
00683 typedef struct DRMS_Record_struct DRMS_Record_t;
00684
00685
00686 #define kRecScopeIndex_B 100
00687 #define kRecScopeSlotted_B 1000
00688
00689
00690 #define kSlotAncKey_Index "_index"
00691 #define kSlotAncKey_Epoch "_epoch"
00692 #define kSlotAncKey_Base "_base"
00693 #define kSlotAncKey_Step "_step"
00694 #define kSlotAncKey_Unit "_unit"
00695 #define kSlotAncKey_Base "_base"
00696 #define kSlotAncKey_Vals "_vals"
00697 #define kSlotAncKey_Round "_round"
00698
00699 extern const DRMS_Type_t kIndexKWType;
00700 extern const char *kIndexKWFormat;
00701
00702 enum DRMS_ExportKeyword_enum
00703 {
00704 kExport_ReqID = 0,
00705 kExport_Request,
00706 kExport_SegList,
00707 kExport_Requestor,
00708 kExport_Notification,
00709 kExport_ReqTime,
00710 kExport_ExpTime,
00711 kExport_DataSize,
00712 kExport_Format,
00713 kExport_FileNameFormat,
00714 kExport_Status
00715 };
00716
00717 typedef enum DRMS_ExportKeyword_enum DRMS_ExportKeyword_t;
00718
00719 struct ExportStrings_struct
00720 {
00721 DRMS_ExportKeyword_t kw;
00722 const char *str;
00723 };
00724
00725 typedef struct ExportStrings_struct ExportStrings_t;
00726
00727 extern ExportStrings_t gExpStr[];
00728
00729 enum DRMS_SlotKeyUnit_enum
00730 {
00732 kSlotKeyUnit_Invalid = 0,
00733 kSlotKeyUnit_TSeconds,
00734 kSlotKeyUnit_Seconds,
00735 kSlotKeyUnit_Minutes,
00736 kSlotKeyUnit_Hours,
00737 kSlotKeyUnit_Days,
00738 kSlotKeyUnit_Degrees,
00739 kSlotKeyUnit_Arcminutes,
00740 kSlotKeyUnit_Arcseconds,
00741 kSlotKeyUnit_MAS,
00742 kSlotKeyUnit_Radians,
00743 kSlotKeyUnit_MicroRadians
00744 };
00745
00746 typedef enum DRMS_SlotKeyUnit_enum DRMS_SlotKeyUnit_t;
00747
00748 enum DRMS_TimeEpoch_enum
00749 {
00751 kTimeEpoch_Invalid = -1,
00752 kTimeEpoch_DRMS,
00753 kTimeEpoch_MDI,
00754 kTimeEpoch_WSO,
00755 kTimeEpoch_TAI,
00756 kTimeEpoch_MJD,
00757 kTimeEpoch_TSEQ,
00758 kTimeEpoch_END
00759 };
00760
00761 typedef enum DRMS_TimeEpoch_enum DRMS_TimeEpoch_t;
00762
00763 enum DRMS_RecScopeType_enum
00764 {
00766 kRecScopeType_Variable = 0,
00768 kRecScopeType_Constant = 1,
00773 kRecScopeType_Index = kRecScopeIndex_B,
00777 kRecScopeType_TS_EQ = kRecScopeSlotted_B,
00778 kRecScopeType_SLOT = kRecScopeSlotted_B + 1,
00779 kRecScopeType_ENUM = kRecScopeSlotted_B + 2,
00780 kRecScopeType_CARR = kRecScopeSlotted_B + 3,
00781 kRecScopeType_TS_SLOT = kRecScopeSlotted_B + 4
00782
00783 };
00784
00785 typedef enum DRMS_RecScopeType_enum DRMS_RecScopeType_t;
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803 enum DRMS_PrimeKeyType_enum
00804 {
00805 kPkeysDRMSInternal = 0,
00806 kPkeysDRMSExternal
00807 };
00808
00809 typedef enum DRMS_PrimeKeyType_enum DRMS_PrimeKeyType_t;
00810
00811 enum DRMS_KeywordFlag_enum
00812 {
00813
00814
00815
00816
00817
00818 kKeywordFlag_PerSegment = 0x00000001,
00819
00820
00821
00822
00823
00824
00825
00826 kKeywordFlag_Implicit = 0x00000002,
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 kKeywordFlag_InternalPrime = 0x00000004,
00847 kKeywordFlag_ExternalPrime = 0x00000008
00848 };
00849
00850 typedef enum DRMS_KeywordFlag_enum DRMS_KeywordFlag_t;
00851
00852
00853
00854
00856 enum DRMS_KeywordClass_enum
00857 {
00859 kDRMS_KeyClass_All = 0,
00862 kDRMS_KeyClass_Explicit,
00864 kDRMS_KeyClass_DRMSPrime,
00866 kDRMS_KeyClass_Persegment
00867 };
00868
00869 typedef enum DRMS_KeywordClass_enum DRMS_KeywordClass_t;
00870
00871 typedef struct DRMS_KeywordInfo_struct
00872 {
00873 char name[DRMS_MAXKEYNAMELEN];
00874
00875
00876
00877
00878
00879 int islink;
00880 char linkname[DRMS_MAXLINKNAMELEN];
00881 char target_key[DRMS_MAXKEYNAMELEN];
00882
00883
00884 DRMS_Type_t type;
00885 char format[DRMS_MAXFORMATLEN];
00886
00887 char unit[DRMS_MAXUNITLEN];
00888 char description[DRMS_MAXCOMMENTLEN];
00889 DRMS_RecScopeType_t recscope;
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 int kwflags;
00903
00904
00905
00906
00907
00908 int rank;
00909
00910
00911
00912
00913
00914 } DRMS_KeywordInfo_t;
00915
00919 struct DRMS_Keyword_struct
00920 {
00921 struct DRMS_Record_struct *record;
00922 struct DRMS_KeywordInfo_struct *info;
00923 DRMS_Type_Value_t value;
00924
00925
00926 };
00927
00929 typedef struct DRMS_Keyword_struct DRMS_Keyword_t;
00930
00931
00932
00933
00934
00935
00936
00937 typedef enum { STATIC_LINK, DYNAMIC_LINK } DRMS_Link_Type_t;
00938
00939
00940 typedef struct DRMS_LinkInfo_struct
00941 {
00942 char name[DRMS_MAXLINKNAMELEN];
00943 char target_series[DRMS_MAXSERIESNAMELEN];
00944 char description[DRMS_MAXCOMMENTLEN];
00945 DRMS_Link_Type_t type;
00946
00947
00948 int pidx_num;
00949 DRMS_Type_t pidx_type[DRMS_MAXPRIMIDX];
00950 char *pidx_name[DRMS_MAXPRIMIDX];
00951 int rank;
00952
00953
00954 } DRMS_LinkInfo_t;
00955
00957 struct DRMS_Link_struct
00958 {
00959 struct DRMS_Record_struct *record;
00960 DRMS_LinkInfo_t *info;
00961
00962
00963 long long recnum;
00964
00965
00966
00967
00968
00969 int isset;
00970 DRMS_Type_Value_t pidx_value[DRMS_MAXPRIMIDX];
00971
00972
00973 int wasFollowed;
00974
00975
00976
00977
00978
00979
00980
00981
00982 };
00983
00985 typedef struct DRMS_Link_struct DRMS_Link_t;
00986
00987
00988
00989
00990
01034 struct DRMS_Array_struct
01035 {
01036
01038 DRMS_Type_t type;
01040 int naxis;
01042 int axis[DRMS_MAXRANK];
01044 void *data;
01045
01046
01048 struct DRMS_Segment_struct *parent_segment;
01050 double bzero;
01059 int israw;
01061 double bscale;
01063 int start[DRMS_MAXRANK];
01064
01065
01067 int dope[DRMS_MAXRANK];
01068
01069
01071 char *strbuf;
01073 long long buflen;
01074 };
01075
01077 typedef struct DRMS_Array_struct DRMS_Array_t;
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01137 typedef enum {
01139 DRMS_CONSTANT,
01141 DRMS_VARIABLE,
01143 DRMS_VARDIM
01144 } DRMS_Segment_Scope_t;
01145
01146 #ifndef DRMS_TYPES_C
01147 extern char *drms_segmentscope_names[];
01148 #else
01149 char *drms_segmentscope_names[] = {"constant", "variable", "vardim"};
01150
01151 #endif
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01165 struct DRMS_SegmentDimInfo_struct {
01167 int naxis;
01169 int axis[DRMS_MAXRANK];
01170 };
01171
01173 typedef struct DRMS_SegmentDimInfo_struct DRMS_SegmentDimInfo_t;
01174
01176 struct DRMS_SegmentInfo_struct {
01177
01179 char name[DRMS_MAXSEGNAMELEN];
01181 int segnum;
01182
01183
01185 char description[DRMS_MAXCOMMENTLEN];
01186
01187
01188
01189
01191 int islink;
01193 char linkname[DRMS_MAXLINKNAMELEN];
01195 char target_seg[DRMS_MAXSEGNAMELEN];
01197 DRMS_Type_t type;
01199 int naxis;
01201 char unit[DRMS_MAXUNITLEN];
01203 DRMS_Protocol_t protocol;
01205 DRMS_Segment_Scope_t scope;
01207 long long cseg_recnum;
01208 };
01209
01211 typedef struct DRMS_SegmentInfo_struct DRMS_SegmentInfo_t;
01212
01294 struct DRMS_Segment_struct {
01296 struct DRMS_Record_struct *record;
01298 DRMS_SegmentInfo_t *info;
01299
01301 char filename[DRMS_MAXSEGFILENAME];
01303 int axis[DRMS_MAXRANK];
01305 int blocksize[DRMS_MAXRANK];
01306 char cparms[DRMS_MAXCPARMS];
01307
01309 double bzero;
01311 double bscale;
01312 };
01313
01315 typedef struct DRMS_Segment_struct DRMS_Segment_t;
01316
01317 #define DRMS_READONLY 1
01318 #define DRMS_READWRITE 2
01319 typedef struct DRMS_StorageUnit_struct {
01320 struct DRMS_SeriesInfo_struct *seriesinfo;
01321 int mode;
01322 long long sunum;
01323 char sudir[DRMS_MAXPATHLEN];
01324 int refcount;
01325 int nfree;
01326
01327 char *state;
01328
01329
01330
01331
01332
01333
01334 long long *recnum;
01335
01336
01337 } DRMS_StorageUnit_t;
01338
01339
01340 typedef struct DRMS_SuAndSeries_struct
01341 {
01342 long long sunum;
01343 char *series;
01344 } DRMS_SuAndSeries_t;
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357 typedef int DRMS_RecQueryInfo_t;
01358
01359 enum DRMS_RecQueryInfoFlag_enum
01360 {
01361 kFilters = 0x00000001,
01362 kAtFile = 0x00000002
01363 };
01364
01365 typedef enum DRMS_RecQueryInfoFlag_enum DRMS_RecQueryInfoFlag_t;
01366
01367
01368 DRMS_Type_t drms_str2type(const char *);
01369
01377 const char *drms_type2str(DRMS_Type_t type);
01378 void drms_missing(DRMS_Type_t type, DRMS_Type_Value_t *val);
01379 void drms_missing_vp(DRMS_Type_t type, void *val);
01380 int drms_copy_db2drms(DRMS_Type_t drms_type, DRMS_Type_Value_t *drms_dst,
01381 DB_Type_t db_type, char *db_src);
01382 void drms_copy_drms2drms(DRMS_Type_t type, DRMS_Type_Value_t *dst,
01383 DRMS_Type_Value_t *src);
01384 DB_Type_t drms2dbtype(DRMS_Type_t type);
01385 int drms_sizeof(DRMS_Type_t type);
01386 void *drms_addr(DRMS_Type_t type, DRMS_Type_Value_t *val);
01387 int drms_strval(DRMS_Type_t type, DRMS_Type_Value_t *val, char *str);
01388 int drms_sprintfval(char *dst, DRMS_Type_t type, DRMS_Type_Value_t *val, int internal);
01389 int drms_sprintfval_format(char *dst, DRMS_Type_t type, DRMS_Type_Value_t *val,
01390 char *format, int internal);
01391 int drms_printfval (DRMS_Type_t type, DRMS_Type_Value_t *val);
01392 int drms_fprintfval(FILE *keyfile, DRMS_Type_t type, DRMS_Type_Value_t *val);
01393 int drms_sscanf_str(const char *str, const char *delim, DRMS_Type_Value_t *dst);
01394 int drms_sscanf2(const char *str, const char *delim, int silent, DRMS_Type_t dsttype, DRMS_Value_t *dst);
01395
01396
01397 int drms_convert(DRMS_Type_t dsttype, DRMS_Type_Value_t *dst,
01398 DRMS_Type_t srctype, DRMS_Type_Value_t *src);
01399 int drms_convert_array(DRMS_Type_t dsttype, char *dst,
01400 DRMS_Type_t srctype, char *src);
01401 char drms2char(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01402 short drms2short(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01403 int drms2int(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01404 long long drms2longlong(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01405 long long conv2longlong(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01406 float drms2float(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01407 double drms2double(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01408 double drms2time(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01409 char *drms2string(DRMS_Type_t type, DRMS_Type_Value_t *value, int *status);
01410
01411
01412 int drms_printfval_raw(DRMS_Type_t type, void *val);
01413 int drms_fprintfval_raw(FILE *keyfile, DRMS_Type_t type, void *val);
01414 long long drms_types_strtoll(const char *str, DRMS_Type_t inttype, int *consumed, int *status);
01415 void drms_byteswap(DRMS_Type_t type, int n, char *val);
01416 void drms_memset(DRMS_Type_t type, int n, void *array, DRMS_Type_Value_t val);
01417 int drms_daxpy(DRMS_Type_t type, const double alpha, DRMS_Type_Value_t *x,
01418 DRMS_Type_Value_t *y );
01419 int drms_equal(DRMS_Type_t type, DRMS_Type_Value_t *x, DRMS_Type_Value_t *y);
01420
01421
01422 const TIME *drms_time_getepoch(const char *str, DRMS_TimeEpoch_t *epochenum, int *status);
01423 void drms_time_term();
01424
01425
01426
01427
01428 static inline TIME _SDO_to_DRMS_time(int sdo_s, int sdo_ss)
01429 {
01430 return(SDO_EPOCH + (TIME)sdo_s + (TIME)sdo_ss/65536.0);
01431 }
01432
01433
01434 static inline void drms_value_free(DRMS_Value_t *val)
01435 {
01436 if (val && val->type == DRMS_TYPE_STRING && val->value.string_val)
01437 {
01438 free(val->value.string_val);
01439 val->value.string_val = NULL;
01440 }
01441 }
01442
01443
01444
01445
01446
01447 #define DRMS_VAL_SET(T, IV, OV) \
01448 { \
01449 int vserror = 0; \
01450 switch (T) \
01451 { \
01452 case DRMS_TYPE_CHAR: \
01453 OV.value.char_val = *(char *)IV; \
01454 break; \
01455 case DRMS_TYPE_SHORT: \
01456 OV.value.short_val = *(short *)IV; \
01457 break; \
01458 case DRMS_TYPE_INT: \
01459 OV.value.int_val = *(int *)IV; \
01460 break; \
01461 case DRMS_TYPE_LONGLONG: \
01462 OV.value.longlong_val = *(long long *)IV; \
01463 break; \
01464 case DRMS_TYPE_FLOAT: \
01465 OV.value.float_val = *(float *)IV; \
01466 break; \
01467 case DRMS_TYPE_DOUBLE: \
01468 OV.value.double_val = *(double *)IV; \
01469 break; \
01470 case DRMS_TYPE_TIME: \
01471 OV.value.time_val = *(double *)IV; \
01472 break; \
01473 case DRMS_TYPE_STRING: \
01474 OV.value.string_val = strdup((char *)IV); \
01475 break; \
01476 default: \
01477 fprintf(stderr, "Invalid drms type: %d\n", (int)T); \
01478 vserror = 1; \
01479 } \
01480 if (!vserror) \
01481 { \
01482 OV.type = T; \
01483 } \
01484 }
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495 static inline DRMS_Value_t drms_val_add(DRMS_Value_t *a, DRMS_Value_t *b)
01496 {
01497 DRMS_Value_t ans;
01498
01499 if (a->type == b->type)
01500 {
01501 ans.type = a->type;
01502
01503 switch(a->type)
01504 {
01505 case DRMS_TYPE_CHAR:
01506 {
01507 int sum = (a->value).char_val + (b->value).char_val;
01508
01509 if (sum >= SCHAR_MIN && sum <= SCHAR_MAX)
01510 {
01511 ans.value.char_val = (char)sum;
01512 }
01513 }
01514 break;
01515 case DRMS_TYPE_SHORT:
01516 {
01517 int sum = (a->value).short_val + (b->value).short_val;
01518
01519 if (sum >= SHRT_MIN && sum <= SHRT_MAX)
01520 {
01521 ans.value.short_val = (short)sum;
01522 }
01523 }
01524 break;
01525 case DRMS_TYPE_INT:
01526 {
01527 long long sum = (a->value).int_val + (b->value).int_val;
01528
01529 if (sum >= INT_MIN && sum <= INT_MAX)
01530 {
01531 ans.value.int_val = (int)sum;
01532 }
01533 }
01534 break;
01535 case DRMS_TYPE_LONGLONG:
01536 {
01537 long long sum = (a->value).longlong_val + (b->value).longlong_val;
01538 ans.value.longlong_val = sum;
01539 }
01540 break;
01541 case DRMS_TYPE_FLOAT:
01542 {
01543 double sum = (a->value).float_val + (b->value).float_val;
01544
01545 if (sum >= -FLT_MAX && sum <= FLT_MAX)
01546 {
01547 ans.value.float_val = (float)sum;
01548 }
01549 }
01550 break;
01551 case DRMS_TYPE_DOUBLE:
01552 {
01553 double sum = (a->value).double_val + (b->value).double_val;
01554 ans.value.double_val = sum;
01555 }
01556 break;
01557 default:
01558 fprintf(stderr, "drms_val_add(): unsupported type.\n");
01559 }
01560 }
01561 else
01562 {
01563 fprintf(stderr, "drms_val_add(): type mismatch.\n");
01564 }
01565
01566 return ans;
01567 }
01568
01569 static inline DRMS_Value_t drms_val_div(DRMS_Value_t *a, DRMS_Value_t *b)
01570 {
01571 DRMS_Value_t ans;
01572
01573 if (a->type == b->type)
01574 {
01575 ans.type = a->type;
01576
01577 switch(a->type)
01578 {
01579 case DRMS_TYPE_CHAR:
01580 {
01581 int res = (int)((a->value).char_val) / (int)((b->value).char_val);
01582
01583 if (res >= SCHAR_MIN && res <= SCHAR_MAX)
01584 {
01585 ans.value.char_val = (char)res;
01586 }
01587 }
01588 break;
01589 case DRMS_TYPE_SHORT:
01590 {
01591 int res = (int)((a->value).short_val) / (int)((b->value).short_val);
01592
01593 if (res >= SHRT_MIN && res <= SHRT_MAX)
01594 {
01595 ans.value.short_val = (short)res;
01596 }
01597 }
01598 break;
01599 case DRMS_TYPE_INT:
01600 {
01601 long long res = (a->value).int_val / (b->value).int_val;
01602
01603 if (res >= INT_MIN && res <= INT_MAX)
01604 {
01605 ans.value.int_val = (int)res;
01606 }
01607 }
01608 break;
01609 case DRMS_TYPE_LONGLONG:
01610 {
01611 long long res = (a->value).longlong_val / (b->value).longlong_val;
01612 ans.value.longlong_val = res;
01613 }
01614 break;
01615 case DRMS_TYPE_FLOAT:
01616 {
01617 double res = (double)((a->value).float_val) / (double)((b->value).float_val);
01618
01619 if (res >= -FLT_MAX && res <= FLT_MAX)
01620 {
01621 ans.value.float_val = (float)res;
01622 }
01623 }
01624 break;
01625 case DRMS_TYPE_DOUBLE:
01626 {
01627 double res = (a->value).double_val / (b->value).double_val;
01628 ans.value.double_val = res;
01629 }
01630 break;
01631 default:
01632 fprintf(stderr, "drms_val_div(): unsupported type.\n");
01633 }
01634 }
01635 else
01636 {
01637 fprintf(stderr, "drms_val_add(): type mismatch.\n");
01638 }
01639
01640 return ans;
01641 }
01642
01643
01644
01645
01646
01651 #endif
01652
01653