Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
PS
PS
Level III

Accessing different data tables in a custom written function

Hi everybody,

 

I have two or more data tables

//First I define my function:
MyFunction = Function({Table},
 For each row(Table,
  shift some coordinates;
  store some values;
  do some other things;
 )
);

//Then I would like to run the function on some existing data tables
MyFunction(dt1);
MyFunction(dt2);
MyFunciton(dt3);

I cannot get it to work at the moment. I the Scripting Guide I find an elaboration using Name Expr() that may have some impact, but so far it is elusive to me.

 

Thanks for your help

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
pmroz
Super User

Re: Accessing different data tables in a custom written function

The problem with your code is that dtinitial and dtoptimizer are not pointing to anything when you call your function.  Hence you're getting an error message.  Some suggestions:

 

  • Don't use the variable Table.  Too close to a reserved word.  Maybe tbl or tbl_name?
  • Since your function creates a table I would have it take the table name as the argument and return the table pointer.
dtinitial = Tabfunction("Initial");
dtoptimizer = Tabfunction("Optimizer");

 

 

View solution in original post

Highlighted
txnelson
Super User

Re: Accessing different data tables in a custom written function

You also need to add your Table variable as the last reference in your function, so that it is passed back as the reference to the table.

abfunction = Function( {Table},
	Xlist = {};
	Ylist = {};
	NumDieX = 10;
	NumDieY = 10;
	x_mm = 10;
	y_mm = 20;
	SLW = 0.1;
	//Define X-List
	For( jj = 0, jj <= NumDieY + 2, jj++,
		For( ii = 0, ii <= NumDieX + 2, ii++,
			Insert Into( Xlist, ii )
		)
	);
	//Define Y-List
	For( kk = 0, kk <= NumDieY + 2, kk++,
		For( mm = 0, mm <= NumDieX + 2, mm++,
			Insert Into( Ylist, kk );
		)
	);
		
	Table = New Table( Char( Table ),
		Add Rows( (NumDieX + 2) * (NumDieY + 2) ),
		New Column( "DieX", Set Values( Xlist ) ),
		New Column( "DieY", Set Values( Ylist ) ),
		New Column( "DieCorXBL" ),
		New Column( "DieCorYBL" ),
		New Column( "DieCorXTL" ),
		New Column( "DieCorYTL" ),
		New Column( "DieCorXTR" ),
		New Column( "DieCorYTR" ),
		New Column( "DieCorXBR" ),
		New Column( "DieCorYBR" )
	);
	
	For Each Row(
		Table,
		:DieCorXBL = :DieX * (SLW + x_mm);
		:DieCorYBL = :DieY * (SLW + y_mm);
		
		:DieCorXTL = :DieX * (SLW + x_mm);
		:DieCorYTL = :DieY * (SLW + y_mm) + y_mm;
		
		:DieCorXTR = :DieX * (SLW + x_mm) + x_mm;
		:DieCorYTR = :DieY * (SLW + y_mm) + y_mm;
		
		:DieCorXBR = :DieX * (SLW + x_mm) + x_mm;
		:DieCorYBR = :DieY * (SLW + y_mm);
	);
	Table << New Column( "Invalid Die", numeric, Set each value( 0 ) );
	Table;
);
Jim

View solution in original post

Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

Hi,

 

now I got it to work, thanks. Below is a simple script that shows a working syntax if anyone else happens to land here:

 

Tabfunction = Function({Tablevar},
   Tablevar = New Table((Char(Tablevar)),
      Add Rows(5),
      New Column ("X1", Numeric, Set Values({1,2,3,4,5})),
      New Column ("Test", Character)
   );
   Tablevar; //pass back Tablevar
);

CalcInvalidDies = Function({Tablevar},
   For Each Row(Tablevar,
      If(:X1>2,:Test="fail",:Test="pass")
   )
);


dtinitial = Tabfunction("initial"); //use pointer
dt2 = Tabfunction ("dt2");
CalcInvalidDies(dtinitial);
CalcInvalidDies(dt2);

View solution in original post

8 REPLIES 8
Highlighted
txnelson
Super User

