<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Helle Richard,<br>
<br>
Le 18/06/2017 à 23:10, Richard llom a écrit :<br>
</div>
<blockquote cite="mid:1497820201592-4036587.post@n3.nabble.com"
type="cite">
<pre wrap="">Hello fellow scilab-users,
I'm writing a script to read and process files, which are constructed as
follows:
<file start>
PCB: 007
ASM: 000
LOT: 00000
FW: 1477971088
CH1: AMPS 10A
CH2: VOLT 60V
SMPL: 0064 0125Hz
DESC: 12V CU LOG
UTC TIME SEC ,CH1 AMPS DC ,CH2 VOLT DC
1497812372.910, 8.609146E-03, 1.210613E001
1497812373.895, 1.577809E-01, 1.207540E001
1497812374.578, 1.010268E000, 1.193087E001
... [snip]
<file end>
To process this file further, I need:
1)
the first eight lines stored in pairs, e.g.
info(1,1) should yield "PCB" and info(1,2) should yield "007" (string is ok)
2)
line #9 (header), should be available as header(1)="UTC TIME SEC", etc...
3)
line 10+
these should be scanned in as a matrix.
I already tried csvread and msscanf (?), however with no luck so far...</pre>
</blockquote>
<br>
You may use the following:<br>
<br>
<tt>[M, comments] = csvRead("data.txt", ",", ".", "double",[],
"/^[^0-9\-]/"); M</tt><tt><br>
</tt><tt>header = tokens(comments($), ",")'</tt><tt><br>
</tt><tt>params = csvTextScan(comments(1:$-1), ":", [], "string")</tt><tt><br>
</tt><tt><br>
</tt><font color="#999999"><tt>-->[M, comments] =
csvRead("data.txt", ",", ".", "double",[], "/^[^0-9\-]/"); M</tt><tt><br>
</tt><tt> M =</tt><tt><br>
</tt><tt> 1.498D+09 0.0086091 12.10613 </tt><tt><br>
</tt><tt> 1.498D+09 0.1577809 12.0754 </tt><tt><br>
</tt><tt> 1.498D+09 1.010268 11.93087 </tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>-->header = tokens(comments($), ",")'</tt><tt><br>
</tt><tt> header =</tt><tt><br>
</tt><tt>!UTC TIME SEC CH1 AMPS DC CH2 VOLT DC !</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>-->params = csvTextScan(comments(1:$-1), ":", [],
"string")</tt><tt><br>
</tt><tt> params =</tt><tt><br>
</tt><tt>!PCB 007 !</tt><tt><br>
</tt><tt>!ASM 000 !</tt><tt><br>
</tt><tt>!LOT 00000 !</tt><tt><br>
</tt><tt>!FW 1477971088 !</tt><tt><br>
</tt><tt>!CH1 AMPS 10A !</tt><tt><br>
</tt><tt>!CH2 VOLT 60V !</tt><tt><br>
</tt><tt>!SMPL 0064 0125Hz !</tt><tt><br>
</tt><tt>!DESC 12V CU LOG !</tt><tt><br>
</tt></font><br>
HTH<br>
Samuel<br>
<br>
</body>
</html>