1% This file shows how to use the varray-module to treat a file as an 2% array of objects. 3import ("varray"); 4 5% First of all, create an array of doubles 6static variable x = [1:1000.0:1.0]; 7 8% and write it to disk 9static variable file = "/tmp/varray_example.dat"; 10static variable fp = fopen (file, "wb"); 11if (fp == NULL) 12{ 13 () = fprintf (stderr, "failed to open %s\n", file); 14 exit (1); 15} 16if ((-1 == fwrite (x, fp)) 17 or (-1 == fclose (fp))) 18{ 19 () = fprintf (stderr, "Failed to write x\n"); 20 exit (1); 21} 22 23% Now associate an array with the file 24variable y = mmap_array (file, 0, _typeof(x), length(x)); 25 26if (length (where (y != x))) 27{ 28 fprintf (stderr, "mmap_array has failed\n"); 29 exit (1); 30} 31 32y = 0; % remove the map 33 34exit (0); 35 36 37 38