00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOI_SDS_INCL
00026
00027
00028
00029
00030
00031 #ifndef SOI_VERSION_INCL
00032 #include <soi_version.h>
00033 #endif
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <ctype.h>
00039 #include "soi_error.h"
00040 #include "soi_key.h"
00041 #include "soi_machine.h"
00042 #include "soi_missing.h"
00043 #include "soi_NaN.h"
00044 #include "soi_args.h"
00045
00046
00047
00048
00049
00050
00051 #define SDS_QUIT(errcode, i) {soi_errno=errcode; return(i);}
00052
00053 #define MAX_TYPE 3
00054 #define MAX_DATATYPE 5
00055 #define MAX_BYTES 20
00056 #define SDS_MAXSTRING (255)
00057 #define SDS_MAXPATH (255)
00058
00059 #define FITSID 51
00060 #define CDFID 52
00061 #define MAXRANK 100
00062
00063 #define FITS_KWSIZE 8
00064 #define FITS_VALSIZE 70
00065 #define FITS_CARDSIZE 80
00066 #define FITS_NCARDS 36
00067
00068 #define SDS_VOID (0)
00069 #define SDS_BYTE (1)
00070 #define SDS_UBYTE (2)
00071 #define SDS_SHORT (3)
00072 #define SDS_USHORT (4)
00073 #define SDS_INT (5)
00074 #define SDS_UINT (6)
00075 #define SDS_LONG (7)
00076 #define SDS_ULONG (8)
00077 #define SDS_FLOAT (9)
00078 #define SDS_DOUBLE (10)
00079 #define SDS_COMPLEX (11)
00080 #define SDS_STRING (12)
00081 #define SDS_TIME (13)
00082 #define SDS_LOGICAL (14)
00083 #define SDS_ANY (15)
00084 #define SDS_ASIS (16)
00085
00086 #define SDS_NOTYPE (0)
00087 #define SDS_RAW (1)
00088 #define SDS_SDS (2)
00089 #define SDS_MDI_HRTLM (3)
00090 #define SDS_MDI_LRTLM (4)
00091 #define SDS_TIFF (5)
00092 #define SDS_FITS (6)
00093 #define SDS_CDF (7)
00094 #define SDS_FITS_TABLE (8)
00095 #define SDS_RDB (9)
00096 #define SDS_GIF (10)
00097
00098 #define SDS_NEVER_FREE (0)
00099 #define SDS_OK_TO_FREE (1)
00100
00101
00102
00103 #define SOI_SDS_VERSION_NUM ("4.5")
00104 #define SOI_SDS_INCL
00105
00106
00107
00108
00109
00110 typedef struct attribute {
00111 struct attribute *next;
00112 char *attrname;
00113 void *attrvalue;
00114 char *comment;
00115 int datatype;
00116 } ATTRIBUTES;
00117
00118
00119 typedef struct history {
00120 struct history *next;
00121 char *text;
00122 } HISTORY;
00123
00124 typedef struct record {
00125
00126 long recvariance;
00127 long startrecord;
00128 long numrecords;
00129 long recinterval;
00130 } RECORD;
00131
00132 typedef struct dimension {
00133
00134 int rank;
00135 int *length;
00136 int *dimvary;
00137 int *startind;
00138 int *indinter;
00139 } DIMENSION;
00140
00141 typedef struct sds_stats_struct {
00142 union {
00143 double dm;
00144 float fm;
00145 long int lm; unsigned int ulm;
00146 int im; unsigned int uim;
00147 short sm; unsigned short usm;
00148 char cm; unsigned char ucm;
00149 } min;
00150 union {
00151 double dm;
00152 float fm;
00153 long int lm;
00154 int im;
00155 short sm;
00156 char cm;
00157 } min_abs;
00158 union {
00159 double dm;
00160 float fm;
00161 long int lm; unsigned int ulm;
00162 int im; unsigned int uim;
00163 short sm; unsigned short usm;
00164 char cm; unsigned char ucm;
00165 } max;
00166 double minact;
00167 double maxact;
00168 double rangemin;
00169 double rangemax;
00170 double median;
00171 double mean;
00172 double stdev;
00173 double skewness;
00174 double kurtosis;
00175 double minabs;
00176 char *var_name;
00177 char *format;
00178 unsigned long numvals;
00179 unsigned long missvals;
00180 unsigned short statvalid;
00181 } SDS_STATS;
00182
00183 typedef struct axis {
00184 int *axis_datatype;
00185 void *start;
00186 void *stepsize;
00187 char **units;
00188 char **format;
00189 char **title;
00190 } AXIS;
00191
00192
00193 typedef struct color {
00194 int BitsPerPixel;
00195 int *Red;
00196 int *Green;
00197 int *Blue;
00198 } SDS_COLOR;
00199
00200
00201 typedef struct sds {
00202 struct sds *next;
00203 RECORD *recinfo;
00204 DIMENSION *diminfo;
00205 SDS_STATS *stats;
00206 SDS_COLOR *color_table;
00207 char *varname;
00208 void *fillvalue;
00209 void *data;
00210 int data_quality;
00211 int datatype;
00212 int numbytes;
00213 AXIS *axisinfo;
00214 ATTRIBUTES *attrinfo;
00215 FILE *fp;
00216 char *filename;
00217 int own_data;
00218 double bscale;
00219 double bzero;
00220 int scale_on_write;
00221 char *comment;
00222 char *history;
00223 } SDS;
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 #define MAX_SDS 128
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 typedef struct _chunk {
00250 struct _chunk *next;
00251 int nElem;
00252 void *base;
00253 } chunk;
00254
00255
00256 typedef struct _clist {
00257 int listSize;
00258 int elemSize;
00259 int chunkSize;
00260 chunk *head;
00261 } clist;
00262
00263
00264
00265 typedef clist SDSlist;
00266
00267 typedef struct {
00268 SDSlist *sdslist;
00269 ATTRIBUTES *Attrinfo;
00270 AXIS *PrimaryAxis;
00271 } IDS;
00272
00273
00274
00275
00276
00277
00278 typedef struct _ll {
00279 struct _ll *next;
00280 } _llist;
00281
00282
00283
00284
00285
00286 typedef int (*_llistFn)(_llist *ll, void *obj);
00287
00288
00289
00290
00291
00292
00293 extern SDS *sds_create (void );
00294 extern int sds_create_data (SDS* sdsptr);
00295 extern SDS_STATS *sds_create_stats (void);
00296 extern void sds_free (SDS **sdsptrptr);
00297 extern void sds_free_attr (ATTRIBUTES *attr);
00298 extern void sds_free_color (SDS *sdsptr);
00299 extern void sds_free_data (SDS *sdsptr);
00300 extern void sds_free_dim (DIMENSION *dim);
00301 extern void sds_free_filename (SDS *sdsptr);
00302 extern void sds_free_ptrs (SDS *sdsptr);
00303 extern void sds_free_varname (SDS *sdsptr);
00304 extern ATTRIBUTES *sds_malloc_attribute (void);
00305 extern SDS_COLOR *sds_malloc_color (void);
00306 extern char *sds_malloc_data (long numobytes);
00307 extern DIMENSION *sds_malloc_dimension (void);
00308 extern void *sds_malloc_fillvalue (int datatype);
00309 extern int *sds_malloc_length (int rank);
00310 extern char *sds_malloc_string (int numochars);
00311 extern void *sds_std_fillvalue (int sds_type);
00312
00313
00314 extern int sds_append_args_tohist (SDS *sds, argument *args, KEY *list);
00315 extern int sds_append_attrs (SDS *sdsout, SDS *sdsin);
00316 extern int sds_append_comment (SDS *sds, char *str);
00317 extern int sds_append_history (SDS *sds, char *str);
00318 extern SDS *sds_construct (int rank, int *length, int datatype, void *fillval);
00319 extern int sds_copy_attrs (SDS *sdsout, SDS *sdsin);
00320 extern int sds_copy_attr (SDS *sdsout, SDS *sdsin, char *key);
00321 extern SDS *sds_dup_header (SDS *sds);
00322 extern int sds_fill_data (SDS *sdsptr, void *fillvalue);
00323 extern SDS *sds_make_sds (int rank, int *length, int datatype, void *data);
00324 extern SDS *sds_replicate (SDS *sds);
00325 extern SDS *sds_steal_data (SDS *sds);
00326
00327 extern SDS *sds_short_template (SDS *sds);
00328
00329 extern char *sds_datatypename (int datatype);
00330 extern char *xsds (SDS *sds);
00331 extern void DEBUGsds(SDS *sds, char *msg);
00332
00333 extern int sds_data_convert (SDS *sds, int datatype);
00334 extern int sds_scale_data (SDS *sds, double scale, double bias);
00335 extern int sds_set_scaling (SDS *sds, int bits, double scale, double bias);
00336
00337 extern int sds_convert (SDS *sds_in, int type_out);
00338
00339 extern SDS *sds_slice (SDS *sds, int *start, int *end);
00340 SDS *sds_slice_file (FILE *fp, int *start, int *end);
00341
00342
00343 extern int sds_datatype (SDS *sds);
00344 extern int sds_numbytes (SDS *sds);
00345 extern FILE *sds_stream (SDS *sds);
00346 extern void *sds_data (SDS *sds);
00347 extern void *sds_fillvalue (SDS *sds);
00348 extern int sds_rank (SDS *sds);
00349 extern int sds_dim_n (SDS *sds, int n);
00350 extern int sds_dim0 (SDS *sds);
00351 extern int sds_dim1 (SDS *sds);
00352 extern int sds_dim2 (SDS *sds);
00353 extern long sds_data_length (SDS *sds);
00354 extern SDS_STATS *sds_stats_ptr (SDS *sds);
00355 extern int sds_sizeof (int datatype);
00356 extern int *sds_length (SDS *sds);
00357 extern char *sds_filename (SDS *sds);
00358 extern char *sds_varname (SDS *sds);
00359 extern int sds_data_quality (SDS *sds);
00360 extern double sds_bscale (SDS *sds);
00361 extern double sds_bzero (SDS *sds);
00362
00363 extern AXIS *sds_axisinfo(SDS *sdsptr);
00364 extern AXIS *sds_nth_axis(SDS *sdsptr, int axis_number);
00365 extern void free_axis(AXIS *axisinfo);
00366
00367 extern int sds_calculate_stats (SDS *sdsptr, int *nmissing, int *npresent,
00368 double *minimum, double *maximum, double *mean,
00369 double *stdv, double *skew, double *kurt);
00370
00371 extern int sds_copy_stats(SDS *sdsin, SDS *sdsout);
00372 extern void sds_stats_info(SDS *sdsptr, int (*message)(const char *, ...));
00373
00374
00375 extern int sds_set_attrvalue (ATTRIBUTES *attr, void *value, int datatype);
00376 extern int sds_set_attrname (ATTRIBUTES *attr, char *attrname);
00377 extern int sds_set_comment (ATTRIBUTES *attr, char *comment);
00378 extern int sds_set_attribute (SDS *sds, char *name, void *value, int attrtype, char *comment);
00379 extern int sds_remove_attribute (SDS *sds, char *name);
00380 extern void sds_set_stdhead (SDS *sds, char *prog_name);
00381
00382 extern int sds_set_data (SDS *sds, void *data);
00383 extern int sds_set_datatype (SDS *sds, int datatype);
00384 extern int sds_set_dim (SDS *sdsptr, int dim, int dimvalue);
00385 extern int sds_set_filename (SDS *sdsptr, char *filename);
00386 extern int sds_set_fillval (SDS *sds, void *fillval);
00387 extern int sds_set_fillvalue (SDS *sds, void *fillvalue);
00388 extern int sds_set_length (SDS *sds, int *length);
00389 extern int sds_set_numbytes (SDS *sds, int numbytes);
00390 extern int sds_set_rank (SDS *sds, int rank);
00391 extern int sds_set_startind (SDS *sds, int *startind);
00392 extern int sds_set_stream (SDS *sdsptr, FILE *fp);
00393 extern int sds_set_varname (SDS *sdsptr, char *varname);
00394
00395 extern int sds_set_axis(SDS *sdsptr, int *axis_datatype,
00396 void *start, void *stepsize,
00397 char **units, char **format, char **title);
00398
00399 extern ATTRIBUTES *sds_attributes(SDS *sds);
00400
00401
00402
00403 extern ATTRIBUTES *sds_first_attr(SDS *sds);
00404 extern ATTRIBUTES *sds_last_attr(SDS *sds);
00405 extern ATTRIBUTES *sds_next_attr(ATTRIBUTES *attr);
00406 extern ATTRIBUTES *sds_search_attr(SDS *sds, char *key);
00407
00408 extern void *sds_search_attrvalue(SDS *sds, char *key);
00409 extern char *sds_search_attrvalue_str(SDS *sds, char *key);
00410 extern double sds_search_attrvalue_double(SDS *sds, char *key);
00411
00412
00413 extern char *sds_attrname(ATTRIBUTES *attrptr);
00414 extern char *sds_attrcomment(ATTRIBUTES *attrptr);
00415 extern void *sds_attrvalue(ATTRIBUTES *attrptr);
00416 extern char *sds_attrvalue_str(ATTRIBUTES *attrptr);
00417 extern int sds_attribute_type(SDS *sdsptr, char *key);
00418 extern int sds_attrtype(ATTRIBUTES *attrptr);
00419
00420
00421 extern char *sds_getkey_str(SDS *sds, char *key);
00422 extern char *SDS_getkey_str(SDS *sds, char *key);
00423 extern int sds_getkey_int(SDS *sds, char *key);
00424 extern double sds_getkey_double(SDS *sds, char *key);
00425 extern TIME sds_getkey_time(SDS *sds, char *key);
00426 extern TIME sds_getkey_time_interval(SDS *sds, char *key);
00427 extern SDS_STATS *SDS_getkey_stats(SDS *sds);
00428
00429 extern int sds_setkey_str(SDS *sds, char *key, char *str);
00430 extern int sds_setkey_int(SDS *sds, char *key, int val);
00431 extern int sds_setkey_double(SDS *sds, char *key, double val);
00432 extern int sds_setkey_time(SDS *sds, char *key, TIME time);
00433 extern int sds_setkey_time_interval(SDS *sds, char *key, TIME time);
00434 extern int sds_setkey_stats(SDS *sds, SDS_STATS *stats);
00435
00436
00437
00438 extern SDS *sds_in (char *infile, int type, int filetype);
00439 extern SDS *sds_read (FILE *infp, int type, int filetype);
00440
00441 extern int sds_out (SDS *sdsptr, char *outfile, int filetype);
00442 extern int sds_write (SDS *sds, FILE *outfp, int filetype);
00443
00444 extern SDS *sds_read_sds(FILE *in);
00445 extern int sds_write_sds(SDS *in, FILE *out);
00446
00447 extern SDS *sds_read_raw(FILE *in, int datatype);
00448 extern int sds_write_raw(SDS *in, FILE *out);
00449
00450
00451 extern SDS *sds_get_fits (char *filename);
00452 extern SDS *sds_read_fits (FILE *in);
00453 extern SDS *sds_get_fits_head (char *filename);
00454 extern SDS *sds_read_fits_head (FILE *in);
00455 extern int sds_read_fits_data (SDS *sds);
00456 extern int sds_put_fits (SDS *sds, char *filename);
00457 extern int sds_write_fits (SDS *sds, FILE *out);
00458 extern int sds_write_fits_head (SDS *sds, FILE *out);
00459
00460
00461 extern int sds_write_gif (SDS *sds, char *filename, int interlace,
00462 double scale, double offset, int transparent, int delay);
00463
00464
00465
00466
00467
00468
00469
00470
00471 extern int sds_flip_data(SDS *sdsptr);
00472 extern int sds_flip(void *data, long length, int num_bytes);
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 extern int sds_stats_valid (SDS *sdsptr);
00483 extern char *sds_min (SDS *sdsptr);
00484 extern char *sds_max (SDS *sdsptr);
00485 extern char *sds_min_abs (SDS *sdsptr);
00486 extern char *sds_mean (SDS *sdsptr);
00487 extern char *sds_skewness (SDS *sdsptr);
00488 extern char *sds_stdev (SDS *sdsptr);
00489 extern char *sds_kurtosis (SDS *sdsptr);
00490 extern char *sds_numvals (SDS *sdsptr);
00491 extern void sds_update_stats (SDS *sdsptr, SDS_STATS *statptr);
00492
00493
00494 extern IDS *ids_init( void );
00495 extern void ids_free(IDS **idsptrptr);
00496 extern SDS *ids_nth_sds(IDS *ids, int n);
00497
00498 extern int ids_get_FITS_series_headers(IDS *ids,char *filename[],int numFiles);
00499
00500 extern IDS *ids_slice_FITS_series_file(IDS *ids, int *start, int *end);
00501 extern SDS *ids_merge_series(IDS *ids, int start, int end);
00502
00503 extern int ids_1st_non_missing_rec(IDS *idsptr);
00504 extern int ids_length(IDS *ids);
00505 extern int ids_rank(IDS *idsptr);
00506 extern int *ids_axis_lengths(IDS *idsptr);
00507 extern int ids_dimn(IDS *idsptr, int axis_number);
00508
00509 extern int ids_add_sds(IDS *ids, SDS *sds);
00510 extern int ids_insert_sds(IDS *ids, SDS *sds, int n);
00511 extern int ids_delete_sds(IDS *ids, int n);
00512
00513
00514
00515
00516
00517 extern clist *CL_InitList(int elemSize, int chunkSize);
00518 extern void *CL_DataAt(clist *list, int pos);
00519 extern int CL_Length(clist *list);
00520 extern void CL_FreeList(clist *list);
00521 extern int CL_InsertAt(clist *list, void *obj, int pos);
00522 extern int CL_DeleteAt(clist *list, int pos);
00523
00524
00525 extern void sds_AddList(_llist **l, _llist *new);
00526 extern void sds_FreeList(_llist **l);
00527 extern int sds_ListSize(_llist **l);
00528 extern _llist *sds_NextElement(_llist **l);
00529 extern _llist *sds_LastElement(_llist **l);
00530 extern _llist *sds_FirstElement(_llist **l);
00531 extern _llist *sds_GetNthElement(_llist **l, int n);
00532 extern _llist *sds_RemoveNthElement(_llist **l, int n);
00533 extern _llist *sds_DeList(_llist **l);
00534 extern _llist *sds_InsertNthElement(_llist **l, _llist *new, int n);
00535 extern _llist *sds_MapList(_llist **l, _llistFn fn, void *obj);
00536 extern char *ConvertToUpper(char *line);
00537 extern char *ConvertToLower(char *line);
00538 extern char *FirstNonWhite(char *line);
00539 extern char *LastNonWhite(char *line);
00540 extern int numType(char *num);
00541 extern int sds_type(char *str);
00542 extern void g_max_min(void *base, long n, int nbytes,
00543 int (*cmp)(void *, void *),
00544 void *maxptr, void *minptr);
00545 #endif
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588