Changeset 26449 in project


Ignore:
Timestamp:
04/10/12 11:36:01 (9 years ago)
Author:
Ivan Raikov
Message:

mat5-lib: finally able to read compressed data

Location:
release/4/mat5-lib/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/mat5-lib/trunk/mat5-lib.scm

    r26440 r26449  
    5959                (only data-structures alist-ref string-intersperse)
    6060                (only extras fprintf sprintf)
    61                 (only posix create-pipe process-fork file-write file-close port->fileno)
     61                (only posix file-write open-output-file* file-mkstemp)
    6262                (only srfi-63
    6363                      A:floR64b A:floR32b A:floR16b
     
    114114      ((_ level x ...)
    115115       (if (>= (MAT5:debug-level) level)
    116            (print (string-append "MAT5[" (number->string level) "]: ") x ...)))
     116           (print (sprintf "MAT5[~A]: " level) x ...)))
    117117      ))
    118118
     
    11551155
    11561156    (MAT5:debug 2 "read-data-element-header: type-word = "
    1157                 (sprintf "0x~X" type-word))
     1157                (if (number? type-word) (sprintf "0x~X" type-word) type-word))
    11581158    (MAT5:debug 2 "read-data-element-header: small element = "
    11591159                (not (zero? (bitwise-and #xFFFF0000 type-word))))
     1160
    11601161    ;; Check for small data element format: when reading a MAT-file,
    11611162    ;; determine that we are processing a small data element by
     
    12141215         (zstr   (z3:decode-buffer (substring (blob->string zdata) 2))))
    12151216
    1216     (let-values (((outfd infd) (create-pipe)))
    1217      
    1218       (process-fork (lambda () (file-write infd zstr)))
    1219      
    1220       (file-close infd)
    1221       (let ((ezport (make-endian-port outfd "compressed data" MSB)))
    1222         (if (eq? (endian-port-byte-order eport) MSB)
    1223             (endian-port-set-bigendian! ezport)
    1224             (endian-port-set-littlendian! ezport))
    1225         (let ((elm (MAT5:read-data-element ezport)))
    1226           (close-endian-port ezport)
    1227           elm
    1228           ))
    1229       )))
     1217    (MAT5:debug 2 "read-compressed-data-element: data decoded" )
     1218
     1219    (let-values (((fd temp-path) (file-mkstemp "/tmp/mat5-lib.XXXXXX")))
     1220      (file-write fd zstr)
     1221
     1222      (MAT5:debug 2 "read-compressed-data-element: decoded data written to temp file" )
     1223
     1224      (let* ((temp-port (open-output-file* fd))
     1225             (ezport (port->endian-port temp-port)))
     1226
     1227          (if (eq? (endian-port-byte-order eport) MSB)
     1228              (endian-port-set-bigendian! ezport)
     1229              (endian-port-set-littlendian! ezport))
     1230          (endian-port-setpos ezport 0)
     1231          (let ((elms (MAT5:read-data-element ezport)))
     1232            (MAT5:debug 2 "read-compressed-data-element: elements read" )
     1233            (close-endian-port ezport)
     1234            (delete-file temp-path)
     1235            (cons size elms)
     1236            ))
     1237        ))
     1238    )
    12301239
    12311240; Procedure:
     
    16781687             (if (< i data-size)
    16791688                 (let ((word  (strict-read-data-element eport data-type data-size)))
    1680                    (loop (+ i (MAT5:data-element-bytes word)) (cons word lst)))
     1689                   (if (pair? word)
     1690                       (loop (+ i (car word)) (append (cdr word) lst))
     1691                       (loop (+ i (MAT5:data-element-bytes word)) (cons word lst))))
    16811692                 (if (= i data-size)
    16821693                     (reverse lst)
    16831694                     (MAT5:error eport "data element size mismatch: i = " i " data-size = " data-size))))))
    1684       (align-eport-pos eport)
    16851695      data)))
    16861696
     
    17041714    (if (> pos1 pos)
    17051715        (let* ((dx   (- pos1 pos))
    1706                (bv   (make-blob dx 0)))
     1716               (bv   (make-blob dx)))
    17071717          (endian-port-write-byte-vector eport bv)
    17081718          dx)  0)))
  • release/4/mat5-lib/trunk/mat5-lib.setup

    r26435 r26449  
    11; -*- Hen -*-
    22
    3 (compile -s -O2 -d1 mat5-lib.scm -j mat5-lib)
     3(compile -s -O -d2 mat5-lib.scm -j mat5-lib)
    44(compile -s mat5-lib.import.scm -O2 -d0)
    55
Note: See TracChangeset for help on using the changeset viewer.