Discussion:
[Scilab-users] GUI save and import data
petarf
2016-09-12 10:25:09 UTC
Permalink
Hello,

I have created GUI whre you put some data and then it does some calculation
as shown in the picture.
Does anyone know how to store this data into a .txt file. Also, I want to be
able to load data from .txt file?

Regards, Petar

<Loading Image...>



--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Paul Bignier
2016-09-12 10:31:26 UTC
Permalink
Hi Petar,

To write to txt, you may add a button with a callback that will call
mopen & mputl.

To read, you may combine uigetfile and mgetl functions.

Regards,

Paul
Post by petarf
Hello,
I have created GUI whre you put some data and then it does some calculation
as shown in the picture.
Does anyone know how to store this data into a .txt file. Also, I want to be
able to load data from .txt file?
Regards, Petar
<http://mailinglists.scilab.org/file/n4034558/data.jpg>
--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
Paul BIGNIER
Development engineer
-----------------------------------------------------------
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France
Phone: +33.1.80.77.04.68
http://www.scilab-enterprises.com
petarf
2016-09-12 10:44:56 UTC
Permalink
Hi Paul,

Thank you for your fast replay. Now I have this problem.


function saveFile

// Gather data
//par=[];
Q=findobj("tag","Q"); par(1)=evstr(Q.string);
dpTot=findobj("tag","dpTot"); par(2)=evstr(dpTot.string);
rho=findobj("tag","rho"); par(3)=evstr(rho.string);
n=findobj("tag","n"); par(4)=evstr(n.string);
eta=findobj("tag","eta"); par(5)=evstr(eta.string);
dh=findobj("tag","dh"); par(6)=evstr(dh.string);
ds=findobj("tag","ds"); par(7)=evstr(ds.string);
z=findobj("tag","z"); par(8)=evstr(z.string);
Lh=findobj("tag","Lh"); par(9)=evstr(Lh.string);
Ls=findobj("tag","Ls"); par(10)=evstr(Ls.string);
beta2h=findobj("tag","beta2h"); par(11)=evstr(beta2h.string);
m=findobj("tag","m"); par(12)=evstr(m.string);
k=findobj("tag","k"); par(13)=evstr(k.string);
sh=findobj("tag","sh"); par(14)=evstr(sh.string);
ss=findobj("tag","ss"); par(15)=evstr(ss.string);
rSl=findobj("tag","rSl"); par(16)=evstr(rSl.string);
rSt=findobj("tag","rSt"); par(17)=evstr(rSt.string);
zetaMax=findobj("tag","zetaMax"); par(18)=evstr(zetaMax.string);



//N=findobj("tag","N"); par(18)=evstr(N.string);

//e=findobj("tag","e"); par(20)=evstr(e.string);
alpha=findobj("tag","alpha"); par(19)=evstr(alpha.string);
rDeltaR=findobj("tag","rDeltaR"); par(20)=evstr(rDeltaR.string);
rVas=findobj("tag","rVas"); par(21)=evstr(rVas.string);
rVah=findobj("tag","rVah"); par(22)=evstr(rVah.string);
rDDVa=findobj("tag","rDDVa"); par(23)=evstr(rDDVa.string);
rDDuVu=findobj("tag","rDDuVu"); par(24)=evstr(rDDuVu.string);
scL=findobj("tag","scL"); par(25)=evstr(scL.string);




[FileName]=uiputfile("","","Choose a file name");
Name=fullfile(FileName);
fidI=mopen(Name,'w');
for i=1:size(par)

mfprintf(fidI,"%0.5f\n",par(i)):
end
mclose(fidI);
endfunction

This is the part where i store data. I get this:
mfprintf(fidI,"%0.5f\n",par(i)):
!--error 2
Invalid factor.
at line 45 of function saveFile called by :
endfunction

Any ideas?

Regards,
Petar




--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034560.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Rafael Guerra
2016-09-12 10:51:45 UTC
Permalink
Hi,

Not related with your error message but the code line:

for i=1:size(par)

does not sound good.
Try replacing by:

for i=1:length(par)

Regards,
Rafael

-----Original Message-----
From: users [mailto:users-***@lists.scilab.org] On Behalf Of petarf
Sent: Monday, September 12, 2016 12:45 PM
To: ***@lists.scilab.org
Subject: Re: [Scilab-users] GUI save and import data

