Author |
Topic  |
|
Selinger78
Germany
Posts |
Posted - 08/26/2004 : 05:16:33 AM
|
Hello! Is there a feature that all the columns where something is calculated via "set column values" automatically calculate values when importing data to referred values or when changing values in other columns? (I am using Origin 6.0).
And is it possible to save a special style of graph in a template which is also automatically drawn and updated when importing or changing values?
Best regards, Selinger78
|
|
Selinger78
Germany
Posts |
Posted - 08/26/2004 : 08:37:57 AM
|
Hello! I solved thr problem above with a worksheet script. But I have another question: Is there somewhere a list of possible commands for the worksheet script and is it possible to download new functions which were implemented and provided by other users? Regards, Selinger78
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 08/26/2004 : 11:03:24 AM
|
quote: Is there somewhere a list of possible commands for the worksheet script
Just about any command, function or object listed in your LabTalk programming guide should work in the Worksheet script.quote: is it possible to download new functions which were implemented and provided by other users?
In principle you should be able to incorporate any add-on module for Origin 6.0 at OriginLab's FileExchange...
http://www.originlab.com/FileExchange/index.aspx?C=5
in your script. The implementation details will depend on the add-on module. There's an email link for each module so you can contact the author for help.
Mike Buess Origin WebRing Member |
 |
