Prompting and Inserting Values
astrotool
I want to do this so when I prompt for the values it will put in the 0.2, 0.5, and 0.8, that I type into the prompt, into this code:
Function RawGraphing(CCNNumberAll, TimeAll, CurrentSSAll)
wave CCNNumberAll, TimeAll, CurrentSSAll
Extract CCNNumberAll, ccnss1, CurrentSSAll == 0.2
Extract TimeAll, timess1, CurrentSSAll == 0.2
Extract CCNNumberAll, ccnss2, CurrentSSAll == 0.5
Extract TimeAll, timess25, CurrentSSAll == 0.5
Extract CCNNumberAll, ccnss3, CurrentSSAll == 0.8
Extract TimeAll, timess3, CurrentSSAll == 0.8
End
wave CCNNumberAll, TimeAll, CurrentSSAll
Extract CCNNumberAll, ccnss1, CurrentSSAll == 0.2
Extract TimeAll, timess1, CurrentSSAll == 0.2
Extract CCNNumberAll, ccnss2, CurrentSSAll == 0.5
Extract TimeAll, timess25, CurrentSSAll == 0.5
Extract CCNNumberAll, ccnss3, CurrentSSAll == 0.8
Extract TimeAll, timess3, CurrentSSAll == 0.8
End
and it will put in the values when I run
Legend/C/N=text0/J/H={0,5,10}/E=2 "\\s(ccnss1) SS=0.2%\r\\s(ccnss2) SS=0.5%\r\\s(ccnss3) SS=0.8%"
Do I prompt for a couple of values, and then assign them to seperate symbols or something so that I then type in SS="ASSIGNMENT"% or CurrentSSAll == "ASSIGNMENT" when writing procedures?
"CCN Setting Values", CCNSettingValues()
End
Function CCNSettingValues()
Variable u=0.2,v=0.5,x=0.8,y=1.1,z=1.4, a=500,b=500,c=250
Prompt u, "Enter the First SS Setting Value (%): "
Prompt v, "Enter the Second SS Setting Value (%): "
Prompt x, "Enter the Third SS Setting Value (%): "
Prompt y, "Enter the Fourth SS Setting Value (%): "
Prompt z, "Enter the FifthSS Setting Value (%): "
Prompt a, "Enter in the Flow Rate (ccm): "
Prompt b, "Time removed at cycle repeat (seconds): "
Prompt c, "Time removed between SS steps (s): "
DoPrompt "Enter CCN Setting Values", u, v, x, y, z, a, b, c
if (V_Flag)
return -1 // User canceled
endif
Make/N=8 CCNSettings
CCNSettings[0]=u
CCNSettings[1]=v
CCNSettings[2]=x
CCNSettings[3]=y
CCNSettings[4]=z
CCNSettings[5]=a
CCNSettings[6]=b
CCNSettings[7]=c
End
Now to figure out how to put it places when I need it like in the textbox so SS="u"%, or CurrentSSAll == "v"
May 28, 2008 at 02:29 pm - Permalink
Prompt
statement is where the value the user enters will be stored. So, in this code you gave earlier:Prompt u, "Enter the First SS Setting Value (%): "
the default value of variable u that the user will see when the prompt is displayed will be 0.2. After DoPrompt is called, if the user changes that value then the new value will be reflected in variable u.
In later code you can just use the variables in statements as you would use any other variables. If you want the values to be placed into a text box, I'd recommend that you use the sprintf operation to build the string you'll then place in a text box or legend. So, as an example, you might do something like this:
sprintf tbString, "\\s(ccnss1) SS=%f%\r\\s(ccnss2) SS=%f%\r\\s(ccnss3) SS=%f%", u, v, x
Legend/C/N=text0/J/H={0,5,10}/E=2 tbString
You should read the command help for the sprintf and printf operations for information on what the various replacement codes (such as %f which is used in my example) mean.
May 28, 2008 at 02:33 pm - Permalink
When I try and enter in the variable to this code
wave DataMean, CurrentSSAll
variable x
Extract DataMean, ccnss1, CurrentSSAll == x
It does not work properly and returns empty tables
May 28, 2008 at 02:56 pm - Permalink
Either pass x into the function ...
...
... or get x within the function ...
wave DataMean, CurrentSSAll
variable x
[... prompt for x ... ]
...
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
May 29, 2008 at 04:54 am - Permalink
May 29, 2008 at 01:12 pm - Permalink
In the meantime, in response to your question about using something such as ...
... this should work as long as all the waves (source, dest, testwave, valuewave) exist before this line of code is reached.
As for setting variables to be permanent, you want to declare them to be global using the /G flag ...
variable xv
print xv
return 0
end
Use this function. Then, on the command line, execute the following:
mytest(5)
mytest(xv)
Check the data browser to see where xv is located.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
May 29, 2008 at 01:15 pm - Permalink
I just didn't want to make two prompts, but it really doesn't matter.
I wanted to have it so I could have a function prompt for values at the beginning, then store them, then later on use them in expressions as values. I tried tons of ways of calling them but to no avail. Thanks for the global variable, I will give that a try
I appreciate all your help, I know I have been a pain :-)
May 29, 2008 at 01:17 pm - Permalink
This helps me understand better why your questions seem to be ... jumbled.
You have two tasks, GET+STORE values and USE values. Write two functions (using globally defined and accessed variables):
// create global variables in a specific place
NewDataFolder/O/S root:MyGlobals
variable/G a, b, c, d
<... prompt to input variables ...>
// return to the root data folder
SetDataFolder root:
return 0
end
Function UseMyValues()
// this is an EXAMPLE of how globals are accessed
// variables
NVAR a = root:MyGlobals:a
NVAR b = root:MyGlobals:b
NVAR c = root:MyGlobals:c
NVAR d = root:MyGlobals:d
// waves
wave mydata = root:data:datawave1
// use the above values
mydata = a+ b*p^2 + c*p^3 - d*p^4
return 0
end
Once you have each of these functions working properly by themselves, then you can use them together ...
GetMyValues()
UseMyValues()
return 0
end
Rather a bit confusing ... certainly not a pain. I suggest, as time permits, you might want to read a book on the basics of programming in a language such as C, javascript (not java), or basic (not visual basic).
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
May 29, 2008 at 01:39 pm - Permalink
Also, I'd recommend that you take a look at the well written Programming.ihf file that comes with Igor. I'd execute:
from the Igor command line and start from there.
May 30, 2008 at 05:37 am - Permalink
sprintf tbString, "\\s(ccnss1) SS=%f%\r\\s(ccnss2) SS=%f%\r\\s(ccnss3) SS=%f%", u, v, x
Legend/C/N=text0/J/H={0,5,10}/E=2 tbString
Can someone explain to me how the '\\s' is this code works and what it does, why its needed? Thanks.
ssmith
October 18, 2017 at 02:04 pm - Permalink
That double backslash is required to make a single backslash in the final textbox text.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 18, 2017 at 02:13 pm - Permalink