%
%
%
%
%
%
%
fclose all;

fid=fopen(fi);

%first line provides all the names
line=fgetl(fid);
head1=textscan(line,'%s','delimiter',',');
head2=char(head1{:});

%naming stuff
idES=head2(:,1)=='E';
wvl=str2num(head2(idES,4:9))';

%naming stuff
idESnum=find(idES);
idESnumNOT=find(~idES);
ES=[];
for i=1:10^5
    line=fgetl(fid);
    if line==-1
        break
    end
    
    %read line
    dat=textscan(line,'%f','delimiter',',');
    dat2=cell2mat(dat)';
    
    %set ES values
    ES=[ES;dat2(:,idESnum);];
        
    for k=2:length(idESnumNOT)
        %naming stuff
        j=idESnumNOT(k);
        idp=strfind(head2(j,:),'(');
        
        %THIS MAY CAUSE AN ERROR
        if isempty(idp)
           idp=5; 
        end
        
        name=head2(j,1:idp-1);
        %this is to establish each variable
        if ~(exist(name)==1)
            eval([name '=[];'])
            
        end
        
        
        val=dat2(:,j);
        eval([name '= [' name ';val];'])
        
        
    end
    
    
    
end

fclose(fid);

clearvars dat* fi* id* i j k name line val head*