|
Selinger78
Germany
Posts |
Posted - 08/31/2004 : 11:16:52 AM
|
When working with the worksheet script, do I have to create a special environment before I can use "If" odr "for" expressions?
In my case I tried to create data using a following example as a basis:
if (testCondition) sentence1 [else sentence2;]
I wrote following lines to to the worksheet script (using two columns "C" and "calc1"):
counter1=1 counter2=10 counterfix=10 if (counter2 == counterfix) col(C)[counter1]=col(calc1)[counter2]/10 [else col(C)[counter1]=(col(calc1)[counter2]-(col(calc1)[counter2-10]))/10;]
However, I don`t get a result. So where is my mistake in using this If-command in the worksheet script? Best regards, Selinger78
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 08/31/2004 : 12:19:08 PM
|
You must place the statements inside curly brackets {}...
if (counter2 == counterfix) {col(C)[counter1]=col(calc1)[counter2]/10} else {col(C)[counter1]=(col(calc1)[counter2]-col(calc1)[counter2-10])/10;};
...If your Worksheet script is long or complicated you'll probably be better off running them from a script file.
1. Create a new text file in your Origin program folder.
2. Start the file with a section header (I'll call it Main but you can name it as you like)...
[Main]
3. Copy the scripts currently assigned to your Worksheet and paste them under the [Main] header.
4. Save the text file as WksScript.ogs (again choose your own name, but use the ogs extension).
5. Open the Worksheet script and replace the current lines with this (use your own file and section names instead of WksScript and Main)...
run.section(%YWksScript.ogs,Main); // run your script section
OGS files are more flexible and easier to read and edit than the Worksheet script dialog. For example, in an OGS file you can split your if-else command into two lines like this...
if (counter2 == counterfix) col(C)[counter1]=col(calc1)[counter2]/10; else col(C)[counter1]=(col(calc1)[counter2]-col(calc1)[counter2-10])/10;
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 08/31/2004 12:56:23 PM
Edited by - Mike Buess on 08/31/2004 12:57:54 PM |
 |
|
Selinger78
Germany
Posts |
Posted - 09/01/2004 : 05:21:18 AM
|
Thanks for the help again! However, he thing with the OGS-file does not work somehow. I did it exactly as you told me but when I execute "run.section(%YWksScript.ogs,Main);" from the skript window, I get an error message which says "COUNTER1++COUNTER2 is a built-in function that can not be renamed". From the workshet script the lines are executed correctly:
col(calc1)=sum(col(intensity)) col(calc2)=col(calc1) col(calc2)=sum.max col(angle)=(90/143) * col(time2) -90 col(IntNorm)=col(intensity)/col(calc2) col(anglesum)=sum(col(angle))
counter1=1 counter2=10 counterfix=10
if (counter2 == counterfix) {col(C)[counter1]=col(calc1)[counter2]/10} {else col(C)[counter1]=(col(calc1)[counter2]-(col(calc1)[counter2-10]))/10;}; counter1++ counter2+=10 type -b "counter1:$(counter1),counter2:$(counter2)"
---------- (In the OGS-file I put the main header of corse)
Two other questions appeared: 1. I know that "win -t plot template.OTP graph;" opens a special graph template, but how can I tell Origin to plot a certain column as x and one as y in this graph?
2.Is there a command to get the length of a column and is there a command to delete a certain row?
Best regards and thanks again for the help (at last from the worksheet script the commands I have so far are executed), Selinger78
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/01/2004 : 07:53:04 AM
|
Each command should terminate with a semicolon. When you enter commands in the script window the semicolons are added automatically. In a script file you need to put them in yourself. (See the LabTalk->Programming section of your LabTalk help file for details about LT syntax and structure.)...
col(calc1)=sum(col(intensity)); col(calc2)=col(calc1); col(calc2)=sum.max; col(angle)=(90/143) * col(time2) -90; col(IntNorm)=col(intensity)/col(calc2); col(anglesum)=sum(col(angle));
counter1=1; counter2=10; counterfix=10;
if (counter2 == counterfix) {col(C)[counter1]=col(calc1)[counter2]/10}; else {col(C)[counter1]=(col(calc1)[counter2]-(col(calc1)[counter2-10]))/10;}; counter1++; counter2+=10; type -b "counter1:$(counter1),counter2:$(counter2)";
1. Column types are identified in the worksheet... A(X), B(Y), C(Y), etc. Use the layer command to specify which Y column(s) to include in the plot. Following script assumes the wks is Data1 and you use the default plot template...
win -t P; // create plot window from default template %W=%H; // save name in string variable %W lay -i Data1_B; // plot col B of Data1 lay -i Data1_C; // plot col C
2. get Data1_A -e nrows; // save number of rows in col A of Data1 to the variable nrows mark -d Data1_A -b r1 -e r2; // delete rows r1 through r2 from all columns in Data1
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 09/01/2004 08:18:49 AM |
 |
|
Selinger78
Germany
Posts |
Posted - 09/01/2004 : 11:00:30 AM
|
Thanks a lot for the help! It is really much mor comfortable to work with a normal editor creating OGS-files than working with the dialoge box!
I have another stupid question (I already looked into the labtalk development guide and also searched the forum, but all the problems somehow do not fit to this simple problem):
I just want to read out the filename of the (I have only one)worksheet (which is atomatically given after importing an ascii file)for being able to use the "get Data1_A -e nrows;" command.
Another possibiliy is to just rename the worksheet to a fix name, is this possible somhow?
And is there a command for "import single ascii" (with the same function as the button has)?
Best regards, Andreas Selinger
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/01/2004 : 11:34:14 AM
|
Hi Andreas,
The string variable %H holds the name of the active window. If you are still launching your script from the Worksheet Script dialog then you can use %H in place of the worksheet name... "get %H_A -e nrows;"
...If you've added your plotting scripts then the graph window becomes active with the win -t P command. So you'll have to save the worksheet name as another string variable. I suggest something like this...
%W=%H; // save wks name as %W win -t P; %P=%H; // save graph name as %P (you might not even need this) lay -i %W_B; // plot column B from %W lay -i %W_C; // plot column C from %W
You can also stop renaming the worksheet to the name of file that was imported. Just open ASCII options for your wks template, click the Other Options button and deselect the "Rename Worksheet to Data File Name" option. You then need to save the template to make that setting permanent.quote: And is there a command for "import single ascii" (with the same function as the button has)?
Use this to import into the active worksheet...
getfile *.dat; // open file dialog for *.dat files (any extension is possible) open -w %A; // import selected file (%A holds the file path\name obtained from file dialog)
If you want to import to a new worksheet insert the following command before the previous two commands...
win -t Data wksTemplate; // create a new wks from the wksTemplate template
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 09/01/2004 11:35:32 AM
Edited by - Mike Buess on 09/01/2004 11:48:28 AM
Edited by - Mike Buess on 09/01/2004 12:14:29 PM |
 |
|
Selinger78
Germany
Posts |
Posted - 09/02/2004 : 08:17:14 AM
|
Hello and thanks a lot again! the script is working so far, also the plot of the graph! Two small (minor priority) problems are still unclear to me. 1. How can I set the color of the curve in the graph (is now black by default)
2. I now set the worksheet I created as default worksheet. when I open a new worksheet ist appears but the worksheet script is not executed. Is there a possibility to automatically execute the script when open the template?
Best regards, Andreas Selinger
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/02/2004 : 08:55:08 AM
|
1. set %W_B -c 2; // make curve red=2 (black=1, green=3, blue=4, etc)
2. The 'Worksheet script' will only run automatically after import or change in dataset. But now that your scripts are in an OGS file you can launch them several ways. The Custom Routine button is easiest to describe. Open Custom.ogs (Origin program folder) in notepad. It's delivered with a [Main] section containing this command...
type -b $General.Userbutton; // informational message box
Replace that command with commands to open your wks template and run your wks script. The new section will probably be as simple as this...
win -t D WksTemplate; run.section(%YWksScript.ogs,Main);
Now you can use Origin's Custom Routine button to open a new wks and run your scripts.
Mike Buess Origin WebRing Member |
 |
|
Selinger78
Germany
Posts |
Posted - 09/02/2004 : 11:10:18 AM
|
Now that I thought that my script was working correctly (and I presented it to my colleagues!) a new interesting thing happend: I am reading a number with following line:
getnumber (Bitte Anzahl eingeben:) counterfix (Ueber wie viele Messwerte soll jeweils gemittelt werden?);
The first time I use it with my template it works, but when I close the worksheet and open the template again, then the variable "counterfix" remains the one from the first worksheet or is no number at all and the whole script does not continue or is not working properly.
Do I have to delete the variable getnumber or even all variables at the end of the script when I use the script several times (what is the command for that?)? And is there a special command for deleting columns (this is also necessary for my script when I want to calculate values with the script several times in the same worksheet.) Best regards, Andreas Selinger
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/02/2004 : 11:36:40 AM
|
Once a variable is defined it retains its value unless you change or delete it. You can delete a variable with 'del -v varName;' but then it will have no value for your next getn command. It's always good to initialize variables before you use them or they will be undefined (as you found out). For example, if you want the default value for counterfix to be 1 you need to do this...
counterfix=1; getnumber (Bitte Anzahl eingeben:) counterfix (Ueber wie viele Messwerte soll jeweils gemittelt werden?);
To delete column B from wks Data1...
del Data1_B;
If Data1 is active you can also use this...
del col(B);
Mike Buess Origin WebRing Member |
 |
|
|
Topic  |
|