SOLVED: Mismatch between declarations?

I´ve spent hours to try to find whats wrong here, with no success. I need help.
The sketch is supposed to give a Setpoint value in oC as input to a PID-calculation. The Setpoint is solely time dependent - its a burning curve for a pottery kiln. The different burning curves characteristics are stored on a mSD-card, with temperatures, times and slopes of the curve. All time variables are in millis. A typical file looks like:

0,0,21600000,650,25200000,960,26100000,960,27000000,20,27600000,0,30093,86110,0,-1044444,-33333\r

The maths I want it to do is fairly simple - just calculate Setpoint by a straight line equation:
Setpoint = dTemp/dTime * time + intersect.

All logics seems to work ok, with the exception of this straight line equation on row 99. Whats wrong?

/*
Calculation of setpoint temperature (C) for time values when thermocouples will be read.
 Linear extrapolation from temperature vs time retrieved from maths on SetPoint-curves caracteristics stored on mSD.
 Logfile created on mSD with time and Setpoint values.
 SetPoint temperature is regarded as input to PID calculations.
 Hardware is Arduino UNO and Sparkfun mSD card. 
 */

#include <SD.h>
#include <ARDUINO.h>

//Declarations
char* BurnCurve[]={
  "GLABEND.TXT", "RAWGLAZ.TXT", "DRYING_.TXT", "STOWARE.TXT", "STOGLAZ.TXT", "CLAGLAZ.TXT", "BISCUIT.TXT"};
int tempArray[6], time0, temp, incomingByte, Wait=0; 
long time, time1, timeDiff, timeDiffmin, timeArray[6], Setpoint;
float konst, konstArray[6];


void setup()
//Open serial comm. & set comm. channels
{
  Serial.begin(9600);
  while (!Serial)
  {  
  }
  pinMode(10,OUTPUT);
  if(!SD.begin(8))
  {
    Serial.println("initialization failed!");
    return;
  }
  // Instructions to choose right Burn curve
  for (int i=0; i<7; i++) 
  {     
    Serial.print(BurnCurve[i]);
    Serial.print(" - Choose ");
    Serial.print(i + 1);
    Serial.println(" for this curve");       
  }
  while(Serial.available()==0)
    ;
  {
    // read the incoming byte:
    incomingByte = Serial.read();
    incomingByte = incomingByte - 49;
    Serial.println("");
    Serial.print("Burn Curve is:  ");
    Serial.println(BurnCurve[incomingByte]);

    File SPFile = SD.open(BurnCurve[incomingByte]);
    Serial.println("");
    if (SPFile) 
    {
      for (int i=0; i<6; i++)
      {
        time = SPFile.parseFloat();
        temp = SPFile.parseFloat();
        tempArray[i] = temp;
        timeArray[i] = time;
        Serial.println("");
        Serial.print(timeArray[i]);
        Serial.print("  ");
        Serial.println(tempArray[i]);
        Serial.println("  ");
      }
      for (int i=1; i<6; i++)
      {
        konst = SPFile.parseFloat();
        konstArray[i] = konst*1E-9;
        Serial.println(konstArray[i],9);
      }   
    }
    else
    {
      // if the file failed to open:
      Serial.println("error opening file");
    }
    // close file:
    SPFile.close();   
  }
  Serial.println("");
  Serial.println("Removing loggfile...");
  SD.remove("datalog.txt");
  Serial.println(" START BURNING! ");
  time0 = millis();
}
void loop ()
{
  delay(1000);    //New setpoint each sec
  long time1 = 100 * millis(); //get current time in ms*100
  long timeDiff = time1 - time0; //Time elapsed since start
  long timeDiffmin = (timeDiff/60000);//Time elapsed in minutes 
  int i = GetIndex(timeDiff); //Calculate current index based on time

  if(i<=5)
  {
    long timeDiffmin = (timeDiff/60000);
    Setpoint = (long)(konstArray[i],9) * ((long)timeDiff - (long)timeArray[i - 1]) + tempArray[i - 1];
    Serial.println ("");
    Serial.print (i);
    Serial.print ("   ");
    Serial.print (tempArray[i - 1]);
    Serial.print ("   ");
    Serial.print (konstArray[i],9);
    Serial.print ("   ");
    Serial.print (timeDiff);
    Serial.print ("   ");
    Serial.print (timeArray[i - 1]);
    Serial.print ("  ");
    Serial.print (Setpoint);
    Serial.print ("  ");
    Serial.println (timeDiffmin);

    // This is where reading of Thermocouples should be done.

    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    if (dataFile) {  
      dataFile.println ("");
      dataFile.print (i);
      dataFile.print ("   ");
      dataFile.print (tempArray[i - 1]);
      dataFile.print ("   ");
      dataFile.print (konstArray[i],9);
      dataFile.print ("   ");
      dataFile.print (timeDiff);
      dataFile.print ("   ");
      dataFile.print (timeArray[i - 1]);
      dataFile.print ("  ");
      dataFile.print (Setpoint);
      dataFile.print ("  ");
      dataFile.println (timeDiffmin);
      dataFile.close();     
    }  
    else {
      Serial.println("error opening datalog.txt");
    } 

  }
  else
  {
    Serial.println("Done!");
    Wait = 1;
  }
  while(Wait==1)
    ;
}
int GetIndex(long Timediff) //Get index from time difference since start
{
  for(int i = 0; i<6; i++)
  {
    if( (long) Timediff < timeArray[i])
      return i;
  }
  return 6;
}

