Strange error when calling the function from within function

Hello.

I'm experiencing a strange (to me) error. 

I have this function (downloaded from the exchange):

#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

//**
// Convert a formatted time string into a number
// of seconds.  The function returns -1 if there
// was an error.
//*
Function Time2Secs(timeString)
    string timeString
 
    // NOTE:  timeString is assumed to be a colon-separated
    // string as hours:minutes:seconds PM where
    // the PM may also be AM or may be omitted.
    // Leading zeros are allowed but not required for each
    // of the three digit groups.
    // The space between the seconds digits and the
    // AM or PM is optional.  If neither AM nor PM is
    // found, the time will be assumed to already be in
    // 24-hour format.  The case of AM and PM does not matter.
    // The range of the digits is not checked.
    Variable hours, minutes, seconds, fract
    String ampmStr = ""
    sscanf  timeString, "%u:%u:%u.%u%s", hours, minutes, seconds,fract, ampmStr
    if (V_flag < 3)
        print "Error in Time2Secs:  could not successfully parse the time."
        return -1
    elseif (V_flag == 4)
        // Determine whether AM or PM or something bogus
        // was used.
        if (cmpstr(" ", ampmStr[0]) == 0)
            // Get rid of the leading space.
            ampmStr = ampmStr[1, strlen(ampmStr) - 1]
        endif
        // Test that ampmStr is now either "AM" or "PM"
        // (case insensitive).  If not, then it's a bogus string.
        ampmStr = UpperStr(ampmStr)
        StrSwitch (ampmStr)
            Case "AM":
                // Compensate for the fact that, eg., 12:30:30 AM is
                // only 30 minutes and 30 seconds past midnight (the
                // beginning of the day), and not 12 hours 30 minutes
                // and 30 seconds.
                if (hours == 12)
                    hours -= 12
                endif
                break
            Case "PM":
                // Compensate for the fact that, eg., 12:30:30 PM is
                // only 30 minutes and 30 seconds past noon, which
                // is 12 hours past midnight (the beginning of the day),
                // and not 24 hours 30 minutes and 30 seconds.
                if (hours == 12)
                    // Don't need to do anything.
                else
                    hours += 12            
                endif
                break
            default:
                // It's bogus, report error to user.
                print "Error in Time2Secs:  Could not parse AM/PM string."
                return -1
        EndSwitch
    endif
 
    // Do the conversion into seconds.
    seconds += (minutes * 60) + (hours * 60 * 60)
    return seconds
End

When I'm calling it from within my main function
 

    make/D/O/N=(dimSize(Time_interp_t,0)), Time_interp 
   
    Time_interp=Time2Secs(Time_interp_t)



and I'm trying to compile my code, I'm getting this error:

got "Time_interp_t" instead of a string variable or string function name.

(Time_interp_t is a T2d wave with labels and text dates)

 

When the compiler fails, I cannot run this assignment in the command prompt, getting this error: 



unknown/inappropriate name or symbol

 

However, when I comment out the assignment line in my main function code, compile it, and then run it in the command prompt again, it is executed without any problem. 

 

Why is this happening? 

 

Regards,

 

JB

 

 

How is Time_interp_t defined ?

I guess there is an issue.
However, Igor should throw an "Expected wave name"-error.

HJ

 

That is a result of duplication of the part of the main data wave to extract only the time values. The main wave is a T2d wave (multiple text and number columns with columns and rows labels). 

It's created like this:

Duplicate/O/R=[1,dimSize(wave0,0)][0] wave0, Time_interp_t

The problem is that the wave assignment works in the command prompt but it does not when called from the main function body...



 

There is no "text and number" in Igor; its either text or number.

You are dealing with text waves. Hence, your duplicate command needs the /T flag.

HJ

In reply to by HJDrescher

Ok then. Everything is in the text wave with labels (wave0). The numbers in there are also in text format and I need to convert them. So is the time column. But why can I do it in the prompt and not from within the main function body? 

Because a function is compiled, it needs to know the type of the Time_interp_t at compile time, when the wave does not yet exist. By using /T with Duplicate, you are telling the compiler that the wave, when it is created, will be a text wave.

This is not a problem from the command line because, when a command is executed, the wave must already exist and Igor can determine the type at that time.

This is explained in the "Type Flags" section of the help for Duplicate and also in the section "Automatic Creation of WAVE References":

DisplayHelpTopic "Automatic Creation of WAVE References"

Another useful topic is:

DisplayHelpTopic "Compile Time Versus Runtime"

I recommend that Igor programmers read the Programming help file (Help->Help Windows->Programming.ihf) and then read it again after you have some experience. As with any programming language, you learn a lot after gaining experience from re-reading the documentation.