Cl_Fl_0_2000__JRP_v1.0


Calc Cl Fl parameters from 0-2000 PAR
// CALCULATIONS FOR PROTON MOTIVE FORCE VIA ECS PORTION OF THE TRACE
//----------------------------

var output = {};
var spad;
var data = json.data_raw;
var vhplus;
var tau;
var ECSt;
var quality_flag = 0;
var i = 0;
var j = 0;
var h = 0;
var k = 0;
var smooth1 = data.slice(300,600);
var smooth0 = data.slice(300,600);

///*

// CALCULATIONS FOR PHI2 PORTION OF THE TRACE
//----------------------------

// calculate the ir baseline for LED 3 which is used as the measuring light.  This subtract IR generated by the LED from the IR generated by the plant
//----------------------------
var sample_cal = json.detector_read1;

//var shinyness = (sample_cal-json.recall["ir_baseline_yint[5]"])/json.recall["ir_baseline_slope[5]"]; // where 0 is dull black electrical tape, and 1 is shiny aluminum
//var baseline = json.recall["ir_baseline_slope[3]"]*shinyness+json.recall["ir_baseline_yint[3]"];

//if (!baseline || !json.recall["ir_baseline_yint[5]"] || sample_cal == 65535) {						// if it hasn't been calibrated or there's an error or it's maxed, set baseline == 0
 // baseline = 0;
//}
baseline = 0;

/*
output["shinyness"] = shinyness;
output["baseline"] = baseline;
output["recall led slope"] = json.recall["ir_baseline_slope[3]"];
output["recall led yint"] = json.recall["ir_baseline_yint[3]"];
output["recall cal slope"] = json.recall["ir_baseline_slope[5]"];
output["recall cal yint"] = json.recall["ir_baseline_yint[5]"];
output["sample led"] = json.detector_read1;
*/

//var sample_cal = MathMEAN(data.slice(2,18));

var inverse_intensity = [1/4500,1/4050,1/3600,1/3150];

//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_0  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_0_start = 0; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_0_Prime, 3 Fm_0_Prime steps, and Fs_0 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_0 = MathMEAN(data.slice(ps2_0_start + 1,ps2_0_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_0_std = MathSTDEV(data.slice(ps2_0_start + 1,ps2_0_start + 4)); // create standard deviation for this value for error checking

