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
 Forum for Origin C
 Automate loop process for all workbooks

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
GaussianFit Posted - 09/17/2012 : 4:33:16 PM
Origin Ver. and Service Release (Select Help-->About Origin): 8.0 SR6
Operating System: Windows XP

Hi,

I'm trying to automate a batch data process with Origin C but couldn't figure it out as I'm not familar with C programming. I'm sorting helps from the gurus here:

There are many workbooks bearing the name like these:

"R=32.976ANDI=0uA.dat",
"R=32.976ANDI=10uA.dat",
"R=32.976ANDI=20uA.dat",
"R=48.295ANDI=0uA.dat",
"R=48.295ANDI=6uA.dat",
"R=48.295ANDI=12uA.dat",
...

The workbooks can be cateogrized/indexed by their "R" (resistance) values. For each R value, there is one "zero-current" workbook with "I=0uA" in its name, and a few "non-zero current" workbooks with non zero values such as I=10uA, I=20uA, etc.

Each workbook has two columns: col(A) and col(B). Col(A) is the index vector and col(B) vector is the real data. An important fact is that all the zero-current workbooks have complete col(A) values, say col(A) = i for i=1 to 200; while for the non-zero current ones, some of col(A) rows (and the corresponding col(B) rows) are missing. So they may have different lengths less than 200. This was done by a previous filtering process that removed "bad" rows.

The batch process should perform the following steps for all the workbooks under the same folder:

- Search for all the zero-current workbooks, for example R=32.976ANDI=0uA.dat, etc. and generate a new workbook called "R=32.976Average.dat", and copy col(A) from the zero-current workbook into the new "Average" workbook. Of course one can also generate col(A) directly by setting a formula like col(A)=i (i=1 to 200).

- For each non-zero-current workbook in the same R value group, e.g. "R=32.976ANDI=10uA.dat", copy its col(B) values to the new "Average" workbook as a new column, and add a long name like "col(B) in I=10uA", here I=10uA is taken from the I value of the workbook. If there are six different I values with the same R value, then six new data columns will be generated. ** Because each non-zero current workbook may have different col(A) vectors, a simple copy & paste won't work. For rows with missing col(A) values, the corresponding col(B) values will be empty in the new "Average workbook. So a row by row loop is probably needed for such a job.

- Convert all the new generated data columns to log scale, by setting their values as log(col()) in the "Average" workbook.

- For the missing rows, use a linear interpolation to calculate their values. For example, if row 3 and 4 are missing in col(B), then calculate their values using linear interpolation from row 2 and 5 values.

- Perform a row statistics: add two more columns, Mean_Log and STDEV_Log, and set their values to be the mean of all the data columns (now in log scale) and the corresponding standard deviations.

Sorry about the lenghthy description, I'm really grateful for any input.
5   L A T E S T    R E P L I E S    (Newest First)
Penn Posted - 09/23/2012 : 11:50:53 PM
Hi,

You can try to do it in a loop for all rows. For example:

int i1 = 0;  // sheetA row index
int i2 = 0;  // sheetB row index
for(int ii=0; ii<sheetC_colA.GetSize(); ii++)  // loop by row index in sheetC, sheetC_colA is the vector for sheet C column A, the same for the following
{
    if(i1<sheetA_colA.GetSize())
    {
        if(sheetA_colA[i1] == sheetC_colA[ii])  // copy sheetA column B data
        {
            sheetC_colB[ii] = sheetA_colB[i1];
            i1++;
        }
    }

    if(i2<sheetB_colA.GetSize())
    {
        if(sheetB_colA[i2] == sheetC_colA[ii])  // copy sheetB column B data
        {
            sheetC_colC[ii] = sheetB_colB[i2];
            i2++;
        }
    }
}


Penn
GaussianFit Posted - 09/21/2012 : 11:57:59 AM
quote:
Originally posted by rlewis

The error arises because you were trying to store WorksheetPage objects in an array designed for pointers to WorksheetPage Objects .. The following modification should execute without error ..



Thanks for pointing it out. With you guys' help I've got the first step done. Still need to figure out the 2nd step. Essentially like this:

Worksheet A (has col(a) as index and col(b) as data)

1   0.2939
2   1.3871
4   1.3047
5   1.3653

Worksheet B (has col(a) as index and col(b) as data)

2   8.3761
3   4.2690
4   6.2603
5   9.1609

Worksheet C (the "Average" workbook, only has col(a) index now)

1
2
3
4
5

