|
a |
|
b/functions/@memmapdata/memmapdata.m |
|
|
1 |
% MEMMAPDATA - create a memory-mapped data class |
|
|
2 |
% |
|
|
3 |
% Usage: |
|
|
4 |
% >> data_class = memmapdata(data); |
|
|
5 |
% |
|
|
6 |
% Inputs: |
|
|
7 |
% data - input data or data file |
|
|
8 |
% |
|
|
9 |
% Outputs: |
|
|
10 |
% data_class - output dataset class |
|
|
11 |
% |
|
|
12 |
% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 |
|
|
13 |
|
|
|
14 |
% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD |
|
|
15 |
% |
|
|
16 |
% This file is part of EEGLAB, see http://www.eeglab.org |
|
|
17 |
% for the documentation and details. |
|
|
18 |
% |
|
|
19 |
% Redistribution and use in source and binary forms, with or without |
|
|
20 |
% modification, are permitted provided that the following conditions are met: |
|
|
21 |
% |
|
|
22 |
% 1. Redistributions of source code must retain the above copyright notice, |
|
|
23 |
% this list of conditions and the following disclaimer. |
|
|
24 |
% |
|
|
25 |
% 2. Redistributions in binary form must reproduce the above copyright notice, |
|
|
26 |
% this list of conditions and the following disclaimer in the documentation |
|
|
27 |
% and/or other materials provided with the distribution. |
|
|
28 |
% |
|
|
29 |
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
|
30 |
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
31 |
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
32 |
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
|
33 |
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
|
34 |
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
|
35 |
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
|
36 |
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
|
37 |
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
|
38 |
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|
|
39 |
% THE POSSIBILITY OF SUCH DAMAGE. |
|
|
40 |
|
|
|
41 |
function dataout = memmapdata(data, datadims); |
|
|
42 |
|
|
|
43 |
dataout.fileformat = 'normal'; |
|
|
44 |
if ischar(data) |
|
|
45 |
if length(data) > 3 |
|
|
46 |
if strcmpi('.dat', data(end-3:end)) |
|
|
47 |
dataout.fileformat = 'transposed'; |
|
|
48 |
end |
|
|
49 |
end |
|
|
50 |
|
|
|
51 |
% check that the file is not empty |
|
|
52 |
% -------------------------------- |
|
|
53 |
a = dir(data); |
|
|
54 |
if isempty(a) |
|
|
55 |
error([ 'Data file ''' data '''not found' ]); |
|
|
56 |
elseif a(1).bytes == 0 |
|
|
57 |
error([ 'Empty data file ''' data '''' ]); |
|
|
58 |
end |
|
|
59 |
|
|
|
60 |
if ~strcmpi(dataout.fileformat, 'transposed') |
|
|
61 |
dataout.data = memmapfile(data, 'writable', false, 'format', { 'single' datadims 'x' }); |
|
|
62 |
else |
|
|
63 |
dataout.data = memmapfile(data, 'writable', false, 'format', { 'single' [ datadims(2:end) datadims(1) ] 'x' }); |
|
|
64 |
end |
|
|
65 |
dataout = class(dataout,'memmapdata'); |
|
|
66 |
else |
|
|
67 |
dataout = data; |
|
|
68 |
end |
|
|
69 |
|