[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #62152] Textscan fails in rare occurences
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #62152] Textscan fails in rare occurences |
Date: |
Mon, 7 Mar 2022 21:27:30 -0500 (EST) |
URL:
<https://savannah.gnu.org/bugs/?62152>
Summary: Textscan fails in rare occurences
Project: GNU Octave
Submitted by: None
Submitted on: Tue 08 Mar 2022 02:27:28 AM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Matlab Compatibility
Status: None
Assigned to: None
Originator Name: maiky76
Originator Email:
Open/Closed: Open
Release: 6.4.0
Discussion Lock: Any
Operating System: Microsoft Windows
_______________________________________________________
Details:
Bug filed from:
https://octave.discourse.group/t/help-on-textscan-rare-occurrences-of-errors/2332/7
I have been having some very rare occurrences (about 0.15% based on 15k
iterations) where the following code does not work.
The files are all generated by a single program and are supposed to strictly
follow the same format.
In some instances the code fails to properly read the content of the file and
stop somewhere for no apparent reason.
The equivalent function in Matlab never fails.
4 files examples are attached to test,
Spectrum_ABEC_OK.txt load with no issue
Spectrum_ABEC_KO.txt only load with the revised code
Spectrum_ABEC_3.txt stops line 27
Spectrum_ABEC_4.txt stops line 5
clear all
close all
clc
Pref = 2e-5;
% EmptyData = 25 about 0.1%
% Total_iter = 24122 37h
% size(SPL) should return 37x40
Path2filename = 'Spectrum_ABEC_OK.txt'; % Vast majority of the files
% Path2filename = 'Spectrum_ABEC_KO.txt'; %
% Path2filename = 'Spectrum_ABEC_3.txt'; % stops line 27
Path2filename = 'Spectrum_ABEC_4.txt'; % stops line 5
%
------------------------------------------------------------------------------
% Read first part of the file never fails
delimiter = ' ';
startRow = 39;
endRow = 78;
formatSpec = '%f%f%f%[^\n]';
fileID = fopen(Path2filename,'r');
dataArrayZ = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter',
delimiter, 'MultipleDelimsAsOne', true, 'HeaderLines', startRow-1,
'ReturnOnError', false, 'EndOfLine', '\n');
fclose(fileID);
FreqZ = cell2mat(dataArrayZ(1));
ZRe = cell2mat(dataArrayZ(2));
ZIm = cell2mat(dataArrayZ(3));
RadZ = [ZRe ZIm];
% Clear temporary variables
clearvars delimiter startRow endRow formatSpec dataArrayZ ans;
if exist('OCTAVE_VERSION', 'builtin') == 0
delimiter = ' ';
startRow = 105;
endRow = 144;
formatSpec =
'%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(Path2filename,'r');
dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter',
delimiter, 'MultipleDelimsAsOne', true, 'TextType', 'string', 'HeaderLines',
startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
fclose(fileID);
Freq = cell2mat(dataArray(1)); % should be indentical to FreqZ
SpectrumABEC = cell2mat(dataArray(2:end-1));
[~, col] = size(SpectrumABEC);
NbSpectra = col/2
else
delimiter = ' ';
startRow = 105;
endRow = 144;
%
------------------------------------------------------------------------------
% original
formatSpec =
'%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%[^\n]';
fileID = fopen(Path2filename,'r');
dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter',
delimiter, 'MultipleDelimsAsOne', true, 'HeaderLines', startRow-1,
'ReturnOnError', false, 'EndOfLine', '\n');
fclose(fileID);
Freq = cell2mat(dataArray(1));
SpectrumABEC = cell2mat(dataArray(2:end-1));
[~, col] = size(SpectrumABEC);
NbSpectra = col/2;
%
------------------------------------------------------------------------------
% Octave help
% formatSpec =
'%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f';
% fileID = fopen(Path2filename,'r');
% dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter',
delimiter, 'MultipleDelimsAsOne', true, 'HeaderLines', startRow-1,
'ReturnOnError', true, 'EndOfLine', '\r\n');
% fclose(fileID);
%
% Freq = cell2mat(dataArray(1));
% SpectrumABEC = cell2mat(dataArray(2:end));
% [~, col] = size(SpectrumABEC);
% NbSpectra = col/2;
%
------------------------------------------------------------------------------
[~, col] = size(SpectrumABEC);
NbSpectra = col/2 % should return 37x40
end
for k = 1:NbSpectra
SPL(:,k) = 20*log10( abs( ( ( SpectrumABEC(:,2*k-1) +
1i*SpectrumABEC(:,2*k) ) /sqrt(2) ) / Pref ) ); % RMS value
deg(k,1) = (k-1)*5;
end
SizeSPL = size(SPL)
figure()
subplot (211)
semilogx(FreqZ, RadZ(:,1), 'k')
hold on
semilogx(FreqZ, RadZ(:,2), 'k--')
grid on
ylabel('Z')
xlabel('Frequency [Hz]')
legend('ReZ', 'ImZ')
title('Waveguide Z');
subplot (212)
semilogx(Freq, SPL)
grid on
ylabel('SPL [dB]')
xlabel('Frequency [Hz]')
legend('SPL 5 deg step')
title('Waveguide SPL');
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Tue 08 Mar 2022 02:27:28 AM UTC Name: Spectrum_ABEC_OK.txt Size: 66KiB
By: None
<http://savannah.gnu.org/bugs/download.php?file_id=52968>
-------------------------------------------------------
Date: Tue 08 Mar 2022 02:27:28 AM UTC Name: Spectrum_ABEC_3.txt Size: 66KiB
By: None
<http://savannah.gnu.org/bugs/download.php?file_id=52969>
-------------------------------------------------------
Date: Tue 08 Mar 2022 02:27:28 AM UTC Name: Spectrum_ABEC_KO.txt Size: 66KiB
By: None
<http://savannah.gnu.org/bugs/download.php?file_id=52970>
-------------------------------------------------------
Date: Tue 08 Mar 2022 02:27:28 AM UTC Name: Spectrum_ABEC_4.txt Size: 66KiB
By: None
<http://savannah.gnu.org/bugs/download.php?file_id=52971>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62152>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #62152] Textscan fails in rare occurences,
anonymous <=