<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Reading array from file.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8d46c97ea6/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8d46c97ea6/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/8d46c97ea6/</id><updated>2020-11-11T23:35:23.072000Z</updated><subtitle>Recent posts to Reading array from file.</subtitle><entry><title>Reading array from file.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8d46c97ea6/?limit=25#c965" rel="alternate"/><published>2020-11-11T23:35:23.072000Z</published><updated>2020-11-11T23:35:23.072000Z</updated><author><name>JAPIB</name><uri>https://forge.codesys.com/u/japib/</uri></author><id>https://forge.codesys.com4738928db1c2e2114d665d1f664102949cb57f33</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;J think you can't read file in only one time.&lt;br/&gt;
You have to read number by number, until you reach the end of file.&lt;br/&gt;
Depending the way  you used to write your file :&lt;br/&gt;
1°) If each number as the same format you can define what you want to read by the length of a number &lt;br/&gt;
2°) if you used a separation character, you can read character by character and concat characters into a string, until you reach the end of line or this special separating character.&lt;br/&gt;
3°) if you write your file with columns (Excel) you can read cell by cell, until you reach the end of the column or the end of line. And perhaps you need read character by character as in the second solution.&lt;/p&gt;
&lt;p&gt;In all cases, don't forget to convert the string you read into numerical value.&lt;/p&gt;
&lt;p&gt;BR&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Reading array from file.</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/8d46c97ea6/?limit=25#246d" rel="alternate"/><published>2020-11-11T09:39:26.484000Z</published><updated>2020-11-11T09:39:26.484000Z</updated><author><name>jsth17</name><uri>https://forge.codesys.com/u/jsth17/</uri></author><id>https://forge.codesys.com0eab978980010e1e5f4ffe89ca7384dd9a523e36</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have been trying to read an array of numbers in a "txt" file from a SD-card with the Sysfile library. The program seems to recognize the file and read some data. The problem is that the number of datapoints is off, and the values make no sense compared with the input file (2.52E-9 instead of the input 100.1).&lt;br/&gt;
The code i use is seen below.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;Trajectory_read&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
    &lt;span class="nt"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;UINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;BOOL&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;ref_xp_buffer&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;ARRAY&lt;/span&gt; &lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="nx"&gt;..20000&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;REAL&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;filename_trajectory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="s1"&gt;'trajectory2.txt'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;file_handle&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;sysFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RTS_IEC_HANDLE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;result_trajectory&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;POINTER&lt;/span&gt; &lt;span class="nt"&gt;TO&lt;/span&gt; &lt;span class="nt"&gt;sysFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RTS_IEC_RESULT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
    &lt;span class="nt"&gt;Read_function&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;__XWORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;Close_function&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;UDINT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;nohandle&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;BOOL&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;FALSE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;test&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;POINTER&lt;/span&gt; &lt;span class="nt"&gt;TO&lt;/span&gt; &lt;span class="nt"&gt;REAL&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;ref_xp_buffer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="nt"&gt;file_handle&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;sysFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SysFileOpen&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;szFile&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;filename_trajectory&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;am&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;AM_READ&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;pResult&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;result_trajectory&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;Read_function&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;sysFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SysFileRead&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;hFile&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;file_handle&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;pbyBuffer&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;test&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;ulSize&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;10001&lt;/span&gt; &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;pResult&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;result_trajectory&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;Close_function&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;sysFile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SysFileClose&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;hFile&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;file_handle&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The file contains an array of 10000 datapoint, and i have tried seperating the the datapoint by "," and "." and " ". I have also tried making it all in one column instead of a row. And i still can't get it to work&lt;/p&gt;
&lt;p&gt;Thanks in advance&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>