#!/usr/local/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 $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 open(O,">$outname$j.txt"); for ($i=1;$i<$vlen+1;$i++) { #read and print lines $ln = ; print O $ln; } close(O); } # } 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 join(' ',@vnames),"\n"; # for ($i=1;$i<$nlines+1;$i++) { #read and print lines $ln = ; print O $ln; } close(O); } # close I; # exit; #