#!/usr/bin/perl # n2m - take an nrn ascii file and make it sutable fo matlab. # If the infile name is 'foo.dat' then you get an output file # named 'foo.m' # Then you type 'foo' in matlab and get a series of vectors called # 'foo1' 'foo2'... open(I,"$ARGV[0]") || die "can't open input file"; # $ARGV[0] =~ /(.*)\..*/; # find the prefix of infile name $outname = $1; # output file prefix open(O,">$outname.m"); $head = ; # remove 'polyline' header which neuron writes if ($head =~ /.*PolyLines.*/ ){ $j = 0; while ($vlen = ) { #get the length of the new vector chop($vlen); #remove the \n $j = $j +1; #vector number print O "$outname$j = [\n"; #start a vector in matlab for ($i=1;$i<$vlen+1;$i++) { #read and print lines $ln = ; print O $ln; } print O "]\;\n"; #end of this vector } # } elsif ($head =~ /.*Graph addvar\/addexpr lines.*/ ) { ($vars,$nlines) = split(' ',); # @vnames = split(' ',); # @newname = grep(tr/\.\(\)/_/d,@vnames); print STDERR "For he following variables \. was changed to _ and \(\) were omitted\n",join(' ',@newname),"\n"; print O "datmat = [\n"; # for ($i=1;$i<$nlines+1;$i++) { #read and print lines $ln = ; print O $ln; } print O "]\;\n"; # for ($i = 0;$i<=$#vnames;$i++) { print O $vnames[$i]," = datmat(:,",$i+1,")\;\n"; } print O "clear datmat\n"; } elsif ( $head =~ /.*label.*/ ) { ($vars,$nlines) = split(' ',); # print O "datmat = [\n"; # for ($i=1;$i<$nlines+1;$i++) { #read and print lines $ln = ; print O $ln; } print O "]\;\n"; # } close I; # print O "\nsave $outname.mat\n"; # close O; # exit; #