| T O P I C R E V I E W |
| bobroff |
Posted - 10/09/2002 : 09:01:08 AM First question : when I import an ascii data and I don't know in advance how many points there will be, how should I change the example given in the help (which proposes a Loop : for(int ii = 0; ii < iXlen; ii++) where Xlen is already known).
Second related question : when I do a loop for data manipulation, following example given in documentation about Data manipulation\creating and accessing data, I write something like (for a worksheet winName with columns named MyX and MyY): { Dataset dd1(winName + "_MyX"); Dataset dd2(winName + "_MyY"); dd1.SetSize(rows); dd2.SetSize(rows); for (int ii = 0; ii < rows; ii++) { dd1[ii] = ii; dd2[ii] = sin(ii); }
if some of the cells of MyX or MyY are empty, It gets stuck because the loop runs over these empty cells. How could I protect the loop from this ?
Thanks in advance Best Julien
|
| 4 L A T E S T R E P L I E S (Newest First) |
| cpyang |
Posted - 10/15/2002 : 08:50:25 AM quote: - first, how should I do to allow the use of an explorer tool for the user to enter the proper file name ? In your present code, the user needs to enter the full path name of the data to be imported, which is painfull.
Check to see if your version of Origin has included the GetOpenBox function, as shown
void test_get_file_name() { string strFilename = GetOpenBox("*.dat"); printf("Filename=%s\n",strFilename); }
CP
Edited by - cpyang on 10/15/2002 08:50:58 AM |
| easwar |
Posted - 10/14/2002 : 3:31:09 PM Hi Julien,
- first, how should I do to allow the use of an explorer tool for the user to enter the proper file name ? In your present code, the user needs to enter the full path name of the data to be imported, which is painfull.
To do this, you can bring up the file dialog from LabTalk using the following code segment for example:
run.section(file,Init); fdlog.useGroup(ASCII); fdlog.addType("[*.dat] *.dat"); fdlog.ShowComment=0; fdlog.dlgName$="Open ASCII File"; fdlog.deftype=5; if(fdlog.Open(A)) return 1; %B=fdlog.path$;
At this point, the LabTalk variables %B and %A will hold the file path and the file name respectively. You could then call your Origin C function to open and process the file, such as: MyOriginCFunction(%B%A); thereby passing the full path + file name to your C function.
- then, if I import for example a 3 column data in ascii, how should I do to transform the string line into 3 numbers ?
You can use the GetToken as follows:
string str1, str2, str3; int iNum1, iNum2, iNum3; ff.ReadString(strLine); str1 = strLine.GetToken(0); str2 = strLine.GetToken(1); str3 = strLine.GetToken(2); iNum1 = atoi(str1); iNum2 = atoi(str2); iNum3 = atoi(str3);
- About the other question, I mean "empty cells" when the cell exists but does not contain any number.
I am still not sure what the problem is?
- finally, is there any way, like in Labtalk, to know how to transform in ORigin C any standard ORIGIN command (like Plot/Scatter, or Analysis/normalize, or whatever) ? It would indeed be more easy to be able to write in C for users like me who don't know much.
Not all LabTalk commands and objects have been ported to Origin C yet. You can execute LabTalk commands from within your Origin C function using the _LT_Execute() command, or an _LT_Obj() section for accessing object properties, and beginning with 7SR2, you can make use of the "using" statement as well. These are all documented in the help files.
In addition to sample code segments in the Help files, there are sample .c files under \OriginC\Samples subfolder and also many sample projects and code examples under \Samples\Programming subfolder, which could be of help to you. Some of the code I posted here comes from the Palette Editor example under \Samples\Programming\Palette Editor. Easwar OriginLab.
Edited by - easwar on 10/14/2002 3:35:34 PM |
| bobroff |
Posted - 10/14/2002 : 06:52:55 AM Hi
thanks for your nice help. Your indication indeed works well. A few more stupid questions : - first, how should I do to allow the use of an explorer tool for the user to enter the proper file name ? In your present code, the user needs to enter the full path name of the data to be imported, which is painfull. - then, if I import for example a 3 column data in ascii, how should I do to transform the string line into 3 numbers ? - About the other question, I mean "empty cells" when the cell exists but does not contain any number. - finally, is there any way, like in Labtalk, to know how to transform in ORigin C any standard ORIGIN command (like Plot/Scatter, or Analysis/normalize, or whatever) ? It would indeed be more easy to be able to write in C for users like me who don't know much.
Thanks in advance Julien
|
| easwar |
Posted - 10/09/2002 : 09:55:03 AM Hi Julien,
For the ASCII import problem, you can use a while loop, such as in the code below.
As for the second problem, I am not sure what you mean by "if some cells are empty...it gets stuck". I do not have a problem with this code. Can you provide more details/steps on what you did?
Easwar OriginLab.
void dd(string strFileName) { stdioFile ff; string strLine; ff.Open(strFileName, file::modeRead ); int iCount = 0; while(ff.ReadString(strLine)) { // strLine has the current line from file // do whatever it is that you want to do iCount++; } printf("No. of lines=%d\n",iCount); }
Edited by - easwar on 10/09/2002 09:58:01 AM |
|
|