function callspec
%overarching function to calculated spectral indices.  outputs return as
%ascii file at end and continuously throughout program as mat-file.

list=input('Enter list number: ','s');
race=input('Enter desired race (1=white,2=black,3=asian,4=hisp) or enter 5 to compute index for all races: ');
distance=input('Enter neighbor distance (in km): ');

listname='listnum.txt';
listname=strrep(listname,'num',list);

msalist=textread(listname,'%s')

%calls function blockspectral and saves msa #, race, si, # connected groups
%in sipartial continuously and spectralindex.dat finally
for i=1:length(msalist)
    msanum=cell2mat(msalist(i));
    msanum=strrep(msanum,'"','');
    if race==5
        count=4*i-3;
        index=count:(count+3);
    else
        count=i;
        index=i;
    end
    si(index,1)=str2num(sprintf(msanum));
    [si(index,2:12),si_length, little_si(1:si_length,2:5)]=blockspectral(msanum,race,distance);   
    little_si(1:si_length,1)=str2num(sprintf(msanum));   
    
    %write each msas' little si's to separate files identified by their
    %msa number
    si_filename='si_num.txt';
    si_filename=strrep(si_filename,'num',msanum);
    save(si_filename,'little_si','-ascii', '-double');
    clear little_si;
    
    disp(msanum);
    
    save sipartial.mat si -append
end

save spectralindex.dat si -ascii
