[Scilab-users] Reg: Reading an s2p file
Giri
giri at leos.gov.in
Tue Aug 19 11:15:32 CEST 2014
On 2014-08-18 16:53, sravanaitha009 wrote:
> Hello,
>
> I have an s2p file with s parameters. Here my task is to write a script about reading the s2p file. So please could you guide me in writing a program about reading an s2p file.
>
> Thanks,
>
> Reagds,
> Sravan
>
> -------------------------
> View this message in context: Reg: Reading an s2p file [2]
> Sent from the Scilab users - Mailing Lists Archives mailing list archive [3] at Nabble.com.
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users [1]
Hello Sravan:
Please find below Scilab code to directly read and plot S2p files saved
from an Agilent PNA.
Do let me know if it works for you.
Sincerely,
Giri
// plotting 2 d VNA data and caclulated data.
// Plotting Insertion Loss, Isolation and Return Loss on different y
axes with common x axis.
// works only in scilab 5.1 and above
clear;
clf;
//Prompting user for input file name of first file
unix_w('dir *.s2p');
fname=input("What is the file name 1(OFF state?)","string");
fid=mopen(fname,'r');
// use niter=-1 to read up to the end of file
// Exracting the file name without extension .s2p
dot_pos=strindex(fname,'.');
fname_tit=part(fname,1:dot_pos-1);
header=mfscanf(1,fid,'%s');
while ~(header=="50")
header=mfscanf(1,fid,'%s');
end
indata1=mfscanf(-1,fid,'%f %f %f %f %f %f %f %f %f');
freq_meas=indata1(:,1);
freq_meas=freq_meas./1e9;
s11_1_real=indata1(:,2);
s11_1_imag=indata1(:,3);
s12_1_real=indata1(:,4);
s12_1_imag=indata1(:,5);
s21_1_real=indata1(:,6);
s21_1_imag=indata1(:,7);
s22_1_real=indata1(:,8);
s22_1_imag=indata1(:,9);
fname=input("What is the file name 2 (ON STATE)?","string");
fid=mopen(fname,'r');
// use niter=-1 to read up to the end of file
// Exracting the file name without extension .s2p
dot_pos=strindex(fname,'.');
fname_tit=part(fname,1:dot_pos-1);
header=mfscanf(1,fid,'%s');
while ~(header=="50")
header=mfscanf(1,fid,'%s');
end
indata2=mfscanf(-1,fid,'%f %f %f %f %f %f %f %f %f');
// indata=mfscanf(-1,fid,'%f %f');
freq_meas=indata2(:,1);
freq_meas=freq_meas./1e9;
s11_2_real=indata2(:,2);
s11_2_imag=indata2(:,3);
s12_2_real=indata2(:,4);
s12_2_imag=indata2(:,5);
s21_2_real=indata2(:,6);
s21_2_imag=indata2(:,7);
s22_2_real=indata2(:,8);
s22_2_imag=indata2(:,9);
//preparing data for output datafile
iso=s12_1_real;
il=s12_2_real;
rl=s11_2_real;
// Plotting IL, RL and ISO in the same plot
//*********** Added in Version 13 ************
scf(2);
plot2d(freq_meas,[rl iso],rect=[0.5,-40,11,0]);
xtitle("",["Frequency(GHz)"],["Return Loss/ Isolation (dB)"]);
xgrid();
a=gca();
poly1_1=a.children(1);
poly1=poly1_1.children(1);
poly1.thickness=2;
poly1.foreground=2;
//poly2=poly1_1.children(2);
//poly2.thickness=2;
//poly2.foreground=1;
xset("font size",4);
a=newaxes();
a.filled="off";
plot2d(freq_meas,il,axesflag=3,rect=[0.5,-1.0,11,0]);
a.axes_visible=["off","on","off"];
xtitle(fname_tit,[("")],["Insertion Loss (dB)"]);
xset("font size",4);
// xgrid();
// Setting polyline properties for plot
a=gca();
poly1_1=a.children(1);
poly1=poly1_1.children(1);
poly1.thickness=2;
poly1.foreground=5;
// Saving the figure in .scg format
// Attaching the .scg extension to file name
name_str=[fname_tit,".scg"];
fname_out=strcat(name_str);
save(fname_out,gcf());
// op_fname=[fname_tit,".dat"];
op_fname=[fname_tit,".dat"];
op_fname=strcat(op_fname);
fid_opfile=mopen(op_fname,'w');
for i=1:length(freq_meas)
mfprintf(fid_opfile,'%f %f %f %f n',freq_meas(i),iso(i),il(i),rl(i));
end
// mfprintf(fid_opfile,'%f',indata1);
mclose('all');
// plotting 2 d VNA data and caclulated data.
// Plotting Insertion Loss, Isolation and Return Loss on different y
axes with common x axis.
// works only in scilab 5.1 and above
clear;
clf;
//Prompting user for input file name of first file
unix_w('dir *.s2p');
fname=input("What is the file name 1(OFF state?)","string");
fid=mopen(fname,'r');
// use niter=-1 to read up to the end of file
// Exracting the file name without extension .s2p
dot_pos=strindex(fname,'.');
fname_tit=part(fname,1:dot_pos-1);
header=mfscanf(1,fid,'%s');
while ~(header=="50")
header=mfscanf(1,fid,'%s');
end
indata1=mfscanf(-1,fid,'%f %f %f %f %f %f %f %f %f');
freq_meas=indata1(:,1);
freq_meas=freq_meas./1e9;
s11_1_real=indata1(:,2);
s11_1_imag=indata1(:,3);
s12_1_real=indata1(:,4);
s12_1_imag=indata1(:,5);
s21_1_real=indata1(:,6);
s21_1_imag=indata1(:,7);
s22_1_real=indata1(:,8);
s22_1_imag=indata1(:,9);
fname=input("What is the file name 2 (ON STATE)?","string");
fid=mopen(fname,'r');
// use niter=-1 to read up to the end of file
// Exracting the file name without extension .s2p
dot_pos=strindex(fname,'.');
fname_tit=part(fname,1:dot_pos-1);
header=mfscanf(1,fid,'%s');
while ~(header=="50")
header=mfscanf(1,fid,'%s');
end
indata2=mfscanf(-1,fid,'%f %f %f %f %f %f %f %f %f');
// indata=mfscanf(-1,fid,'%f %f');
freq_meas=indata2(:,1);
freq_meas=freq_meas./1e9;
s11_2_real=indata2(:,2);
s11_2_imag=indata2(:,3);
s12_2_real=indata2(:,4);
s12_2_imag=indata2(:,5);
s21_2_real=indata2(:,6);
s21_2_imag=indata2(:,7);
s22_2_real=indata2(:,8);
s22_2_imag=indata2(:,9);
//preparing data for output datafile
iso=s12_1_real;
il=s12_2_real;
rl=s11_2_real;
// Plotting IL, RL and ISO in the same plot
//*********** Added in Version 13 ************
scf(2);
plot2d(freq_meas,[rl iso],rect=[0.5,-40,11,0]);
xtitle("",["Frequency(GHz)"],["Return Loss/ Isolation (dB)"]);
xgrid();
a=gca();
poly1_1=a.children(1);
poly1=poly1_1.children(1);
poly1.thickness=2;
poly1.foreground=2;
//poly2=poly1_1.children(2);
//poly2.thickness=2;
//poly2.foreground=1;
xset("font size",4);
a=newaxes();
a.filled="off";
plot2d(freq_meas,il,axesflag=3,rect=[0.5,-1.0,11,0]);
a.axes_visible=["off","on","off"];
xtitle(fname_tit,[("")],["Insertion Loss (dB)"]);
xset("font size",4);
// xgrid();
// Setting polyline properties for plot
a=gca();
poly1_1=a.children(1);
poly1=poly1_1.children(1);
poly1.thickness=2;
poly1.foreground=5;
// Saving the figure in .scg format
// Attaching the .scg extension to file name
name_str=[fname_tit,".scg"];
fname_out=strcat(name_str);
save(fname_out,gcf());
// op_fname=[fname_tit,".dat"];
op_fname=[fname_tit,".dat"];
op_fname=strcat(op_fname);
fid_opfile=mopen(op_fname,'w');
for i=1:length(freq_meas)
mfprintf(fid_opfile,'%f %f %f %f n',freq_meas(i),iso(i),il(i),rl(i));
end
// mfprintf(fid_opfile,'%f',indata1);
mclose('all');
Links:
------
[1] http://lists.scilab.org/mailman/listinfo/users
[2]
http://mailinglists.scilab.org/Reg-Reading-an-s2p-file-tp4031062.html
[3]
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140819/a2f64dc4/attachment.htm>
More information about the users
mailing list