The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Nested Loop and conditional statements
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Zac10sim

USA
1 Posts

Posted - 05/03/2016 :  10:46:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I am new to Origin LabTalk coding. I have experimented to the point I feel comfortable constructing code strings individually however; this is my first attempt at a full import code.

I have files which are sorted by scan number and then sample number afterwards. what I want is to sort all the run with the same sample number into a single folder. The file name is constructed as such.

APS10_Scannumber_Samplenumber.extension.

I have thus constructed my code to step this way.
Create new folder
import samples into folder
Rename project folder repeat.

For this I need two nested for loops and a conditional if-else statement as a result of the file naming scheme.

The main issue I run into is the code will not add the filename strings to the variable stack and sometimes will not enter the if loop.

Any advice you can give would be much appreciated.

//Declare Initial Variables
int samplenum = 1;
int filenumber = 1;
int scannumber = 148;

//Main for loop for creating folder structure
for(samplenum =1 ; samplenum < 18 ; samplenum++)
{

//Creates new project folder
doc -nf;


//Nested for loop which is designed to import the files directly into newly created project folder.
for (filenumber =1; filenumber < 18; filenumber++)
{

//Convert Ints to string for use in file name creation
int scanstring = scannumber
string scannum$ = $(scanstring);
int filestring = filenumber
string filenum$ = $(filestring);

// If-else loop differentiates between file name because after the 9th file the final four numbers become 0010 instead of 00010.
if (filenumber < 10)
string filename$ = "Aps10_" + scannum$ + "_000" + filenum$;

else
string filename$ = "Aps10_" + scannum$ + "_00" + filenum$;

//Creates filename string which will be used with import command to follow.
string fullfilename$ ="C:\Users\zm1\Dropbox (ORNL)\Cerium-Aluminum-Directory\XRD\Synchrotrom\Al-Ce (F)\Al-Ce (F)\" + filename$ +".chi";

//Imports file using fullfilename variable
impasc fname := fullfilename$;

//Iterates scannumber up one to move to the next scan.
int temp1 = scannumber;
int scannumber = temp1 + 1;
};

//Renames the folder and then navigates back to project root directory.
string SampleNumber$ = $(samplenum);
String FolderName = "Sample ";
string Foldername2 = Foldername$ + SampleNumber$;
pe_cd /;
pe_rename Folder1 Foldername2$;

};

In Christ,
Zach

SeanMao

China
288 Posts

Posted - 05/04/2016 :  04:57:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I did a simple test and write the following code, you can revise it accordingly to fit your own case:


int scannum = 1; 
int filenumber =1;
pe_path path:=rootpath$; // Remeber rootpath
//Main for loop for creating folder structure
for(samplenum =1 ; samplenum < 5  ; samplenum++)
{
string temp$ = $(samplenum);
string Foldername$ = "Sample"+ temp$;
pe_mkdir folder:=Foldername$ cd:=1 path:=fpath$; // make new folder with name
//Nested for loop which is designed to import the files directly into newly created project folder. 
for (filenumber =1; filenumber < 5; filenumber++)
{
//Convert Ints to string for use in file name creation
int scanstring = scannum;
string scannum$ = $(scanstring); 
int filestring = filenumber;
string filenum$ = $(filestring);
string filename$;
scannum$=;
filenum$=;
// If-else loop differentiates between file name because after the 9th file the final four numbers become 0010 instead of 00010. 
if (filenumber < 10)
	filename$ = "Aps10_" + scannum$ + "_000" + filenum$;
else 
	filename$ = "Aps10_" + %(scannum$) + "_00" + %(filenum$);
filename$=;
//Creates filename string which will be used with import command to follow. 
string fullfilename$ ="E:\\Subfolders\\"+filename$+".txt";
fullfilename$=;
//Imports file using fullfilename variable
impasc fname:= fullfilename$ options.impmode:=3;  //start new book
//Iterates scannumber up one to move to the next scan. 
};
pe_cd rootpath$; // Return to rootpath
};




Regards!

Sean

OriginLab Tech.
Go to Top of Page

Shirley_GZ

China
Posts

Posted - 11/25/2021 :  02:16:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Zach,

The issue about "Support More LabTalk Options for Fill Area Under Curve(ORG-14660)" has been fixed in recently-released Origin 2022.

Please download or upgrade to Origin 2022 to have a try.

Thanks,
Shirley

Originlab Technical Service Team
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000