Thursday, November 22, 2018

TCL Practice Task 3 (Scripting Language)

TCL is very important from automation point of view in VLSI Industry but somehow students are not ready to learn this. They think it's a programing (like software programing) and they are in VLSI Industry to do some hardware related job. Reason of this - they don't know the application of TCL in VLSI Industry. In these series of articles, I am listing down few of the small projects or say programs or say exercise which can help anyone to understand the use-model of TCL inside the Industry. As a fresher, it's worth trying these task/programs/exercise, it will boost your confidence.
This is third part. If you have missed first and second part, please visit it. TCL Practice Task 1 and TCL Practice Task 2.

To understand this Task, you should have Task 1 and Task 2 program handy. :)

After the first 2 task, Now it's time to add some features in those programs/tasks. :)

Task 3:- User Input and Runtime decision

Step 1: Create 1 Input file ("file_input1.txt")
Content of "file_input1.txt" is same as in the first 2 Tasks. So, you can copy this file from previous programs. Snapshot of the file is present below.

Input File: “file_input1.txt”

    Name        Delay    Trans    Load
    ---------------------------------------------
    AND1_2X      1.50ns    0.1    1.25ff
    AND1_3X      1.75ns    0.2    1.98ff
    AND2_3X      2.37ns    0.3    2.27ff
    AND2_4X      1.82ns    0.5    2.54ff
    NAND1_2X    2.14ns    0.2    1.69ff
    NAND2_3X    2.48ns    0.3    2.11ff

Step 2: Write a TCL program, where you will read input files "file_input1.txt" and then you will display the name of these cells to the user as an info and ask them to choose cell name (or cells name) from the displayed list (which you have provided). According to the user input or inputs, you have to extract below information from input file ("file_input1.txt") and display it in the below format (This is same output format as per Task 2 output).

Example 1:- If user Enter Cell name AND1_2X then display data should be

    Name        Trans    Load    Delay    Total_Delay
    ----------------------------------------------------------------------------
    AND1_2X      0.1    1.25ff    1.50ns      1.50ns

Example 2:- If user Enter Cell name AND1_2X, AND2_3X, AND2_4X & NAND2_3X then display data should be

    Name        Trans    Load    Delay    Total_Delay
    ----------------------------------------------------------------------------
    AND1_2X      0.1    1.25ff    1.50ns      1.50ns
    AND2_3X      0.3    2.27ff    2.37ns      3.87ns
    AND2_4X      0.5    2.54ff    1.82ns      5.69ns
    NAND2_3X    0.3    2.11ff    2.48ns      8.17ns

Note:
  • About Total Delay, We have already discussed in previous task (TCL Practice Task 2)
  • How are you going to ask data from user, you have freedom.
  • User should be able to enter 1 (One) or multiple CELL name.
  • If user enter wrong name, you should be able to provide them proper information / warning (that Cell name is incorrect).
  • In case of wrong input, give user 2 more chances before exiting the program.
  • After every wrong input, provide a option to user to quit (if they want).

Step 3: Print the above formated data as per user input onto the terminal & in output file "file_output2.txt"

Hint:
  • You have to reuse TCL program of Task 1 and Task 2.
    • Reading of File "file_input1.txt" should be with the help of previous program only.
    • Get the user input and create a new file (temporary file) as per second input file (file_input2.txt) format of Task 2.
    • Once you create a temp file, you can reuse the program of Task 2 as it is (just by converting that into procedure)

Learning after this Program:
  • How to Open & Close Input files
  • How to Read or Write from/in a file
  • How to take inputs from the users.
  • How to display info, warning and Error messages to user.
  • Looping in a program and resetting a particular variable.
  • Exit option.
  • How to save user inputs in a variable or list of variables, even you don't know the number of inputs.
  • How to save data in List and do different operations on that
  • How to do Matching or say comparison of Data
  • How to select only a specific data
  • How to do mathematical calculations
  • Different commands use-model
    • list, lindex, lappend
    • Foreach loop, While loop, If-else loop
    • gets and puts
    • split
    • expr
    • incr
  • How to manage single space, multiple space
  • Regular expression concepts
  • Procedure concepts (proc in tcl)
    • How to write a Procedure
    • How to pass a value to Procedure
    • How to call a Procedure
    • How to get return from a Procedure (return command)

Industrial Use of this Task:
During the automation of data, many times either we work on input Template file (where user need to provide inputs by filling that) or ask inputs from user directly during runtime. These inputs can be in the form of YES/NO or may be some small inputs like Cell name or Path name.

I am sure this article will help you. In the Next article, we will discuss about a task where you have to take inputs from user as a command line option (even before running a program and not as Template file).

-By Rajat Bansal
(Btech-EC:- 2019 Passout)
(ABES Engineering College)


-Supervised By Puneet Mittal
(Founder & Director)
(VLSI Expert Private Limited)

