[Scilab-users] Regex problem
Gerhard Kreuzer
gerhard.kreuzer at liftoff.at
Sat Aug 27 08:10:47 CEST 2016
Hi Jan,
get it.
Yesterday I faild until I see that the file wasn’t accessible, for what reason ever. I don’t get an error message, but after mgetstr I don’t have any data read. After rebooting the machine, this problem dissappears.
Here the working version:
// Copyright (C) 2016 - Liftoff - Gerhard Kreuzer msc.
//
// Date of creation: 26.08.2016
//
// Just for tests
clear;
fnRawData='Works.raw';
fnRawData='Fails.raw' // Comment out to see working file which contains only dummy data
// HEUREKA, both files working now
fdRawData = mopen(fnRawData,'rb');
// Find start of binary data by searching the first non ascii value
// No problem if the exact end is missed, regex will do the rest
if ~meof(fdRawData) then c = mgeti(1, 'uc', fdRawData); end
while ( c < 128 & c >= 32 ) & ~meof(fdRawData)
c = mgeti(1, 'uc', fdRawData);
end
metaDataEnd = mtell(fdRawData) // Note down this position
mseek(0, fdRawData, 'set'); // Rewind file //
strData = mgetstr(metaDataEnd - 1, fdRawData); // Read whole meta data block, only ASCII values go here
[dummy,dataStart,dataMatch,data]=regexp(strData,'/#data#/'); // Analyze meta data, we just seek for the begin of the binary data here
mseek(dataStart, fdRawData, 'set'); // Set file pointer to correct position
sset = mgeti(7, 'il', fdRawData); // Read first sample set, just for test.
mclose(fdRawData); // Ich habe fertig
I am sure ther could be done some optimization, but ist a good start now.
Thanks a lot.
With best regards
Gerhard
Von: JLan [via Scilab / Xcos - Mailing Lists Archives] [mailto:ml-node+s994242n4034504h24 at n3.nabble.com]
Gesendet: Freitag, 26. August 2016 19:09
An: Gerhard Kreuzer
Betreff: Re: Regex problem
Gerhard
Would this work? Read as much as you need as binary and convert the non ascii values to an ascii value, for instance 0.
The below is not optimized, and I have no idea why the strsplit is needed, but I got an "unknown error" without it:
fid=mopen(datafile,"rb");
btr=1000;
B=mgeti(btr+1,"uc",fid);
for i=1:btr+1
if B(i)>128 | B(i)<32 then B(i)=48; end
end
S=strsplit(ascii(B),btr);
strData=S(1);
[dataStart,dataEnd,dataMatch,data]=regexp(strData,'/#data#/')
...
Jan Å
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_____
If you reply to this email, your message will be added to the discussion below:
http://mailinglists.scilab.org/Scilab-users-Regex-problem-tp4034446p4034504.html
To unsubscribe from [Scilab-users] Regex problem, click here <http://mailinglists.scilab.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4034446&code=Z2VyaGFyZC5rcmV1emVyQGxpZnRvZmYuYXR8NDAzNDQ0NnwtMTk4MzI4ODE5Mg==> .
<http://mailinglists.scilab.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML
--
View this message in context: http://mailinglists.scilab.org/Scilab-users-Regex-problem-tp4034446p4034507.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160826/40327990/attachment.htm>
More information about the users
mailing list