octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #60533] some Octave functions unable to read a


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #60533] some Octave functions unable to read ascii data file if D used as exponential separator
Date: Wed, 5 May 2021 10:50:03 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36

URL:
  <https://savannah.gnu.org/bugs/?60533>

                 Summary: some Octave functions unable to read ascii data file
if D used as exponential separator
                 Project: GNU Octave
            Submitted by: nrjank
            Submitted on: Wed 05 May 2021 10:50:01 AM EDT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Nicholas Jankowski
        Originator Email: 
             Open/Closed: Open
                 Release: 6.2.0
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

attempting to load a text file containing data using D as the exponential
separator (apparently used in some systems to distinguish double and single
precision data), load produces an error and dlmread reads the data ignoring
the D and numbers the D. 

e.g., a text file 'testdata.dat' containing:


1.00000 .509844D-02 .334798D-02 .100602D-03
2.00000 .511026D-02 .334856D-02 .101089D-03


(as well as a separate testdata2.dat where the D has been replaced with E)

in matlab:

>> format long 

>> a = load('testdata.dat')
a =

   1.000000000000000   0.005098440000000   0.003347980000000  
0.000100602000000
   2.000000000000000   0.005110260000000   0.003348560000000  
0.000101089000000

>> b = dlmread('testdata.dat')

b =

   1.000000000000000   0.005098440000000   0.003347980000000  
0.000100602000000
   2.000000000000000   0.005110260000000   0.003348560000000  
0.000101089000000

>> c = textread('testdata.dat')

c =

   1.000000000000000   0.005098440000000   0.003347980000000  
0.000100602000000
   2.000000000000000   0.005110260000000   0.003348560000000  
0.000101089000000

>> fid = fopen('testdata.dat');d = textscan(fid, '%f %f %f %f')

d =

  1×4 cell array

    {2×1 double}    {2×1 double}    {2×1 double}    {2×1 double}

>> d{4}

ans =

   1.0e-03 *

   0.100602000000000
   0.101089000000000

>> e = importdata('testdata.dat', ' ')

e =

  2×1 cell array

    {'1.00000 .509844D-02 .334798D-02 .100602D-03'}
    {'2.00000 .511026D-02 .334856D-02 .101089D-03'}

>> e = importdata('testdata2.dat', ' ')

e =

   1.000000000000000   0.005098440000000   0.003347980000000  
0.000100602000000
   2.000000000000000   0.005110260000000   0.003348560000000  
0.000101089000000

>> f = readtable('testdata.dat')

f =

  2×4 table

    Var1       Var2          Var3          Var4    
    ____    __________    __________    ___________

     1      0.00509844    0.00334798    0.000100602
     2      0.00511026    0.00334856    0.000101089


Not sure if I've missed any that should be tested.  So other than importdata,
all matlab data reading functions appear able to properly interpret the D.

in Octave 6.2.1 (hg id: 6fc423987872):

>> format long

>> a = load('testdata.dat')
error: load: failed to read matrix from file 'testdata.dat'

>> b = dlmread('testdata.dat')
b =

   1.000000000000000   0.509844000000000   0.334798000000000  
0.100602000000000
   2.000000000000000   0.511026000000000   0.334856000000000  
0.101089000000000

>> c = textread('testdata.dat')
c =

     1
   NaN
   NaN
   NaN
     2
   NaN
   NaN
   NaN

>> fid = fopen('testdata.dat');d = textscan(fid, '%f %f %f %f')
d =
{
  [1,1] =

     1
     2

  [1,2] =

     5.098440000000001e-03
     5.110260000000000e-03

  [1,3] =

     3.347980000000000e-03
     3.348560000000001e-03

  [1,4] =

     1.006020000000000e-04
     1.010890000000000e-04

}

>>
>> d{4}
ans =

   1.006020000000000e-04
   1.010890000000000e-04

>>  e = importdata('testdata.dat', ' ')
e =

   1.000000000000000   0.509844000000000   0.334798000000000  
0.100602000000000
   2.000000000000000   0.511026000000000   0.334856000000000  
0.101089000000000

>> f = readtable('testdata.dat')
error: 'readtable' undefined near line 1, column 1

The 'readtable' function is not yet implemented in Octave.


So, it looks like in octave only textscan is able to interpret a D exponential
separator.  




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60533>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]