<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Need Help with JSL for Pressure Compensated Temperature Formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288056#M55534</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for an example or some guidance on how to get started writing JSL for the following Pressure Compensated Temperature:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Create a UI to select a Temperature column and Pressure Column.&amp;nbsp; Also have user input a Reference Pressure, Conversion Factor, Purity factor.&lt;/LI&gt;&lt;LI&gt;Calculate the Pressure Compensated Temperature for each row using several IF statements and mathematical expressions using the UI data.&lt;/LI&gt;&lt;LI&gt;Create a new column and fill it in with the Pressure Compensated Temperature calculated above.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 23:36:03 GMT</pubDate>
    <dc:creator>texas_stats</dc:creator>
    <dc:date>2023-06-09T23:36:03Z</dc:date>
    <item>
      <title>Need Help with JSL for Pressure Compensated Temperature Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288056#M55534</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for an example or some guidance on how to get started writing JSL for the following Pressure Compensated Temperature:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Create a UI to select a Temperature column and Pressure Column.&amp;nbsp; Also have user input a Reference Pressure, Conversion Factor, Purity factor.&lt;/LI&gt;&lt;LI&gt;Calculate the Pressure Compensated Temperature for each row using several IF statements and mathematical expressions using the UI data.&lt;/LI&gt;&lt;LI&gt;Create a new column and fill it in with the Pressure Compensated Temperature calculated above.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:36:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288056#M55534</guid>
      <dc:creator>texas_stats</dc:creator>
      <dc:date>2023-06-09T23:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with JSL for Pressure Compensated Temperature Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288101#M55546</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Read the Scripting Guide in the JMP Documentation Library downloaded when JMP was installed&lt;/LI&gt;
&lt;LI&gt;I can help you a bit with the UI, but "&lt;SPAN&gt;Calculate the Pressure Compensated Temperature for each row using several IF statements and mathematical expressions using the UI data.&lt;/SPAN&gt;"&amp;nbsp; is too vague to really guide you.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dlg.PNG" style="width: 443px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/26409iBCFC365A0D13C183/image-size/large?v=v2&amp;amp;px=999" role="button" title="dlg.PNG" alt="dlg.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is the JSL for the above.&amp;nbsp; You will just need to take the info from the window and plug it into your formulas.&amp;nbsp; Read the sections in the documentation on Column Dialog() and on New Column()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
dtList = New Table("Example Data",
	new column("Temperature"),
	new column("Pressure")
);

dlg = Column Dialog(
	temperatureCol = ColList( "Temperature", Min Col( 1 ), Max Col( 2 ), Data Type( "Numeric" ) ),
	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( . ),
		Text Box( "Purity Factor" ), purFactor = EditNumber( . )
	));

show(dlg);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 21:02:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288101#M55546</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-08-25T21:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with JSL for Pressure Compensated Temperature Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288115#M55555</link>
      <description>&lt;P&gt;Cool! not sure I ever used column dialog, but it seems perfect for this job.&lt;/P&gt;&lt;P&gt;After you get Jim's example running, try some code like this to add a formula column to your table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; New Column( "adjusted",
			formula( // random formula that uses all the variables AND shows an if() stmt
				If( Expr( dlg["refPressure"] ) &amp;gt; Expr( dlg["pressureCol"][1] ), 
					Expr( dlg["temperatureCol"][1] ) + // first item of list
					Expr( dlg["pressureCol"][1] ) + //
					Expr( dlg["conFactor"] ) + // simple value
					Expr( dlg["purFactor"] ) + //
					Expr( dlg["refPressure"] )// do the ususal stuff...
				, // else refPressure &amp;lt;= pressureCol...
					Expr( dlg["temperatureCol"][1] ) + // first item of list
					Expr( dlg["pressureCol"][1] ) + //
					Expr( dlg["conFactor"] ) + // simple value
					Expr( dlg["purFactor"] ) + //
					Sqrt( Expr( dlg["refPressure"] ) )// do something extra for low ref
				)
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are several things going on here.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;formula() does not evaluate its argument, so you have to give it some help&lt;/LI&gt;&lt;LI&gt;I fall back on the eval(evalexpr(expr(...))) technique. There are other ways.&lt;/LI&gt;&lt;LI&gt;you said you need an if(...) so I made one. You can use any JSL you like that produces a simple number for a result. The result of an if() is the last value it computes.&lt;/LI&gt;&lt;LI&gt;if you need to use a variable more than once in your formula, look at the formula above.&lt;/LI&gt;&lt;LI&gt;Clearly my formula is not the one you are looking for!&lt;/LI&gt;&lt;LI&gt;For simple formulas, you don't need all the evalexpr stuff. formula(:pressure * :temperature) works fine. But in this example, you don't know the names of the columns; instead you know the name of a variable that holds the name of the column.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;for reference, the dlg returns this list:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// this is what the dlg returns; the columns are a list of 1 item
// and the parameters are simple values:
//
// {temperatureCol = {:Temperature}, pressureCol = {:Pressure}, 
// Text Box, refPressure = 3, Text Box, conFactor = 33, 
// Text Box, purFactor = 333, Button( 1 )}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Finally, be sure to look at the formula you created using the formula editor to make sure it is really what you expect!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Click the + next to the column name to open the formula in the editor" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/26413iB95D0FC7E732ED84/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Click the + next to the column name to open the formula in the editor" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Click the + next to the column name to open the formula in the editor&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 00:09:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288115#M55555</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2020-08-26T00:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with JSL for Pressure Compensated Temperature Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288132#M55559</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;What do you mean by "&lt;SPAN&gt;Pressure Compensated Temperature"? More specific details would be easier for support&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 03:41:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288132#M55559</guid>
      <dc:creator>ThuongLe</dc:creator>
      <dc:date>2020-08-26T03:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with JSL for Pressure Compensated Temperature Formula</title>
      <link>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288305#M55569</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you both very much!&amp;nbsp; This is exactly what I needed.&amp;nbsp; This may not be optimal, but I ended up creating intermediate columns with formulas to derive the pressure compensated temperature (pct).&amp;nbsp; I didn't want several intermediate columns in my data table, so I removed the formula from the pct and deleted the intermediate columns.&amp;nbsp; If I ever add more rows of data I'll have to rerun the script.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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)&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//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 &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; 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 &amp;lt;&amp;lt; 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 &amp;gt;= 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 &amp;gt;= 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") &amp;lt;&amp;lt; delete formula;
Column("TB") &amp;lt;&amp;lt; Set Name( dlg["pcompTag"] ); 

dtList &amp;lt;&amp;lt; delete columns( {"PA","PB","TA","AA","AB","DEN"} );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Aug 2020 13:09:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Need-Help-with-JSL-for-Pressure-Compensated-Temperature-Formula/m-p/288305#M55569</guid>
      <dc:creator>texas_stats</dc:creator>
      <dc:date>2020-08-26T13:09:35Z</dc:date>
    </item>
  </channel>
</rss>