Hi Paul,

Thank you for your fast replay. Now I have this problem.


function saveFile

// Gather data
//par=[];
Q=findobj("tag","Q"); par(1)=evstr(Q.string);
dpTot=findobj("tag","dpTot"); par(2)=evstr(dpTot.string);
rho=findobj("tag","rho"); par(3)=evstr(rho.string);
n=findobj("tag","n"); par(4)=evstr(n.string);
eta=findobj("tag","eta"); par(5)=evstr(eta.string);
dh=findobj("tag","dh"); par(6)=evstr(dh.string);
ds=findobj("tag","ds"); par(7)=evstr(ds.string);
z=findobj("tag","z"); par(8)=evstr(z.string);
Lh=findobj("tag","Lh"); par(9)=evstr(Lh.string);
Ls=findobj("tag","Ls"); par(10)=evstr(Ls.string);
beta2h=findobj("tag","beta2h"); par(11)=evstr(beta2h.string);
m=findobj("tag","m"); par(12)=evstr(m.string);
k=findobj("tag","k"); par(13)=evstr(k.string);
sh=findobj("tag","sh"); par(14)=evstr(sh.string);
ss=findobj("tag","ss"); par(15)=evstr(ss.string);
rSl=findobj("tag","rSl"); par(16)=evstr(rSl.string);
rSt=findobj("tag","rSt"); par(17)=evstr(rSt.string);
zetaMax=findobj("tag","zetaMax"); par(18)=evstr(zetaMax.string);



//N=findobj("tag","N"); par(18)=evstr(N.string);

//e=findobj("tag","e"); par(20)=evstr(e.string);
alpha=findobj("tag","alpha"); par(19)=evstr(alpha.string);
rDeltaR=findobj("tag","rDeltaR"); par(20)=evstr(rDeltaR.string);
rVas=findobj("tag","rVas"); par(21)=evstr(rVas.string);
rVah=findobj("tag","rVah"); par(22)=evstr(rVah.string);
rDDVa=findobj("tag","rDDVa"); par(23)=evstr(rDDVa.string);
rDDuVu=findobj("tag","rDDuVu"); par(24)=evstr(rDDuVu.string);
scL=findobj("tag","scL"); par(25)=evstr(scL.string);




[FileName]=uiputfile("","","Choose a file name");
Name=fullfile(FileName);
fidI=mopen(Name,'w');
for i=1:size(par)

mfprintf(fidI,"%0.5f\n",par(i)):
end
mclose(fidI);
endfunction

This is the part where i store data. I get this:
mfprintf(fidI,"%0.5f\n",par(i)):
!--error 2
Invalid factor.
at line 45 of function saveFile called by :
endfunction

Any ideas?

Regards,
Petar




--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034560.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
petarf
2016-09-13 12:12:01 UTC
Permalink
Hi, I managed to write function to place new values from txt. file instead of
old values. But now when I run the calculation

Q=findobj("tag","Q"); par(1)=evstr(Q.string);
dpTot=findobj("tag","dpTot"); par(2)=evstr(dpTot.string);

these set of lines do not read new values. String Q is evaluated as old
value. Any ideas?

Regards,
Petar



--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034566.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Rafael Guerra
2016-09-13 14:14:07 UTC
Permalink
Hi,



Without seeing the details of your code and with no experience with findobj, from what I could understand from the help file, the command lines like: Q=findobj("tag","Q");

do not sound good.

As findobj outputs an handle to your uicontrol object, you could try:

hdl = findobj("tag","Q");

Q = hdl.Q; // or: Q = evstr(hdl.Q); if data stored as string

dpTot = hdl.dpTot; // etc..



Regards,

Rafael



-----Original Message-----
From: users [mailto:users-***@lists.scilab.org] On Behalf Of petarf
Sent: Tuesday, September 13, 2016 2:12 PM
To: ***@lists.scilab.org
Subject: Re: [Scilab-users] GUI save and import data



Hi, I managed to write function to place new values from txt. file instead of

old values. But now when I run the calculation



Q=findobj("tag","Q"); par(1)=evstr(Q.string);

dpTot=findobj("tag","dpTot"); par(2)=evstr(dpTot.string);



these set of lines do not read new values. String Q is evaluated as old

value. Any ideas?



Regards,

Petar







--

View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034566.html

Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.

