File: varray_ex.sl

package info (click to toggle)
slang2 2.3.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,488 kB
  • sloc: ansic: 101,756; sh: 3,435; makefile: 1,046; pascal: 440
file content (35 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (7)
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
% This file shows how to use the varray-module to treat a file as an
% array of objects.
import ("varray");

% First of all, create an array of doubles
static variable x = [1:1000.0:1.0];

% and write it to disk
static variable file = "varray_example.dat";
static variable fp = fopen (file, "wb");
if (fp == NULL)
{
   () = fprintf (stderr, "failed to open %s\n", file);
   exit (1);
}
if ((-1 == fwrite (x, fp))
    or (-1 == fclose (fp)))
{
   () = fprintf (stderr, "Failed to write x\n");
   exit (1);
}

% Now associate an array with the file
variable y = mmap_array (file, 0, _typeof(x), length(x));

if (length (where (y != x)))
{
   fprintf (stderr, "mmap_array has failed\n");
   exit (1);
}

y = 0;				       %  remove the map

exit (0);