# nex_info

## PURPOSE

nex_info(filename) -- read and display .nex file info

## SYNOPSIS

function [nvar, names, types] = nex_info(filename)

## DESCRIPTION

     nex_info(filename) -- read and display .nex file info

     [nvar, names, types] = nex_info(filename)

     INPUT:
       filename - if empty string, will use File Open dialog
     OUTPUT:
       nvar - number of variables in the file
       names - [nvar 64] array of variable names
       types - [1 nvar] array of variable types
               Interpretation of type values: 0-neuron, 1-event, 2-interval, 3-waveform,
                            4-population vector, 5-continuous variable, 6 - marker

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- test_nex

## SOURCE CODE

    0001 function [nvar, names, types] = nex_info(filename)
    0002 % nex_info(filename) -- read and display .nex file info
    0003 %
    0004 % [nvar, names, types] = nex_info(filename)
    0005 %
    0006 % INPUT:
    0007 %   filename - if empty string, will use File Open dialog
    0008 % OUTPUT:
    0009 %   nvar - number of variables in the file
    0010 %   names - [nvar 64] array of variable names
    0011 %   types - [1 nvar] array of variable types
    0012 %           Interpretation of type values: 0-neuron, 1-event, 2-interval, 3-waveform,
    0013 %                        4-population vector, 5-continuous variable, 6 - marker
    0014
    0015 if(nargin ~= 1)
    0016    disp('1 input arguments are required')
    0017    return
    0018 end
    0019
    0020 if(isempty(filename))
    0021    [fname, pathname] = uigetfile('*.nex', 'Select a Nex file');
    0022     filename = strcat(pathname, fname);
    0023 end
    0024
    0025 fid = fopen(filename, 'r');
    0026 if(fid == -1)
    0027     disp('cannot open file');
    0028    return
    0029 end
    0030
    0031 disp(strcat('file = ', filename));
    0032 magic = fread(fid, 1, 'int32');
    0033 version = fread(fid, 1, 'int32');
    0034 comment = fread(fid, 256, 'char');
    0035 freq = fread(fid, 1, 'double');
    0036 tbeg = fread(fid, 1, 'int32');
    0037 tend = fread(fid, 1, 'int32');
    0038 nvar = fread(fid, 1, 'int32');
    0039 fseek(fid, 260, 'cof');
    0040 disp(strcat('version = ', num2str(version)));
    0041 disp(strcat('frequency = ', num2str(freq)));
    0042 disp(strcat('duration (sec) = ', num2str((tend - tbeg)/freq)));
    0043 disp(strcat('number of variables = ', num2str(nvar)));
    0044 names = zeros(1, 64);
    0045 types=zeros(nvar);
    0046 for i=1:nvar
    0047     types(i) = fread(fid, 1, 'int32');
    0048     var_version = fread(fid, 1, 'int32');
    0049     names(i, :) = fread(fid, [1 64], 'char');
    0050     dummy = fread(fid, 128+8, 'char');
    0051 end
    0052 names = char(names);
    0053 fclose(fid);