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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 set the color and style of several curves...?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hancok

Norway
Posts

Posted - 04/28/2005 :  06:27:55 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version: v7.03
Operating System: windows XP

Hi,
I am try to program a button that I placed in a graph window.
The graph window contains 12 layers (to make 12 graphs on the same page) and each layer will contain 4 curves (after importation). I would like to have different color (red or blue) and style (solid or dot) for these 4 curves.
Each curve is one Ascii file. So I use "import mulpile" function.
here is what I made:

--------------------------------------
fdlog.ShowComment = 0;
fdlog.UseGroup(Ascii);

if (fdlog.MultiOpen() != 0/0)
{
loop (ii, 1, fdlog.MultiOpen.Count)
{
win -t data Origin;
FDlog.Get(A, ii);
open -w %A;

for (i=1;i<=12;i++) //"i" represents the nb of layer in the graph
{
window -a graph1;
layer -s $(i); //Active the layer one by one

for (j=1;j<=4;j++) //"j" represents the nb of curves I import in 1 layer.
{
layer -i Data$(i)C$(j)_B;

if (j=1) {set Data$(i)C$(j)_B -c 2
set Data$(i)C$(j)_B -d 0};// 1st curve: red + solid line
else
{ if (j=2) {set Data$(i)C$(j)_B -c 2
set Data$(i)C$(j)_B -d 2};//2nd curve: red + dot line
};
else
{ if (j=3) {set Data$(i)C$(j)_B -c 4
set Data$(i)C$(j)_B -d 0};//3rd curve: blue + solid line
};
else
{ if (j=4) {set Data$(i)C$(j)_B -c 4
set Data$(i)C$(j)_B -d 2};//4th curve: blue + dot line
};

rescale;
}; // end first loop for

}; // end second loop for
}
}
window -a graph1;

----------------------------------

However it doesn't work as I wish....it plots the 4 curves I ask for in each of the 12 layers (that is correct) but they are all solid and black line. I don't manage to get blue or red or dot line...

thanks a lot for your help.

Mike Buess

USA
3037 Posts

Posted - 04/28/2005 :  08:24:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Several semicolons are missing. For example,

if (j=1) {set Data$(i)C$(j)_B -c 2; // this semicolon was missing
set Data$(i)C$(j)_B -d 0};// 1st curve: red + solid line
else
{ if (j=2) {set Data$(i)C$(j)_B -c 2; // this semicolon was missing
set Data$(i)C$(j)_B -d 2};//2nd curve: red + dot line
};

You code will probably work once you insert all necessary semicolons.

Mike Buess
Origin WebRing Member
Go to Top of Page

hancok

Norway
Posts

Posted - 04/28/2005 :  09:01:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Yes.. I have seen that afterward I send the message...I added the missing semicolons (as showed lower) but it is still not giving me dot line or color line...

Is it correct to write like this:

If (condition1) {expression1;expression2;}
else
{
if (condition2) {expression3;expression4;}
};
else
{
if (condition3) {expression5;expression6;}
};
else
{
if (condition4) {expression7;expression8;}
};

because it is actually what I am doing...
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/28/2005 :  09:11:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I think you're only allowed one 'else' per 'if'. Try switch instead...

switch( j )
{
case 1:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 0;
break;
case 2:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 2;
break;
case 3:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 0;
break;
case 4:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 2;
break;
}

...Also your 'if' conditions were incorrect in your original post. Should be if( j==1 ) not if( j=1 ). So this should also work (else statements are not necessary)...

if( j==1 ) {
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 0;
};
if( j==2 ) {
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 2;
};
if( j==3 ) {
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 0;
};
if( j==4 ) {
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 2;
};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/28/2005 09:25:38 AM
Go to Top of Page

hancok

Norway
Posts

Posted - 04/28/2005 :  09:47:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the tip !
However it seems there is still something wrong: when I click on the button to start the program it just plot the first curve even if I select 4 files when importing files...It seems it stops after the first loop (j=1) in the second loop for.

Do you see something strange in the code which could explain why it is stopping after the 1st loop?

-----------------------------------------------
fdlog.ShowComment = 0;
fdlog.UseGroup(Ascii);

