Choose Language Hide Translation Bar
Highlighted
Stokes
Level III

Debug a JSL for Dat File open and modify then save to close

Anyone can help to fix the jsl below,

The goal is to open all dat file under the same directory and delete 2 rows, then save it.

Thanks

 

 

directory = Pick Directory();

fileNames = Files In Directory( directory );

For( iFile = 1, iFile <= N Items( fileNames ), iFile++, 

    filename = fileNames[iFile];

    If( Ends With( filename, ".dat" ), 

        dt = Open( directory || filename );

        //delete first 2 rows
        dt << Select Where( Row() < 3 );
        dt << delete rows;

        Close( dt, "save" );

    );
);

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
txnelson
Super User

Re: Debug a JSL for Dat File open and modify then save to close

Do you get any errors in the log?  If so, what are they?

 

I suspect the Select Where is running too soon, because the file is opening, which JMP will do in the background.  Try putting the line

dt << rerun formulas;

after the open() and see if that works.

What I usually do with code like this, is to run lines 1&2.  Find the first file that ends in .dat, and set your "filename' to its value, and then run one at a time, the open, select where, delete and close lines to see what happens.

Jim

View solution in original post

Highlighted
gzmorgan0
Super User

Re: Debug a JSL for Dat File open and modify then save to close

@Stokes,

 

Jim gave you some great debug suggestions. Below are a couple notes/potential issues. As Jim suggested, the errors in the LOG  or a description your task and what happens when you run the script would be informative.

 

  • Instead of select where() and delete, you can use dt << delete rows(1::2);
  • I often use wait( 0 ); after the save, to force its completion before continuing.
  • Your script is looking for files with .DAT extension, which is a generic file type. You are reading it into JMP data table and then script a SAVE.  This has several potential issues,, unintended consequences:
  1. The file type might need more details to be read properly, so the open might be causing an error. 
  2. Assuming the file is read properly into a JMP data table, a SAVE will save the file as a .JMP file. Is that your intention? or do you want to save it as a .DAT file?  Often when users ask this type of question, they are wanting to use JMP to clean up a data file written by some automated metrology tool that has header information in a different format. That header information can cause Open() errors and other problems. So knowing the task will help the JMP community provide a solution. Depending upon the task, a Load Text File() or Open() with import text options might be required.
  3. If the response to the Pick Directory() prompt is a directory that is readable but not writable, this could cause an error, or the file being saved in an unintended directory. For example if I modify your script to read .TXT files and pick the directory for JMP Samples/Import Data, the program will read the .txt files but save them as .JMP files, but not in the JMP Samples/Import Data directory because it is not writable. 

These items are intended to help clarify the type of details that are needed to help you.

 

View solution in original post

4 REPLIES 4
Highlighted
txnelson
Super User

Re: Debug a JSL for Dat File open and modify then save to close

Do you get any errors in the log?  If so, what are they?

 

I suspect the Select Where is running too soon, because the file is opening, which JMP will do in the background.  Try putting the line

dt << rerun formulas;

after the open() and see if that works.

What I usually do with code like this, is to run lines 1&2.  Find the first file that ends in .dat, and set your "filename' to its value, and then run one at a time, the open, select where, delete and close lines to see what happens.

Jim

View solution in original post

Highlighted
gzmorgan0
Super User

Re: Debug a JSL for Dat File open and modify then save to close

@Stokes,

 

Jim gave you some great debug suggestions. Below are a couple notes/potential issues. As Jim suggested, the errors in the LOG  or a description your task and what happens when you run the script would be informative.

 

  • Instead of select where() and delete, you can use dt << delete rows(1::2);
  • I often use wait( 0 ); after the save, to force its completion before continuing.
  • Your script is looking for files with .DAT extension, which is a generic file type. You are reading it into JMP data table and then script a SAVE.  This has several potential issues,, unintended consequences:
  1. The file type might need more details to be read properly, so the open might be causing an error. 
  2. Assuming the file is read properly into a JMP data table, a SAVE will save the file as a .JMP file. Is that your intention? or do you want to save it as a .DAT file?  Often when users ask this type of question, they are wanting to use JMP to clean up a data file written by some automated metrology tool that has header information in a different format. That header information can cause Open() errors and other problems. So knowing the task will help the JMP community provide a solution. Depending upon the task, a Load Text File() or Open() with import text options might be required.
  3. If the response to the Pick Directory() prompt is a directory that is readable but not writable, this could cause an error, or the file being saved in an unintended directory. For example if I modify your script to read .TXT files and pick the directory for JMP Samples/Import Data, the program will read the .txt files but save them as .JMP files, but not in the JMP Samples/Import Data directory because it is not writable. 

These items are intended to help clarify the type of details that are needed to help you.

 

View solution in original post

Highlighted
Stokes
Level III

Re: Debug a JSL for Dat File open and modify then save to close

Thanks Jim, Morgon.

I used step by step method to check the loop, and it turns out the issue happens when open the .dat file.

There is no response after run open .dat.

I change it to open .txt and it works fine.

Do you have any idea why this happens and how to fix it?
Thanks

Highlighted
Stokes
Level III

Re: Debug a JSL for Dat File open and modify then save to close

I fixed the bug by doing modification below,

If( Right( y[i], 3 ) == "dat", ...............

 

Thanks a lot

Article Labels