# Vector/matrix: reading data

## Exercises

1) Run the plotdata.hoc file in the vec directory. This reads the contents of data4.dat and displays all the lines in a Graph. Look at the hoc file and the format of the data file. Notice that the first number is the number of rows of data (Strings like #9 are not numbers. Numbers are strings that start with a 0-9, ., or +-. Modify the plotdata.hoc file so it uses a File chooser to read the file.

The following hints may help with this exercise. For information about File.chooser, in the NEURON console, type

    	help File

or else navigate there manually with the web browser.
Is a file open for the File referenced by f? Type `f.isopen()`
Define the chooser to be a read type: `f.chooser("r")`
Pop up the chooser: `f.chooser()` : and select data4.dat
Is a file open?

2) Save these data using the Print&FileWindowManager/PrintFile/Ascii menu item into the file temp1.dat . Look at the format of the temp1.dat file. Fix the temp1.dat file so it can be read with plotdata.hoc.

3) The data are in a Matrix. Prove this to yourself by typing `m` and then `m.printf`. Save the matrix by opening the file with `f.wopen("temp2.dat")` and then `m.fprint(f)`. Look at the contents of the file and verify that it can be read with plotdata.hoc.

4) Pick one of the data lines into the clipboard and save it using the NEURONMainMenu/Vector/SaveToFile menu item as temp2.dat . Verify that temp2.dat can be read correctly with the NEURONMainMenu/Vector/RetrieveFromFile. Fix the temp2.dat file so it can be read with plotdata.hoc.

## An observation

There are probably more data formats than there are programs that write data files. Data in ASCII can generally be read with a hoc program (see File.scanvar, File.gets, sscanf, Vector.x and Matrix.x). Some formats are very complicated and are in binary, e.g. PClamp binary data files. Cases like this can only be handled with model descriptions like clampex.mod. After the data are in a Matrix or Vector set, they are generally fairly easy to display with the GUI or manipulate with simple hoc programs.

NEURON hands-on course
Copyright © 1998, 1999 by N.T. Carnevale and M.L. Hines, all rights reserved.