[XOP] C macros for printing to the history

Average rating
(1 vote)

The following C macros provide a convenient way to print to the Igor Pro history from C/C++ code in XOPs.
One can also move the variable definition char buf[] out of the macro and use a global buffer instead (single threaded code only).

#define ARRAY_SIZE 1024
// Accepts multipe arguments like printf and prints them to the history
// Custom prefixes can be also inserted, see the DEBUGPRINT macro
// Copies only ARRAY_SIZE-2 characters in _snprintf, because we want to have space for the terminating \0 (1) and for the CR (1)
// Checking the return value of _snprintf is not done on purpose, we just always append a \0 to be safe
// @param A prints only if A evaluates to true
// @param B uses silent printing (does not mark the experiment as changed) if true
#define PRINT_TO_HISTORY(A,B,...)                \
  if (RunningInMainThread() && A)                \
  {                                              \
    char buf[ARRAY_SIZE];                        \
    _snprintf(buf,ARRAY_SIZE-2, __VA_ARGS__);    \
    buf[ARRAY_SIZE-2] = '\0';                    \
    strcat(buf,CR_STR);                          \
    if (!B)                                      \
    {                                            \
      XOPNotice(buf);                            \
    }                                            \
    else                                         \
    {                                            \
      XOPNotice2(buf,0);                         \
    }                                            \
// debuggingEnabled is a global boolean variable or similar which turns debug output on/off
// Convenience wrapper using silent debug print
#define DEBUGPRINT_SILENT(...) \
  PRINT_TO_HISTORY(debuggingEnabled,true,"DEBUG: "__VA_ARGS__)
// Convenience wrapper using debug print
#define DEBUGPRINT(...) \
  PRINT_TO_HISTORY(debuggingEnabled,false,"DEBUG: "__VA_ARGS__)
// Convenience wrapper for printing
#define HISTPRINT(...) \
// Convenience wrapper for silent printing
#define HISTPRINT_SILENT(...) \


  int ret = MDSetWaveScaling(m_waveHandle,dimension,sfAPtr,sfBPtr);
  if(ret != 0){
    HISTPRINT("MDSetWaveScaling returned error %d",ret);
  // [...]
  // [...]

Back to top