function [s11,s21,s12,s22,begin_freq,end_freq,numpoints]=HP8510test(file);
% function [s11,begin_freq,end_freq,numpoints]=test(file);
% test file
% S Paramter Matrix extracter for the HP8510C Network Analyzer
% Copyright 1999 -- Robert Duane Hill
% This function maybe distributed freely for academic/educational use only.
%
% Usage
% s=HP8510C2S('file')
% s = S parameter matrix
% file = file from HP8510C network analyzer
%BEGIN
format long g;
fid=fopen(file,'r');
% Move file pointer to frequency vector
status=fseek(fid,177,'bof');
if(status==0)
freq=fscanf(fid,'%e');
end
begin_freq=freq(1); % beginning frequency
end_freq=freq(2); % end frequency
numpoints=freq(3); % number of points in frequency vector
% Initialize s11 parameter matrix
s11=zeros(numpoints,1);
% Read In S11
s11_offset=323; %byte offset into file where s11 parameter starts
%real and imaginary parts are 12 bytes apart
%this includes the comma or /n
status=fseek(fid,s11_offset,'bof'); %move pointer to s11_offset
line=fgetl(fid);
% Read S11 Parameters
for n=1:numpoints % should be numpoints
line=fgetl(fid);
y=str2strs(line);
ry=eval('y(1)');
ri=eval('y(2)');
real=str2num(ry{1});
imag=str2num(ri{1});
s11(n)=real+i*imag;
end
line=fgetl(fid); % read end of s11 parameters
line=fgetl(fid); % read begin of s21 parameters
% Read S21 Parameters
for n=1:numpoints
line=fgetl(fid);
y=str2strs(line);
ry=eval('y(1)');
ri=eval('y(2)');
real=str2num(ry{1});
imag=str2num(ri{1});
s21(n)=real+i*imag;
end
line=fgetl(fid); % read end of s21 parameters
line=fgetl(fid); % read begin of s12 parameters
% Read S12 Parameters
for n=1:numpoints
line=fgetl(fid);
y=str2strs(line);
ry=eval('y(1)');
ri=eval('y(2)');
real=str2num(ry{1});
imag=str2num(ri{1});
s12(n)=real+i*imag;
end
line=fgetl(fid); % read end of s12 parameters
line=fgetl(fid); % read begin of s22 parameters
% Read S22 Parameters
for n=1:numpoints
line=fgetl(fid);
y=str2strs(line);
ry=eval('y(1)');
ri=eval('y(2)');
real=str2num(ry{1});
imag=str2num(ri{1});
s22(n)=real+i*imag;
end
fclose(fid);