If col(a) in worksheet A = col(a) in worksheet C,
copy col(b) in worksheet A into col(b) in worksheet C.
Repeat the same for worksheet B (by adding another col(c) in C)

The final worksheet C becomes:

1   0.2939
2   1.3871   8.3761
3            4.2690
4   1.3047   6.2603
5   1.3653   9.1609
rlewis Posted - 09/19/2012 : 1:42:17 PM
The error arises because you were trying to store WorksheetPage objects in an array designed for pointers to WorksheetPage Objects .. The following modification should execute without error ..


void WkbProcess()
{
	Array<PageBase&> DataWorkBooks;     // Declare an Array of pointers to PageBase Objects
	DataWorkBooks.SetAsOwner(false);
	DataWorkBooks.SetSize(0);
	
	foreach (PageBase pB in Project.Pages)
	{
		if(pB.GetType()==EXIST_WKS)
		{
			WorksheetPage Wpg(pB);
			if(Wpg.IsValid()==false)
			{
				out_str("Error Accessing WorksheetPage : "+pB.GetName());
				return;
			}
			
			WorksheetPage *pwPg;          //  Declare a pointer to a WorksheetPage Object
			pwPg=new WorksheetPage(Wpg);  //  Assign the pointer the Adress of the Worksheet Object Wpg
			DataWorkBooks.Add(*pwPg);     //  Add the Pointer to the Array DataWorkbooks
			string strName = Wpg.GetLongName();
        	printf("%s\n", strName );
		}
	}
	
	printf("Number of Workbooks in the array = %d\n", DataWorkBooks.GetSize());

	for(int i=0;i<DataWorkBooks.GetSize();i++)
	{
		WorksheetPage wpRef=DataWorkBooks.GetAt(i);
		if(wpRef.IsValid()==false)
		{
			out_str("Error in Accessing Referenced Workbook ...");
		}
	}

}

GaussianFit Posted - 09/19/2012 : 12:57:47 PM
quote:
Originally posted by Penn

Hi,

Basically, your requirement is covering lots of trial things. Maybe you can refer to the following hints.

1. Searching workbook is quite like the string manipulation. For these step, you can refer to Pages in Folder, Check Page Type, and string manipulation.

2. This is mostly about accessing worksheet data, you can refer to AddCol method, SetLongName method, and Data Access from Worksheet.

3. Please see Exponential Functions.

4. Interpolation functions can be found here. Especially, ocmath_interpolate is able to perform linear interpolation.

5. The ocmath_row_desc_stats function can be used to perform row statistics.

Penn



Hi Penn,

Thanks for the tips! I'm still at the beginner stage in learing Origin C (or any programming) so many of these are not trival at all for me.

Here is the first problem I ran into: the code is trying to collect all the workbook pages in the project into an array for easier calling. It compiles ok but returns "External call execution error" when executed:

void WkbProcess()
{
	Array<PageBase&> DataWorkBooks;
	DataWorkBooks.SetAsOwner(false);
	DataWorkBooks.SetSize(0);
	
	foreach (PageBase pB in Project.Pages)
	{
		if(pB.GetType()==EXIST_WKS)
		{
			WorksheetPage Wpg(pB);
			if(Wpg.IsValid()==false)
			{
				out_str("Error Accessing WorksheetPage : "+pB.GetName());
				return;
			}
		string strName = Wpg.GetLongName();
        printf("%s\n", strName );
        DataWorkBooks.Add(Wpg);
		}
	}
	
	printf("Number of Workbooks in the array = %d\n", DataWorkBooks.GetSize());

	for(int i=0;i<DataWorkBooks.GetSize();i++)
	{
		WorksheetPage wpRef=DataWorkBooks.GetAt(i);
		if(wpRef.IsValid()==false)
		{
			out_str("Error in Accessing Referenced Workbook ...");
		}
	}

}


Penn Posted - 09/18/2012 : 03:53:59 AM
Hi,

Basically, your requirement is covering lots of trial things. Maybe you can refer to the following hints.

1. Searching workbook is quite like the string manipulation. For these step, you can refer to Pages in Folder, Check Page Type, and string manipulation.

2. This is mostly about accessing worksheet data, you can refer to AddCol method, SetLongName method, and Data Access from Worksheet.

3. Please see Exponential Functions.

4. Interpolation functions can be found here. Especially, ocmath_interpolate is able to perform linear interpolation.

5. The ocmath_row_desc_stats function can be used to perform row statistics.

Penn

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