1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
|
/* (C) Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
*
* This file is part of MCL. You can redistribute and/or modify MCL under the
* terms of the GNU General Public License; either version 2 of the License or
* (at your option) any later version. You should have received a copy of the
* GPL along with MCL, in the file COPYING.
*/
#ifndef impala_io_h
#define impala_io_h
#include <math.h>
#include <stdio.h>
#include "ivp.h"
#include "vector.h"
#include "matrix.h"
#include "tab.h"
#include "util/io.h"
#include "util/types.h"
#include "util/ting.h"
#include "util/list.h" /* needed for mclpTFparse */
/* TODO:
* Make ascii format parsing looser (not line based).
* The ascii parsing code is not all that great, heavy-weight.
* mcl input format needs a clean approach with grammar and parsing.
* Then it would be (much?) faster if not fgetc based but does buffering.
*
* There should be a clearer framework for rewinding streams after gathering
* partial information (readDomains, readDimensions).
*
* There is now a funky callback mclxIOinfoReset, invoked by mclxIOclose.
* Look out for implications.
*
* mclvaDump and mclvaDump2 are weird.
*/
#define mclxCookie 0x0d141831u /* MTX1 */
#define mclvCookie 0x16050331u /* VEC1 */
#define MCL_APP_VB_NO 2
#define MCL_APP_VB_YES 8
#define MCL_APP_WB_NO 2
#define MCL_APP_WB_YES 8
/* 1,2 4,8
* MCLXIOFORMAT ascii binary
* MCLXIOVERBOSITY silent verbose
*/
mcxbool mclxIOgetQMode /* quad mode */
( const char* opt
) ;
mcxbool mclxIOsetQMode /* quad mode */
( const char* opt
, unsigned long mode
) ;
/* get format: 'a' or 'b' or '0' (unknown) */
int mclxIOformat
( mcxIO* xf
) ;
/* *********************
*/
mclMatrix* mclxRead
( mcxIO* xfIn
, mcxOnFail ON_FAIL
) ;
/* *********************
*
* requires equal domains.
*/
#define MCL_READX_GRAPH 1
mclMatrix* mclxReadx
( mcxIO* xfIn
, mcxOnFail ON_FAIL
, mcxbits bits
) ;
/* *********************
*
* colmask and rowmask are assimilated into matrix.
*/
mclMatrix* mclxSubRead
( mcxIO* xfIn
, mclVector* colmask /* create submatrix on this domain */
, mclVector* rowmask /* create submatrix on this domain */
, mcxOnFail ON_FAIL
) ;
/* *********************
*
* colmask and rowmask are assimilated into matrix.
*/
mclMatrix* mclxSubReadx
( mcxIO* xf
, mclVector* colmask /* create submatrix on this domain */
, mclVector* rowmask /* create submatrix on this domain */
, mcxOnFail ON_FAIL
, mcxbits bits /* refer to mclxReadx */
) ;
/* *********************
*
*
* Tries to read cookie, then branches of ascii or binary.
*/
mcxstatus mclxReadDomains
( mcxIO* xf
, mclv* dom_cols
, mclv* dom_rows
) ;
/* *********************
*/
mcxstatus mclxReadDimensions
( mcxIO* xfIn
, long *n_cols
, long *n_rows
) ;
#define MCLXIO_VALUE_NONE -1
#define MCLXIO_VALUE_INT 0
#define MCLXIO_VALUE_GETENV -2
#define MCLXIO_FORMAT_ASCII 1
#define MCLXIO_FORMAT_BINARY 2
#define MCLXIO_FORMAT_GETENV 3
mcxstatus mclxWrite
( const mclMatrix* mx
, mcxIO* xfout
, int valdigits /* only relevant for ascii writes */
, mcxOnFail ON_FAIL
) ;
mcxstatus mclxaWrite
( const mclMatrix* mx
, mcxIO* xfOut
, int valdigits
, mcxOnFail ON_FAIL
) ;
mcxstatus mclxbWrite
( const mclMatrix* mtx
, mcxIO* xfOut
, mcxOnFail ON_FAIL
) ;
enum
{ MCLXR_ENTRIES_ADD
, MCLXR_ENTRIES_MAX
, MCLXR_ENTRIES_MUL
, MCLXR_ENTRIES_POP
, MCLXR_ENTRIES_PUSH
, MCLXR_VECTORS_ADD
, MCLXR_VECTORS_MAX
, MCLXR_VECTORS_MUL
, MCLXR_VECTORS_POP
, MCLXR_VECTORS_PUSH
} ;
mclVector* mclvaReadRaw
( mcxIO *xf
, mclpAR* ar
, mcxOnFail ON_FAIL
, int fintok /* e.g. '\n' or EOF or '$' */
, mcxbits warn_repeat
, void (*ivpmerge)(void* ivp1, const void* ivp2)
) ;
mcxstatus mclxaSubReadRaw
( mcxIO *xf
, mclMatrix *mx
, mclv *dom_cols
, mclv *dom_rows
, mcxOnFail ON_FAIL
, int fintok /* e.g. EOF or ')' */
, mcxbits warn_repeat
, mclpAR* transform
, void (*ivpmerge)(void* ivp1, const void* ivp2)
, double (*fltbinary)(pval val1, pval val2)
) ;
void mcxPrettyPrint
( const mclMatrix* mx
, FILE* fp
, int width
, int digits
, const char msg[]
) ;
void mclFlowPrettyPrint
( const mclMatrix* mx
, FILE* fp
, int digits
, const char msg[]
) ;
mcxstatus mclxTaggedWrite
( const mclMatrix* mx
, const mclMatrix* dom
, mcxIO* xfOut
, int valdigits
, mcxOnFail ON_FAIL
) ;
void mclxBoolPrint
( mclMatrix* mx
, int mode
) ;
mcxstatus mclIOvcheck
( mclv* vec
, mclv* dom
) ;
mcxstatus mclvEmbedRead
( mclVector* vec
, mcxIO* xf
, mcxOnFail ON_FAIL
) ;
mcxstatus mclvWrite
( const mclVector* vec
, mcxIO* xfOut
, mcxOnFail ON_FAIL
) ;
mcxstatus mclvEmbedWrite
( const mclVector* vec
, mcxIO* xfOut
) ;
void mclvaWrite
( const mclVector* vec
, FILE* fp
, int valdigits
) ;
/*************************************
* *
**
*
*/
/* does *not* accept MCLXIO_VALUE_GETENV */
void mclvaDump
( const mclVector* vec
, FILE* fp
, int idxwidth
, int valdigits
, mcxbool doHeader
) ;
/* Does *not* accept MCLXIO_VALUE_GETENV.
* The default corresponds with a vector printed in a matrix:
* no header nor trail, eov values and vid indeed.
*/
#define MCLVA_DUMP_HEADER_YES 1
#define MCLVA_DUMP_VALUE_NO 2
#define MCLVA_DUMP_VID_NO 4
#define MCLVA_DUMP_EOV_NO 8
#define MCLVA_DUMP_TRAIL_YES 16
void mclvaDump2
( const mclVector* vec
, FILE* fp
, int n_per_line
, int valdigits
, const char* sep
, mcxbits opts
) ;
/*************************************
* *
**
*
*/
#define MCLX_DUMP_VALUES 1 << 0
#define MCLX_DUMP_PAIRS 1 << 1
#define MCLX_DUMP_LINES 1 << 2
#define MCLX_DUMP_RLINES 1 << 3
#define MCLX_DUMP_LOOP_ASIS 1 << 4
#define MCLX_DUMP_LOOP_NONE 1 << 5
#define MCLX_DUMP_LOOP_FORCE 1 << 6
typedef struct
{ mcxbits modes
; const char* sep_lead
; const char* sep_row
; const char* sep_val
; double threshold
;
} mclxIOdumper ;
/* Note. we could stabilize the interface by a string-based format
* + hiding the mclxIOdumper struct. oh well.
*/
void mclxIOdumpSet
( mclxIOdumper* dump
, mcxbits modes
, const char* sep_lead
, const char* sep_row
, const char* sep_val
) ;
mcxstatus mclxIOdump
( mclx* mx
, mcxIO* xf_dump
, mclxIOdumper* dump
, const mclTab* tabc
, const mclTab* tabr
, mcxOnFail ON_FAIL
) ;
/*************************************/
mclpAR *mclpaReadRaw
( mcxIO *xf
, mcxOnFail ON_FAIL
, int fintok /* e.g. EOF or '$' */
) ;
/* supply either encoding_link OR encoding_ting.
ting e.g.: log(3), ceil(5), gq(2)
link e.g.: mcxTokArgs of the above.
*/
mclpAR* mclpTFparse
( mcxLink* encoding_link
, mcxTing* encoding_ting
) ;
#endif
|