Tuesday, June 9, 2015

Converting Excel Macros to Perl

I'm currently working on porting our Excel macros at work to LabView. To get a quick prototype up and running I have been translating the Visual Basic code and the formulas in all of the spreadsheet cell to Perl 6. In the process I get to learn more about Perl 6 and see what all the fuss is about. The Excel macro takes a directory of data files from our transistor testing procedure and extracts certain model parameters for our design engineers. The data is located in tab separated plain text files. They contain voltage and current data for different aspects of the transistor. Each folder contains the data of over a dozen transistors. Here is what I've done so far:

#!/usr/bin/env perl6
use v6;

my $Append = False;
my $Test_Descriptor_Keys_File = "(compute)";
my $Lot_ID = "E1517-002";
my @Wafer_List = "Wafer_11", "Wafer_12";
my @Analysis_Master_Name = "AnalysisMaster_Autoprobe_Prod_20111005";
my $Test_Name_For_Processing = "COW";
my $Path_To_Data_File = "./";
my $Process_Reverse_Sweeps = 1;  my $Print_Graphs = 1;
my $Print_Graphs_To_File = 1;
my $Delete_Summary_Filename_Sheets = 0;
my %Environment = Lot_ID => $Lot_ID, Wafer_List => @Wafer_List, Path_To_Data_File => $Path_To_Data_File,
    Test_Name_For_Processing => $Test_Name_For_Processing, Analysis_Master_Name => $Analysis_Master_Name,
    Test_Descriptor_Keys_File => $Test_Descriptor_Keys_File, Append => $Append, Process_Reverse_Sweeps => $Process_Reverse_Sweeps,
    Print_Graphs => $Print_Graphs, Print_Graphs_To_File => $Print_Graphs_To_File, Delete_Summary_Filenames_Sheets => $Delete_Summary_Filename_Sheets;

sub main() {
    say "Starting...";
    my $myReturn = 1;
    my $myInput = "";
    my $PrintGraphsStatus = "(yes)";
    my $PrintGraphsToFileStatus = "(yes)";
    my $ProcessReverseSweeps = "(yes)";
    my $AppendDataToSummary = "(no)";

    while ($myReturn) {
        say "Choose Function: ";
        say "1. Process TFT Autoprobe Data";
        say "2. Process TFT Princeton Data";
        say "3. Print Graphs? " ~ $PrintGraphsStatus;
        say "4. Print Graphs to File? " ~ $PrintGraphsToFileStatus;
        say "5. Process TFT Data";
        say "6. Delete Summary & Filenames Sheets";
        say "7. Process Reverse Sweeps " ~ $ProcessReverseSweeps;
        say "8. Append Data to Summary " ~ $AppendDataToSummary;
        say "9. Quit";

        $myInput = get();

        given ($myInput) {
            when 1 { $myReturn = &Process_TFT_Autoprobe_Data(%Environment); }
            when 2 { $myReturn = &Process_TFT_Princeton_Data(%Environment); }
            when 3 { $myReturn = &Print_Graphs(%Environment); }
            when 4 { $myReturn = &Print_Graphs_To_File(%Environment); }
            when 5 { $myReturn = &Process_TFT_Data(%Environment); }
            when 6 { $myReturn = &Delete_Summary_Filenames_Sheets(%Environment); }
            when 7 { $myReturn = &Process_Reverse_Sweeps(%Environment); }
            when 8 { $myReturn = &Append_Data_to_Summary(%Environment); }
            when 9 { exit(0); }
            default { $myReturn = 1; }
        }
    }
}

sub Process_TFT_Autoprobe_Data() {
    my %Environment = shift;
    my $Lot_ID = %Environment{'Lot_ID'};
    my @Wafer_List = %Environment{'Wafer_List'};
    my $Path_To_Data_File = %Environement{'Path_To_Data_File'};

    say "Enter your lot ID:";
    $Lot_ID = get();



    say "called Process TFT Autoprobe Data";
}

sub Process_TFT_Princeton_Data() {
    my %Environment = shift;
    say "called Process TFT Princeton Data";
}

sub Print_Graphs() {
    my %Environment = shift;
    say "called Print Graphs";
}

sub Print_Graphs_To_File() {
    my %Environment = shift;
    say "called Print Graphs to File";
}

sub Process_TFT_Data() {
    my %Environment = shift;
    say "called Process TFT Data";
}

sub Delete_Summary_Filenames_Sheets() {
    my %Environment = shift;
    say "called Delete Summary Filenames Sheets";
}

sub Process_Reverse_Sweeps() {
    my %Environment = shift;
    say "called Process Reverse Sweeps";
}

sub Append_Data_to_Summary() {
    my %Environment = shift;
    say "called Append Data to Summary";
}

main();
1;