Re: Accessing different data tables in a custom written function

It is pretty tough to attempt to debug your code with the cryptic form it is in.  Are you getting any error messages in the log?  

For Each Row() can only have one instance running in your script, at one time.  I have a tendency to avoid it in functions.  I also typically go to a complete column reference of

Table:a[15] = 43;
// or
column( Table, "a" )[15] = 43;

to avoid having the function point to the wrong table.

Jim
Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

Hi Jim,

 

I see your point. I was working under the impression that my syntax is fundamentally wrong so I didn't need to share too many details, but it appears not to be. It works exactly as described above.

 

I spent three hours trying to fix the problem, then I wrote this question. Then I spent two ours implementing a work around, then I tried to build back the code to the initial state to reproduce an error message for you, and now everything works fine. So thanks, I guess

Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

 

Hi again,

 

the problem returned over night without changing the code. In fact that happens quite often because some variables appear to be stored somehow and after restarting the software they are deleted. Below is the code I would like to use.

Using the custom function Tabfunction I would like to create a given number of tables as shown below called dtinitial, dtoptimizer, and so forth.

 

When I run below code the error message says

"Name Unresolved: dtinitial in access or evaluation of 'dtinitial', dtinitial/*###*/"

and point to the second last row.

 

It appears I am using the function arguments wrong, am I?

 

Thanks

 

