density
12345
viscosity
678910
surface tension
11121314
........
and so on. the file is called "properties.txt" and it is a list of
fluid properties that I need to use for my calculations.
What command could I use to extract the numbers from the text file and
assign them to variables in scilab. I have tried:
mopen
file('open',...)
fscanfMat
read
nothing seems to get the job done. fscanfMat came close but it reads
only the first number and not the rest of them.
I would appreciate it if someone could suggest a method of extracting
the numbers as, say a column vector to be later assigned to different
variables or directly assign them from the text file that has the
data.
Thank you
Vikram
In a case like this, I would pass the source file through another "pre-
processor" application such as Perl. I'm sure that Scilab is general-
purpose enough to do the file manipulation with native functions but a
tool like Perl (available for free for pretty much every O/S out there)
seems to be a better fit for text file operations.
--
Rich Webb Norfolk, VA
On a mac/unix or with cgywin
sed -e 's/ //' -e 's/\([0-9]\)$/\1];/' -e 's/\([^;]\)$/\1=[/' text > text2
so the file now looks like
density=[
12345];
viscosity=[
678910];
surfacetension=[
11121314];
and one can
exec text2
-->density=[
-->12345];
-->viscosity=[
-->678910];
-->surfacetension=[
-->11121314];
--
Steven Bellenot http://www.math.fsu.edu/~bellenot
Professor and Associate Chair phone: (850) 644-7405
Department of Mathematics office: 223 Love
Florida State University email: bellenot at math.fsu.edu
A possibility is the following :
[fd,err]=mopen("properties.txt");
txt=mgetl(fd); // get all lines
mclose(fd);
prop = txt(1:2:$); // extract properties names
val = evstr(txt(2:2:$)); // extract values
hth
Bruno
>On a mac/unix or with cgywin
>sed -e 's/ //' -e 's/\([0-9]\)$/\1];/' -e 's/\([^;]\)$/\1=[/' text > text2
>
>so the file now looks like
>density=[
>12345];
>viscosity=[
>678910];
>surfacetension=[
>11121314];
Very nice!
If the OP is on an MS Windows box, he may also want to try MinGW + MSYS
for a lighter-weight but still decent shell, utility, and compiler
environment.