[Scilab-users] Scilab API sciprint to print on the same line

classic Classic list List threaded Threaded
11 messages Options
Tan Chin Luh Tan Chin Luh
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Scilab API sciprint to print on the same line

Hi,

I am trying to print some progress of a for loop in C api which will print the output in scilab console using the sciprint.

Is there anyway to print the output to a same line as normal C printf could be achieved using '\r' ? 

e.g.:

currently my out out showing:

Train Epoch: 10 [ 1000/15416] Loss: 0.5961
Train Epoch: 10 [ 2000/15416] Loss: 0.6794
Train Epoch: 10 [ 3000/15416] Loss: 0.3965
Train Epoch: 10 [ 4000/15416] Loss: 0.8110
Train Epoch: 10 [ 5000/15416] Loss: 0.7892

I would like to have the output to show on the same line. 

I tried \r with fflush(stdout) it seems not working.

Thanks.

rgds,
Chin Luh


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

Le 11/12/2019 à 14:31, Chin Luh Tan a écrit :
Hi,

I am trying to print some progress of a for loop in C api which will print the output in scilab console using the sciprint.

Is there anyway to print the output to a same line as normal C printf could be achieved using '\r' ? 

e.g.:

currently my out out showing:

Train Epoch: 10 [ 1000/15416] Loss: 0.5961
Train Epoch: 10 [ 2000/15416] Loss: 0.6794
Train Epoch: 10 [ 3000/15416] Loss: 0.3965
Train Epoch: 10 [ 4000/15416] Loss: 0.8110
Train Epoch: 10 [ 5000/15416] Loss: 0.7892

I would like to have the output to show on the same line. 

I tried \r with fflush(stdout) it seems not working.

Thanks.

rgds,
Chin Luh


In the C API i don't know, but in Scilab language, this mprintf("..\r") feature is broken.

It is possible to mimik it with (example):

for i = 1:100
    mprintf("Static counter: %d\n \n\n",i)
    sleep(300)
    clc(1)
end

Samuel



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Tan Chin Luh Tan Chin Luh
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

Hi Samuel, 

Thanks for your reply. 

Previously I was using clc(linenumtoclear) for showing this effect in scilab, but i never thought of the mprintf, i was using disp that time

for i = 1:100
disp("Static counter : " + string(i));
sleep(1); clc(1)
end

it seems that the mprintf also kind of broken? as it needs 3 \n to get this result?

I also tried to look into the clc C source and see whether I could use the c code of clc in scilab api but no luck, but your example of mprintf which need 3 \n inspired me to look into the mprintf c code and see how it works. 

I will get back to you on this, thanks again.

rgds,
CL

---- On Thu, 12 Dec 2019 04:09:25 +0800 Samuel Gougeon <[hidden email]> wrote ----

Le 11/12/2019 à 14:31, Chin Luh Tan a écrit :


In the C API i don't know, but in Scilab language, this mprintf("..\r") feature is broken.

It is possible to mimik it with (example):

for i = 1:100
    mprintf("Static counter: %d\n \n\n",i)
    sleep(300)
    clc(1)
end

Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Hi,

I am trying to print some progress of a for loop in C api which will print the output in scilab console using the sciprint.

Is there anyway to print the output to a same line as normal C printf could be achieved using '\r' ? 

e.g.:

currently my out out showing:

Train Epoch: 10 [ 1000/15416] Loss: 0.5961
Train Epoch: 10 [ 2000/15416] Loss: 0.6794
Train Epoch: 10 [ 3000/15416] Loss: 0.3965
Train Epoch: 10 [ 4000/15416] Loss: 0.8110
Train Epoch: 10 [ 5000/15416] Loss: 0.7892

I would like to have the output to show on the same line. 

I tried \r with fflush(stdout) it seems not working.

Thanks.

rgds,
Chin Luh



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

Hello Chin Luh

Le 12/12/2019 à 17:10, Chin Luh Tan a écrit :
Hi Samuel, 

Thanks for your reply. 

Previously I was using clc(linenumtoclear) for showing this effect in scilab, but i never thought of the mprintf, i was using disp that time

for i = 1:100
disp("Static counter : " + string(i));
sleep(1); clc(1)
end

I could not think using disp(). According to its expected behavior, it always appends an \n, while we want to stay on the line, what's the purpose of \r instead of \n, and mprintf() does not append anything to what it is requested to display.


