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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Nested Loop and conditional statements

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Zac10sim Posted - 05/03/2016 : 10:46:50 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
Shirley_GZ Posted - 11/25/2021 : 02:16:58 AM
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
SeanMao Posted - 05/04/2016 : 04:57:58 AM
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.

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000