File: gzfile.mw

package info (click to toggle)
mwrap 1.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,548 kB
  • sloc: cpp: 3,315; python: 1,850; ansic: 856; makefile: 258; lex: 233; sh: 145
file content (78 lines) | stat: -rw-r--r-- 1,435 bytes parent folder | download | duplicates (3)
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
% gzfile.mw
%   MWrap wrapper to the ZLib compression library.
%
% Copyright (c) 2007  David Bindel
% See the file COPYING for copying permissions

$#include <zlib.h>


// ----
@function [gzf] = gzopen(path, mode)
% [gzf] = gzopen(path, mode)
%
% Open a zlib output file.

# gzFile gzf = gzopen(cstring path, cstring mode);


// ----
@function gzclose(gzf)
% gzclose(gzf)
%
% Close a zlib output file.

# gzclose(gzFile gzf);


// ----
@function [A] = gzread(gzf)
% [A] = gzread(gzf)
% 
% Read a matrix from a zlib file.

# int isize = sizeof(int 0);
# int dsize = sizeof(double 0);
nbytes = 2*isize;
# gzread(gzFile gzf, output int[2] dims, int nbytes);
m = dims(1); n = dims(2); nbytes = m*n*dsize;
# gzread(gzFile gzf, output double[m,n] A, int nbytes);
% gzwrite(gzf, A)
%
% Write a matrix to a zlib file.


// ----
@function gzwrite(gzf, A)
% [A] = gzwrite(gzf, A)
% 
% Write a matrix from a zlib file.

# int isize = sizeof(int 0);
# int dsize = sizeof(double 0);
nbytes = 2*isize;
[m,n] = size(A);
dims = [m,n];
# gzwrite(gzFile gzf, int[2] dims, int nbytes);
m = dims(1); n = dims(2); nbytes = m*n*dsize;
# gzwrite(gzFile gzf, double[m,n] A, int nbytes);


// ----
@function gzsave(path, A)
% gzsave(path, A)
% 
% Save a matrix to a zlib file.

gzf = gzopen(path, 'w+');
gzwrite(gzf, A)


// ----
@function [A] = gzload(path)
% [A] = gzload(path)
% 
% Read a matrix from a zlib file.

gzf = gzopen(path, 'r');
A = gzread(gzf);