var sat_0_vals = data.slice(ps2_0_start + 25,ps2_0_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_0_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_0_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_0_vals = data.slice(ps2_0_start + 84,ps2_0_start + 110).sort();  // sort the saturating light values from low to high
var Fm_0_P_end = MathMEAN(sat_0_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_0_P_end_std = MathSTDEV(sat_0_vals); // create standard deviation for this value for error checking

sat_0_vals = data.slice(ps2_0_start + 52,ps2_0_start + 60).sort();  // sort the saturating light values from low to high
var Fm_0_P_step1 = MathMEAN(sat_0_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_0_P_step1_std = MathSTDEV(sat_0_vals); // create standard deviation for this value for error checking

sat_0_vals = data.slice(ps2_0_start + 62,ps2_0_start + 70).sort();  // sort the saturating light values from low to high
var Fm_0_P_step2 = MathMEAN(sat_0_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_0_P_step2_std = MathSTDEV(sat_0_vals); // create standard deviation for this value for error checking

sat_0_vals = data.slice(ps2_0_start + 72,ps2_0_start + 80).sort();  // sort the saturating light values from low to high
var Fm_0_P_step3 = MathMEAN(sat_0_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_0_P_step3_std = MathSTDEV(sat_0_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_0_Prime_0_values = json.data_raw.slice(ps2_0_start + 160,ps2_0_start + 270).sort();
var Fo_0_Prime = MathMEAN(Fo_0_Prime_0_values.slice(5,10)) - baseline;
var Fo_0_Prime_std = MathSTDEV(Fo_0_Prime_0_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_0_Prime using multi-phase flash
// ----------------------------
var reg_0 = MathLINREG(inverse_intensity, [A0FmP,Fm_0_P_step1,Fm_0_P_step2,Fm_0_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_0_fm_noMPF = (A0FmP-Fs_0)/A0FmP;
var fv_0_fm_MPF = (reg_0.b-Fs_0)/reg_0.b;


// Calculate NPQt,PhiNPQ_0, PhiNO_0, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_0_MPF = (4.88 / ((reg_0.b / Fo_0_Prime) -1) )-1;
var npqt_0_noMPF = (4.88 / ((A0FmP / Fo_0_Prime) -1) )-1;
var qL_0_MPF = ((reg_0.b - Fs_0)*Fo_0_Prime)/((reg_0.b-Fo_0_Prime)*Fs_0);
var qL_0_noMPF = ((A0FmP - Fs_0)*Fo_0_Prime)/((A0FmP-Fo_0_Prime)*Fs_0);
var PhiNO_0_MPF = 1/(npqt_0_MPF + 1 + qL_0_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_0_noMPF = 1/(npqt_0_noMPF + 1 + qL_0_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_0_MPF = 1-fv_0_fm_MPF-PhiNO_0_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_0_noMPF = 1-fv_0_fm_noMPF-PhiNO_0_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_0_MPF = (reg_0.b - Fs_0)/(reg_0.b - Fo_0_Prime);
var qP_0_noMPF = (Fm_0_Prime - Fs_0)/(Fm_0_Prime - Fo_0_Prime);
var FvP_Fm_0_P_MPF = (reg_0.b-Fo_0_Prime)/reg_0.b;
var FvP_Fm_0_P_noMPF = (A0FmP-Fo_0_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_0_fm = fv_0_fm_MPF;
var npqt_0  = npqt_0_MPF;
var PhiNO_0 = PhiNO_0_MPF;
var PhiNPQ_0 = PhiNPQ_0_MPF;
var qL_0 = qL_0_MPF;
var Fm_0_Prime = reg_0.b;
var qP_0 = qP_0_MPF;
var FvP_Fm_0_P = FvP_Fm_0_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;


//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_100  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_100_start = 280; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_100_Prime, 3 Fm_100_Prime steps, and Fs_100 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_100 = MathMEAN(data.slice(ps2_100_start + 1,ps2_100_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_100_std = MathSTDEV(data.slice(ps2_100_start + 1,ps2_100_start + 4)); // create standard deviation for this value for error checking

var sat_100_vals = data.slice(ps2_100_start + 25,ps2_100_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_100_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_100_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_100_vals = data.slice(ps2_100_start + 84,ps2_100_start + 110).sort();  // sort the saturating light values from low to high
var Fm_100_P_end = MathMEAN(sat_100_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_100_P_end_std = MathSTDEV(sat_100_vals); // create standard deviation for this value for error checking

sat_100_vals = data.slice(ps2_100_start + 52,ps2_100_start + 60).sort();  // sort the saturating light values from low to high
var Fm_100_P_step1 = MathMEAN(sat_100_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_100_P_step1_std = MathSTDEV(sat_100_vals); // create standard deviation for this value for error checking

sat_100_vals = data.slice(ps2_100_start + 62,ps2_100_start + 70).sort();  // sort the saturating light values from low to high
var Fm_100_P_step2 = MathMEAN(sat_100_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_100_P_step2_std = MathSTDEV(sat_100_vals); // create standard deviation for this value for error checking

sat_100_vals = data.slice(ps2_100_start + 72,ps2_100_start + 80).sort();  // sort the saturating light values from low to high
var Fm_100_P_step3 = MathMEAN(sat_100_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_100_P_step3_std = MathSTDEV(sat_100_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_100_Prime_100_values = json.data_raw.slice(ps2_100_start + 160,ps2_100_start + 270).sort();
var Fo_100_Prime = MathMEAN(Fo_100_Prime_100_values.slice(5,10)) - baseline;
var Fo_100_Prime_std = MathSTDEV(Fo_100_Prime_100_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_100_Prime using multi-phase flash
// ----------------------------
var reg_100 = MathLINREG(inverse_intensity, [A0FmP,Fm_100_P_step1,Fm_100_P_step2,Fm_100_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_100_fm_noMPF = (A0FmP-Fs_100)/A0FmP;
var fv_100_fm_MPF = (reg_100.b-Fs_100)/reg_100.b;


// Calculate NPQt,PhiNPQ_100, PhiNO_100, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_100_MPF = (4.88 / ((reg_100.b / Fo_100_Prime) -1) )-1;
var npqt_100_noMPF = (4.88 / ((A0FmP / Fo_100_Prime) -1) )-1;
var qL_100_MPF = ((reg_100.b - Fs_100)*Fo_100_Prime)/((reg_100.b-Fo_100_Prime)*Fs_100);
var qL_100_noMPF = ((A0FmP - Fs_100)*Fo_100_Prime)/((A0FmP-Fo_100_Prime)*Fs_100);
var PhiNO_100_MPF = 1/(npqt_100_MPF + 1 + qL_100_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_100_noMPF = 1/(npqt_100_noMPF + 1 + qL_100_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_100_MPF = 1-fv_100_fm_MPF-PhiNO_100_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_100_noMPF = 1-fv_100_fm_noMPF-PhiNO_100_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_100_MPF = (reg_100.b - Fs_100)/(reg_100.b - Fo_100_Prime);
var qP_100_noMPF = (Fm_100_Prime - Fs_100)/(Fm_100_Prime - Fo_100_Prime);
var FvP_Fm_100_P_MPF = (reg_100.b-Fo_100_Prime)/reg_100.b;
var FvP_Fm_100_P_noMPF = (A0FmP-Fo_100_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_100_fm = fv_100_fm_MPF;
var npqt_100  = npqt_100_MPF;
var PhiNO_100 = PhiNO_100_MPF;
var PhiNPQ_100 = PhiNPQ_100_MPF;
var qL_100 = qL_100_MPF;
var Fm_100_Prime = reg_100.b;
var qP_100 = qP_100_MPF;
var FvP_Fm_100_P = FvP_Fm_100_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_250  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_250_start = 560; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_250_Prime, 3 Fm_250_Prime steps, and Fs_250 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_250 = MathMEAN(data.slice(ps2_250_start + 1,ps2_250_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_250_std = MathSTDEV(data.slice(ps2_250_start + 1,ps2_250_start + 4)); // create standard deviation for this value for error checking

var sat_250_vals = data.slice(ps2_250_start + 25,ps2_250_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_250_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_250_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_250_vals = data.slice(ps2_250_start + 84,ps2_250_start + 110).sort();  // sort the saturating light values from low to high
var Fm_250_P_end = MathMEAN(sat_250_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_250_P_end_std = MathSTDEV(sat_250_vals); // create standard deviation for this value for error checking

sat_250_vals = data.slice(ps2_250_start + 52,ps2_250_start + 60).sort();  // sort the saturating light values from low to high
var Fm_250_P_step1 = MathMEAN(sat_250_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_250_P_step1_std = MathSTDEV(sat_250_vals); // create standard deviation for this value for error checking

sat_250_vals = data.slice(ps2_250_start + 62,ps2_250_start + 70).sort();  // sort the saturating light values from low to high
var Fm_250_P_step2 = MathMEAN(sat_250_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_250_P_step2_std = MathSTDEV(sat_250_vals); // create standard deviation for this value for error checking

sat_250_vals = data.slice(ps2_250_start + 72,ps2_250_start + 80).sort();  // sort the saturating light values from low to high
var Fm_250_P_step3 = MathMEAN(sat_250_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_250_P_step3_std = MathSTDEV(sat_250_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_250_Prime_250_values = json.data_raw.slice(ps2_250_start + 160,ps2_250_start + 270).sort();
var Fo_250_Prime = MathMEAN(Fo_250_Prime_250_values.slice(5,10)) - baseline;
var Fo_250_Prime_std = MathSTDEV(Fo_250_Prime_250_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_250_Prime using multi-phase flash
// ----------------------------
var reg_250 = MathLINREG(inverse_intensity, [A0FmP,Fm_250_P_step1,Fm_250_P_step2,Fm_250_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_250_fm_noMPF = (A0FmP-Fs_250)/A0FmP;
var fv_250_fm_MPF = (reg_250.b-Fs_250)/reg_250.b;


// Calculate NPQt,PhiNPQ_250, PhiNO_250, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_250_MPF = (4.88 / ((reg_250.b / Fo_250_Prime) -1) )-1;
var npqt_250_noMPF = (4.88 / ((A0FmP / Fo_250_Prime) -1) )-1;
var qL_250_MPF = ((reg_250.b - Fs_250)*Fo_250_Prime)/((reg_250.b-Fo_250_Prime)*Fs_250);
var qL_250_noMPF = ((A0FmP - Fs_250)*Fo_250_Prime)/((A0FmP-Fo_250_Prime)*Fs_250);
var PhiNO_250_MPF = 1/(npqt_250_MPF + 1 + qL_250_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_250_noMPF = 1/(npqt_250_noMPF + 1 + qL_250_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_250_MPF = 1-fv_250_fm_MPF-PhiNO_250_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_250_noMPF = 1-fv_250_fm_noMPF-PhiNO_250_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_250_MPF = (reg_250.b - Fs_250)/(reg_250.b - Fo_250_Prime);
var qP_250_noMPF = (Fm_250_Prime - Fs_250)/(Fm_250_Prime - Fo_250_Prime);
var FvP_Fm_250_P_MPF = (reg_250.b-Fo_250_Prime)/reg_250.b;
var FvP_Fm_250_P_noMPF = (A0FmP-Fo_250_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_250_fm = fv_250_fm_MPF;
var npqt_250  = npqt_250_MPF;
var PhiNO_250 = PhiNO_250_MPF;
var PhiNPQ_250 = PhiNPQ_250_MPF;
var qL_250 = qL_250_MPF;
var Fm_250_Prime = reg_250.b;
var qP_250 = qP_250_MPF;
var FvP_Fm_250_P = FvP_Fm_250_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_500  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_500_start = 840; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_500_Prime, 3 Fm_500_Prime steps, and Fs_500 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_500 = MathMEAN(data.slice(ps2_500_start + 1,ps2_500_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_500_std = MathSTDEV(data.slice(ps2_500_start + 1,ps2_500_start + 4)); // create standard deviation for this value for error checking

var sat_500_vals = data.slice(ps2_500_start + 25,ps2_500_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_500_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_500_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_500_vals = data.slice(ps2_500_start + 84,ps2_500_start + 110).sort();  // sort the saturating light values from low to high
var Fm_500_P_end = MathMEAN(sat_500_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_500_P_end_std = MathSTDEV(sat_500_vals); // create standard deviation for this value for error checking

sat_500_vals = data.slice(ps2_500_start + 52,ps2_500_start + 60).sort();  // sort the saturating light values from low to high
var Fm_500_P_step1 = MathMEAN(sat_500_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_500_P_step1_std = MathSTDEV(sat_500_vals); // create standard deviation for this value for error checking

sat_500_vals = data.slice(ps2_500_start + 62,ps2_500_start + 70).sort();  // sort the saturating light values from low to high
var Fm_500_P_step2 = MathMEAN(sat_500_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_500_P_step2_std = MathSTDEV(sat_500_vals); // create standard deviation for this value for error checking

sat_500_vals = data.slice(ps2_500_start + 72,ps2_500_start + 80).sort();  // sort the saturating light values from low to high
var Fm_500_P_step3 = MathMEAN(sat_500_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_500_P_step3_std = MathSTDEV(sat_500_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_500_Prime_500_values = json.data_raw.slice(ps2_500_start + 160,ps2_500_start + 270).sort();
var Fo_500_Prime = MathMEAN(Fo_500_Prime_500_values.slice(5,10)) - baseline;
var Fo_500_Prime_std = MathSTDEV(Fo_500_Prime_500_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_500_Prime using multi-phase flash
// ----------------------------
var reg_500 = MathLINREG(inverse_intensity, [A0FmP,Fm_500_P_step1,Fm_500_P_step2,Fm_500_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_500_fm_noMPF = (A0FmP-Fs_500)/A0FmP;
var fv_500_fm_MPF = (reg_500.b-Fs_500)/reg_500.b;


// Calculate NPQt,PhiNPQ_500, PhiNO_500, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_500_MPF = (4.88 / ((reg_500.b / Fo_500_Prime) -1) )-1;
var npqt_500_noMPF = (4.88 / ((A0FmP / Fo_500_Prime) -1) )-1;
var qL_500_MPF = ((reg_500.b - Fs_500)*Fo_500_Prime)/((reg_500.b-Fo_500_Prime)*Fs_500);
var qL_500_noMPF = ((A0FmP - Fs_500)*Fo_500_Prime)/((A0FmP-Fo_500_Prime)*Fs_500);
var PhiNO_500_MPF = 1/(npqt_500_MPF + 1 + qL_500_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_500_noMPF = 1/(npqt_500_noMPF + 1 + qL_500_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_500_MPF = 1-fv_500_fm_MPF-PhiNO_500_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_500_noMPF = 1-fv_500_fm_noMPF-PhiNO_500_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_500_MPF = (reg_500.b - Fs_500)/(reg_500.b - Fo_500_Prime);
var qP_500_noMPF = (Fm_500_Prime - Fs_500)/(Fm_500_Prime - Fo_500_Prime);
var FvP_Fm_500_P_MPF = (reg_500.b-Fo_500_Prime)/reg_500.b;
var FvP_Fm_500_P_noMPF = (A0FmP-Fo_500_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_500_fm = fv_500_fm_MPF;
var npqt_500  = npqt_500_MPF;
var PhiNO_500 = PhiNO_500_MPF;
var PhiNPQ_500 = PhiNPQ_500_MPF;
var qL_500 = qL_500_MPF;
var Fm_500_Prime = reg_500.b;
var qP_500 = qP_500_MPF;
var FvP_Fm_500_P = FvP_Fm_500_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;

//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_1000  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_1000_start = 1120; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_1000_Prime, 3 Fm_1000_Prime steps, and Fs_1000 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_1000 = MathMEAN(data.slice(ps2_1000_start + 1,ps2_1000_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_1000_std = MathSTDEV(data.slice(ps2_1000_start + 1,ps2_1000_start + 4)); // create standard deviation for this value for error checking

var sat_1000_vals = data.slice(ps2_1000_start + 25,ps2_1000_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_1000_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_1000_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_1000_vals = data.slice(ps2_1000_start + 84,ps2_1000_start + 110).sort();  // sort the saturating light values from low to high
var Fm_1000_P_end = MathMEAN(sat_1000_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_1000_P_end_std = MathSTDEV(sat_1000_vals); // create standard deviation for this value for error checking

sat_1000_vals = data.slice(ps2_1000_start + 52,ps2_1000_start + 60).sort();  // sort the saturating light values from low to high
var Fm_1000_P_step1 = MathMEAN(sat_1000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_1000_P_step1_std = MathSTDEV(sat_1000_vals); // create standard deviation for this value for error checking

sat_1000_vals = data.slice(ps2_1000_start + 62,ps2_1000_start + 70).sort();  // sort the saturating light values from low to high
var Fm_1000_P_step2 = MathMEAN(sat_1000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_1000_P_step2_std = MathSTDEV(sat_1000_vals); // create standard deviation for this value for error checking

sat_1000_vals = data.slice(ps2_1000_start + 72,ps2_1000_start + 80).sort();  // sort the saturating light values from low to high
var Fm_1000_P_step3 = MathMEAN(sat_1000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_1000_P_step3_std = MathSTDEV(sat_1000_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_1000_Prime_1000_values = json.data_raw.slice(ps2_1000_start + 160,ps2_1000_start + 270).sort();
var Fo_1000_Prime = MathMEAN(Fo_1000_Prime_1000_values.slice(5,10)) - baseline;
var Fo_1000_Prime_std = MathSTDEV(Fo_1000_Prime_1000_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_1000_Prime using multi-phase flash
// ----------------------------
var reg_1000 = MathLINREG(inverse_intensity, [A0FmP,Fm_1000_P_step1,Fm_1000_P_step2,Fm_1000_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_1000_fm_noMPF = (A0FmP-Fs_1000)/A0FmP;
var fv_1000_fm_MPF = (reg_1000.b-Fs_1000)/reg_1000.b;


// Calculate NPQt,PhiNPQ_1000, PhiNO_1000, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_1000_MPF = (4.88 / ((reg_1000.b / Fo_1000_Prime) -1) )-1;
var npqt_1000_noMPF = (4.88 / ((A0FmP / Fo_1000_Prime) -1) )-1;
var qL_1000_MPF = ((reg_1000.b - Fs_1000)*Fo_1000_Prime)/((reg_1000.b-Fo_1000_Prime)*Fs_1000);
var qL_1000_noMPF = ((A0FmP - Fs_1000)*Fo_1000_Prime)/((A0FmP-Fo_1000_Prime)*Fs_1000);
var PhiNO_1000_MPF = 1/(npqt_1000_MPF + 1 + qL_1000_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_1000_noMPF = 1/(npqt_1000_noMPF + 1 + qL_1000_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_1000_MPF = 1-fv_1000_fm_MPF-PhiNO_1000_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_1000_noMPF = 1-fv_1000_fm_noMPF-PhiNO_1000_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_1000_MPF = (reg_1000.b - Fs_1000)/(reg_1000.b - Fo_1000_Prime);
var qP_1000_noMPF = (Fm_1000_Prime - Fs_1000)/(Fm_1000_Prime - Fo_1000_Prime);
var FvP_Fm_1000_P_MPF = (reg_1000.b-Fo_1000_Prime)/reg_1000.b;
var FvP_Fm_1000_P_noMPF = (A0FmP-Fo_1000_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_1000_fm = fv_1000_fm_MPF;
var npqt_1000  = npqt_1000_MPF;
var PhiNO_1000 = PhiNO_1000_MPF;
var PhiNPQ_1000 = PhiNPQ_1000_MPF;
var qL_1000 = qL_1000_MPF;
var Fm_1000_Prime = reg_1000.b;
var qP_1000 = qP_1000_MPF;
var FvP_Fm_1000_P = FvP_Fm_1000_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;


//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
//        ps2_2000  
//    -----------------------------  //
//    -----------------------------  //
//    -----------------------------  //
var ps2_2000_start = 1400; // when does the Phi2 measurement start - usando el nuevo protocolo
// Set our Apparent Fm_2000_Prime, 3 Fm_2000_Prime steps, and Fs_2000 to calculate both traditional fv/fm and new Multi-phase flash fv/fm
//----------------------------
var Fs_2000 = MathMEAN(data.slice(ps2_2000_start + 1,ps2_2000_start + 4)) - baseline; // take only the first 4 values in the Fs range, excluding the very first
var Fs_2000_std = MathSTDEV(data.slice(ps2_2000_start + 1,ps2_2000_start + 4)); // create standard deviation for this value for error checking

var sat_2000_vals = data.slice(ps2_2000_start + 25,ps2_2000_start + 48).sort();  // sort the saturating light values from low to high
var A0FmP = MathMEAN(sat_2000_vals.slice(2,20)) - baseline; // take the 18 largest values and average them
var A0FmP_std = MathSTDEV(sat_2000_vals); // create standard deviation for this value for error checkingjson.data_raw.slice(953,955)

sat_2000_vals = data.slice(ps2_2000_start + 84,ps2_2000_start + 110).sort();  // sort the saturating light values from low to high
var Fm_2000_P_end = MathMEAN(sat_2000_vals.slice(2,23)) - baseline; // take the 21 largest values and average them
var Fm_2000_P_end_std = MathSTDEV(sat_2000_vals); // create standard deviation for this value for error checking

sat_2000_vals = data.slice(ps2_2000_start + 52,ps2_2000_start + 60).sort();  // sort the saturating light values from low to high
var Fm_2000_P_step1 = MathMEAN(sat_2000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_2000_P_step1_std = MathSTDEV(sat_2000_vals); // create standard deviation for this value for error checking

sat_2000_vals = data.slice(ps2_2000_start + 62,ps2_2000_start + 70).sort();  // sort the saturating light values from low to high
var Fm_2000_P_step2 = MathMEAN(sat_2000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_2000_P_step2_std = MathSTDEV(sat_2000_vals); // create standard deviation for this value for error checking

sat_2000_vals = data.slice(ps2_2000_start + 72,ps2_2000_start + 80).sort();  // sort the saturating light values from low to high
var Fm_2000_P_step3 = MathMEAN(sat_2000_vals.slice(2,6)) - baseline; // take the 4 largest values and average them
var Fm_2000_P_step3_std = MathSTDEV(sat_2000_vals); // create standard deviation for this value for error checking

// Calculations for F0'
// ----------------------------
var Fo_2000_Prime_2000_values = json.data_raw.slice(ps2_2000_start + 160,ps2_2000_start + 270).sort();
var Fo_2000_Prime = MathMEAN(Fo_2000_Prime_2000_values.slice(5,10)) - baseline;
var Fo_2000_Prime_std = MathSTDEV(Fo_2000_Prime_2000_values); // create standard deviation for this value for error checking

// Calculations for corrected Fm_2000_Prime using multi-phase flash
// ----------------------------
var reg_2000 = MathLINREG(inverse_intensity, [A0FmP,Fm_2000_P_step1,Fm_2000_P_step2,Fm_2000_P_step3]);

// Calculate Phi2 w/ and w/out multi-phase flash
// ----------------------------
var fv_2000_fm_noMPF = (A0FmP-Fs_2000)/A0FmP;
var fv_2000_fm_MPF = (reg_2000.b-Fs_2000)/reg_2000.b;


// Calculate NPQt,PhiNPQ_2000, PhiNO_2000, qL w/ and w/out multi-phase flash
// ----------------------------
var npqt_2000_MPF = (4.88 / ((reg_2000.b / Fo_2000_Prime) -1) )-1;
var npqt_2000_noMPF = (4.88 / ((A0FmP / Fo_2000_Prime) -1) )-1;
var qL_2000_MPF = ((reg_2000.b - Fs_2000)*Fo_2000_Prime)/((reg_2000.b-Fo_2000_Prime)*Fs_2000);
var qL_2000_noMPF = ((A0FmP - Fs_2000)*Fo_2000_Prime)/((A0FmP-Fo_2000_Prime)*Fs_2000);
var PhiNO_2000_MPF = 1/(npqt_2000_MPF + 1 + qL_2000_MPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNO_2000_noMPF = 1/(npqt_2000_noMPF + 1 + qL_2000_noMPF*4.88); //based on equation 52 in Kramer et al., 2004 PRES
var PhiNPQ_2000_MPF = 1-fv_2000_fm_MPF-PhiNO_2000_MPF; //based on equation 53 in Kramer et al., 2004 PRES 
var PhiNPQ_2000_noMPF = 1-fv_2000_fm_noMPF-PhiNO_2000_noMPF; //based on equation 53 in Kramer et al., 2004 PRES 

var qP_2000_MPF = (reg_2000.b - Fs_2000)/(reg_2000.b - Fo_2000_Prime);
var qP_2000_noMPF = (Fm_2000_Prime - Fs_2000)/(Fm_2000_Prime - Fo_2000_Prime);
var FvP_Fm_2000_P_MPF = (reg_2000.b-Fo_2000_Prime)/reg_2000.b;
var FvP_Fm_2000_P_noMPF = (A0FmP-Fo_2000_Prime)/A0FmP;

// Create the variables to be printed (assume to use the MPF values unless there is a good reason not to)
// ----------------------------
var fv_2000_fm = fv_2000_fm_MPF;
var npqt_2000  = npqt_2000_MPF;
var PhiNO_2000 = PhiNO_2000_MPF;
var PhiNPQ_2000 = PhiNPQ_2000_MPF;
var qL_2000 = qL_2000_MPF;
var Fm_2000_Prime = reg_2000.b;
var qP_2000 = qP_2000_MPF;
var FvP_Fm_2000_P = FvP_Fm_2000_P_MPF;
var b = json.b;
var r = json.r;
var g = json.g;































/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_0, PhiNO_0... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_0.m > 0) {
  fv_0_fm = fv_0_fm_noMPF;
  npqt_0 = npqt_0_noMPF;
  PhiNO_0 = PhiNO_0_noMPF;
  PhiNPQ_0 = PhiNPQ_0_noMPF;
  qL_0 = qL_0_noMPF;
  Fm_0_Prime = A0FmP;
  qP = qP_0_noMPF;
  FvP_Fm_0_P = FvP_FmP_noMPF;
  
  if (fv_0_fm <= 0) {
    output["Phi2_0"] 			= 0;
	warning('Phi2_0 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_0_noMPF"] 	= MathROUND(npqt_0,3);
  }
  if (fv_0_fm >=.85) {
    output["Phi2_0"] 			= -1;
	danger("Phi2_0 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_0"] 		= MathROUND(fv_0_fm,3);
  }
  
  if (npqt_0 <= 0) {
	output["PhiNPQ_0"]		= 0;
    output["NPQt_0"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_0_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_0_noMPF"]  = MathROUND(PhiNPQ_0,3);
	output["npqt_0_noMPF"]	= MathROUND(npqt_0,3);
  }
  else {
	output["PhiNPQ_0"]  = MathROUND(PhiNPQ_0,3);
	output["NPQt_0"]		= MathROUND(npqt_0,3);
  }
	output["PhiNO_0"]		= MathROUND(PhiNO_0,3);
	output["qL_0"]		= MathROUND(qL_0,3);
    output['FvP/Fm_0_P']		= MathROUND(FvP_Fm_0_P,3);
    output['qP_0']			= MathROUND(qP_0,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_0... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_0_fm <= 0) {
    output["Phi2_0"] 			= 0;
	warning("Phi2_0 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_0_MPF"] 	= MathROUND(npqt_0,3);
  }
  if (fv_0_fm >=.85) {
    output["Phi2_0"] 			= -1;
	danger("Phi2_0 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_0"]			= MathROUND(fv_0_fm,3);
  }
  if (npqt_0 <= 0) {
	output["PhiNPQ_0"]		= 0;
    output["NPQt_0"]			= 0;
	warning("NPQt_0 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_0_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_0_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_0_MPF"]		= MathROUND(npqt_0,3);
  }
  else {
	output["PhiNPQ_0"]  = MathROUND(PhiNPQ_0,3);
	output["NPQt_0"]		= MathROUND(npqt_0,3);
  }
	output["PhiNO_0"]		= MathROUND(PhiNO_0,3);
	output["qL_0"]			= MathROUND(qL_0,3);
    output['FvP/Fm_0_P']		= MathROUND(FvP_Fm_0_P,3);
    output['qP_0']			= MathROUND(qP_0,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_0_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_0_std > 100) {
	danger("noisy Fs_0", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_0_Prime", output);
}
*/
if (Fm_0_P_step1_std > 120 | Fm_0_P_step2_std > 120 | Fm_0_P_step3_std > 120 | Fm_0_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_0_Prime_std > 150) {
	danger("noisy Fo_0_Prime", output);
}
/*
if (reg_0.m > 0) {
	info("Used Phi2_0 and not Phi2_0 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_0_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_0_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_0_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_0_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/




/****************OUTPUT VALUES FROM MACRO fro 100umol*******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_100, PhiNO_100... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_100.m > 0) {
  fv_100_fm = fv_100_fm_noMPF;
  npqt_100 = npqt_100_noMPF;
  PhiNO_100 = PhiNO_100_noMPF;
  PhiNPQ_100 = PhiNPQ_100_noMPF;
  qL_100 = qL_100_noMPF;
  Fm_100_Prime = A0FmP;
  qP = qP_100_noMPF;
  FvP_Fm_100_P = FvP_FmP_noMPF;
  
  if (fv_100_fm <= 0) {
    output["Phi2_100"] 			= 0;
	warning('Phi2_100 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_100_noMPF"] 	= MathROUND(npqt_100,3);
  }
  if (fv_100_fm >=.85) {
    output["Phi2_100"] 			= -1;
	danger("Phi2_100 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_100"] 		= MathROUND(fv_100_fm,3);
  }
  
  if (npqt_100 <= 0) {
	output["PhiNPQ_100"]		= 0;
    output["NPQt_100"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_100_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_100_noMPF"]  = MathROUND(PhiNPQ_100,3);
	output["npqt_100_noMPF"]	= MathROUND(npqt_100,3);
  }
  else {
	output["PhiNPQ_100"]  = MathROUND(PhiNPQ_100,3);
	output["NPQt_100"]		= MathROUND(npqt_100,3);
  }
	output["PhiNO_100"]		= MathROUND(PhiNO_100,3);
	output["qL_100"]		= MathROUND(qL_100,3);
    output['FvP/Fm_100_P']		= MathROUND(FvP_Fm_100_P,3);
    output['qP_100']			= MathROUND(qP_100,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_100... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_100_fm <= 0) {
    output["Phi2_100"] 			= 0;
	warning("Phi2_100 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_100_MPF"] 	= MathROUND(npqt_100,3);
  }
  if (fv_100_fm >=.85) {
    output["Phi2_100"] 			= -1;
	danger("Phi2_100 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_100"]			= MathROUND(fv_100_fm,3);
  }
  if (npqt_100 <= 0) {
	output["PhiNPQ_100"]		= 0;
    output["NPQt_100"]			= 0;
	warning("NPQt_100 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_100_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_100_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_100_MPF"]		= MathROUND(npqt_100,3);
  }
  else {
	output["PhiNPQ_100"]  = MathROUND(PhiNPQ_100,3);
	output["NPQt_100"]		= MathROUND(npqt_100,3);
  }
	output["PhiNO_100"]		= MathROUND(PhiNO_100,3);
	output["qL_100"]			= MathROUND(qL_100,3);
    output['FvP/Fm_100_P']		= MathROUND(FvP_Fm_100_P,3);
    output['qP_100']			= MathROUND(qP_100,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_100_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_100_std > 100) {
	danger("noisy Fs_100", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_100_Prime", output);
}
*/
if (Fm_100_P_step1_std > 120 | Fm_100_P_step2_std > 120 | Fm_100_P_step3_std > 120 | Fm_100_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_100_Prime_std > 150) {
	danger("noisy Fo_100_Prime", output);
}
/*
if (reg_100.m > 0) {
	info("Used Phi2_100 and not Phi2_100 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_100_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_100_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_100_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_100_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/





output["Fm_0_Prime"] 		= MathROUND(Fm_0_Prime,3);
output["Fs_0"] 			= MathROUND(Fs_0,1);
output['Fo_0_Prime']		= MathROUND(Fo_0_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_0_Prime/Fs_0)-1),3));
//output["ratio MPF/noMPF, Phi2_0"] = MathROUND(fv_0_fm_MPF / fv_0_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_0"] = MathROUND(PhiNPQ_0_MPF / PhiNPQ_0_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_0"] = MathROUND(PhiNO_0_MPF / PhiNO_0_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_0"] = MathROUND(npqt_0_MPF / npqt_0_noMPF,5);
output["MPF_slope_0"] 	= MathROUND(reg_0.m,3);
output["MPF_rsquared_0"] 	= MathROUND(reg_0.r,3);
/*
output["Phi2_0_MPF"] 		= MathROUND(fv_0_fm_MPF,3);
output["Phi2_0_noMPF"] 	= MathROUND(fv_0_fm,3);
output["Fm_0_Prime_MPF"] 	= MathROUND(reg_0.b,3);
output["Fm_0_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_0_MPF']		= MathROUND(qL_0_MPF,3);
output['qL_0_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_0_MPF']		= MathROUND(PhiNO_0_MPF,3);
output['PhiNO_0_noMPF']	= MathROUND(PhiNO_0,3);
output["Fs_0_std"] 			= MathROUND(Fs_0_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_0_P_step1_std"] 	= MathROUND(Fm_0_P_step1_std,1);
output["Fm_0_P_step2_std"] 	= MathROUND(Fm_0_P_step2_std,1);
output["Fm_0_P_step3_std"] 	= MathROUND(Fm_0_P_step3_std,1);
output["Fm_0_P_end_std"] 		= MathROUND(Fm_0_P_end_std,1);
output["Fo_0_Prime_std"] 			= MathROUND(Fo_0_Prime_std,1);
*/

//output["Fm_0_P_step1"] = MathROUND(Fm_0_P_step1,3);
//output["Fm_0_P_step2"] = MathROUND(Fm_0_P_step2,3);
//output["Fm_0_P_step3"] = MathROUND(Fm_0_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_0_P_step1,Fm_0_P_step2,Fm_0_P_step3];
//output["slopey"] = Fm_0_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;


output["Fm_100_Prime"] 		= MathROUND(Fm_100_Prime,3);
output["Fs_100"] 			= MathROUND(Fs_100,1);
output['Fo_100_Prime']		= MathROUND(Fo_100_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_100_Prime/Fs_100)-1),3));
//output["ratio MPF/noMPF, Phi2_100"] = MathROUND(fv_100_fm_MPF / fv_100_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_100"] = MathROUND(PhiNPQ_100_MPF / PhiNPQ_100_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_100"] = MathROUND(PhiNO_100_MPF / PhiNO_100_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_100"] = MathROUND(npqt_100_MPF / npqt_100_noMPF,5);
output["MPF_slope_100"] 	= MathROUND(reg_100.m,3);
output["MPF_rsquared_100"] 	= MathROUND(reg_100.r,3);
/*
output["Phi2_100_MPF"] 		= MathROUND(fv_100_fm_MPF,3);
output["Phi2_100_noMPF"] 	= MathROUND(fv_100_fm,3);
output["Fm_100_Prime_MPF"] 	= MathROUND(reg_100.b,3);
output["Fm_100_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_100_MPF']		= MathROUND(qL_100_MPF,3);
output['qL_100_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_100_MPF']		= MathROUND(PhiNO_100_MPF,3);
output['PhiNO_100_noMPF']	= MathROUND(PhiNO_100,3);
output["Fs_100_std"] 			= MathROUND(Fs_100_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_100_P_step1_std"] 	= MathROUND(Fm_100_P_step1_std,1);
output["Fm_100_P_step2_std"] 	= MathROUND(Fm_100_P_step2_std,1);
output["Fm_100_P_step3_std"] 	= MathROUND(Fm_100_P_step3_std,1);
output["Fm_100_P_end_std"] 		= MathROUND(Fm_100_P_end_std,1);
output["Fo_100_Prime_std"] 			= MathROUND(Fo_100_Prime_std,1);
*/

//output["Fm_100_P_step1"] = MathROUND(Fm_100_P_step1,3);
//output["Fm_100_P_step2"] = MathROUND(Fm_100_P_step2,3);
//output["Fm_100_P_step3"] = MathROUND(Fm_100_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_100_P_step1,Fm_100_P_step2,Fm_100_P_step3];
//output["slopey"] = Fm_100_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;



output["order"] = ["Phi2_0","PhiNPQ_0","PhiNO_0","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];




/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_250, PhiNO_250... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_250.m > 0) {
  fv_250_fm = fv_250_fm_noMPF;
  npqt_250 = npqt_250_noMPF;
  PhiNO_250 = PhiNO_250_noMPF;
  PhiNPQ_250 = PhiNPQ_250_noMPF;
  qL_250 = qL_250_noMPF;
  Fm_250_Prime = A0FmP;
  qP = qP_250_noMPF;
  FvP_Fm_250_P = FvP_FmP_noMPF;
  
  if (fv_250_fm <= 0) {
    output["Phi2_250"] 			= 0;
	warning('Phi2_250 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_250_noMPF"] 	= MathROUND(npqt_250,3);
  }
  if (fv_250_fm >=.85) {
    output["Phi2_250"] 			= -1;
	danger("Phi2_250 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_250"] 		= MathROUND(fv_250_fm,3);
  }
  
  if (npqt_250 <= 0) {
	output["PhiNPQ_250"]		= 0;
    output["NPQt_250"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_250_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_250_noMPF"]  = MathROUND(PhiNPQ_250,3);
	output["npqt_250_noMPF"]	= MathROUND(npqt_250,3);
  }
  else {
	output["PhiNPQ_250"]  = MathROUND(PhiNPQ_250,3);
	output["NPQt_250"]		= MathROUND(npqt_250,3);
  }
	output["PhiNO_250"]		= MathROUND(PhiNO_250,3);
	output["qL_250"]		= MathROUND(qL_250,3);
    output['FvP/Fm_250_P']		= MathROUND(FvP_Fm_250_P,3);
    output['qP_250']			= MathROUND(qP_250,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_250... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_250_fm <= 0) {
    output["Phi2_250"] 			= 0;
	warning("Phi2_250 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_250_MPF"] 	= MathROUND(npqt_250,3);
  }
  if (fv_250_fm >=.85) {
    output["Phi2_250"] 			= -1;
	danger("Phi2_250 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_250"]			= MathROUND(fv_250_fm,3);
  }
  if (npqt_250 <= 0) {
	output["PhiNPQ_250"]		= 0;
    output["NPQt_250"]			= 0;
	warning("NPQt_250 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_250_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_250_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_250_MPF"]		= MathROUND(npqt_250,3);
  }
  else {
	output["PhiNPQ_250"]  = MathROUND(PhiNPQ_250,3);
	output["NPQt_250"]		= MathROUND(npqt_250,3);
  }
	output["PhiNO_250"]		= MathROUND(PhiNO_250,3);
	output["qL_250"]			= MathROUND(qL_250,3);
    output['FvP/Fm_250_P']		= MathROUND(FvP_Fm_250_P,3);
    output['qP_250']			= MathROUND(qP_250,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_250_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_250_std > 100) {
	danger("noisy Fs_250", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_250_Prime", output);
}
*/
if (Fm_250_P_step1_std > 120 | Fm_250_P_step2_std > 120 | Fm_250_P_step3_std > 120 | Fm_250_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_250_Prime_std > 150) {
	danger("noisy Fo_250_Prime", output);
}
/*
if (reg_250.m > 0) {
	info("Used Phi2_250 and not Phi2_250 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_250_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_250_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_250_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_250_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_250_Prime"] 		= MathROUND(Fm_250_Prime,3);
output["Fs_250"] 			= MathROUND(Fs_250,1);
output['Fo_250_Prime']		= MathROUND(Fo_250_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_250_Prime/Fs_250)-1),3));
//output["ratio MPF/noMPF, Phi2_250"] = MathROUND(fv_250_fm_MPF / fv_250_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_250"] = MathROUND(PhiNPQ_250_MPF / PhiNPQ_250_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_250"] = MathROUND(PhiNO_250_MPF / PhiNO_250_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_250"] = MathROUND(npqt_250_MPF / npqt_250_noMPF,5);
output["MPF_slope_250"] 	= MathROUND(reg_250.m,3);
output["MPF_rsquared_250"] 	= MathROUND(reg_250.r,3);
/*
output["Phi2_250_MPF"] 		= MathROUND(fv_250_fm_MPF,3);
output["Phi2_250_noMPF"] 	= MathROUND(fv_250_fm,3);
output["Fm_250_Prime_MPF"] 	= MathROUND(reg_250.b,3);
output["Fm_250_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_250_MPF']		= MathROUND(qL_250_MPF,3);
output['qL_250_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_250_MPF']		= MathROUND(PhiNO_250_MPF,3);
output['PhiNO_250_noMPF']	= MathROUND(PhiNO_250,3);
output["Fs_250_std"] 			= MathROUND(Fs_250_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_250_P_step1_std"] 	= MathROUND(Fm_250_P_step1_std,1);
output["Fm_250_P_step2_std"] 	= MathROUND(Fm_250_P_step2_std,1);
output["Fm_250_P_step3_std"] 	= MathROUND(Fm_250_P_step3_std,1);
output["Fm_250_P_end_std"] 		= MathROUND(Fm_250_P_end_std,1);
output["Fo_250_Prime_std"] 			= MathROUND(Fo_250_Prime_std,1);
*/

//output["Fm_250_P_step1"] = MathROUND(Fm_250_P_step1,3);
//output["Fm_250_P_step2"] = MathROUND(Fm_250_P_step2,3);
//output["Fm_250_P_step3"] = MathROUND(Fm_250_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_250_P_step1,Fm_250_P_step2,Fm_250_P_step3];
//output["slopey"] = Fm_250_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_250","PhiNPQ_250","PhiNO_250","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];

 
/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_500, PhiNO_500... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_500.m > 0) {
  fv_500_fm = fv_500_fm_noMPF;
  npqt_500 = npqt_500_noMPF;
  PhiNO_500 = PhiNO_500_noMPF;
  PhiNPQ_500 = PhiNPQ_500_noMPF;
  qL_500 = qL_500_noMPF;
  Fm_500_Prime = A0FmP;
  qP = qP_500_noMPF;
  FvP_Fm_500_P = FvP_FmP_noMPF;
  
  if (fv_500_fm <= 0) {
    output["Phi2_500"] 			= 0;
	warning('Phi2_500 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_500_noMPF"] 	= MathROUND(npqt_500,3);
  }
  if (fv_500_fm >=.85) {
    output["Phi2_500"] 			= -1;
	danger("Phi2_500 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_500"] 		= MathROUND(fv_500_fm,3);
  }
  
  if (npqt_500 <= 0) {
	output["PhiNPQ_500"]		= 0;
    output["NPQt_500"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_500_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_500_noMPF"]  = MathROUND(PhiNPQ_500,3);
	output["npqt_500_noMPF"]	= MathROUND(npqt_500,3);
  }
  else {
	output["PhiNPQ_500"]  = MathROUND(PhiNPQ_500,3);
	output["NPQt_500"]		= MathROUND(npqt_500,3);
  }
	output["PhiNO_500"]		= MathROUND(PhiNO_500,3);
	output["qL_500"]		= MathROUND(qL_500,3);
    output['FvP/Fm_500_P']		= MathROUND(FvP_Fm_500_P,3);
    output['qP_500']			= MathROUND(qP_500,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_500... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_500_fm <= 0) {
    output["Phi2_500"] 			= 0;
	warning("Phi2_500 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_500_MPF"] 	= MathROUND(npqt_500,3);
  }
  if (fv_500_fm >=.85) {
    output["Phi2_500"] 			= -1;
	danger("Phi2_500 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_500"]			= MathROUND(fv_500_fm,3);
  }
  if (npqt_500 <= 0) {
	output["PhiNPQ_500"]		= 0;
    output["NPQt_500"]			= 0;
	warning("NPQt_500 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_500_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_500_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_500_MPF"]		= MathROUND(npqt_500,3);
  }
  else {
	output["PhiNPQ_500"]  = MathROUND(PhiNPQ_500,3);
	output["NPQt_500"]		= MathROUND(npqt_500,3);
  }
	output["PhiNO_500"]		= MathROUND(PhiNO_500,3);
	output["qL_500"]			= MathROUND(qL_500,3);
    output['FvP/Fm_500_P']		= MathROUND(FvP_Fm_500_P,3);
    output['qP_500']			= MathROUND(qP_500,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_500_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_500_std > 100) {
	danger("noisy Fs_500", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_500_Prime", output);
}
*/
if (Fm_500_P_step1_std > 120 | Fm_500_P_step2_std > 120 | Fm_500_P_step3_std > 120 | Fm_500_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_500_Prime_std > 150) {
	danger("noisy Fo_500_Prime", output);
}
/*
if (reg_500.m > 0) {
	info("Used Phi2_500 and not Phi2_500 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_500_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_500_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_500_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_500_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_500_Prime"] 		= MathROUND(Fm_500_Prime,3);
output["Fs_500"] 			= MathROUND(Fs_500,1);
output['Fo_500_Prime']		= MathROUND(Fo_500_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_500_Prime/Fs_500)-1),3));
//output["ratio MPF/noMPF, Phi2_500"] = MathROUND(fv_500_fm_MPF / fv_500_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_500"] = MathROUND(PhiNPQ_500_MPF / PhiNPQ_500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_500"] = MathROUND(PhiNO_500_MPF / PhiNO_500_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_500"] = MathROUND(npqt_500_MPF / npqt_500_noMPF,5);
output["MPF_slope_500"] 	= MathROUND(reg_500.m,3);
output["MPF_rsquared_500"] 	= MathROUND(reg_500.r,3);
/*
output["Phi2_500_MPF"] 		= MathROUND(fv_500_fm_MPF,3);
output["Phi2_500_noMPF"] 	= MathROUND(fv_500_fm,3);
output["Fm_500_Prime_MPF"] 	= MathROUND(reg_500.b,3);
output["Fm_500_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_500_MPF']		= MathROUND(qL_500_MPF,3);
output['qL_500_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_500_MPF']		= MathROUND(PhiNO_500_MPF,3);
output['PhiNO_500_noMPF']	= MathROUND(PhiNO_500,3);
output["Fs_500_std"] 			= MathROUND(Fs_500_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_500_P_step1_std"] 	= MathROUND(Fm_500_P_step1_std,1);
output["Fm_500_P_step2_std"] 	= MathROUND(Fm_500_P_step2_std,1);
output["Fm_500_P_step3_std"] 	= MathROUND(Fm_500_P_step3_std,1);
output["Fm_500_P_end_std"] 		= MathROUND(Fm_500_P_end_std,1);
output["Fo_500_Prime_std"] 			= MathROUND(Fo_500_Prime_std,1);
*/

//output["Fm_500_P_step1"] = MathROUND(Fm_500_P_step1,3);
//output["Fm_500_P_step2"] = MathROUND(Fm_500_P_step2,3);
//output["Fm_500_P_step3"] = MathROUND(Fm_500_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_500_P_step1,Fm_500_P_step2,Fm_500_P_step3];
//output["slopey"] = Fm_500_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_500","PhiNPQ_500","PhiNO_500","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];

  
/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_1000, PhiNO_1000... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_1000.m > 0) {
  fv_1000_fm = fv_1000_fm_noMPF;
  npqt_1000 = npqt_1000_noMPF;
  PhiNO_1000 = PhiNO_1000_noMPF;
  PhiNPQ_1000 = PhiNPQ_1000_noMPF;
  qL_1000 = qL_1000_noMPF;
  Fm_1000_Prime = A0FmP;
  qP = qP_1000_noMPF;
  FvP_Fm_1000_P = FvP_FmP_noMPF;
  
  if (fv_1000_fm <= 0) {
    output["Phi2_1000"] 			= 0;
	warning('Phi2_1000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_1000_noMPF"] 	= MathROUND(npqt_1000,3);
  }
  if (fv_1000_fm >=.85) {
    output["Phi2_1000"] 			= -1;
	danger("Phi2_1000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_1000"] 		= MathROUND(fv_1000_fm,3);
  }
  
  if (npqt_1000 <= 0) {
	output["PhiNPQ_1000"]		= 0;
    output["NPQt_1000"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_1000_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_1000_noMPF"]  = MathROUND(PhiNPQ_1000,3);
	output["npqt_1000_noMPF"]	= MathROUND(npqt_1000,3);
  }
  else {
	output["PhiNPQ_1000"]  = MathROUND(PhiNPQ_1000,3);
	output["NPQt_1000"]		= MathROUND(npqt_1000,3);
  }
	output["PhiNO_1000"]		= MathROUND(PhiNO_1000,3);
	output["qL_1000"]		= MathROUND(qL_1000,3);
    output['FvP/Fm_1000_P']		= MathROUND(FvP_Fm_1000_P,3);
    output['qP_1000']			= MathROUND(qP_1000,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_1000... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_1000_fm <= 0) {
    output["Phi2_1000"] 			= 0;
	warning("Phi2_1000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_1000_MPF"] 	= MathROUND(npqt_1000,3);
  }
  if (fv_1000_fm >=.85) {
    output["Phi2_1000"] 			= -1;
	danger("Phi2_1000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_1000"]			= MathROUND(fv_1000_fm,3);
  }
  if (npqt_1000 <= 0) {
	output["PhiNPQ_1000"]		= 0;
    output["NPQt_1000"]			= 0;
	warning("NPQt_1000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_1000_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_1000_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_1000_MPF"]		= MathROUND(npqt_1000,3);
  }
  else {
	output["PhiNPQ_1000"]  = MathROUND(PhiNPQ_1000,3);
	output["NPQt_1000"]		= MathROUND(npqt_1000,3);
  }
	output["PhiNO_1000"]		= MathROUND(PhiNO_1000,3);
	output["qL_1000"]			= MathROUND(qL_1000,3);
    output['FvP/Fm_1000_P']		= MathROUND(FvP_Fm_1000_P,3);
    output['qP_1000']			= MathROUND(qP_1000,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_1000_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_1000_std > 100) {
	danger("noisy Fs_1000", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_1000_Prime", output);
}
*/
if (Fm_1000_P_step1_std > 120 | Fm_1000_P_step2_std > 120 | Fm_1000_P_step3_std > 120 | Fm_1000_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_1000_Prime_std > 150) {
	danger("noisy Fo_1000_Prime", output);
}
/*
if (reg_1000.m > 0) {
	info("Used Phi2_1000 and not Phi2_1000 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_1000_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_1000_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_1000_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_1000_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_1000_Prime"] 		= MathROUND(Fm_1000_Prime,3);
output["Fs_1000"] 			= MathROUND(Fs_1000,1);
output['Fo_1000_Prime']		= MathROUND(Fo_1000_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_1000_Prime/Fs_1000)-1),3));
//output["ratio MPF/noMPF, Phi2_1000"] = MathROUND(fv_1000_fm_MPF / fv_1000_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_1000"] = MathROUND(PhiNPQ_1000_MPF / PhiNPQ_1000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1000"] = MathROUND(PhiNO_1000_MPF / PhiNO_1000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_1000"] = MathROUND(npqt_1000_MPF / npqt_1000_noMPF,5);
output["MPF_slope_1000"] 	= MathROUND(reg_1000.m,3);
output["MPF_rsquared_1000"] 	= MathROUND(reg_1000.r,3);
/*
output["Phi2_1000_MPF"] 		= MathROUND(fv_1000_fm_MPF,3);
output["Phi2_1000_noMPF"] 	= MathROUND(fv_1000_fm,3);
output["Fm_1000_Prime_MPF"] 	= MathROUND(reg_1000.b,3);
output["Fm_1000_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_1000_MPF']		= MathROUND(qL_1000_MPF,3);
output['qL_1000_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_1000_MPF']		= MathROUND(PhiNO_1000_MPF,3);
output['PhiNO_1000_noMPF']	= MathROUND(PhiNO_1000,3);
output["Fs_1000_std"] 			= MathROUND(Fs_1000_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_1000_P_step1_std"] 	= MathROUND(Fm_1000_P_step1_std,1);
output["Fm_1000_P_step2_std"] 	= MathROUND(Fm_1000_P_step2_std,1);
output["Fm_1000_P_step3_std"] 	= MathROUND(Fm_1000_P_step3_std,1);
output["Fm_1000_P_end_std"] 		= MathROUND(Fm_1000_P_end_std,1);
output["Fo_1000_Prime_std"] 			= MathROUND(Fo_1000_Prime_std,1);
*/

//output["Fm_1000_P_step1"] = MathROUND(Fm_1000_P_step1,3);
//output["Fm_1000_P_step2"] = MathROUND(Fm_1000_P_step2,3);
//output["Fm_1000_P_step3"] = MathROUND(Fm_1000_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_1000_P_step1,Fm_1000_P_step2,Fm_1000_P_step3];
//output["slopey"] = Fm_1000_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_1000","PhiNPQ_1000","PhiNO_1000","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];




/****************OUTPUT VALUES FROM MACRO *******************/

// If multi-phase flash steps are flat or positive slope, then just use the normal Phi2, NPQt, PhiNPQ_2000, PhiNO_2000... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
if (reg_2000.m > 0) {
  fv_2000_fm = fv_2000_fm_noMPF;
  npqt_2000 = npqt_2000_noMPF;
  PhiNO_2000 = PhiNO_2000_noMPF;
  PhiNPQ_2000 = PhiNPQ_2000_noMPF;
  qL_2000 = qL_2000_noMPF;
  Fm_2000_Prime = A0FmP;
  qP = qP_2000_noMPF;
  FvP_Fm_2000_P = FvP_FmP_noMPF;
  
  if (fv_2000_fm <= 0) {
    output["Phi2_2000"] 			= 0;
	warning('Phi2_2000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_noMPF variable',output);
	output["Phi2_2000_noMPF"] 	= MathROUND(npqt_2000,3);
  }
  if (fv_2000_fm >=.85) {
    output["Phi2_2000"] 			= -1;
	danger("Phi2_2000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);

  }
  else {
	  output["Phi2_2000"] 		= MathROUND(fv_2000_fm,3);
  }
  
  if (npqt_2000 <= 0) {
	output["PhiNPQ_2000"]		= 0;
    output["NPQt_2000"]			= 0;
	warning("NPQt_) is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_2000_noMPF and PhiNPQ_noMPF variable",output);
	output["PhiNPQ_2000_noMPF"]  = MathROUND(PhiNPQ_2000,3);
	output["npqt_2000_noMPF"]	= MathROUND(npqt_2000,3);
  }
  else {
	output["PhiNPQ_2000"]  = MathROUND(PhiNPQ_2000,3);
	output["NPQt_2000"]		= MathROUND(npqt_2000,3);
  }
	output["PhiNO_2000"]		= MathROUND(PhiNO_2000,3);
	output["qL_2000"]		= MathROUND(qL_2000,3);
    output['FvP/Fm_2000_P']		= MathROUND(FvP_Fm_2000_P,3);
    output['qP_2000']			= MathROUND(qP_2000,3);
}

// Otherwise, use the multi-phase flash calculation for Phi2, NPQt, PhiNPQ, PhiNO_2000... etc.
// If Phi2 or NPQt is less than zero, make zero and give user warning.  If Phi2 is higher than .85, give user danger flag.
// ----------------------------
else {
  if (fv_2000_fm <= 0) {
    output["Phi2_2000"] 			= 0;
	warning("Phi2_2000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see Phi2_MPF variable",output);
	output["Phi2_2000_MPF"] 	= MathROUND(npqt_2000,3);
  }
  if (fv_2000_fm >=.85) {
    output["Phi2_2000"] 			= -1;
	danger("Phi2_2000 above the normal range (0 - 0.85).  Please check the raw trace and seriously consider excluding this point.", output);
  }
  else {
    output["Phi2_2000"]			= MathROUND(fv_2000_fm,3);
  }
  if (npqt_2000 <= 0) {
	output["PhiNPQ_2000"]		= 0;
    output["NPQt_2000"]			= 0;
	warning("NPQt_2000 is negative (should be positive).  This may be due to a sample that is not doing photosynthesis, or you may have missed the leaf.  It has been set to zero, but check raw trace and consider excluding this point.  To see original negative value, see npqt_2000_MPF and PhiNPQ_MPF variables",output);
	output["PhiNPQ_2000_MPF"]  = MathROUND(PhiNPQ,3);
	output["npqt_2000_MPF"]		= MathROUND(npqt_2000,3);
  }
  else {
	output["PhiNPQ_2000"]  = MathROUND(PhiNPQ_2000,3);
	output["NPQt_2000"]		= MathROUND(npqt_2000,3);
  }
	output["PhiNO_2000"]		= MathROUND(PhiNO_2000,3);
	output["qL_2000"]			= MathROUND(qL_2000,3);
    output['FvP/Fm_2000_P']		= MathROUND(FvP_Fm_2000_P,3);
    output['qP_2000']			= MathROUND(qP_2000,3);
}

// only display LEF if there is a light intensity measurement > 0 
// ----------------------------
if (typeof json.light_intensity != "undefined" && json.light_intensity > 0) {
	output["LEF"] 		= MathROUND((fv_2000_fm  * 0.45 * json.light_intensity),3);
}

if (Fs_2000_std > 100) {
	danger("noisy Fs_2000", output);
}
/*
if (A0FmP_std > 300) {
	danger("noisy Fm_2000_Prime", output);
}
*/
if (Fm_2000_P_step1_std > 120 | Fm_2000_P_step2_std > 120 | Fm_2000_P_step3_std > 120 | Fm_2000_P_end_std > 300) {
	danger("noisy  multi-phase flash steps",output);
}

if (Fo_2000_Prime_std > 150) {
	danger("noisy Fo_2000_Prime", output);
}
/*
if (reg_2000.m > 0) {
	info("Used Phi2_2000 and not Phi2_2000 MPF - ambient light level was too low to apply MPF calculation", output);
}
if (Fm_2000_P_end/A0FmP - A0FmP/A0FmP > .1) {	
	info("Fm_2000_Prime slopes down.  This may mean that saturating flash is not bright enough... consider using a protocol with lower saturating light on these samples", output);
}
if (Fm_2000_P_end/A0FmP - A0FmP/A0FmP < -.1) {
	info("Fm_2000_Prime slopes up.  This may mean that saturating flash is too bright... consider using a protocol with higher saturating light on these samples",output);
}
*/

output["Fm_2000_Prime"] 		= MathROUND(Fm_2000_Prime,3);
output["Fs_2000"] 			= MathROUND(Fs_2000,1);
output['Fo_2000_Prime']		= MathROUND(Fo_2000_Prime,0);
output["RFd"]           = Number(MathROUND(((Fm_2000_Prime/Fs_2000)-1),3));
//output["ratio MPF/noMPF, Phi2_2000"] = MathROUND(fv_2000_fm_MPF / fv_2000_fm_noMPF,5);
//output["ratio MPF/noMPF, PhiNPQ_2000"] = MathROUND(PhiNPQ_2000_MPF / PhiNPQ_2000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_2000"] = MathROUND(PhiNO_2000_MPF / PhiNO_2000_noMPF,5);
//output["ratio MPF/noMPF, PhiNO_2000"] = MathROUND(npqt_2000_MPF / npqt_2000_noMPF,5);
output["MPF_slope_2000"] 	= MathROUND(reg_2000.m,3);
output["MPF_rsquared_2000"] 	= MathROUND(reg_2000.r,3);
/*
output["Phi2_2000_MPF"] 		= MathROUND(fv_2000_fm_MPF,3);
output["Phi2_2000_noMPF"] 	= MathROUND(fv_2000_fm,3);
output["Fm_2000_Prime_MPF"] 	= MathROUND(reg_2000.b,3);
output["Fm_2000_Prime_noMPF"] = MathROUND(A0FmP,1);
output['qL_2000_MPF']		= MathROUND(qL_2000_MPF,3);
output['qL_2000_noMPF']      = MathROUND(qL,3);
output['PhiNPQ_MPF']    = MathROUND(PhiNPQ_MPF,3);
output['PhiNPQ_noMPF']  = MathROUND(PhiNPQ,3);
output['PhiNO_2000_MPF']		= MathROUND(PhiNO_2000_MPF,3);
output['PhiNO_2000_noMPF']	= MathROUND(PhiNO_2000,3);
output["Fs_2000_std"] 			= MathROUND(Fs_2000_std,1);
output["A0FmP_std"] 			= MathROUND(A0FmP_std,1);
output["Fm_2000_P_step1_std"] 	= MathROUND(Fm_2000_P_step1_std,1);
output["Fm_2000_P_step2_std"] 	= MathROUND(Fm_2000_P_step2_std,1);
output["Fm_2000_P_step3_std"] 	= MathROUND(Fm_2000_P_step3_std,1);
output["Fm_2000_P_end_std"] 		= MathROUND(Fm_2000_P_end_std,1);
output["Fo_2000_Prime_std"] 			= MathROUND(Fo_2000_Prime_std,1);
*/

//output["Fm_2000_P_step1"] = MathROUND(Fm_2000_P_step1,3);
//output["Fm_2000_P_step2"] = MathROUND(Fm_2000_P_step2,3);
//output["Fm_2000_P_step3"] = MathROUND(Fm_2000_P_step3,3);
//output["intensity inverse"] = inverse_intensity;
//output["steps"] = [A0FmP,Fm_2000_P_step1,Fm_2000_P_step2,Fm_2000_P_step3];
//output["slopey"] = Fm_2000_P_end/A0FmP - A0FmP/A0FmP ;

  output["baseline"] 	= baseline;

// Check for data quality issues and add warning or danger flags
//----------------------------

// Finally, use the "order" object to define the order of the outputs (focus on the top 6 most important for the user to see)
//----------------------------
output["Light Intensity (PAR)"] = json.light_intensity;
output["Leaf Temp Differential"] = json.contactless_temp - json.temperature;

 	
output["Ambient Temperature"] = json.temperature;
output["Ambient Humidity"] = json.humidity;
output["Leaf Angle"] = json.angle;

output["order"] = ["Phi2_2000","PhiNPQ_2000","PhiNO_2000","Leaf Temp Differential","Leaf Angle", "Light Intensity (PAR)","Ambient Temperature","Ambient Humidity"];

//maxvalue = MathMAX([json.r,json.g,json.b]);
//output["R"] = Number(json.r);
//output["G"] = Number(json.g);
//output["B"] = Number(json.b);
//output["rval"] = json.r*(255/maxvalue);
//output["gval"] = json.g*(255/maxvalue);
//output["bval"] = json.b*(255/maxvalue);

//output["Color"] = [MathROUND(json.r*(255/maxvalue),2),MathROUND(json.g*(255/maxvalue),2),MathROUND(json.b*(255/maxvalue),2)];

             


return output;
{
  "time_offset": 240,
  "time": 1497030791784,
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:55:81",
  "device_battery": 93,
  "device_firmware": 1.17,
  "sample": [
    {
      "time": 1497030791832,
      "protocol_id": 1,
      "detector_read1": 14499,
      "light_intensity": 374,
      "r": 455,
      "g": 185,
      "b": 159,
      "light_intensity_raw": 730,
      "temperature": 29.219999,
      "humidity": 46.021484,
      "pressure": 990.003601,
      "temperature2": 29.48,
      "humidity2": 45.594727,
      "pressure2": 989.987183,
      "contactless_temp": 32.29,
      "thickness": 0.5,
      "compass_direction": "E",
      "compass": "90.00",
      "angle": 4.75,
      "angle_direction": "NE",
      "pitch": -3.48,
      "roll": 3.24,
      "data_raw": [
        6875,
        7004,
        7099,
        7200,
        7269,
        7333,
        7380,
        7429,
        7481,
        7511,
        7542,
        7569,
        7603,
        7619,
        7628,
        7647,
        7658,
        7667,
        7691,
        7688,
        15231,
        16020,
        16270,
        16403,
        16481,
        16562,
        16598,
        16639,
        16663,
        16679,
        16705,
        16726,
        16726,
        16728,
        16753,
        16743,
        16758,
        16753,
        16758,
        16754,
        16767,
        16755,
        16759,
        16763,
        16758,
        16760,
        16773,
        16754,
        16752,
        16764,
        16739,
        16735,
        16728,
        16740,
        16729,
        16723,
        16733,
        16731,
        16716,
        16718,
        16698,
        16704,
        16686,
        16685,
        16686,
        16688,
        16685,
        16687,
        16685,
        16693,
        16646,
        16639,
        16643,
        16619,
        16626,
        16631,
        16641,
        16622,
        16626,
        16647,
        16721,
        16740,
        16765,
        16761,
        16762,
        16775,
        16773,
        16761,
        16779,
        16761,
        16773,
        16766,
        16755,
        16779,
        16767,
        16772,
        16766,
        16767,
        16773,
        16771,
        16764,
        16763,
        16761,
        16769,
        16768,
        16762,
        16763,
        16762,
        16769,
        16753,
        13693,
        11740,
        10437,
        9610,
        9125,
        8852,
        8663,
        8556,
        8473,
        8412,
        8356,
        8308,
        8264,
        8232,
        8207,
        8170,
        8154,
        8133,
        8111,
        8095,
        7214,
        7097,
        7037,
        7000,
        6963,
        6945,
        6927,
        6908,
        6889,
        6870,
        6875,
        6850,
        6850,
        6843,
        6827,
        6833,
        6828,
        6823,
        6809,
        6802,
        6808,
        6802,
        6795,
        6794,
        6797,
        6795,
        6793,
        6783,
        6781,
        6789,
        6791,
        6783,
        6784,
        6774,
        6778,
        6783,
        6766,
        6772,
        6788,
        6777,
        6757,
        6773,
        6761,
        6769,
        6775,
        6769,
        6762,
        6763,
        6755,
        6765,
        6761,
        6765,
        6754,
        6767,
        6756,
        6767,
        6766,
        6751,
        6756,
        6756,
        6766,
        6743,
        6759,
        6749,
        6753,
        6751,
        6759,
        6761,
        6755,
        6754,
        6751,
        6747,
        6763,
        6757,
        6754,
        6751,
        6751,
        6765,
        6748,
        6753,
        6755,
        6756,
        6751,
        6751,
        6747,
        6764,
        6757,
        6743,
        6759,
        6756,
        6751,
        6747,
        6756,
        6752,
        6751,
        6759,
        6741,
        6757,
        6755,
        6755,
        6755,
        6755,
        6746,
        6758,
        6753,
        6750,
        6762,
        6761,
        6756,
        6747,
        6758,
        6756,
        6749,
        6757,
        6754,
        6755,
        6760,
        6762,
        6757,
        6755,
        6754,
        6766,
        6761,
        6756,
        6754,
        6758,
        6759,
        6762,
        6765,
        6765,
        6769,
        6773,
        6755,
        6763,
        6760,
        6766,
        6756,
        6755,
        6766,
        6762,
        6772,
        6763,
        6768,
        6777,
        6772,
        6765,
        6764,
        6772,
        6773,
        6769,
        8109,
        8121,
        8146,
        8154,
        8153,
        8165,
        8178,
        8180,
        8189,
        8194,
        8189,
        8201,
        8198,
        8203,
        8205,
        8215,
        8207,
        8225,
        8222,
        8216,
        10958,
        11583,
        11952,
        12189,
        12333,
        12408,
        12444,
        12469,
        12487,
        12493,
        12488,
        12505,
        12499,
        12507,
        12500,
        12515,
        12513,
        12511,
        12521,
        12517,
        12521,
        12517,
        12542,
        12515,
        12511,
        12515,
        12519,
        12520,
        12526,
        12512,
        12494,
        12486,
        12483,
        12493,
        12487,
        12486,
        12491,
        12481,
        12482,
        12479,
        12458,
        12461,
        12443,
        12429,
        12449,
        12445,
        12443,
        12421,
        12442,
        12422,
        12389,
        12411,
        12395,
        12381,
        12371,
        12377,
        12383,
        12385,
        12362,
        12378,
        12447,
        12444,
        12453,
        12473,
        12461,
        12444,
        12441,
        12449,
        12452,
        12435,
        12443,
        12455,
        12431,
        12435,
        12421,
        12422,
        12415,
        12421,
        12414,
        12402,
        12408,
        12401,
        12393,
        12392,
        12399,
        12394,
        12391,
        12390,
        12379,
        12366,
        11398,
        10661,
        10051,
        9601,
        9281,
        9070,
        8945,
        8867,
        8811,
        8779,
        8772,
        8741,
        8739,
        8727,
        8737,
        8723,
        8725,
        8725,
        8713,
        8722,
        6606,
        6510,
        6462,
        6421,
        6387,
        6367,
        6345,
        6321,
        6309,
        6297,
        6286,
        6281,
        6267,
        6263,
        6241,
        6243,
        6240,
        6225,
        6214,
        6226,
        6217,
        6211,
        6212,
        6205,
        6215,
        6211,
        6197,
        6202,
        6201,
        6188,
        6184,
        6197,
        6190,
        6179,
        6180,
        6181,
        6191,
        6174,
        6183,
        6191,
        6183,
        6179,
        6176,
        6185,
        6184,
        6179,
        6181,
        6182,
        6183,
        6174,
        6176,
        6185,
        6182,
        6177,
        6183,
        6179,
        6182,
        6179,
        6186,
        6182,
        6173,
        6181,
        6200,
        6183,
        6179,
        6180,
        6191,
        6199,
        6177,
        6189,
        6188,
        6188,
        6183,
        6183,
        6195,
        6181,
        6185,
        6186,
        6191,
        6195,
        6191,
        6192,
        6187,
        6197,
        6186,
        6198,
        6196,
        6191,
        6193,
        6199,
        6189,
        6195,
        6210,
        6202,
        6211,
        6199,
        6203,
        6210,
        6206,
        6199,
        6207,
        6210,
        6211,
        6212,
        6206,
        6209,
        6205,
        6210,
        6213,
        6214,
        6213,
        6218,
        6218,
        6219,
        6217,
        6220,
        6229,
        6223,
        6221,
        6223,
        6226,
        6229,
        6224,
        6235,
        6234,
        6225,
        6234,
        6235,
        6244,
        6247,
        6243,
        6245,
        6246,
        6234,
        6248,
        6242,
        6245,
        6240,
        6254,
        6257,
        6253,
        6248,
        6257,
        6262,
        6255,
        6258,
        6262,
        6262,
        6262,
        6273,
        8984,
        8987,
        8990,
        8996,
        8991,
        9008,
        9000,
        9015,
        9004,
        9018,
        9004,
        9011,
        9008,
        9012,
        9006,
        9023,
        9009,
        9011,
        9007,
        9009,
        10229,
        10473,
        10612,
        10684,
        10747,
        10782,
        10801,
        10823,
        10822,
        10854,
        10845,
        10846,
        10856,
        10839,
        10860,
        10844,
        10853,
        10847,
        10849,
        10868,
        10849,
        10849,
        10859,
        10854,
        10860,
        10852,
        10861,
        10851,
        10858,
        10853,
        10831,
        10835,
        10837,
        10842,
        10843,
        10822,
        10827,
        10831,
        10822,
        10840,
        10807,
        10807,
        10838,
        10809,
        10818,
        10797,
        10803,
        10808,
        10805,
        10816,
        10783,
        10788,
        10781,
        10781,
        10777,
        10771,
        10785,
        10767,
        10781,
        10779,
        10811,
        10831,
        10824,
        10841,
        10829,
        10842,
        10830,
        10835,
        10831,
        10838,
        10833,
        10845,
        10820,
        10829,
        10827,
        10821,
        10824,
        10839,
        10835,
        10836,
        10813,
        10829,
        10828,
        10822,
        10819,
        10819,
        10828,
        10827,
        10811,
        10822,
        10134,
        9582,
        9097,
        8699,
        8418,
        8208,
        8085,
        7977,
        7921,
        7874,
        7843,
        7818,
        7809,
        7799,
        7795,
        7788,
        7781,
        7779,
        7780,
        7770,
        6290,
        6207,
        6165,
        6130,
        6110,
        6070,
        6053,
        6042,
        6022,
        6004,
        5998,
        5985,
        5979,
        5958,
        5959,
        5947,
        5948,
        5941,
        5923,
        5929,
        5925,
        5919,
        5916,
        5916,
        5923,
        5902,
        5911,
        5901,
        5903,
        5895,
        5907,
        5904,
        5891,
        5896,
        5895,
        5894,
        5885,
        5889,
        5888,
        5885,
        5883,
        5888,
        5888,
        5883,
        5889,
        5898,
        5887,
        5884,
        5878,
        5881,
        5878,
        5889,
        5876,
        5877,
        5889,
        5893,
        5892,
        5877,
        5891,
        5880,
        5882,
        5894,
        5893,
        5895,
        5879,
        5899,
        5891,
        5881,
        5887,
        5891,
        5893,
        5894,
        5893,
        5891,
        5893,
        5890,
        5893,
        5899,
        5885,
        5893,
        5894,
        5895,
        5889,
        5899,
        5906,
        5902,
        5908,
        5896,
        5907,
        5902,
        5909,
        5901,
        5897,
        5912,
        5912,
        5908,
        5911,
        5911,
        5908,
        5907,
        5920,
        5904,
        5916,
        5910,
        5917,
        5923,
        5924,
        5927,
        5913,
        5924,
        5924,
        5928,
        5927,
        5929,
        5921,
        5927,
        5938,
        5930,
        5936,
        5936,
        5928,
        5941,
        5943,
        5943,
        5934,
        5942,
        5949,
        5944,
        5951,
        5936,
        5950,
        5947,
        5959,
        5954,
        5958,
        5957,
        5950,
        5958,
        5954,
        5963,
        5959,
        5962,
        5973,
        5965,
        5968,
        5962,
        5968,
        5971,
        5976,
        5975,
        9654,
        9639,
        9652,
        9649,
        9664,
        9641,
        9646,
        9650,
        9653,
        9649,
        9653,
        9655,
        9657,
        9647,
        9652,
        9649,
        9647,
        9642,
        9643,
        9647,
        10261,
        10381,
        10426,
        10450,
        10484,
        10485,
        10494,
        10501,
        10491,
        10498,
        10514,
        10505,
        10519,
        10514,
        10511,
        10507,
        10511,
        10519,
        10511,
        10513,
        10511,
        10511,
        10509,
        10521,
        10514,
        10509,
        10509,
        10523,
        10513,
        10506,
        10503,
        10501,
        10498,
        10499,
        10501,
        10485,
        10488,
        10499,
        10498,
        10511,
        10486,
        10482,
        10475,
        10487,
        10474,
        10485,
        10482,
        10476,
        10472,
        10470,
        10461,
        10457,
        10454,
        10458,
        10448,
        10447,
        10455,
        10448,
        10452,
        10460,
        10482,
        10487,
        10503,
        10497,
        10497,
        10509,
        10502,
        10489,
        10490,
        10495,
        10496,
        10495,
        10493,
        10493,
        10485,
        10486,
        10493,
        10502,
        10493,
        10501,
        10483,
        10482,
        10489,
        10480,
        10487,
        10483,
        10487,
        10481,
        10478,
        10482,
        9891,
        9374,
        8895,
        8511,
        8208,
        8019,
        7872,
        7770,
        7702,
        7652,
        7615,
        7602,
        7580,
        7556,
        7545,
        7545,
        7530,
        7531,
        7525,
        7526,
        6215,
        6127,
        6087,
        6055,
        6024,
        5994,
        5979,
        5955,
        5941,
        5929,
        5915,
        5904,
        5898,
        5888,
        5889,
        5879,
        5865,
        5868,
        5872,
        5861,
        5858,
        5842,
        5838,
        5839,
        5840,
        5838,
        5828,
        5820,
        5830,
        5829,
        5825,
        5815,
        5819,
        5827,
        5825,
        5825,
        5810,
        5809,
        5807,
        5816,
        5814,
        5804,
        5803,
        5816,
        5816,
        5812,
        5807,
        5800,
        5810,
        5810,
        5809,
        5802,
        5799,
        5803,
        5806,
        5806,
        5803,
        5814,
        5812,
        5806,
        5809,
        5806,
        5812,
        5807,
        5810,
        5810,
        5811,
        5813,
        5812,
        5813,
        5811,
        5814,
        5805,
        5818,
        5809,
        5815,
        5826,
        5806,
        5806,
        5817,
        5820,
        5816,
        5814,
        5813,
        5822,
        5814,
        5815,
        5823,
        5813,
        5826,
        5825,
        5823,
        5822,
        5820,
        5837,
        5823,
        5836,
        5829,
        5825,
        5835,
        5834,
        5836,
        5838,
        5831,
        5828,
        5834,
        5836,
        5844,
        5841,
        5848,
        5838,
        5847,
        5849,
        5837,
        5847,
        5857,
        5860,
        5852,
        5857,
        5847,
        5856,
        5858,
        5860,
        5865,
        5857,
        5861,
        5858,
        5865,
        5870,
        5865,
        5861,
        5870,
        5873,
        5874,
        5866,
        5868,
        5877,
        5879,
        5879,
        5871,
        5878,
        5890,
        5879,
        5886,
        5886,
        5886,
        5890,
        5895,
        5897,
        5894,
        10012,
        10016,
        10008,
        10004,
        9999,
        10000,
        10000,
        9993,
        9994,
        10001,
        10001,
        9999,
        9994,
        9997,
        9993,
        9995,
        9993,
        9995,
        9991,
        9991,
        10268,
        10322,
        10345,
        10346,
        10351,
        10362,
        10361,
        10359,
        10363,
        10364,
        10361,
        10367,
        10354,
        10362,
        10365,
        10371,
        10370,
        10368,
        10365,
        10367,
        10369,
        10368,
        10362,
        10373,
        10362,
        10364,
        10369,
        10366,
        10365,
        10357,
        10349,
        10351,
        10350,
        10350,
        10356,
        10352,
        10351,
        10348,
        10349,
        10350,
        10344,
        10339,
        10338,
        10331,
        10334,
        10335,
        10336,
        10333,
        10332,
        10335,
        10318,
        10309,
        10307,
        10305,
        10307,
        10306,
        10305,
        10304,
        10303,
        10309,
        10341,
        10339,
        10351,
        10353,
        10347,
        10349,
        10359,
        10350,
        10349,
        10349,
        10346,
        10352,
        10352,
        10344,
        10343,
        10343,
        10341,
        10339,
        10335,
        10343,
        10341,
        10342,
        10338,
        10342,
        10341,
        10340,
        10347,
        10341,
        10340,
        10344,
        9766,
        9250,
        8773,
        8393,
        8109,
        7892,
        7746,
        7639,
        7563,
        7513,
        7476,
        7453,
        7440,
        7415,
        7402,
        7398,
        7388,
        7386,
        7376,
        7373,
        6145,
        6075,
        6028,
        5995,
        5975,
        5945,
        5933,
        5912,
        5894,
        5882,
        5874,
        5862,
        5847,
        5833,
        5825,
        5823,
        5814,
        5811,
        5805,
        5795,
        5795,
        5789,
        5789,
        5784,
        5780,
        5778,
        5775,
        5776,
        5768,
        5768,
        5765,
        5764,
        5762,
        5760,
        5767,
        5762,
        5764,
        5757,
        5758,
        5759,
        5752,
        5758,
        5752,
        5751,
        5751,
        5753,
        5750,
        5753,
        5752,
        5750,
        5748,
        5750,
        5750,
        5750,
        5752,
        5748,
        5749,
        5749,
        5749,
        5751,
        5752,
        5751,
        5758,
        5751,
        5750,
        5754,
        5752,
        5754,
        5752,
        5753,
        5756,
        5753,
        5758,
        5759,
        5753,
        5753,
        5754,
        5758,
        5756,
        5756,
        5757,
        5759,
        5762,
        5761,
        5765,
        5762,
        5767,
        5759,
        5764,
        5775,
        5765,
        5776,
        5765,
        5771,
        5767,
        5767,
        5773,
        5771,
        5769,
        5770,
        5783,
        5779,
        5789,
        5775,
        5775,
        5785,
        5777,
        5778,
        5781,
        5775,
        5783,
        5785,
        5785,
        5784,
        5793,
        5787,
        5793,
        5792,
        5797,
        5795,
        5793,
        5797,
        5797,
        5797,
        5799,
        5805,
        5801,
        5802,
        5800,
        5806,
        5809,
        5807,
        5810,
        5805,
        5809,
        5817,
        5816,
        5820,
        5814,
        5816,
        5823,
        5829,
        5825,
        5819,
        5823,
        5829,
        5827,
        5827,
        5831,
        5832
      ]
    }
  ],
  "app_os": "mac",
  "app_name": "PhotosynQ",
  "app_version": "0.3.8",
  "app_device": "x86-64",
  "location": [
    "43.0087809",
    "-78.7838237"
  ],
  "notes": "macro_Dev"
}
Default avatar
Created by

Jonathan R Pleban


Protocol connections:
0
Latest Update:
Jun 2017