Author |
Topic  |
|
peter.cook
UK
356 Posts |
Posted - 02/11/2006 : 02:48:50 AM
|
Origin Version (Select Help-->About Origin): Origin 7.5 SR6 Operating System: Win 2000
Hi,
Could anyone please help by providing a simple example (Origin C code + C++) to manipulate a worksheet with a text and a numeric column using an external dll. Thanks in advance.
Cheers,
Pete
|
|
cpyang
USA
1406 Posts |
Posted - 02/11/2006 : 8:49:23 PM
|
Can you give a bit more details? Text column might be a problem. If you have text in a "Text & Numeric" column, then you can use GetStringArray to get all the text, and then you can pass as vector<string> into a DLL and get the pointer of CStringArray.
CP
|
 |
|
peter.cook
UK
356 Posts |
Posted - 02/12/2006 : 05:04:30 AM
|
Hi CP,
Thanks for the reply.
My immediate problem is simply trying to speed up data processing. The rate limiting step is some OC code that scans Text columns to replace '--' by a blank ie delete. The '--' missing symbol values arise from missing numeric data in either text & numeric or numeric columns. I have requested the option to not have the '--' displayed via the beta forum and personally would like to see it done away with (at least as an option). The file export option only works for numeric columns not text or text and numeric.
We have to match data format to the Oracle settings so for example I need to :
set/check number of decimal places set/check number of significant figures set/check number of max characters trim trailing zeroes remove '--'
This entails conversion to text columns for the last 3 steps. (I can submit the code if you wish).
So, I was hoping to use an external dll to speed this up, hence my request.
On another point the only example is accessing a matrix which seems to be the simplest case? It would be really useful to have a simple example or two to show how to inteface with datasets, columns and worksheets though I had completely missed the approach (not that it would have occurred) of passing as string array.
I should also mention that some numeric data ie sample ids needs to be treated as text hence I can't readily use text & numeric.
Thanks,
Cheers,
Pete
|
 |
|
ML
USA
63 Posts |
Posted - 02/17/2006 : 2:48:51 PM
|
Hi Pete,
You put the processed array back into the dataset eventually. Are the values yout put back all numeric?
Would it work if you just worked with the actual numeric values (i.e. doubles) instead of strings? This way you can recognize a missing value (NANUM which is a special value), and change this double value according to your desires as to trimming, removing missing values, changing the maximum of chars (I don't quite understand what that means, though) - all that by changing the actual numeric values. In your DLL you would make use of things like sprintf() and atof() to go back and forth. Numeric values can easily be passed in as an array via one double* (i.e. pointer) plus an integer indicating the total size. In terms of interfacing with Origin the double* method would be by far the fastest.
If you would like to turn some cells into string cells with empty strings (because they were NANUM originally), you supply an addtional array of bool's (size one byte each) that would be populated by your DLL with indices of cells where the empty string should be, and then separately looping only over those in OC and putting them into the dataset as such. If the number of such cells is small, this would still be reasonably fast.
Thanks,
ML
|
 |
|
peter.cook
UK
356 Posts |
Posted - 02/18/2006 : 04:49:24 AM
|
Hi Marko,
Thanks for reply. There are a few issues here and I'll also provide furtherexample code via email.
I'll try and be clearer...
The area I'm working on is a significant rate limiting hence my desire for speed as much as possible.
What we need to end up with is a worksheet contsining data to be uploaded to our Oracle database that is either saved or passed via COM to a .NET application. All the columns have a designated format of either max number of characters (eg length <=50) or specified max number of decimal places and digits eg 14.7 = max 7 decimal places and 14 'characters' including '.'.
The worksheet contains eg 60 columns treated as either text data or numeric data. Some 'numeric' data eg Sample no.s, Batch no.s are to be regarded as text - I have to use text columns here to avoid any formatting of these 'no.s'.
The use of text columns comes from the need to remove trailing zeroes and the missing value '--'. Both these issues are something I would like to see incorporated into Origin. I see the '--' as a hindrance and would like to see it as an option (default if you wish) - what do other users think?
I also need to avoid exponential terms in the cells.
A large proportion of numeric data is missing.
My approach is :
i) set system.sigDigitsL to -20 and system.sigDigitsU to 20 (extreme values) to avoid exponential terms ii) loop through all columns and ensure they are either text or numeric. For numeric columns I the set to the required SetDigitMode (decimal or significant figures) and SetDigits THEN change format to text. I then (in Origin C) read in the cell values as string and use wks.GetCell(NumRow-1,NumCol-1,rString); if(strchr(rString,'.')!=NULL) { rString.TrimRight("0"); rString.TrimRight("."); wks.SetCell(NumRow-1,NumCol-1,rString);
For text columns I will just check the number of characters and flag or truncate as appropiate.
I am then left with the need to remove (a large number) of missing characters from the worksheet of text columns. Easy enough with Origin C.
All the above I wanted to speed up hence the strong interest in external Dlls and my original query. By the way, a general 'FindAndReplace' function would be nice!; I fully appreciate the ease of manipulating double data - this isn't the issue,as I understand it.
I had no joy after a lot of work following CP's suggestion - can this actually be done. Creating the Dll to accept a pointer to a CStringArray was difficult enough but then Origin wouldn't communicate with it. If so, example c and Origin C code would be appreciated! I still have a need to use text columns! Can they be used with external Dlls? I've always felt that text columns are the poor relation in Origin worksheets - character limitations / ease of use in code - why is this so?
We then adopted a different approach and treated each cell as char arrays and passing over to the dll a pointer to an array of pointers - I think I have that right (?) - and have sent example code. This is a bit faster than Origin C and I can set text and numeric cells to blank using eg sa[i]0]='\0'. A general question - how can I fix the text and numeric cells to blank - depending on the process (set range / maximise / minimise / refresh) you may then repopulate empty cells with '--'.
A separate point - I have done this a few years back using MOCA dlls but tried to follow the recommendation of using external dlls & hit the problems described above. Could you please clarify when we might still need to consider MOCA dlls or do you expect all requirements to be met by MOCA dlls (with as good as or better perofrmance)
A number of issues / requests / questions here I guess so..
Thanks,
cheers,
pete
Edited by - peter.cook on 02/18/2006 2:39:36 PM |
 |
|
|
Topic  |
|
|
|