| Author |
Topic  |
|
|
amyz
Canada
Posts |
Posted - 06/01/2005 : 2:10:26 PM
|
After importing an ascii file with 6 columns of data, and adding on 12 blank columns, I'd like to sort the first 3 columns [coordinate values], calculate some numerical derivatives, then sort columns again to calculate another set of derivatives, and so forth.
The script never works if I paste the entire thing [below] into Worksheet Script and click 'Do it'. Sometimes, it doesn't even work when I break it into chunks, and execute sub-sections separately. The problem lies with the execution of the sort command, it seems: either the columns are not sorted as desired, or the 3 columns are sorted, but the other columns didn't move at all, so that their values in any row do not correspond to the coordinate values in the 3 sorted columns. Usually, the sort script would work if I break the entire thing up so that sort.Wks() is the last line in any executed chunk of commands...
Any ideas what's wrong?
Thanks a bunch!
//first do deriatives w.r.t. z: cols 13, 14, and 15; sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: A; sort.cname2$ = A: B; sort.cname3$ = A: C; sort.wks();
//dBx/dz for(ii=2;ii<68921;ii++) { col(13)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
//dBy/dz for(ii=2;ii<68921;ii++) { col(14)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
dBz/dz for(ii=2;ii<68921;ii++) { col(15)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
//Now sort data, so that z=primary sort, x=secondary sort, y (col(B))=tertiary sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: C; sort.cname2$ = A: A; sort.cname3$ = A: B; sort.wks();
//do deriatives w.r.t. y: cols 10, 11, and 12; //dBx/dy for(ii=2;ii<68921;ii++) { col(10)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
//dBy/dy for(ii=2;ii<68921;ii++) { col(11)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
//dBz/dy for(ii=2;ii<68921;ii++) { col(12)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
//Now sort data, so that z=primary sort, y=secondary sort, x (col(1))=tertiary sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: C; sort.cname2$ = A: B; sort.cname3$ = A: A; sort.wks();
//do deriatives w.r.t. x: cols 7, 8, and 9; //dBx/dx for(ii=2;ii<68921;ii++) { col(7)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
//dBy/dx for(ii=2;ii<68921;ii++) { col(8)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
//dBz/dx for(ii=2;ii<68921;ii++) { col(9)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
|
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/01/2005 : 2:53:26 PM
|
It's possible that your script is too long for a worksheet script. In any case it will be much easier to manage in a script file. I don't know which version of Origin you're using so I'll give generic instructions.
1. Create a new text file in Notepad.
2. Add this line to the top...
[Main]
3. Open the Worksheet script, select all lines and click copy. (Or just Ctrl+C).
4. Paste the script under [Main] in the new file and save as anyname.ogs in your user folder (Origin 7.5) or in Origin's program folder (<Origin 7.5). Make sure the file name does not end up as anyname.ogs.txt.
5. Open the Worksheet script again and replace the entire script with this single command...
run.section(%Yanyname.ogs,Main);
Hopefully that will solve your problem. If not post back any we'll take a closer look.
Mike Buess Origin WebRing Member |
 |
|
|
amyz
Canada
Posts |
Posted - 06/01/2005 : 3:03:24 PM
|
| Thanks Mike. I have Origin 7.0...what do you mean by 'Origin program folder'? |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/01/2005 : 3:16:15 PM
|
That's the folder that contains the Origin program file... Origin70.exe
Right-click on the shortcut you use to start Origin and select Properties. It will be the folder labelled "Start in".
...Turns out that the length of the script may not be the problem but my suggestion probably stands. See the final reply (by cpyang) to this earlier forum topic...
http://www.originlab.com/forum/topic.asp?TOPIC_ID=2075
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 06/01/2005 3:18:49 PM
Edited by - Mike Buess on 06/01/2005 5:13:13 PM |
 |
|
|
amyz
Canada
Posts |
Posted - 06/01/2005 : 5:10:43 PM
|
| Hi Mike, sorry, but nothing happens when I run the command line, although I've made sure my script file has an ogs extension and is saved in the same folder as Origin70.exe. |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/01/2005 : 5:24:51 PM
|
1. What is the exact file name? 2. What are the first three or four lines of the file? 3. What is the exact command you are using to run the file?
You can find out about the syntax and usage of run.section() from the Programming Guide... LabTalk Language Reference > Object Reference > Alphabetical Listing > Run
Mike Buess Origin WebRing Member |
 |
|
|
amyz
Canada
Posts |
Posted - 06/01/2005 : 6:09:14 PM
|
Hi Mike,
Turned out that was b/c my first line didn't have a semicolon at the end - now it runs.
However, I still obtain the same spurious results, as the columns weren't sorted properly in some intermediate step. My original post here contains the main body of my script. I believe the problem lies somewhere in there. Let me know if I can supply any other info.
Thank you! |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/02/2005 : 10:38:29 AM
|
I'm not very familiar with the sort object but you left out the comment signs in front of one of the comments. The third derivative after the first sort should be...
//dBz/dz for(ii=2;ii<68921;ii++) { col(15)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
That will definitely affect your results. If they are still not right I can only suggest that you execute it in steps to determine where the error occurs.
Mike Buess Origin WebRing Member |
 |
|
|
amyz
Canada
Posts |
Posted - 06/02/2005 : 1:10:52 PM
|
Hi Mike,
Oops, yes, I did have the '//' in my actual script.
When I run the script in steps, it's always the sort object that gives me problems: the sort is often improper. Could you please suggest an alternative method on sorting the entire worksheet of data, as I'm unable to find anything else to implement? I have preset columns in mind as primary, secondary, and tertiary sort columns - I'd like to specify those in my script, instead of manually inputting them each time.
Thanks
~Amy |
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/02/2005 : 2:35:05 PM
|
As I mentioned in my last post I'm not familiar with the sort object, but as far as I know it's the only sorting method in Origin that gives you a secondary and tertiary sort order. All I can suggest is that you rewrite your script file as shown below. You can perform each sort and derivative separately by commenting/uncommenting the appropriate lines in the new Main section, saving the file and running the worksheet script. In that way you might be able to determine which sort fails and fix it.
One thing that occurs to me is that your derivative scripts leave missing values in the first row of the results column. I don't think you are sorting against those columns but if you are you should take the missing values into account.
[Main] run.section(,Sort1); // look at results of the first sort //run.section(,Deriv1); //run.section(,Sort2); //run.section(,Deriv2); //run.section(,Sort3); //run.section(,Deriv3); [Sort1] //first do deriatives w.r.t. z: cols 13, 14, and 15; sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: A; sort.cname2$ = A: B; sort.cname3$ = A: C; sort.wks();
[Sort2] //Now sort data, so that z=primary sort, x=secondary sort, y (col(B))=tertiary sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: C; sort.cname2$ = A: A; sort.cname3$ = A: B; sort.wks();
[Sort3] //Now sort data, so that z=primary sort, y=secondary sort, x (col(1))=tertiary sort.wksname$ = data1; sort.c1 = 0; sort.r1 = 1; sort.r2 = 68921; sort.cname1$ = A: C; sort.cname2$ = A: B; sort.cname3$ = A: A; sort.wks();
[Deriv1] //dBx/dz for(ii=2;ii<68921;ii++) { col(13)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
//dBy/dz for(ii=2;ii<68921;ii++) { col(14)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
//dBz/dz for(ii=2;ii<68921;ii++) { col(15)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(3)[ii+1] - col(3)[ii-1]); };
[Deriv2] //do deriatives w.r.t. y: cols 10, 11, and 12; //dBx/dy for(ii=2;ii<68921;ii++) { col(10)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
//dBy/dy for(ii=2;ii<68921;ii++) { col(11)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
//dBz/dy for(ii=2;ii<68921;ii++) { col(12)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(2)[ii+1] - col(2)[ii-1]); };
[Deriv3] //do deriatives w.r.t. x: cols 7, 8, and 9; //dBx/dx for(ii=2;ii<68921;ii++) { col(7)[ii]=(col(4)[ii+1] - col(4)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
//dBy/dx for(ii=2;ii<68921;ii++) { col(8)[ii]=(col(5)[ii+1] - col(5)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
//dBz/dx for(ii=2;ii<68921;ii++) { col(9)[ii]=(col(6)[ii+1] - col(6)[ii-1])/(col(1)[ii+1] - col(1)[ii-1]); };
Mike Buess Origin WebRing Member |
 |
|
| |
Topic  |
|
|
|