File: tsgLoadGridFromFile.m

package info (click to toggle)
tasmanian 8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,852 kB
  • sloc: cpp: 34,523; python: 7,039; f90: 5,080; makefile: 224; sh: 64; ansic: 8
file content (71 lines) | stat: -rw-r--r-- 1,870 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
function [lGrid] = tsgLoadGridFromFile(sGridName, sFilename)
%
% [lGrid] = tsgLoadGridFromFile(sGridName, sFilename)
%
% Creates an lGrid object referencing an arbitrary file.
% The temporary folder will still be used for data such as points,
% weights and model values, therefore a unique name is still needed.
%
% The method is intended to simplify interfaces with other languages,
% e.g., the grid can be constructed with C++ and stored in a file
% then post-processing can done with MATLAB.
%
% Note: this does not check if there are already other lGrid objects
% associated with the file, aliasing can cause issues here.
%
% INPUT:
%
% sGridName: unique identifier string used for temporary filenames
%
% sFilename: existing file holding a Tasmanian sparse grid
%
% OUTPUT:
%
% lGrid: list containing information about the sparse grid,
%        can be used to call other functions
%

if (exist(sFilename, 'file') ~= 2)
    error(['invalid filename, cannot find file: ',sFilename]);
end

[sFiles, sTasGrid] = tsgGetPaths();
lGrid.sName = sGridName;
lGrid.sFilename = sFilename;

sCommand = [sTasGrid,' -summary -gridfile ', sFilename];

[status, cmdout] = system(sCommand);

if (max(size(strfind(cmdout, 'ERROR'))) ~= 0)
    disp(cmdout);
    error('The tasgrid execurable returned an error, see above');
end

sLines = strsplit(cmdout, {'\n','\r'});

l1 = strsplit(sLines{2});

l2 = strsplit(sLines{3});

l3 = strsplit(sLines{4});

% create lGrid object
lGrid.sName = sGridName;

if (strcmp(l1{4}, 'Global'))
    lGrid.sType = 'global';
elseif (strcmp(l1{4}, 'Sequence'))
    lGrid.sType = 'sequence';
elseif (strcmp(l1{4}, 'Local'))
    lGrid.sType = 'localpolynomial';
elseif (strcmp(l1{4}, 'Wavelets'))
    lGrid.sType = 'wavelet';
elseif (strcmp(l1{4}, 'Fourier'))
    lGrid.sType = 'fourier';
end

lGrid.iDim = str2num(l2{3});
lGrid.iOut = str2num(l3{3});

end