Discussion:
Problems in 5.3.1 version Regarding mfscanf and mfprintf functions
(too old to reply)
Sukumar
2011-04-11 13:43:27 UTC
Permalink
Dear All,

I am using Scilab 5.3.1 in Linux 32 bit (OS-Fedora 12), installed from
binary package and I am facing problem regarding mfscanf and mfprintf
functions.
My function is somewhat like this

The infile contains Text and Numeric data and Out file will be a
formatted result file.

function []=fun1(inFile,Outfile)
fidIn=mopen(inFile)
text=mfscanf(17,fidIn,'%s\n')
a=mfscanf(1,fidIn,'%lg\n')
b=mfscanf(1,fidIn,'%lg\n')
...
etc
endfunction

When I call this function, it reads the text but returns empty
matrices for a, b., etc. The problem remains with %f or %e formats as
well.
Then I used mfscanfMat function for reading the data and text. This of
course worked and returned the text as well as the matrix.

Then, When I want to write out the results using mfprintf or fprintf
in outFile, it exits Scilab.
The error msg in the terminal where Scilab started is shown as
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
^"
Should I make a bug report?
Tim Wescott
2011-04-11 17:21:05 UTC
Permalink
Post by Sukumar
Dear All,
I am using Scilab 5.3.1 in Linux 32 bit (OS-Fedora 12), installed from
binary package and I am facing problem regarding mfscanf and mfprintf
functions.
My function is somewhat like this
The infile contains Text and Numeric data and Out file will be a
formatted result file.
function []=fun1(inFile,Outfile)
fidIn=mopen(inFile)
text=mfscanf(17,fidIn,'%s\n')
a=mfscanf(1,fidIn,'%lg\n')
b=mfscanf(1,fidIn,'%lg\n')
...
etc
endfunction
When I call this function, it reads the text but returns empty
matrices for a, b., etc. The problem remains with %f or %e formats as
well.
Then I used mfscanfMat function for reading the data and text. This of
course worked and returned the text as well as the matrix.
Then, When I want to write out the results using mfprintf or fprintf
in outFile, it exits Scilab.
The error msg in the terminal where Scilab started is shown as
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
^"
Should I make a bug report?
mfscanf is quite picky about what you feed it. As specified, you're
saying that the input file has a line that is _just_ a number -- no
spaces, no letters, no commas, no nothing else, followed by a linefeed.
If mfscanf doesn't see _exactly_ that, it'll throw up it's little
computerized hands and give you a null matrix.

A good diagnostic tool is to slurp the whole file into a text matrix
using mgetl, then practice on the resulting lines of text using msscanf.
When you find a format specification that works, use it on the whole file.

Note, too, that texts on C usage discourage the use of mscanf if there
is _any_ uncertainty about the format -- if there is (i.e., if you're
working off of human-generated text instead of machine-generated), you
should parse the file manually. Having said that, I should also say
that I've had great success with mfscanf for machine-generated text --
after I've struggled a bit with getting the format specification just right.

Show us the mfprintf line that you're using and its context -- perhaps
the error message makes sense given what you're asking mfprintf to do.
--
Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Sukumar
2011-04-12 13:02:55 UTC
Permalink
Post by Sukumar
Dear All,
I am using Scilab 5.3.1 in Linux 32 bit (OS-Fedora 12), installed from
binary package and I am facing problem regarding mfscanf and mfprintf
functions.
My function is somewhat like this
The infile contains Text and Numeric data and Out file will be a
formatted result file.
function []=fun1(inFile,Outfile)
fidIn=mopen(inFile)
text=mfscanf(17,fidIn,'%s\n')
a=mfscanf(1,fidIn,'%lg\n')
b=mfscanf(1,fidIn,'%lg\n')
...
etc
endfunction
When I call this function, it reads the text but returns empty
matrices for a, b., etc. The problem remains with %f or %e formats as
well.
Then I used mfscanfMat function for reading the data and text. This of
course worked and returned the text as well as the matrix.
Then, When I want to write out the results using mfprintf or fprintf
in outFile, it exits Scilab.
The error msg in the terminal where Scilab started is shown as
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
   ^"
Should I make a bug report?
mfscanf is quite picky about what you feed it.  As specified, you're
saying that the input file has a line that is _just_ a number -- no
spaces, no letters, no commas, no nothing else, followed by a linefeed.
  If mfscanf doesn't see _exactly_ that, it'll throw up it's little
computerized hands and give you a null matrix.
A good diagnostic tool is to slurp the whole file into a text matrix
using mgetl, then practice on the resulting lines of text using msscanf.
  When you find a format specification that works, use it on the whole file.
Note, too, that texts on C usage discourage the use of mscanf if there
is _any_ uncertainty about the format -- if there is (i.e., if you're
working off of human-generated text instead of machine-generated), you
should parse the file manually.  Having said that, I should also say
that I've had great success with mfscanf for machine-generated text --
after I've struggled a bit with getting the format specification just right.
Show us the mfprintf line that you're using and its context -- perhaps
the error message makes sense given what you're asking mfprintf to do.
--
Tim Wescott
Wescott Design Serviceshttp://www.wescottdesign.com
Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details athttp://www.wescottdesign.com/actfes/actfes.html
Thanks Tim,
If I have understood you correctly, I should use mgetl and then
msscanf to read the kind of file I was mentioning. BTW, I could not
succeed even when my numbers were arranged in a line with spaces in
between. I will use mgetl and msscanf and report how it goes. BTW, I
of course want finally to output my results in a file using mfprintf.
But in that case, as i mentioned already, my scilab crashes and I
get Fortran run time error in the terminal where I started Scilab. I
am repeating the error message here for convenience
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
^"
So pl advise where does the problem lies.