if (fdlog.MultiOpen() != 0/0)
{
loop (ii, 1, fdlog.MultiOpen.Count)
{
win -t data Origin;
FDlog.Get(A, ii);
open -w %A;

for (i=1;i<=12;i++)
{
window -a graph1;
layer -s $(i);

for (j=1;j<=4;j++)
{
layer -i Data$(i)C$(j)_B;
switch( j )
{
case 1:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 0;
break;
case 2:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 2;
break;
case 3:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 0;
break;
case 4:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 2;
break;
}

}; // end first loop for
}; // end second loop for

} //end loop
} //end if
window -a graph1;
----------------------------------
Go to Top of Page

hancok

Norway
Posts

Posted - 04/28/2005 :  10:14:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ok I think I found the pb.. it was the:
} //end loop
} //end if

which was not at the right place...I hope it will be ok now.
Thanks for the help!
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/28/2005 :  10:22:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The break statement in the switch command might also be breaking the for loop which contains it. There are two possible solutions...

1) Replace the switch command with the four consecutive if statements I suggested at the bottom of my last post. (This is easiest.)

2) Place the switch statement in a separate program section. (This is possible only if your script is in an OGS file.)

[Main]
fdlog.ShowComment = 0;
fdlog.UseGroup(Ascii);

if (fdlog.MultiOpen() != 0/0)
{
loop (ii, 1, fdlog.MultiOpen.Count)
{
win -t data Origin;
FDlog.Get(A, ii);
open -w %A;

for (i=1;i<=12;i++)
{
window -a graph1;
layer -s $(i);

for (j=1;j<=4;j++)
{
layer -i Data$(i)C$(j)_B;
run.section(,RunSwitch);
}; // end first loop for
}; // end second loop for

} //end loop
} //end if
window -a graph1;

[RunSwitch]
switch( j )
{
case 1:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 0;
break;
case 2:
set Data$(i)C$(j)_B -c 2;
set Data$(i)C$(j)_B -d 2;
break;
case 3:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 0;
break;
case 4:
set Data$(i)C$(j)_B -c 4;
set Data$(i)C$(j)_B -d 2;
break;
}

Mike Buess
Origin WebRing Member
Go to Top of Page

hancok

Norway
Posts

Posted - 04/29/2005 :  04:03:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Here is my program now:

[Main]
fdlog.ShowComment = 0;
fdlog.UseGroup(Ascii);

if (fdlog.MultiOpen() != 0/0)
{
loop (ii, 1, fdlog.MultiOpen.Count)
{
win -t data Origin;
FDlog.Get(A, ii);
open -w %A;
} //end loop
} //end if

for (i=1;i<=12;i++)
{
window -a graph1;
layer -s $(i);
for (j=1;j<=4;j++)
{
layer -i data$(i)C$(j)_B;
run.section(,RunSwitch);
}; // end first loop for
}; // end second loop for
window -a graph1;

[RunSwitch]
switch(j)
{
case 1:
set data$(i)C$(j)_B -c 2;
set data$(i)C$(j)_B -d 0;
break;
case 2:
set data$(i)C$(j)_B -c 2;
set data$(i)C$(j)_B -d 2;
break;
case 3:
set data$(i)C$(j)_B -c 4;
set data$(i)C$(j)_B -d 0;
break;
case 4:
set data$(i)C$(j)_B -c 4;
set data$(i)C$(j)_B -d 2;
break;
}
-------------------------

You said I should save the all script in a OGS file so I opened the script window, pasted the script as written above and save as ImportFile.OGS.
However I don't manage to execute the code now...I created a button and put in the script part ImportFile but nothing happen when I click on the button so I guess that's not the right way to executate the code which is in the ImportFile.OGS file...
thanks for your help.
Go to Top of Page

hancok

Norway
Posts

Posted - 04/29/2005 :  04:24:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ok I found out...
I just put the part:

[RunSwitch]
Switch(j)
{
...
...
}


in a script window that I saved as ImportFile.ogs
Then I call it as run.section(ImportFile.ogs,RunSwitch) and it works fine now.
thanks again.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/29/2005 :  06:44:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Put your entire script in ImportFile.ogs like you had said in your next to last post, i.e.,...

[Main]
// Main code

[RunSwitch]
// Switch code

Call it from the script window with run.section(ImportFile.ogs,Main) or run from a button by making the button settings look like this...

File: ImportFile.ogs
Section: Main
Context: Always
Other settings are irrelavent

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/29/2005 06:47:54 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000