Reading Text file from IMC company

18 views (last 30 days)
Aubai
Aubai on 31 May 2021
Edited: Jan on 28 Jul 2021
Dear All,
I am trying to read .raw files created by IMC measurement devices (basically it is a Text file). for that i am using the following code:
fid = fopen(FullRawData,'r');
Textall=fscanf(fid,'%c');
And in most cases it is working yet in some cases Matlab is not reading the correct text data. E.g.:
When showing the .raw file in WordPad:
|CF,2,1,1;|CK,1,3,1,1;|NO,1, 91,0,83,imc STUDIO 5.2 R13 (02.01.2020)@imc DEVICES 2.13R4 (2020-01-13)@imcDev__16200173@PC,0,;|NL,1, 8,1252,0x0;|CG,1, 5,1,1,1;|CD,2, 65, 2.000000000000000e-004,1,1,s,0,0,0, 0.000000000000000e+000,1;|NT,1, 14,1,1,1980,0,0,0;|CC,1, 3,1,1;|CP,1, 16,1,2,4,16,0,0,1,0;|CR,1, 59,1, -3.051944088384301e-001, 0.000000000000000e+000,1,1,A;|ND,1, 63, -1, -1, -1, 0.000000000000000e+000, 0.000000000000000e+000;|Np,1, 399,"imc1000" "Analog" 0 0,"imc1058" "200173" 0 0,"imc07" "0" 4 0,"ExpGuid" "d5c3232f-2ecd-4433-83eb-8688a4163b82" 0 0,"ORIGINALDATAPATH" "D:xxxxxxx\I3_Netz.raw " 0 0;|CN,1, 18,0,0,0,7,I3_Netz,0,;|Cb,1, 124, 1,0, 1, 1,0, 6000000, 0, 6000000,1, 2.216397344000004e+005, 1.296383160265600e+009,;|CS,1, 6000011, 1,æ
which is ok as i expected. Yet in matlab the Texall looks like this:
  4 Comments
Rik
Rik on 31 May 2021
It is not clear to me what kind of data you're expecting and how this is different from what you're getting. Are you sure the file was not changed by opening it with WordPad? Some rich text editors will attempt to repair a file when reading it. If the format doesn't actually match what the editor thinks, that may result in file damage. I would personally recommend Notepad++ if you want to explore plain text files.
You could also contact the author of that submission, either by posting a comment, or by sending an email.
Aubai
Aubai on 31 May 2021
Hallo Rik,
Even when opening the file in normal standard Notepad i am still getting the expected file format (header) and when opining the file in FAMOS-Software (from the IMC-manufacutrer) there is no error or nothing.
Unfortionatily i already tried this and no replay.
Best Regards

Sign in to comment.

Accepted Answer

Aubai
Aubai on 28 Jul 2021
so i solve it by using different functions till i get the answer:
here is the code if anyone out there is interested in that
fid1 = fopen(FullRawData,'r','a','US-ASCII');
tline = fgets(fid1);
  2 Comments
Rik
Rik on 28 Jul 2021
I doubt this works as intended with the file you shared, as the file isn't ASCII until the end.
You're also forgetting fclose.
fn=unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/637080/I3_Netz.zip');
FullRawData=fn{1};
fid1 = fopen(FullRawData,'r','a','US-ASCII');
tline = fgets(fid1),fclose(fid1);
tline =
'|CF,2,1,1;|CK,1,3,1,1;|NO,1, 91,0,83,imc STUDIO 5.2 R13 (02.01.2020)@imc DEVICES 2.13R4 (2020-01-13)@imcDev__16200173@PC,0,;|NL,1, 8,1252,0x0;|CG,1, 5,1,1,1;|CD,2, 65, 2.000000000000000e-004,1,1,s,0,0,0, 0.000000000000000e+000,1;|NT,1, 14,1,1,1980,0,0,0;|CC,1, 3,1,1;|CP,1, 16,1,2,4,16,0,0,1,0;|CR,1, 59,1, -3.051944088384301e-001, 0.000000000000000e+000,1,1,A;|ND,1, 63, -1, -1, -1, 0.000000000000000e+000, 0.000000000000000e+000;|Np,1, 399,"imc1000" "Analog" 0 0,"imc1058" "200173" 0 0,"imc07" "0" 4 0,"ExpGuid" "d5c3232f-2ecd-4433-83eb-8688a4163b82" 0 0,"ORIGINALDATAPATH" "D:\imcStudio\StandardProject\StandardProject\StandardProject\E138_EP3_E2_Janneby_ver12\2021-02-01 00-00-00 (2)\I3_Netz.raw " 0 0;|CN,1, 18,0,0,0,7,I3_Netz,0,;|Cb,1, 124, 1,0, 1, 1,0, 6000000, 0, 6000000,1, 2.216397344000004e+005, 1.296383160265600e+009,;|CS,1, 6000011, 1,� ; � � � � � y � } ? Z W E ��z j H���8 ��L�"�5�>�v�����'�����W���������E�-���k�v���������n���J����r��e�_�A�����������F 5 ������I ��� � ��E���� �� ��K� � Kk 5=� �N| K,^� DG� � � � � � y � w ( � O Y�}�� U �2 ��4�< ������������������ �G���-���E�K�����O�P���������~������a���/�w�-�s��������� ��! i���P � � ��� � _� � �C*[TC� � � ��� �2� �,q�G � � � � � � a ~ C �� ��2 ��b�}���G�������s���P������������2�%�k��������f�W���I�6���<��V���M�}�8�e�������������u�O ] �� G ) u T � 'N � }� #v*p� � '
Notice that from about halfway this array, the data isn't real ASCII anymore.
Aubai
Aubai on 28 Jul 2021
It is working for me as i need the header first and then i extract infromation of what to read afterword.
yes i did not close this as i just wanted to show what options i used.

Sign in to comment.

More Answers (1)

Jan
Jan on 31 May 2021
Edited: Jan on 28 Jul 2021
From a certain byte in the text the contents is not plain ASCII anymore. I guess boldly, that this was a problem during writing the data. If this is the case, there is no chance to repair the file afterwards.
  2 Comments
Aubai
Aubai on 31 May 2021
hallo Jan,
The file is wirtten correctly and it is intented not to be seen without a further discrption form the manufacurer.
yet my problem is simple the code above is working for alot of raw data of that time (.raw) yet sometimes i am getting the problem that it is not loading correctly and my question is why?
Best Regards
Rik
Rik on 31 May 2021
The function you linked to assumes everything in this file is plain ASCII. It is not. You can clearly see this if you open the file with Notepad++. You might be able to circumvent this by loading the file as uint8 and then casting to char. That will avoid Matlab from interpreting the file, which might be the part causing issues.
The main point is that the assumption is false: the file contains data that is not plain text. Any function based on that assumption is doomed to fail.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!