00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef DATASETINCLUDED
00018 #define DATASETINCLUDED
00019
00020 #include <local.h>
00021 #include <stdtime.h>
00022 #include <stdio.h>
00023 #include <constant.h>
00024 #include <strings.h>
00025 #include <math.h>
00026 #include <param.h>
00027 #include <keywords.h>
00028 #include <nametables.h>
00029
00030 #include <sys/types.h>
00031 #include <unistd.h>
00032 #include <errno.h>
00033
00034 #ifndef __linux__
00035 extern int errno;
00036 #endif
00037
00038 #define ds_is(such,ds) (ds->ds_access&such)
00039 #define ds_return(r) \
00040 {\
00041 ds->ds_blocktrap=FALSE;\
00042 if(ds->ds_pendingtrap)\
00043 ds_die();\
00044 return(r);\
00045 }
00046
00047 #define TRUE 1
00048 #define FALSE 0
00049 #define MAXT 16
00050 #define MAXPATH 256
00051
00052
00053 #define ds_USED '\01'
00054 #define ds_EMPTY '\0'
00055
00056 #define ds_allmissing(ds) ( \
00057 ds->ds_now >= ds->ds_last || \
00058 ds->ds_now < ds->ds_first || \
00059 (ds->ds_gaps && *ds->ds_rbuf == ds_EMPTY) )
00060
00061
00062 #define AFTEROPEN 1
00063 #define IO_PENDING 2
00064 #define IO_OK 3
00065 #define SEEKERROR 4
00066 #define AFTERCLOSE 5
00067 #define CLOSED 6
00068
00069 #define RD 001
00070 #define WRT 002
00071 #define RAND 004
00072 #define APND 010
00073 #define PIPE 020
00074 #define BLK 040
00075 #define FOURK 0100
00076
00077 #define ds_LIST 1
00078 #define ds_TIME 2
00079 #define ds_CARR 3
00080 #define ds_FREQ 4
00081
00082
00083 #define ds_DIE 1
00084
00085
00086 #define ds_KEYBEGIN "### KEYWORD BEGIN ###\n"
00087 #define ds_KEYEND "### KEYWORD END ###\n"
00088
00089
00090 #define d_CHAR 7
00091 #define d_BYTE 6
00092 #define d_SHORT 1
00093 #define d_LONG 2
00094 #define d_FLOAT 3
00095 #define d_DOUBLE 4
00096 #define d_TIME 5
00097
00098 extern short d_tsize[8];
00099
00100
00101 #define ds_f_VAX 0
00102 #define ds_f_IEEE 16
00103
00104
00105 #define ds_VAX ( ds_f_VAX )
00106 #define ds_DECMIPS ( ds_f_IEEE )
00107 #define ds_SGIMIPS ( ds_f_IEEE )
00108 #define ds_NOMACHINE (0177777)
00109
00110
00111
00112
00113
00114
00115
00116 #ifdef vax
00117 #define ds_MACHINE ds_VAX
00118
00119 #define ds_INDS_ID(id)
00120 #define ds_INDOUBLE(d) { if (ds->ds_id & ds_f_IEEE) IEEE_to_VAX_d(d); }
00121 #define ds_INFLOAT(d) { if (ds->ds_id & ds_f_IEEE) IEEE_to_VAX_f(d); }
00122 #define ds_INLONG(i)
00123 #define ds_INSHORT(i)
00124 #define ds_OUTDOUBLE(d) { if (ds->ds_id & ds_f_IEEE) VAX_to_IEEE_d(d); }
00125 #define ds_OUTFLOAT(d) { if (ds->ds_id & ds_f_IEEE) VAX_to_IEEE_f(d); }
00126 #define ds_OUTLONG(i)
00127 #define ds_OUTSHORT(i)
00128 #endif
00129
00130
00131 #ifdef __linux
00132 #define MIPSEL
00133 #endif
00134
00135 #ifdef MIPSEL
00136 #define ds_MACHINE ds_DECMIPS
00137 #define ds_INDS_ID(id)
00138 #define ds_INDOUBLE(d) { if (!(ds->ds_id & ds_f_IEEE)) VAX_to_IEEE_d(d); }
00139 #define ds_INFLOAT(d) { if (!(ds->ds_id & ds_f_IEEE)) VAX_to_IEEE_f(d); }
00140 #define ds_INLONG(i)
00141 #define ds_INSHORT(i)
00142 #define ds_OUTDOUBLE(d) { if (!(ds->ds_id & ds_f_IEEE)) IEEE_to_VAX_d(d); }
00143 #define ds_OUTFLOAT(d) { if (!(ds->ds_id & ds_f_IEEE)) IEEE_to_VAX_f(d); }
00144 #define ds_OUTLONG(i)
00145 #define ds_OUTSHORT(i)
00146 #endif
00147
00148
00149 #ifdef __sun
00150 #define MIPSEB
00151 #endif
00152
00153 #ifdef MIPSEB
00154 #define ds_MACHINE ds_SGIMIPS
00155 #define ds_INDS_ID(id) { gen_swap(id,1,2); }
00156 #define ds_INDOUBLE(d) { \
00157 if (ds->ds_id & ds_f_IEEE) \
00158 gen_swap(d,1,sizeof(double)); \
00159 else \
00160 { \
00161 VAX_to_IEEE_d(d); \
00162 } \
00163 }
00164 #define ds_INFLOAT(d) { \
00165 if (ds->ds_id & ds_f_IEEE) \
00166 gen_swap(d,1,sizeof(float)); \
00167 else \
00168 { \
00169 VAX_to_IEEE_f(d); \
00170 } \
00171 }
00172 #define ds_INLONG(i) { gen_swap(i,1,sizeof(long)); }
00173 #define ds_INSHORT(i) { gen_swap(i,1,sizeof(short)); }
00174 #define ds_OUTDOUBLE(d) { \
00175 if (ds->ds_id & ds_f_IEEE) \
00176 gen_swap(d,1,sizeof(double)); \
00177 else \
00178 { \
00179 IEEE_to_VAX_d(d); \
00180 } \
00181 }
00182 #define ds_OUTFLOAT(d) { \
00183 if (ds->ds_id & ds_f_IEEE) \
00184 gen_swap(d,1,sizeof(float)); \
00185 else \
00186 { \
00187 IEEE_to_VAX_f(d); \
00188 } \
00189 }
00190 #define ds_OUTLONG(i) { gen_swap(i,1,sizeof(long)); }
00191 #define ds_OUTSHORT(i) { gen_swap(i,1,sizeof(short)); }
00192 #endif
00193
00194 #ifndef ds_MACHINE
00195 #define ds_MACHINE ds_NOMACHINE
00196 #define ds_INDOUBLE(d)
00197 #define ds_INFLOAT(d)
00198 #define ds_INLONG(i)
00199 #define ds_INSHORT(i)
00200 #define ds_OUTDOUBLE(d)
00201 #define ds_OUTFLOAT(d)
00202 #define ds_OUTLONG(i)
00203 #define ds_OUTSHORT(i)
00204 #endif
00205
00206 typedef struct
00207 {
00208 short d_type;
00209 short d_xwidth;
00210 short d_ywidth;
00211 short d_off_old;
00212 char d_layout[MAXT];
00213 char d_name[MAXT];
00214 char d_unit[MAXT];
00215 short d_chars;
00216 short d_valid;
00217 double d_scale;
00218 double d_base;
00219 long d_n;
00220 double d_min;
00221 double d_max;
00222 double d_mean;
00223 double d_stddev;
00224 double d_miss;
00225 long d_off;
00226 long d_l1;
00227 double d_d2;
00228 } DS_DESC;
00229 #define ds_desc DS_DESC
00230
00231 #define ds_HEADSIZE 84
00232
00233 typedef struct
00234 {
00235 char ds_name[MAXT];
00236 short ds_numitem;
00237 short ds_gaps;
00238 char ds_tname[MAXT];
00239 TIME ds_first;
00240 TIME ds_last;
00241 TIME ds_inc;
00242 short ds_kind;
00243 short ds_id;
00244 long ds_txtsz;
00245 double ds_d1;
00246 double ds_d2;
00247
00248 ds_desc **ds_item;
00249 TIME ds_now;
00250 long ds_ngrps;
00251 FILE *ds_fp;
00252 long ds_fd;
00253 short ds_access;
00254 char *ds_fullpath;
00255 short ds_state;
00256 TIME ds_clk;
00257 long ds_offset;
00258 long ds_begin;
00259 long ds_end;
00260 long ds_sizeof;
00261 char *ds_rbuf;
00262 char *ds_group;
00263 char *ds_mgrp;
00264 short ds_erract;
00265 FILE *ds_txtfp;
00266 char ds_txtnm[20];
00267 KEYWORDS *ds_keywords;
00268 FILE *ds_tmpfp;
00269 char ds_tmpnm[20];
00270 char ds_firststr[80];
00271 char ds_laststr[80];
00272 long ds_thisds;
00273 long ds_blocktrap;
00274 long ds_pendingtrap;
00275 } DATASET;
00276
00277 #define dataset DATASET
00278
00279 typedef struct
00280 {
00281 long item;
00282 long takeall;
00283 long xind;
00284 long yind;
00285 } SELECTLIST;
00286
00287 #define dsdefine ds_def
00288 double dget(DATASET *ds, int sel, int ix, int iy);
00289 int dget_i(DATASET *ds, int sel, int ix, int iy);
00290 double dsgetind();
00291 TIME dstimeparam(DATASET *ds, char *parm, TIME dflt);
00292 TIME dsincparam(DATASET *ds, char *parm, TIME dflt);
00293 double *dgetitem(DATASET *ds, int sel, double *buf);
00294 double *dgetitem_d(DATASET *ds, int sel, double *buf);
00295 float *dgetitem_f(DATASET *ds, int sel, float *buf);
00296 long *dgetitem_l(DATASET *ds, int sel, long *buf);
00297 short *dgetitem_s(DATASET *ds, int sel, short *buf);
00298 char *dgetitem_c(DATASET *ds, int sel, char *buf);
00299
00300 int ds_ismissing(DATASET *ds);
00301 DATASET *ds_def(int numitems);
00302 char *dslayout(DS_DESC *ditem);
00303 char *ditemalloc();
00304 DATASET *dsmake(FILE *fp);
00305 DS_DESC *d_deflt();
00306 DATASET *dsdup();
00307 DATASET *scanopen();
00308 SELECTLIST *dsselectlist(DATASET *dsout, DATASET *dsin);
00309 SELECTLIST *dsselparam();
00310 unsigned int ds_minalloc(DATASET *ds);
00311 void *malloc();
00312 TIME dstimeok(DATASET *ds, TIME want);
00313 int dsOKstats(DATASET *ds, char *dsname, int sel);
00314 int ds_lookup(char *n, nametable *t);
00315 char *ds_pukool(int a, nametable *t);
00316 void dsset (DATASET *ds, char *sds);
00317 TIME atodsindex(int kind, char *stringtime);
00318 int dput(DATASET *ds, int sel, int ix, int iy, double data);
00319 int dput_i(DATASET *ds, int sel, int ix, int iy, int data_i);
00320 void dputitem(DATASET *ds, int sel, double *data);
00321 void dputitem_d(DATASET *ds, int sel, double *data);
00322 void dputitem_f(DATASET *ds, int sel, float *data);
00323 void dputitem_l(DATASET *ds, int sel, long *data);
00324 void dputitem_s(DATASET *ds, int sel, short *data);
00325 void dputitem_c(DATASET *ds, int sel, char *data);
00326 void ds_cleanlbl(DATASET *ds);
00327 void ds_cpgrp(DATASET *dsin, DATASET *dsout);
00328 void ds_cpmgrp(DATASET *dsin, DATASET *dsout);
00329 DATASET *dsdup(DATASET *ds);
00330 void ds_err(DATASET *ds);
00331 void ds_fillin(DATASET *ds, char *key, char *tok);
00332 int ds_geth(DATASET *ds);
00333 void ds_gtxt(DATASET *ds);
00334 int ds_scantxt(DATASET *ds, FILE *fp);
00335 void ds_help(DATASET *ds, char *str);
00336 int ds_init(DATASET *ds);
00337 void ds_ptxt(DATASET *ds);
00338 void ds_putkeys(DATASET *ds);
00339 void ds_fprintkeys(DATASET *ds, FILE *fp);
00340 int ds_sizetext(DATASET *ds);
00341 int ds_puth(DATASET *ds);
00342 DS_DESC *dsadditem(DATASET *ds, DS_DESC *desc);
00343 DATASET *dsgetalld(char *fn, double **dp, int *np);
00344 DATASET *dsgetall(char *fn, float **dp, int *np);
00345 int dsgrp(DATASET *ds);
00346 void ds_flush(DATASET *ds);
00347 void ds_clean(DATASET *ds);
00348 void dsclose(DATASET *ds);
00349 char *ds_info(DATASET *ds, char *key);
00350 char *ds_info_value(DATASET *ds, char *key);
00351 char *ds_info_comment(DATASET *ds, char *key);
00352 void ds_info_new(DATASET *ds, char *key, char *value);
00353 void ds_info_newval(DATASET *ds, char *key, char *val, char *comment);
00354 void dscopy(DATASET *ds, char *key, DATASET *oldds);
00355 int wdparam(DATASET *ds, double *offset);
00356 void dsmk (char *filename,char *name,char *type,TIME start,TIME inc,float *darray,int n);
00357 void dsmkd (char *filename,char *name,char *type,TIME start,TIME inc,double *darray,int n);
00358 int dsnew(DATASET *ds, char *fname, char *mode);
00359 DATASET *dsopen(char *str, char *mode);
00360 int dsparam(DATASET *ds, char *par, int def);
00361 void dsplotmap(DATASET *ds,TIME tt,int sel, double *levels);
00362 void printtds(DATASET *ds, TIME B);
00363 void fprinttds(DATASET *ds, FILE *A, TIME B);
00364 void dsfprint(DATASET *ds,FILE *fp);
00365 void dfprint(DATASET *ds, FILE *fp,int sel);
00366 void dfprintq(DATASET *ds, FILE *fp, int sel);
00367 void dsplot1D(DATASET *ds, TIME start, TIME stop, int sel, double *levels);
00368 void dprint(DATASET *ds, int sel, int ix, int iy, FILE *fp);
00369 void ditemprint(DATASET *ds, int sel, FILE *fp);
00370 void dsprintgrp(DATASET *ds, FILE *fp);
00371 int dscan(DATASET *ds, int sel, int ix, int iy, FILE *fp);
00372 int ditemscan(DATASET *ds, int sel, FILE *fp);
00373 int dsscangrp(DATASET *ds, FILE *fp);
00374 int dssametime(DATASET *ds, TIME a, TIME b);
00375 int dsseek(DATASET *ds, TIME tm);
00376 SELECTLIST *dsselparam(char *sel, DATASET *dsin);
00377 void dstitle(DATASET *ds, char *progname, char *params);
00378 int nmtosel(DATASET *ds, char *nm);
00379
00380
00381 #endif