1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
###############################################################################
# Copyright (c) 2009-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform.  As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose.  Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
#   @userware
#       Access the Analog Waveform Parser
#   @section
#       Miscellaneous Userware Examples
#   @description
#       This file contains an example for the use of the Analog Waveform
#       library access functions.
#
#       The used functions allow to parse spice simulation results and to
#       retrieve the contained data.
#
#       The comments in the example code give more explanations on the
#       performed API function calls.
#   @files
#       analogWave/waveform_parser.tcl
#   @example
#       demo/spice/Fig24_30/Fig24_30.sp
#       demo/spice/Fig24_30/Fig24_30.csv
#   @tag
#       gui analog
###############################################################################


##
#
#
set script_path [file dirname [file normalize [info script]]]
source [file join $script_path print_functions.tcl]

##
# This function loads the waveform parser
#       and makes the functions af_wp_... and af_sv_... available.
#
af_waveform_parser_create

##
# Sets the logger level to receive all error messages.
#
af_wp_set_logger_level 3

##
# If this option is set, a hierarchy of instances will be generated.
#
af_wp_set_option "prop_parser_option_generate_instance_hierarchy"  1

##
# Parse a waveform file.
#
set file_name "${script_path}/../../spice/Fig24_30/Fig24_30.csv"
set file_name [tk_getOpenFile -title "Open Waveform File" \
                    -initialdir $script_path -initialfile ${file_name}]
set return_code [af_wp_read_file ${file_name}]

##
# File parsing succeeded
#
if {${return_code} eq "ok"} {
    ##
    # Parse succeeded. We print all data.
    #
    set output_fp stdout
    set output_dir [pwd]
    set output_file [tk_getSaveFile -title "Open Data Output File" \
                            -initialdir $output_dir]
    if {${output_file} != ""} {
        set output_fp [open $output_file w]
    }

    puts $output_fp " === waveform parser data read from file ${file_name}"

    ##
    # We limit the output to a vector of 10 values here.
    #
    print_data $output_fp 10

    if {${output_file} != ""} {
        close $output_fp
    }
} else {
    zmessage print ERR "failed to load file ${file_name}"
}

##
# Everything is released.
#
af_wp_release_all

##
# unloads the waveform parser
#
af_waveform_parser_delete