%save trace for 8703A
%clean up trace:

%%
%delete spaces
space=sprintf('%c', ' ');
null=sprintf('%s', '0.000000000000000E+00');
counter=1;
for j=1:(length(trace));
    if(trace(j)~=space)
        tracenew(counter)=trace(j);
        counter = counter+1;
    end
end
%delete nulls
badvals=strfind(tracenew, null);
tracenew2=tracenew(1:(badvals(1)-1));
for j=2:length(badvals)
    tracenew2=strcat(tracenew2, tracenew((badvals(j-1)+length(null)):(badvals(j)-1)));
    
end
%replace commas with spaces
for j=1:length(tracenew2)
    if(tracenew2(j)==',');
        tracenew2(j)=sprintf('%s', ' ');
    end
end
%replace spaces with new lines
for j=1:(length(tracenew2)-1)
    if(isspace(tracenew2(j)))
        if(tracenew2(j:(j+1))~='\n')
            tracenew2(j:(j+1))=sprintf('%s', '\n');
        end
    end
end
%replace new lines with spaces
for j=1:(length(tracenew2)-1)
        if(tracenew2(j:(j+1))=='\n')
            tracenew2(j:(j+1))=sprintf('%s', '  ');
        end
end
tracedata=str2num(tracenew2);
figure(1)
plot(freq, tracedata);
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
%%
csvwrite('.\BW_3_28_2011\m4V_Zinlogmag_50mA.csv', [freq' [tracedata]']);

%%

H2 = fopen('.\BW_3_11_2011\test.csv', 'a+');
fseek(H2, 0, 1);
fprintf(H2, '%s\t', trace);
fclose(H2);