2 comments:


  1. #
    proc calc_old_delay {user_input} {

    switch $user_input {
    AND1_2X {
    set old_delay 0
    }
    AND2_3X {
    set old_delay 1.50
    }
    AND2_4X {
    set old_delay 3.87
    }
    NAND2_3X {
    set old_delay 5.69
    }
    }
    return $old_delay
    } ;#proc
    #
    #
    if {[catch {open "file_input1.txt"} file_input1_id] && [catch {open "file_input2.txt"} file_input2_id]} {
    puts stderr "error1: $file_input1_id"
    puts stderr "error2: $file_input2_id"

    } else {
    source "/nfs/iind/disks/pds.tfm.disk_0001/Abhishek/task2/file_handling_2.tcl"

    puts "Enter the cell's name you want information about?"
    gets stdin user_input

    set got_data_from_fileinput1 [get_data_from_fileinput1 $array_to_list $user_input]
    #puts $got_data_from_fileinput1
    set old_delay [calc_old_delay $user_input]
    set delays [total_delay_calc $got_data_from_fileinput1 $old_delay]
    set tot_delay_1 [lindex $delays 0]
    set array_to_list [array get row]

    set row_cell_1 [add_total_delay_to_row $array_to_list $tot_delay_1 $got_data_from_fileinput1]
    puts [format "%-12s %-9s %-9s %-9s %-5s" $name $Trans $Load $Delay {Total Delay}]
    #puts $ohye
    puts "---------------------------------------------------------"
    puts $row_cell_1
    }



    ReplyDelete
  2. set file4 [open "/mnt/c/Users/rajes/VLSI_TASK_TCL/Task2_op.txt" "r"]
    set argc 6
    set L1 [lindex $argv 0]
    set L2 [lindex $argv 1]
    set L3 [lindex $argv 2]
    set L4 [lindex $argv 3]
    set L5 [lindex $argv 4]
    set L6 [lindex $argv 5]
    # list1 == AND1_2X AND1_3X AND2_3X AND2_4X NAND1_2X NAND2_3X [TAKEN FROM OTHER SCRIPT]
    set J1 [llength $argv]

    if { $J1 == 0 } {
    puts "please provide atleast 1 input
    available cell names are 'AND1_2X' 'AND1_3X' 'AND2_3X' 'AND2_4X' 'NAND1_2X' 'NAND2_3X' "
    } elseif { $J1 >= 7 } {
    puts "number of inputs must not be greater than 6
    available cell names are 'AND1_2X' 'AND1_3X' 'AND2_3X' 'AND2_4X' 'NAND1_2X' 'NAND2_3X' "
    } elseif {$J1 == 1} {
    lappend list2 $L1
    } elseif {$J1 == 2} {
    lappend list2 $L1
    lappend list2 $L1
    } elseif {$J1 == 3} {
    lappend list2 $L1
    lappend list2 $L2
    lappend list2 $L3
    } elseif {$J1 == 4} {
    lappend list2 $L1
    lappend list2 $L2
    lappend list2 $L3
    lappend list2 $L4
    } elseif {$J1 == 5} {
    lappend list2 $L1
    lappend list2 $L2
    lappend list2 $L3
    lappend list2 $L4
    lappend list2 $L5
    } elseif {$J1 == 6} {
    lappend list2 $L1
    lappend list2 $L2
    lappend list2 $L3
    lappend list2 $L4
    lappend list2 $L5
    lappend list2 $L6
    }
    if {$J1 >= 1 && $J1 <= 6} {
    foreach eleme $list2 {
    if {[lsearch $list1 $eleme] < 0} {
    puts "cell name not found, available cell names are 'AND1_2X' 'AND1_3X' 'AND2_3X' 'AND2_4X' 'NAND1_2X' 'NAND2_3X' "
    }
    }
    }
    while {[gets $file4 line4] >= 0} {
    if {$J1 >= 1 && $J1 <= 6} {
    if {[regexp "Name" $line4]} {
    puts $line4
    }
    }
    if {$J1 == 1} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    }
    } elseif {$J1 == 2} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    } elseif {[regexp "^$L2" $line4]} {
    puts $line4
    }
    } elseif {$J1 == 3} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    } elseif {[regexp "^$L2" $line4]} {
    puts $line4
    } elseif {[regexp "^$L3" $line4]} {
    puts $line4
    }
    } elseif {$J1 == 4} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    } elseif {[regexp "^$L2" $line4]} {
    puts $line4
    } elseif {[regexp "^$L3" $line4]} {
    puts $line4
    } elseif {[regexp "^$L4" $line4]} {
    puts $line4
    }
    } elseif {$J1 == 5} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    } elseif {[regexp "^$L2" $line4]} {
    puts $line4
    } elseif {[regexp "^$L3" $line4]} {
    puts $line4
    } elseif {[regexp "^$L4" $line4]} {
    puts $line4
    } elseif {[regexp "^$L5" $line4]} {
    puts $line4
    }
    } elseif {$J1 == 6} {
    if {[regexp "^$L1" $line4]} {
    puts $line4
    } elseif {[regexp "^$L2" $line4]} {
    puts $line4
    } elseif {[regexp "^$L3" $line4]} {
    puts $line4
    } elseif {[regexp "^$L4" $line4]} {
    puts $line4
    } elseif {[regexp "^$L5" $line4]} {
    puts $line4
    } elseif {[regexp "^$L6" $line4]} {
    puts $line4
    }
    }
    }

    ReplyDelete