it seems that the mprintf also kind of broken? as it needs 3 \n to get this result?


I do not think that disp() is broken. It looks OK, while clc(1) is bugged. This is why extra \n are required for this workaround using clc.

I also tried to look into the clc C source and see whether I could use the c code of clc in scilab api but no luck, but your example of mprintf which need 3 \n inspired me to look into the mprintf c code and see how it works.


Now that you know the clc code, please do not hesitate to propose a patch for its clc(1) bug ;-))

Regards

Samuel



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

...even more strange than the reported bug:
clc(1) seems to behave different when directly written into the console vs used from SciNotes.

from SciNotes:

clc();
for i=1:10 mprintf("%d\n",i)end
clc(1)
result in console:
 1
2
3
4
5
6
7  // note that number 8,9,10 are cleared..so it's 3 lines, not only two

-->

code directly put into console...do this step by step
--> clc();
--> for i=1:10 mprintf("%d\n",i) end
1
2
3
4
5
6
7
8
9
10

--> clc(1)
1
2
3
4
5
6
7
8
9

-->  // works as expected

tested on win7, Scilab 6.0.2

best regards,
Philipp




Am Do., 12. Dez. 2019 um 23:20 Uhr schrieb Samuel Gougeon <[hidden email]>:
Hello Chin Luh

Le 12/12/2019 à 17:10, Chin Luh Tan a écrit :
Hi Samuel, 

Thanks for your reply. 

Previously I was using clc(linenumtoclear) for showing this effect in scilab, but i never thought of the mprintf, i was using disp that time

for i = 1:100
disp("Static counter : " + string(i));
sleep(1); clc(1)
end

I could not think using disp(). According to its expected behavior, it always appends an \n, while we want to stay on the line, what's the purpose of \r instead of \n, and mprintf() does not append anything to what it is requested to display.


it seems that the mprintf also kind of broken? as it needs 3 \n to get this result?


I do not think that disp() is broken. It looks OK, while clc(1) is bugged. This is why extra \n are required for this workaround using clc.

I also tried to look into the clc C source and see whether I could use the c code of clc in scilab api but no luck, but your example of mprintf which need 3 \n inspired me to look into the mprintf c code and see how it works.


Now that you know the clc code, please do not hesitate to propose a patch for its clc(1) bug ;-))

Regards

Samuel


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Antoine Monmayrant-2 Antoine Monmayrant-2
Reply | Threaded
Open this post in threaded view
|

Re: ?==?utf-8?q? Scilab API sciprint to print on the same line

Well, I can see the same behaviour under linux.
But while playing with your example, I discovered a nice bug:
    sleep 100
just kills scilab (Segmentation fault (core dumped)).
It works from both scinotes or the console.
Can anyone give it a try under windows so that I can make an accurate bug report?

Cheers,

Antoine
 
 
Le Vendredi, Décembre 13, 2019 09:08 CET, P M <[hidden email]> a écrit:
 

> ...even more strange than the reported bug:
> clc(1) seems to behave different when directly written into the console vs
> used from SciNotes.
>
> from SciNotes:
>
> clc();for i=1:10 mprintf("%d\n",i)endclc(1)
>
> result in console:
>  1
> 2
> 3
> 4
> 5
> 6
> 7  // note that number 8,9,10 are cleared..so it's 3 lines, not only two
>
> -->
>
> code directly put into console...do this step by step
> --> clc();
> --> for i=1:10 mprintf("%d\n",i) end
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>
> --> clc(1)
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
>
> -->  // works as expected
>
> tested on win7, Scilab 6.0.2
>
> best regards,
> Philipp
>
>
>
>
> Am Do., 12. Dez. 2019 um 23:20 Uhr schrieb Samuel Gougeon <[hidden email]
> >:
>
> > Hello Chin Luh
> >
> > Le 12/12/2019 à 17:10, Chin Luh Tan a écrit :
> >
> > Hi Samuel,
> >
> > Thanks for your reply.
> >
> > Previously I was using clc(linenumtoclear) for showing this effect in
> > scilab, but i never thought of the mprintf, i was using disp that time
> >
> > for i = 1:100
> > disp("Static counter : " + string(i));
> > sleep(1); clc(1)
> > end
> >
> >
> > I could not think using disp(). According to its expected behavior, it
> > always appends an \n, while we want to stay on the line, what's the purpose
> > of \r instead of \n, and mprintf() does not append anything to what it is
> > requested to display.
> >
> >
> > it seems that the mprintf also kind of broken? as it needs 3 \n to get
> > this result?
> >
> >
> > I do not think that disp() is broken. It looks OK, while clc(1) is bugged
> > <http://bugzilla.scilab.org/show_bug.cgi?id=16143>. This is why extra \n
> > are required for this workaround using clc.
> >
> > I also tried to look into the clc C source and see whether I could use the
> > c code of clc in scilab api but no luck, but your example of mprintf which
> > need 3 \n inspired me to look into the mprintf c code and see how it works.
> >
> >
> > Now that you know the clc code, please do not hesitate to propose a patch
> > for its clc(1) bug ;-))
> > Regards
> >
> > Samuel
> >
> >
> > _______________________________________________
> > users mailing list
> > [hidden email]
> > http://lists.scilab.org/mailman/listinfo/users
> >

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
mottelet mottelet
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

