TABLE OF CONTENTS


::pwtk::card_math_parser

SYNOPSIS

proc ::pwtk::input::card_math_parser {content} {

PURPOSE

Generic math parser for cards

SOURCE

    set parsedContent ""

    foreach line [split $content \n] {
        # if the first character of the line is "#', it is a comment
        if { [::pwtk::is_comment $line] } {
            set parsedLine [string trim $line]
        } else {        
            set  parsedLine ""
            foreach field $line {           
                if { [catch {::pwtk::mathParser $field}] } {
                    # not a number (string)
                    append parsedLine "  $field "
                } elseif { [string is integer $field] } {
                    append parsedLine "  $field "
                } else {
                    set parsedNumber [::pwtk::evalExpr $field]
                    #set parsedNumber [::pwtk::mathParser $field]
                
                    if { ! [string is double $parsedNumber] } {
                        # not a floating point number, print as is
                        append parsedLine "  $field "
                    } else {
                        # floating point number
                        append parsedLine "   $parsedNumber "
                        #append parsedLine [format "  %20.16f " $parsedNumber]
                    }
                }       
            }
        }
        append parsedContent ${parsedLine}\n
    }
    if { $parsedContent eq {} } { set parsedContent \n }
    
    return $parsedContent
}