_______________________________________________

users mailing list

***@lists.scilab.org<mailto:***@lists.scilab.org>

http://lists.scilab.org/mailman/listinfo/users
Rafael Guerra
2016-09-13 14:17:48 UTC
Permalink
I am sorry, please discard my previous comment... after further reading of the help doc, it does not make sense.

From: users [mailto:users-***@lists.scilab.org] On Behalf Of Rafael Guerra
Sent: Tuesday, September 13, 2016 4:14 PM
To: Users mailing list for Scilab <***@lists.scilab.org>
Subject: Re: [Scilab-users] GUI save and import data


Hi,



Without seeing the details of your code and with no experience with findobj, from what I could understand from the help file, the command lines like: Q=findobj("tag","Q");

do not sound good.

As findobj outputs an handle to your uicontrol object, you could try:

hdl = findobj("tag","Q");

Q = hdl.Q; // or: Q = evstr(hdl.Q); if data stored as string

dpTot = hdl.dpTot; // etc..



Regards,

Rafael



-----Original Message-----
From: users [mailto:users-***@lists.scilab.org] On Behalf Of petarf
Sent: Tuesday, September 13, 2016 2:12 PM
To: ***@lists.scilab.org<mailto:***@lists.scilab.org>
Subject: Re: [Scilab-users] GUI save and import data



Hi, I managed to write function to place new values from txt. file instead of

old values. But now when I run the calculation



Q=findobj("tag","Q"); par(1)=evstr(Q.string);

dpTot=findobj("tag","dpTot"); par(2)=evstr(dpTot.string);



these set of lines do not read new values. String Q is evaluated as old

value. Any ideas?



Regards,

Petar







--

View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034566.html

Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.

_______________________________________________

users mailing list

***@lists.scilab.org<mailto:***@lists.scilab.org>

http://lists.scilab.org/mailman/listinfo/users
petarf
2016-09-15 08:10:06 UTC
Permalink
Hi Rafael,

Thank you for your reply. It is hard for me to explain this but I will try
to make it simple and effective. I have master file in which I create GUI
and set initial values. Part of the code where I set inital values is:

//
labels1=["Q","dpTot","rho","n","eta"];
labels2=["m^3/s","Pa","kg/m^3","rev/min","-",];
values1=[0,0,0,0,0];

for k=1:size(labels1,2)
//

guientry1(k)=uicontrol("parent",axfanblade,"style","edit","string",string(values1(k)),"position",[L3,guih1-k*20+guih1o,180,20],"horizontalalignment","left","fontsize",14,"background",[.9
.9 .9],"tag",labels1(k));
//
end


After that, master file creates push button which calls script that do some
calculation. In that file I obtain values that I enter manually with "tag"
option as I mentioned in previous comment.
//
Q=findobj("tag","Q"); param.Q=evstr(Q.string);
etc.
//

This works when parameters are set in GUI master file or when I enter them
manually in the created GUI.

Next I have created scrtip which opens a text file and read parameters from
.txt file. But it seems that values are only replaced in GUI, I see them in
GUI but they are not read with "tag" option in the scritp that do
calculation. Scritp does the calculation with old parameters. I have 25
parameters that I need to eneter to do calculation it is annoying to enter
them manually all over again.

Regards,
Petar




--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034574.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Rafael Guerra
2016-09-15 12:11:37 UTC
Permalink
Hi Petar,



From the code you provided, you may have consulted the Openeering tutorial "How to develop a GUI in Scilab".

With regards to the detailed example in that tutorial, it seems possible to reuse the newly input GUI input parameters (par variable) if:

- the par(k) variable is not reset inside syscompute function (par =[]);

- the par(k) variable is declared inside (and outside) syscompute as global

- the GUI figure is closed and reopened before reusing the new input parameters



Not sure if this is might be the source of your problem nor if all the points above are necessary or correct but, hopefully the example below that seems to work may help you:





global par;



function syscompute(par)

global par;

Q = findobj("tag", "Q"); par(1) = evstr(Q.string);

dpTot = findobj("tag", "dpTot"); par(2) = evstr(dpTot.string);



y = par(1)*sqrt(par(2)); // or call some function from here

printf("Q= %.3f, dpTot= %.3f\n",par(1),par(2));

printf("Result = %.3f\n\n",y);

endfunction



f=figure();

labels1=["Q","dpTot"];