With Regards
Sukumar
2011-04-12 13:09:17 UTC
Permalink
Post by Sukumar
Post by Sukumar
Dear All,
I am using Scilab 5.3.1 in Linux 32 bit (OS-Fedora 12), installed from
binary package and I am facing problem regarding mfscanf and mfprintf
functions.
My function is somewhat like this
The infile contains Text and Numeric data and Out file will be a
formatted result file.
function []=fun1(inFile,Outfile)
fidIn=mopen(inFile)
text=mfscanf(17,fidIn,'%s\n')
a=mfscanf(1,fidIn,'%lg\n')
b=mfscanf(1,fidIn,'%lg\n')
...
etc
endfunction
When I call this function, it reads the text but returns empty
matrices for a, b., etc. The problem remains with %f or %e formats as
well.
Then I used mfscanfMat function for reading the data and text. This of
course worked and returned the text as well as the matrix.
Then, When I want to write out the results using mfprintf or fprintf
in outFile, it exits Scilab.
The error msg in the terminal where Scilab started is shown as
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
   ^"
Should I make a bug report?
mfscanf is quite picky about what you feed it.  As specified, you're
saying that the input file has a line that is _just_ a number -- no
spaces, no letters, no commas, no nothing else, followed by a linefeed.
  If mfscanf doesn't see _exactly_ that, it'll throw up it's little
computerized hands and give you a null matrix.
A good diagnostic tool is to slurp the whole file into a text matrix
using mgetl, then practice on the resulting lines of text using msscanf.
  When you find a format specification that works, use it on the whole file.
Note, too, that texts on C usage discourage the use of mscanf if there
is _any_ uncertainty about the format -- if there is (i.e., if you're
working off of human-generated text instead of machine-generated), you
should parse the file manually.  Having said that, I should also say
that I've had great success with mfscanf for machine-generated text --
after I've struggled a bit with getting the format specification just right.
Show us the mfprintf line that you're using and its context -- perhaps
the error message makes sense given what you're asking mfprintf to do.
--
Tim Wescott
Wescott Design Serviceshttp://www.wescottdesign.com
Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details athttp://www.wescottdesign.com/actfes/actfes.html
Thanks Tim,
If I have understood you correctly, I should use mgetl and then
msscanf to read the kind of file I was mentioning. BTW, I could not
succeed even when my numbers were arranged in a line with spaces in
between. I will use mgetl and msscanf and report how it goes. BTW, I
of course want finally to output my results in a file using mfprintf.
But in that case, as i mentioned already,  my scilab crashes and  I
get Fortran run time error in the terminal where I started Scilab.  I
am repeating the error message here for convenience
"At line 206 of file src/fortran/error.f
Fortran runtime error: Nonnegative width required in format
(i**)
  ^"
So pl advise where does the problem lies.
With Regards
Further, my mfprintf lines are as follows:
===============================================================
fidOut=mopen(outFile,'w')

//Write Headings
mfprintf(fidOut,'Results of Nodal Mass Calculation \n')
mfprintf(fidOut,'====================================\n')
mfprintf(fidOut, 'Nodal Mass of First Floor\n')
mfprintf(fidOut,'Mass of Internal Nodes= %f \n', mIFloor1)
mfprintf(fidOut,'Mass of External Nodes in X direction= %f',
mXeFloor1)
mfprintf(fidOut,'Mass of External Nodes in Z direction=%f',
mZeFloor1)
mfprintf(fidOut,'Mass of Corner Nodes in =%f', mCornerFloor1)
mfprintf(fidOut,'----------------------------------------------
\n')
mfprintf(fidOut, 'Nodal Mass of Other Floors\n')
mfprintf(fidOut,'Mass of Internal Nodes=%f\n', mIFloor)
mfprintf(fidOut,'Mass of External Nodes in X direction=%f',
mXeFloor)
mfprintf(fidOut,'Mass of External Nodes in Z direction=%f',
mZeFloor)
mfprintf(fidOut,'Mass of Corner Nodes in =%f', mCornerFloor)
mfprintf(fidOut,'----------------------------------------------
\n')
mfprintf(fidOut, 'Nodal Mass of Roof\n')
mfprintf(fidOut,'Mass of Internal Nodes=%f\n', mIRoof)
mfprintf(fidOut,'Mass of External Nodes in X direction=%f',
mXeRoof)
mfprintf(fidOut,'Mass of External Nodes in Z direction=%f',
mZeRoof)
mfprintf(fidOut,'Mass of Corner Nodes in =%f', mCornerRoof)
mclose(fidOut)
================================================================
Thanks Tim again
c***@cparticulas.com
2020-02-18 14:23:32 UTC
Permalink
Dear all,

I have tried something to read words inside of an archive with extension .txt, I can read every word in the text, but only once, after I want to see the same word with the same command but it respond with an empty vector.

--> msg=mopen("B:\SCILAB\PROGRAMAS\hola.txt",'rt')
Warning: file 'B:\SCILAB\PROGRAMAS\hola.txt' already opened in Scilab.
msg =

2.


--> second=mfscanf(2,msg,'%s')
second =

!hola !
! !
!pumpum !


--> mfscanf(1,msg,'%s')
ans =

[]
mfscanf(2,msg,'%s')
ans =

[]
I don´t know if command mfscanf has flags or something like that.
Loading...