Show Posts
Pages: [1]
1  Using Arduino / Storage / Re: how to read long csv and save it value to matrix ? on: April 22, 2012, 05:31:14 am
what i confused here is " how do i use delimiter inside ?"

Code:
while (sdin.getline(buffer, line_buffer_size, '\n') || sdin.gcount())
here as i know, it read every line

and if i use modify the code
Code:

while (sdin.getline(buffer, line_buffer_size, '\n') || sdin.gcount()) {
        while (sdin.getline(buffer, line_buffer_size, '\,') || sdin.gcount()){
       ... code here }
}// end of line

(1) from above code : first line loop till the '\n' but i don't know what  object to hold that string for limiter  ?
( 2 ) do i have to write in another csv and read it ?

( 3 ) or please have a code example ?

is it look like this ?

what i confused is what object do i have to hold the buffer ? for get the variable
2  Using Arduino / Storage / Re: Storing large amount of integers? on: April 20, 2012, 11:58:34 pm
i'm want to use 16 bit int , number of integers : 256*256 , row*line

The csv is 2d array And want to read only 1 line for calculation , so only 256
3  Using Arduino / Storage / Re: Storing large amount of integers? on: April 20, 2012, 09:51:39 am
How do i read csv from sdcard ? as i know, it read certain pattern only

something look like this ,the modified code from sdfatlib :

Code:
sdin >> f1 >> c1

for 1,2,3,...,N

but it read only 1,2,3,... but in the last number it failed

do i have to read through byte , gain it to char[number of array] then convert from array of char to int
4  Using Arduino / Storage / how to read long csv and save it value to matrix ? on: April 18, 2012, 03:38:19 am
my question ( explanation below ):
#1. How do i effectively read long csv using sdfatlib
#2. is there any solution to stdio.h for feof ( read whole file ), fscanf ( change reading data to integer for me)

here's my pseudocode :
#1. know how much integer in csv
#2. using malloc to provide 16-bit array with csv integer length
#3. get every integer from csv to array
#end return array
below i add csv that i want to read in my arduino uno ( lena.csv )? , any guidance here ?

i tried to modified readCSV example from sdfatlib http://code.google.com/p/sdfatlib/


this is what i changed :

Code:
void readFile() {
  //int nilai;
  long lg;
  float f1, f2;
  char c1, c2; // ;
  int jumlahPix=0;
  
  // open input file
  ifstream sdin(fileName);
  
  // check for open error
  if (!sdin.is_open()) error("open");
  
  // read until input fails
  // while (sdin >> lg >> c1 >> f1 >> c2 >> f2) {
    while (sdin >> f1 >> c1 ) {
    
    // error in line if not commas
    if (c1 != ',' ) error("comma"); // || c2 != ',') error("comma");
    
    // print in six character wide columns
    cout << setw(6) << f1 << endl;
    
    jumlahPix++;
  }
  char c3 = 10;
  while (sdin >> f1){
  // print in six character wide columns
    cout << setw(6) << f1 << endl;
    
    jumlahPix++;
  }
  // Error in an input line if file is not at EOF.
  if (!sdin.eof()) error("readFile");
  // Tampilkan jumlah pixel
  cout << "jumlah pixel : " << jumlahPix << endl;
}
//------------------------------------------------------------------------------
// write test file
void writeFile() {

  // create or open and truncate output file
  ofstream sdout(fileName);
  
  // write file from string stored in flash
  sdout << pstr(
    "1,2.3,4.5,"
    "6,7.8,9.0,"
    "9,8.7,6.5,"
    "-4,-3.2,-1\n") << flush;

  // check for any errors
  if (!sdout) error("writeFile");
  
  // file is closed by destructor when it goes out of scope.
}

it is what the result :

Quote
 1.00
  2.30
  4.50
  6.00
  7.80
  9.00
  9.00
  8.70
  6.50
 -4.00
 -3.20
jumlah pixel : 11 // the result in this line should be 12
Done


if the format look like the example :
Quote
%f,%f,%f
<-- it is what i mean complete fix format

so the problem :

Quote
%f,
, continously till value of -1, but it doesn't get proper answer cause of none fixed format


what i thought is when we provide  the complete fix format is easy for short length csv ?
but how to apply it in long length csv ? smiley-sad

and heres

Code:
FILE *fp = fopen(filename, "rb");
  if (fp == NULL) {
    fprintf(stderr, "Can't open input file\n");
    exit(1);
  }
  int value;
  //first estimate no of pixels:
  int NoPix=0;
  while (!feof(fp)) {fscanf(fp,"%i ",&value);NoPix++;}
what should be like in c programming language, in the last line it skip white space and save the value as integer

and i had search another solution, like http://www.parashift.com/c++-faq-lite/input-output.html

in the section [15.12] How can I open a stream in binary mode?, but when i done i get char which cannot be processed as integer

and the last one, i read http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga67bae1ad3af79809fd770be392f90e21
but it didn't clearly understand by me
Pages: [1]