SD card value extraction

Hi, I’m very new to programming. Got stuck trying to extract values from a data set from an SD card.

data looks like this:

Date (D/M/YYYY),Time (H:MM:SS),Topocentric zenith angle,Top. azimuth angle (westward from S),Local sunrise time,Local sunset time
23/3/2021,0:00:00,125.340051,172.923232,6.253369,18.528729
23/3/2021,0:05:00,125.420558,174.453236,6.253369,18.528729
23/3/2021,0:10:00,125.481254,175.985957,6.253369,18.528729
...
20/4/2021,17:50:00,76.765365,92.059922,5.154649,19.374483
...

I want to find the correct line in the set given any given date and time (I’ll try to hook it up to DS3231 real time clock, later on, to get date and time reading) then extract the other 4 values as variables (preferably integers rather than float).

From what I read I need to use strtok then parse and save the variables however, I can’t seem to wrap my head around the proper usage of this function.

I found a code to a similar problem, but lack the skill to adjust it to suit my needs.

// SD card read/write

#include <SPI.h>
#include <SD.h>
File myFile;
const int chipSelect = 53;
 // WRITE DATA
int rotDegree = 4;
int rotDirec = 1;
int tilDegree = 4;
int tilDirec = 2;
int travPower = 90;
int travDirec = 1;
int OperateMotors = 50;
int DelayMotors = 30;
int bracket = 3;
int intervalometerSET = 1;
int EVComp = 2;
int Camera_Make = 1;
  //READ DATA
int rotDegreeR;
int rotDirecR;
int tilDegreeR;
int tilDirecR;
int travPowerR ;
int travDirecR;
int OperateMotorsR;
int DelayMotorsR;
int bracketR;
int intervalometerSETR;
int EVCompR;
int Camera_MakeR;

void setup()
{
// Open serial communications and wait for port to open:
 Serial.begin(9600);
  while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }


 Serial.print("Initializing SD card...");
  pinMode(SS, OUTPUT);
 
 if (!SD.begin(chipSelect)) {
   Serial.println("initialization failed!");
   return;
 }
 Serial.println("initialization done.");
 
 SD.remove("test.txt") ;                                             // if file is present delete it before writing new data
 
 myFile = SD.open("test.txt", FILE_WRITE);                           // open the file.
 
 if (myFile) {
   Serial.print("Writing to test.txt...");                           // if the file opened okay, write to it:
   
   myFile.print("rotDegree = ");myFile.println(rotDegree);
   myFile.print("rotDirec = ");myFile.println(rotDirec);
   myFile.print("tilDegree = ");myFile.println(tilDegree);
   myFile.print("tilDirec = ");myFile.println(tilDirec);
   myFile.print("travPower = ");myFile.println(travPower);
   myFile.print("travDirec = ");myFile.println(travDirec);
   myFile.print("OperateMotors = ");myFile.println(OperateMotors);
   myFile.print("DelayMotors = ");myFile.println(DelayMotors);
   myFile.print("bracket = ");myFile.println(bracket);
   myFile.print("intervalometerSET = ");myFile.println(intervalometerSET);
   myFile.print("EVComp = ");myFile.println(EVComp);
   myFile.print("Camera_Make = ");myFile.println(Camera_Make);
     
   myFile.close();  Serial.println("done.");                       // close the file:
 } else {
    Serial.println("error opening test.txt");                      // if the file didn't open, print an error:
 }
 
// re-open the file for reading:
 myFile = SD.open("test.txt");
 if (myFile) {
   Serial.println("test.txt:");
   
// read from the file
char buffer[40]; // May need to be a bit bigger if you have long names
   byte index = 0;
   while (myFile.available())
   {
    char c = myFile.read();
       if(c == '\n' || c == '\r') // Test for <cr> and <lf>
       {
           parseAndSave(buffer);
           index = 0;
           buffer[index] = '\0'; // Keep buffer NULL terminated
       }
       else
       {
           buffer[index++] = c;
           buffer[index] = '\0'; // Keep buffer NULL terminated
       }
   }

   myFile.close();                                                 // close the file:
 } else {
   Serial.println("error opening test.txt");                // if the file didn't open, print an error:
 }

Serial.print("Rotation degrees ");Serial.println(rotDegreeR);
Serial.print("Rotation direction ");Serial.println(rotDirecR);
Serial.print("Tilt degrees ");Serial.println(tilDegreeR);
Serial.print("Tilt direction ");Serial.println(tilDirecR);
Serial.print("Traverser Power ");Serial.println(travPowerR) ;
Serial.print("Traverser Direction ");Serial.println(travDirecR);
Serial.print("Operate Motors for ");Serial.println(OperateMotorsR);
Serial.print("Pause Motors for ");Serial.println(DelayMotorsR);
Serial.print("Bracketing ");Serial.println(bracketR);
Serial.print("Intervalometer ");Serial.println(intervalometerSETR);
Serial.print("EV Compensator ");Serial.println(EVCompR);
Serial.print("Camera Make ");Serial.println(Camera_MakeR);

}
void loop()
{
  // main code and function calls
}
void parseAndSave(char *buff)
{
   char *name = strtok(buff, " =");
   if(name)
   {
       char *junk = strtok(NULL, " ");
       if(junk)
       {
           char *valu = strtok(NULL, " ");
           if(valu)
           {
               int val = atoi(valu);
               if(strcmp(name, "rotDegree") == 0)
               {
                   rotDegreeR = val;
               }
               if(strcmp(name, "rotDirec") == 0)
               {
                   rotDirecR = val;
               }
               if(strcmp(name, "tilDegree") == 0)
               {
                   tilDegreeR = val;
               }
               if(strcmp(name, "tilDirec") == 0)
               {
                   tilDirecR = val;
               }
               if(strcmp(name, "travPower") == 0)
               {
                   travPowerR = val;
               }
               if(strcmp(name, "travDirec") == 0)
               {
                   travDirecR = val;
               }
               if(strcmp(name, "OperateMotors") == 0)
               {
                   OperateMotorsR = val;
               }
               if(strcmp(name, "DelayMotors") == 0)
               {
                   DelayMotorsR = val;
               }
               if(strcmp(name, "bracket") == 0)
               {
                   bracketR = val;
               }
               if(strcmp(name, "intervalometerSET") == 0)
               {
                   intervalometerSETR = val;
               }
               if(strcmp(name, "EVComp") == 0)
               {
                   EVCompR = val;
               }
               else if(strcmp(name, "Camera_Make") == 0)
               {
                   Camera_MakeR = val;
               }
           }
        }
     }
}

could anyone please help me make the required adjustments?

Also, I’m using Elgoo mega.

Here's a very simple example of how the strtok function works : C library function - strtok() - Tutorialspoint

.