File MIES_Utilities_Conversions.ipf

Utility functions for conversions.

Functions

variable ConvertFromBytesToMiB(variable var)

Convert Bytes to MiBs, a mebibyte being 2^20.

variable ConvertSamplingIntervalToRate(variable val)

Convert the sampling interval in microseconds (1e-6s) to the rate in kHz.

variable ConvertRateToSamplingInterval(variable val)

Convert the rate in kHz to the sampling interval in microseconds (1e-6s)

string TextWaveToList(WaveTextOrNull txtWave, string rowSep, string colSep = defaultValue, string layerSep = defaultValue, string chunkSep = defaultValue, variable stopOnEmpty = defaultValue, variable maxElements = defaultValue, variable trailSep = defaultValue)

Convert a text wave to string list.

Counterpart

See also

ConvertListToTextWave

Parameters:
  • txtWave – input text wave

  • rowSep – separator for row entries

  • colSep – [optional, default = “,”] separator for column entries

  • layerSep – [optional, default = “:”] separator for layer entries

  • chunkSep – [optional, default = “/”] separator for chunk entries

  • stopOnEmpty – [optional, default = 0] when 1 stops generating the list when an empty string entry in txtWave is encountered

  • maxElements – [optional, defaults to inf] output only the first maxElements entries

  • trailSep – [optional, defaults to true] add trailing separators at the very end

Returns:

string with wave entries separated as list using given separators

wave ListToTextWaveMD(string list, variable dims, string rowSep = defaultValue, string colSep = defaultValue, string laySep = defaultValue, string chuSep = defaultValue)

Converts a list to a multi dimensional text wave, treating it row major order The output wave does not contain unused dimensions, so if dims = 4 is specified but no chunk separator is found then the returned wave is 3 dimensional. An empty list results in a zero dimensional wave.

The following call ListToTextWaveMD(“1/5/6/:8/:,;2/:,;3/7/:,;4/:,;”, 4, rowSep=”;”, colSep=”,”,laySep=”:”, chuSep=”/”) returns ‘free’[0][0][0][0]= {“1”,”2”,”3”,”4”} ‘free’[0][0][1][0]= {“8”,””,””,””} ‘free’[0][0][0][1]= {“5”,””,”7”,””} ‘free’[0][0][1][1]= {“”,””,””,””} ‘free’[0][0][0][2]= {“6”,””,””,””} ‘free’[0][0][1][2]= {“”,””,””,””}

Parameters:
  • list[in] input string with list

  • dims[in] number of dimensions the output text wave should have

  • rowSep[in] [optional, default = “;”] row separator

  • colSep[in] [optional, default = “,”] column separator

  • laySep[in] [optional, default = “:”] layer separator

  • chuSep[in] [optional, default = “/”] chunk separator

Returns:

text wave with at least dims dimensions

string NumericWaveToList(WaveOrNull wv, string sep, string format = defaultValue, string colSep = defaultValue, variable trailSep = defaultValue)

Convert a 1D or 2D numeric wave to string list.

Counterpart

See also

TextWaveToList

Parameters:
  • wv – numeric wave

  • sep – separator

  • colSep – [optional, default = ,] separator for column entries

  • format – [optional, defaults to g] sprintf conversion specifier

  • trailSep – [optional, defaults to false] don’t add a row separator after the last row

static string WaveToListFast(wave wv, string format, string sep, string colSep, variable trailSep)
wave ListToNumericWave(string list, string sep, variable type = defaultValue, variable ignoreErr = defaultValue)

Convert a list to a numeric wave.

Counterpart

See also

TextWaveToList

Parameters:
  • list – list with numeric entries

  • sep – separator

  • type – [optional, defaults to double precision float (IGOR_TYPE_64BIT_FLOAT)] type of the created numeric wave

  • ignoreErr – [optional, defaults 0] when this flag is set conversion errors are ignored, the value placed is NaN (-9223372036854775808 for int type)

variable str2numSafe(string str)

str2num variant with no runtime error on invalid conversions