Bisquit_overwiev.doc (16.5 KB)

Setpoint = (long)(konstArray[i],9) * ((long)timeDiff - (long)timeArray[i - 1]) + tempArray[i - 1];

What is the purpose of the comma and 9 after konstArray*?*

It of course, is the comma operator which will dutifully access the array, discard the result and then return the 9.

That 9 was an attempt to use all significant content of konstArray. :slight_smile:

And without the 9, I just recieving 0 , 0, 0, 0 ...instead of nice, long numbers like 3588156, 4516056......

You're mixing floats, longs, and ints in this equation:

    Setpoint = (long)(konstArray[i],9) * ((long)timeDiff - (long)timeArray[i - 1]) + tempArray[i - 1];

Does this form make any difference?

    Setpoint = (long)((long)konstArray[i]) * ((long)timeDiff - (long)timeArray[i - 1]) +(long)tempArray[i - 1];

Now it seems as Setpoint always equals tempArray[i-1]; konstArray_*(timeDiff-timeArray[i-1]) =0. For all time values._

So casting only these values that are non long to long gives the result:

Setpoint = (long)konstArray[i]*(timeDiff - timeArray[i - 1])+(long)tempArray[i - 1];

Am I correct?
And
(long)konstArray[i]*(timeDiff - timeArray[i - 1])
Always equals 0, even if konstArray[] doesnt equal 0 and timeDiff is different from timeArray[i - 1]?
I dont know what values are storred under konstArray[], but if they are smaller than 1 (like 0.5) you will always get 0, because long cast will cut whats after 0.

Edit:
Ok, now I read again and saw: konstArray[] = konst*1E-9;
That probably means Im correct - u store values smaller than 1 and long cast rounds it to 0

And finally it works OK! Here´s the correct expression for Setpoint:

Setpoint = (long)((konstArray[i]) * ((long)timeDiff - (long)timeArray[i - 1]) +(long)tempArray[i - 1]);

The difference between those last 2 Setpoint expression is a (long) and a ).
So yes Disty, your on the line. Keep konstArray[ ] float within the expression, and transform the whole monty to (long), then it works. Thanks a lot all of you!!

Actually I think you dont need long casts. How about:

Setpoint = konstArray[i]*(timeDiff -timeArray[i - 1])+tempArray[i - 1]

Disty - why make it so easy when you can complicate it beyond madness?
I have been trying to figure out what kind of expression that is correct, so in the end I just never saw the simplicity of your suggestion. It workas well.

Thank you very much!