values1=[0,0];

par = values1;



for k=1:size(labels1,2)

uicontrol("parent",f,"style","text","string",labels1(k),"position",[0,300-k*20,100,20]);

guientry1(k)=uicontrol("parent",f,"style","edit","string",string(values1(k)),"position",...

[100,300-k*20,50,20],"tag",labels1(k));

end

hb = uicontrol(f, "style","pushbutton", ...

"Position",[50 200 100 20], "String","Compute", ...

"Callback","syscompute");



input("Input new values in GUI, hit Compute, then ENTER here to continue...","string");



// Show below the reusability of newly input GUI parameters (above):

close(f);

f=figure();

for k=1:size(labels1,2)

values1(k)= par(k);

uicontrol("parent",f,"style","text","string",labels1(k),"position",[0,300-k*20,100,20]);

guientry1(k)=uicontrol("parent",f,"style","edit","string",string(values1(k)),"position",[100,300-k*20,50,20],"tag",labels1(k));

end

hb = uicontrol(f, "style","pushbutton", ...

"Position",[50 200 100 20], "String","Compute", ...

"Callback","syscompute");



input("Do Compute in GUI then ENTER here to continue......","string")

close(f)





Regards,

Rafael

petarf
2016-09-12 10:56:49 UTC
Permalink
Hi Paul,

Thank you for you fast reply. I managed to do something with save option.

function saveFile

// Gather data
Q=findobj("tag","Q"); parameter(1)=evstr(Q.string);
dpTot=findobj("tag","dpTot"); parameter(2)=evstr(dpTot.string);
rho=findobj("tag","rho"); parameter(3)=evstr(rho.string);
n=findobj("tag","n"); parameter(4)=evstr(n.string);
eta=findobj("tag","eta"); parameter(5)=evstr(eta.string);
dh=findobj("tag","dh"); parameter(6)=evstr(dh.string);
ds=findobj("tag","ds"); parameter(7)=evstr(ds.string);
z=findobj("tag","z"); parameter(8)=evstr(z.string);
Lh=findobj("tag","Lh"); parameter(9)=evstr(Lh.string);
Ls=findobj("tag","Ls"); parameter(10)=evstr(Ls.string);
beta2h=findobj("tag","beta2h"); parameter(11)=evstr(beta2h.string);
m=findobj("tag","m"); parameter(12)=evstr(m.string);
k=findobj("tag","k"); parameter(13)=evstr(k.string);
sh=findobj("tag","sh"); parameter(14)=evstr(sh.string);
ss=findobj("tag","ss"); parameter(15)=evstr(ss.string);
rSl=findobj("tag","rSl"); parameter(16)=evstr(rSl.string);
rSt=findobj("tag","rSt"); parameter(17)=evstr(rSt.string);
zetaMax=findobj("tag","zetaMax"); parameter(18)=evstr(zetaMax.string);
alpha=findobj("tag","alpha"); parameter(19)=evstr(alpha.string);
rDeltaR=findobj("tag","rDeltaR"); parameter(20)=evstr(rDeltaR.string);
rVas=findobj("tag","rVas"); parameter(21)=evstr(rVas.string);
rVah=findobj("tag","rVah"); parameter(22)=evstr(rVah.string);
rDDVa=findobj("tag","rDDVa"); parameter(23)=evstr(rDDVa.string);
rDDuVu=findobj("tag","rDDuVu"); parameter(24)=evstr(rDDuVu.string);
scL=findobj("tag","scL"); parameter(25)=evstr(scL.string);




[FileName]=uiputfile("","","Choose a file name");
Name=fullfile(FileName);
fidI=mopen(Name,'w');
for i=1:size(parameter)

mfprintf(fidI,"%0.5f\n",parameter(i));
end
mclose(fidI);
endfunction

But when I choose to save this parameters to file called data.txt the file
is created but empty. This error occurs:

!--error 204
':': Wrong type for argument #2: Scalar expected.
at line 36 of function saveFile called by :





--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034563.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
petarf
2016-09-12 11:02:11 UTC
Permalink
I apologise for posting twice. I deleted previous post but nothing happend.

Problem was with size/lenght. Thnak you for your help!

Regards,
Petar



--
View this message in context: http://mailinglists.scilab.org/GUI-save-and-import-data-tp4034558p4034564.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Loading...