function [data,names]=runwinspice(cirfile)
% [data,names]=runwinspice(cirfile)
%
% cirfile = SPICE circuit netlist
%           write as 'myfile.cir' (with the single quotes)
% data    = output of the simulation
%           only variables that were saved in the SPICE deck
% names   = names of the  variables that were saved
%           corresponds to the columns of the matrix "data"
%
% NOTES
% Using an AC analysis, there are twice as many columns in the data matrix
% as there are names.  Each variable that is saved uses two columns to
% represent the data -- one for the real part, and one for the imaginary
% part.  All odd-numbered columns are the real parts, and all even-numbered
% columns are the imaginary parts.  
%
% To speed up simulation time, do not display any waveforms.  
% 
% Be sure to save the desired voltages and currents in the SPICE deck.  Only 
% the voltages and currents that you save will be written to the variable 
% "data."  Save only the voltages and currents you need (to speed up 
% simulation time).  
%

copyfile(cirfile,'temp.cir');

fprintf('*****Running WinSPICE*****\n\n');
!wspice3 -b -r temp.csv temp.cir

fprintf('\n*****Reading Data*****\n');
fid=fopen('temp.csv');
dataline = fgetl(fid);
names = strread(dataline,'%s','delimiter',',');
data = csvread('temp.csv',1,0);
fclose(fid);

% [p,n,e,v]=fileparts(cirfile);

delete('temp.csv');
delete('temp.cir');
% if(savedata == 1)
%     fprintf('\n*****Saving %s*****\n',n);
%     save(n,'names','data');
% else
%     fprintf('*****DATA NOT SAVED*****\n');
% end

