Please explain how the $ works
ssmith911
ssmith
Make/O/T Metwaves = {"temp_2", "temp_10", "temp_50", "temp_85", "speed_10", "speed_50", "speed_85","gust_10", "gust_50", "gust_85", "dir_10", "dir_50",
"dir_85", "deviation_10", "deviation_50", "deviation_85", "rh", "baro", "solar", "precip"}
Variable selects
FOR(selects = 0; selects < (numpnts(Metwaves)); selects += 1)
Wave tempwave = $Metwaves[selects]
tempwave = (numtype(tempwave) == 2) ? -999 : tempwave[p]
ENDFOR
$ is used when a command requires a name but you have only a String.
It converts the contents of the string into a name.
Look at the command syntax for WAVE:
WAVE [/C][/T][/Z] localName [= pathToWave ][, localName1 [= pathToWave1 ]]...
pathToWave isn't shown as pathToWaveStr, just pathToWave.
Without the Str ending, that's a hint that the parameter is a name, like for the Make command:
Make [flags ] waveName [, waveName ]...
Thus code like this won't work:
Make/O theWaveName // "Inconsistent type for a wave reference" error: expected the name of a wave (and got the name of a string)
But this will:
Make/O $theWaveName // $ "looks inside" the string for the name. The created wave is named dest.
For more about this, use this command:
DisplayHelpTopic "Converting a String into a Reference Using $"
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
April 25, 2017 at 12:55 pm - Permalink
I've added comments to the code:
Make/O/T Metwaves = {"temp_2", "temp_10", "temp_50", "temp_85", "speed_10", "speed_50", "speed_85","gust_10", "gust_50", "gust_85", "dir_10", "dir_50",
"dir_85", "deviation_10", "deviation_50", "deviation_85", "rh", "baro", "solar", "precip"}
Variable selects
FOR(selects = 0; selects < (numpnts(Metwaves)); selects += 1)
// Make a reference to one of the waves using the name in the wave of strings.
Wave tempwave = $Metwaves[selects] // reference to wave of the given name. $ converts string to name
// Now tempwave is a "pointer" or "reference" to the global wave.
// tempwave is NOT a local wave
// For each point (row) p in that wave, assign back to tempwave[p] either its current value, or -999 if a NaN
tempwave = (numtype(tempwave) == 2) ? -999 : tempwave[p]
// The previous line is clearer if rewritten as:
// tempwave = (numtype(tempwave[p]) == 2) ? -999 : tempwave[p]
ENDFOR
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
April 25, 2017 at 01:06 pm - Permalink
ssmith
April 26, 2017 at 05:42 am - Permalink
April 27, 2017 at 10:08 am - Permalink