Tabfunction = Function({Table},
	Xlist={};
	Ylist={};
	NumDieX=10;
	NumDieY=10;
x_mm=10; y_mm=20;
SLW = 0.1;
//Define X-List For (jj=0, jj <= NumDieY+2, jj++, For (ii=0, ii <= NumDieX+2, ii++, InsertInto(Xlist,ii) ); ); //Define Y-List For (kk=0, kk <= NumDieY+2, kk++, For (mm=0, mm <= NumDieX+2, mm++, InsertInto(Ylist,kk) ); ); Table = New Table (Char(Table), Add Rows((NumDieX+2)*(NumDieY+2)), New Column ("DieX", Set Values (Xlist)), New Column ("DieY", Set Values (Ylist)), New Column ("DieCorXBL"), New Column ("DieCorYBL"), New Column ("DieCorXTL"), New Column ("DieCorYTL"), New Column ("DieCorXTR"), New Column ("DieCorYTR"), New Column ("DieCorXBR"), New Column ("DieCorYBR") ); For each row (Table, :DieCorXBL=:DieX*(SLW+x_mm); :DieCorYBL=:DieY*(SLW+y_mm); :DieCorXTL=:DieX*(SLW+x_mm); :DieCorYTL=:DieY*(SLW+y_mm)+y_mm; :DieCorXTR=:DieX*(SLW+x_mm)+x_mm; :DieCorYTR=:DieY*(SLW+y_mm)+y_mm; :DieCorXBR=:DieX*(SLW+x_mm)+x_mm; :DieCorYBR=:DieY*(SLW+y_mm); ); Table << New Column ("Invalid Die", numeric, Set each value (0)); ); Tabfunction(dtinitial); Tabfunction(dtoptimizer);

 

 

Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

By the way, this works:

Then, in the initial table, the invalid dies will be calculated in the appropriate column.

Only in combination with New Table () there appears to be trouble.

 

CalcInvalidDies = Function({Table},
	For Each Row(Table,
		If(SQRT((:DieCorXBL-100)^2+(:DieCorYBL-100)^2)>(WaferSize/2-EE), :Invalid Die = :Invalid Die +1);
		If(SQRT((:DieCorXTL-100)^2+(:DieCorYTL-100)^2)>(WaferSize/2-EE), :Invalid Die = :Invalid Die +1);
		If(SQRT((:DieCorXTR-100)^2+(:DieCorYTR-100)^2)>(WaferSize/2-EE), :Invalid Die = :Invalid Die +1);
		If(SQRT((:DieCorXBR-100)^2+(:DieCorYBR-100)^2)>(WaferSize/2-EE), :Invalid Die = :Invalid Die +1);
		If(:DieCorYBL<FlatEE,:Invalid Die = :Invalid Die +1);
		If(:DieCorYBR<FlatEE,:Invalid Die = :Invalid Die +1)
	)
);

CalcInvalidDies(dtinitial)
Highlighted
pmroz
Super User

Re: Accessing different data tables in a custom written function

The problem with your code is that dtinitial and dtoptimizer are not pointing to anything when you call your function.  Hence you're getting an error message.  Some suggestions:

 

  • Don't use the variable Table.  Too close to a reserved word.  Maybe tbl or tbl_name?
  • Since your function creates a table I would have it take the table name as the argument and return the table pointer.
dtinitial = Tabfunction("Initial");
dtoptimizer = Tabfunction("Optimizer");

 

 

View solution in original post

Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

Hi,

 

this works. Still not entirely, because I have the Tabfunction in a separate file and use Include("that separate file.jsl"). But further down in that separate file is some bug that makes something. If I /*comment*/ away everything below the first part, it works. I am positive I will find out what the problem is. Thanks!

 

Highlighted
txnelson
Super User

Re: Accessing different data tables in a custom written function

You also need to add your Table variable as the last reference in your function, so that it is passed back as the reference to the table.

abfunction = Function( {Table},
	Xlist = {};
	Ylist = {};
	NumDieX = 10;
	NumDieY = 10;
	x_mm = 10;
	y_mm = 20;
	SLW = 0.1;
	//Define X-List
	For( jj = 0, jj <= NumDieY + 2, jj++,
		For( ii = 0, ii <= NumDieX + 2, ii++,
			Insert Into( Xlist, ii )
		)
	);
	//Define Y-List
	For( kk = 0, kk <= NumDieY + 2, kk++,
		For( mm = 0, mm <= NumDieX + 2, mm++,
			Insert Into( Ylist, kk );
		)
	);
		
	Table = New Table( Char( Table ),
		Add Rows( (NumDieX + 2) * (NumDieY + 2) ),
		New Column( "DieX", Set Values( Xlist ) ),
		New Column( "DieY", Set Values( Ylist ) ),
		New Column( "DieCorXBL" ),
		New Column( "DieCorYBL" ),
		New Column( "DieCorXTL" ),
		New Column( "DieCorYTL" ),
		New Column( "DieCorXTR" ),
		New Column( "DieCorYTR" ),
		New Column( "DieCorXBR" ),
		New Column( "DieCorYBR" )
	);
	
	For Each Row(
		Table,
		:DieCorXBL = :DieX * (SLW + x_mm);
		:DieCorYBL = :DieY * (SLW + y_mm);
		
		:DieCorXTL = :DieX * (SLW + x_mm);
		:DieCorYTL = :DieY * (SLW + y_mm) + y_mm;
		
		:DieCorXTR = :DieX * (SLW + x_mm) + x_mm;
		:DieCorYTR = :DieY * (SLW + y_mm) + y_mm;
		
		:DieCorXBR = :DieX * (SLW + x_mm) + x_mm;
		:DieCorYBR = :DieY * (SLW + y_mm);
	);
	Table << New Column( "Invalid Die", numeric, Set each value( 0 ) );
	Table;
);
Jim

View solution in original post

Highlighted
PS
PS
Level III

Re: Accessing different data tables in a custom written function

Hi,

 

now I got it to work, thanks. Below is a simple script that shows a working syntax if anyone else happens to land here:

 

Tabfunction = Function({Tablevar},
   Tablevar = New Table((Char(Tablevar)),
      Add Rows(5),
      New Column ("X1", Numeric, Set Values({1,2,3,4,5})),
      New Column ("Test", Character)
   );
   Tablevar; //pass back Tablevar
);

CalcInvalidDies = Function({Tablevar},
   For Each Row(Tablevar,
      If(:X1>2,:Test="fail",:Test="pass")
   )
);


dtinitial = Tabfunction("initial"); //use pointer
dt2 = Tabfunction ("dt2");
CalcInvalidDies(dtinitial);
CalcInvalidDies(dt2);

View solution in original post

Article Labels

    There are no labels assigned to this post.