In reply to this post by Samuel GOUGEON

Besides the clc bug, why don't we try to repair mprinf ?

Le 12/12/2019 à 23:19, Samuel Gougeon a écrit :
Hello Chin Luh

Le 12/12/2019 à 17:10, Chin Luh Tan a écrit :
Hi Samuel, 

Thanks for your reply. 

Previously I was using clc(linenumtoclear) for showing this effect in scilab, but i never thought of the mprintf, i was using disp that time

for i = 1:100
disp("Static counter : " + string(i));
sleep(1); clc(1)
end

I could not think using disp(). According to its expected behavior, it always appends an \n, while we want to stay on the line, what's the purpose of \r instead of \n, and mprintf() does not append anything to what it is requested to display.


it seems that the mprintf also kind of broken? as it needs 3 \n to get this result?


I do not think that disp() is broken. It looks OK, while clc(1) is bugged. This is why extra \n are required for this workaround using clc.

I also tried to look into the clc C source and see whether I could use the c code of clc in scilab api but no luck, but your example of mprintf which need 3 \n inspired me to look into the mprintf c code and see how it works.


Now that you know the clc code, please do not hesitate to propose a patch for its clc(1) bug ;-))

Regards

Samuel



_______________________________________________
users mailing list
[hidden email]
https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

In reply to this post by der_Phil
Le 13/12/2019 à 09:08, P M a écrit :

> .../...
> code directly put into console...do this step by step
> --> clc();
> --> for i=1:10 mprintf("%d\n",i) end
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>
> --> clc(1)
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
>
> -->  // works as expected


No, 2 lines preceding the prompt are cleared instead of one: the 10, and
the next blank line.


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

In reply to this post by mottelet
Le 13/12/2019 à 18:00, Stéphane Mottelet a écrit :

Besides the clc bug, why don't we try to repair mprinf ?


Please follow the report, the dedicated commit, and comment it.



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Tan Chin Luh Tan Chin Luh
Reply | Threaded
Open this post in threaded view
|

Re: Scilab API sciprint to print on the same line

In reply to this post by Samuel GOUGEON
Hi, 

Looks like the last command followed by the clc(1) would be ignore :

example 1: 

--> for i=1:10 mprintf("%d\n",i) end;
1
2
3
4
5
6
7
8
9
10

--> clc(1)
1
2
3
4
5
6
7
8
9
10  <-- cleared
      <--cleared

example 2:
 
--> for i=1:10 mprintf("%d\n",i) end;clc(1)
1
2
3
4
5
6
7

when the for loop printing 10, the clc(1) followed will immediately clear 9 and 8 making the 10 as never been exist. 


thanks.

CL


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Christophe Dang Ngoc Chan Christophe Dang Ngoc Chan
Reply | Threaded
Open this post in threaded view
|

Re: {EXT} Re: Scilab API sciprint to print on the same line

Hello,

> De : Chin Luh Tan
> Envoyé : mercredi 18 décembre 2019 02:36
>
> Looks like the last command followed by the clc(1) would be ignore :
>
> [...]

I've got the same result as you but additionally, I've got a different result using disp((1:10)') instead of the loop.

The result is also weird but the number of lines that are suppressed is different.

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer

General
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
--
Christophe Dang Ngoc Chan
Mechanical calculation engineer