UTF_NOINSTRUMENTATION

string FloatWithMinSigDigits(variable var, variable numMinSignDigits = defaultValue)

Return a floating point value as string rounded to the given number of minimum significant digits.

This allows to specify the minimum number of significant digits. The normal printf/sprintf specifier only allows the maximum number of significant digits for g.

string ToPassFail(variable passedOrFailed)
string ToTrueFalse(variable var)
string ToOnOff(variable var)
string DAQRunModeToString(variable runMode)

Convert the DAQ run mode to a string.

Parameters:

runMode – One of DAQRunModes

string TestPulseRunModeToString(variable runMode)

Convert the Testpulse run mode to a string.

Parameters:

runMode – One of TestPulseRunModes

string num2strHighPrec(variable val, variable precision = defaultValue, variable shorten = defaultValue)

Converts a number to a string with specified precision (digits after decimal dot). This function is an extension for the regular num2str that is limited to 5 digits. Input numbers are rounded using the “round-half-to-even” rule to the given precision. The default precision is 5. If val is complex only the real part is converted to a string.

Parameters:
  • val[in] number that should be converted to a string

  • precision[in] [optional, default 5] number of precision digits after the decimal dot using “round-half-to-even” rounding rule. Precision must be in the range 0 to MAX_DOUBLE_PRECISION.

  • shorten[in] [optional, defaults to false] Remove trailing zeros and optionally the decimal dot to get a minimum length string

Returns:

string with textual number representation

variable ScaleToIndexWrapper(wave wv, variable scale, variable dim)

wrapper to ScaleToIndex

ScaleToIndex treats input inf to scale always as the last point in a wave. -inf on the other hand is undefined. This wrapper function respects the scaled point wave. -inf refers to the negative end of the scaled wave and +inf is the positive end of the scaled wave. This means that this wrapper function also respects the DimDelta direction of the wave scaling. and always returns the closest matching (existing) point in the wave. This also means that the returned values cannot be negative or larger than the numer of points in the wave.

Returns:

an existing index in wv between 0 and DimSize(wv, dim) - 1

variable HexToNumber(string ch)

Convert a hexadecimal character into a number.

UTF_NOINSTRUMENTATION

string NumberToHex(variable var)

Convert a number into hexadecimal.

UTF_NOINSTRUMENTATION

wave HexToBinary(string str)

Convert a string in hex format to an unsigned binary wave.

This function works on a byte level so it does not care about endianess.

UTF_NOINSTRUMENTATION

string ConvertListToRegexpWithAlternations(string list, variable literal = defaultValue, string sep = defaultValue)

Turn a list of entries into a regular expression with alternations.

Can be used for GetListOfObjects() if you know in advance which entries to filter out.

Parameters:
  • list – semicolon separated list of strings to match

  • literal – [optional, default = 1] when this flag is cleared the string elements of the list are treated as regular expressions

  • sep – [optional, default = “;”] separator for list

wave ConvertToUniqueNumber(WaveText wv, variable doZapNaNs = defaultValue, variable doSort = defaultValue)

Convert a text wave to a double wave with optional support for removing NaNs and sorting.

string GetCodeForWaveContents(WaveText wv)

Prepare wave for inline definition.

Outputs a wave in a format so that it can be initialized with these contents in an Igor Pro procedure file.

variable WaveTypeStringToNumber(string type)

Returns the wave type as constant.

Same constant as WaveType with selector zero (default) and Redimension/Y.

string WaveToJSON(WaveOrNull wv)

Serialize a wave as JSON and return it as string.

The format is documented here.

wave JSONToWave(string str, string path = defaultValue)

Deserialize a JSON document generated by WaveToJSON()

Supports only a currently used subset.

See also

WaveToJSON

Parameters:
  • str – serialized JSON document

  • path – [optional, defaults to “”] json path with the serialized wave info

wave UTF8StringToTextWave(string str)

Converts a string in UTF8 encoding to a text wave where each wave element contains one UTF8 characters.