@txnelson @Craige_Hales
Thank you both very much! This is exactly what I needed. This may not be optimal, but I ended up creating intermediate columns with formulas to derive the pressure compensated temperature (pct). I didn't want several intermediate columns in my data table, so I removed the formula from the pct and deleted the intermediate columns. If I ever add more rows of data I'll have to rerun the script.
I pasted the code I came up with below (but note that I had to change all the constants / coefficients since it's for my work)
//Script for creating a pressure compensated temperature tag
//Rev 1 8/25/20
names default to here(1);
/*dtList = New Table("Example Data",
new column("Temperature"),
new column("Pressure")
);*/
dtList = CurrentDataTable();
dlg = Column Dialog(
temperatureCol = ColList( "Temperature", Max Col( 1 ), Modeling Type( {"Continuous", "Multiple Response"} ) ),
pressureCol = ColList( "Pressure", Max Col( 1 ), Modeling Type( {"Continuous", "Multiple Response"} ) ),
Line Up( 2,
Text Box( "Reference Pressure" ), refPressure = EditNumber( . ),
Text Box( "Conversion Factor" ), conFactor = EditNumber( 1 ),
Text Box( "Purity Factor" ), purFactor = EditNumber( 1 ),
Text Box( "Pressure Units"), unitsP = comboBox( {"Gauge","Absolute"}),
Text Box( "PComp Tag Name"), pcompTag = EditText( "PComp Tag" )
),
Text Box("
**Reference Pressure is the base pressure and must be in the same units as the pressure tag.
**Pressure Units is a logical to indicate if the pressure being measured is absolute or gauge. For most
situations, the pressure will be measure in terms of gauge. However, vacuum pipestills typically use absolute.
**PComp Tag Name will be the column name of the new Pressure Compensate Temperature tag.
"),
);
show(dlg);
//Absolute needs to be 0 and Gauge needs to be 1. The combo box has Absolute as 2 and Gauge as 1,
If( dlg["unitsP"] == 1, dlg["unitsP"] = 1, dlg["unitsP"] = 0 );
//Write("unitsP equals: ", dlg["unitsP"]);
Eval( // run the code below
Eval Expr( // convert the Expr(...) below into a hard coded value
// eval(evalexpr(expr(...))) is a pattern for getting values from the dlg INTO
// A FORMULA. if you follow this pattern, the formula will be self contained.
dtList << New Column( "PA",
formula( // random formula that uses all the variables AND shows an if() stmt
Expr( dlg["purFactor"] ) *
(Expr( dlg["unitsP"] ) + Expr( dlg["pressureCol"][1] ) * Expr( dlg["purFactor"] ) / 12)
)
)
)
);
Eval( // run the code below
Eval Expr(
dtList << New Column( "PB",
formula( // random formula that uses all the variables AND shows an if() stmt
Expr( dlg["refPressure"] ) * Expr( dlg["conFactor"] ) / 12 + Expr( dlg["unitsP"] )
)
)
)
);
Eval(
Eval Expr(
dtList << New Column( "TA",
formula( // random formula that uses all the variables AND shows an if() stmt
Expr( dlg["temperatureCol"][1] ) + 400
)
)
)
);
New Column( "AA",
formula(
If( :PA >= 1.1111 ,
(4 - LOG10(:PA)) / (2000 - 25*LOG10(:PA)) - 0.0001
, // else
(3- LOG10(:PA)) / (2000 - 25*LOG10(:PA)) - 0.0001
)
)
);
New Column( "AB",
formula(
If( :PB >= 1.1111 ,
(4 - LOG10(:PB)) / (2000 - 25*LOG10(:PB)) - 0.0001
, // else
(3 - LOG10(:PB)) / (2000 - 100*LOG10(:PB)) - 0.0001
)
)
);
New Column( "DEN",
formula(
:AB / :AA * ((1.1 / :TA) - 0.0001) + 0.0001
)
);
New Column( "TB",
formula(
1.1 / :DEN - 400
)
);
Column("TB") << delete formula;
Column("TB") << Set Name( dlg["pcompTag"] );
dtList << delete columns( {"PA","PB","TA","AA","AB","DEN"} );