/* * ReadData_demo.sli * * This file is part of NEST. * * Copyright (C) 2004 The NEST Initiative * * NEST is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * NEST is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NEST. If not, see <http://www.gnu.org/licenses/>. * */ % This program demonstrates reading a weight matrix into SLI % % Requires: ReadData_demo.dat % % Hans Ekkehard Plesser, 2004-09-02 /* Expected file format: N^2 doubles or integers */ % file name for input data /dataname (SLIHOME) getenv ; (/examples/ReadData_demo.dat) join def % open file for reading /datastream dataname ifstream not { (Could not open data file: ) dataname join M_ERROR message } if def % read data as one vector datastream [/Double] ReadList /Wmat Set datastream close % find length, root /L Wmat length def % elements in vector /N L sqrt cvi def % elements per row N N mul L neq { (Data cannot be converted to square matrix) M_ERROR message } if % reshape data, store as Wmat again Wmat N Partition /Wmat Set /* show row-wise: should be (as doubles) 11 12 13 21 22 23 31 32 33 */ Wmat { == } forall