<commit_before># $Id$
#
#      Copyright (C) 2004  <NAME>
#      Copyright (C) 2008  <NAME>
#
#
#      This file is part of PLplot.
#
#      PLplot is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Library Public License as
#      published by the Free Software Foundation; either version 2 of the
#      License, or (at your option) any later version.
#
#      PLplot is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU Library General Public License for more details.
#
#      You should have received a copy of the GNU Library General Public
#      License along with PLplot; if not, write to the Free Software
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#
#      plimage demo
#
#

#static PLOptionTable options[] = {
#{
#    "dbg",			/* extra debugging plot */
#    NULL,
#    NULL,
#    &dbg,
#    PL_OPT_BOOL,
#    "-dbg",
#    "Extra debugging plot" },
#{
#    "nosombrero",			/* Turns on test of xor function */
#    NULL,
#    NULL,
#    &nosombrero,
#    PL_OPT_BOOL,
#    "-nosombrero",
#    "No sombrero plot" },
#{
#    "nointeractive",			/* Turns on test of xor function */
#    NULL,
#    NULL,
#    &nointeractive,
#    PL_OPT_BOOL,
#    "-nointeractive",
#    "No interactive selection" },
#{
#    "save",			/* For saving in postscript */
#    NULL,
#    NULL,
#    &f_name,
#    PL_OPT_STRING,
#    "-save filename",
#      "Save sombrero plot in color postscript `filename'" },
#{
#    NULL,			/* option */
#    NULL,			/* handler */
#    NULL,			/* client data */
#    NULL,			/* address of variable to set */
#    0,				/* mode flag */
#    NULL,			/* short syntax */
#    NULL }			/* long syntax */
#};

proc x20 {{w loopback}} {

    set PI   [expr {4.0*atan(1.0)}]

    set XDIM 260
    set YDIM 220

    matrix x f $XDIM
    matrix y f $YDIM
    matrix z f $XDIM $YDIM
    matrix r f $XDIM $YDIM

#
#     Bugs in plimage():
#      -at high magnifications, the left and right edge are ragged, try
#         ./x20c -dev xwin -wplt 0.3,0.3,0.6,0.6 -ori 0.5
#
#     Bugs in x20c.c:
#      -if the window is resized after a selection is made on 'lena', when
#       making a new selection the old one will re-appear.
#
#
#     Parse and process command line arguments
#
#      $w cmd plMergeOpts options "x20c options" NULL

    set dbg            0
    set nosombrero     0
    set nointeractive  0
    set f_name         ""

    set XDIMM1 [expr {$XDIM-1}]
    set YDIMM1 [expr {$YDIM-1}]

#   View image border pixels
    if { $dbg} {
        $w cmd plenv 1. $XDIM 1. $YDIM 1 1

        for { set i 0 } { $i < $YDIM } { incr i } {
            for { set j 0 } { $j < $YDIM } { incr j } {
                z $i $j = 0.0
            }
        }

#       Build a one pixel square border, for diagnostics

        for { set i 0 } { $i <$XDIM } { incr i } {
#           Right
            z $i $YDIMM1 = 1.0
#           Left
            z $i 0       = 1.0
        }

        for { set i 0 } { $i <$YDIM } { incr i } {
#           Top
            z 0 $i       = 1.0
#           Bottom
            z $XDIMM1 $i = 1.0
        }

        $w cmd pllab "...around a blue square." " " \
            "A red border should appear..."

        $w cmd plimage z 1. $XDIM 1. $YDIM 0. 0. 1. $XDIM 1.$YDIM

        $w cmd pladv 0
    }

#   Sombrero-like demo
    if { ! $nosombrero } {
#       draw a yellow plot box, useful for diagnostics# :(
        $w cmd plcol0 2
        $w cmd plenv 0. [expr {2.*$PI}] 0.0 [expr {3.*$PI}] 1 -1

        for { set i 0 } { $i < $XDIM } { incr i } {
            x $i = [expr {double($i)*2.*$PI/double($XDIMM1)}]
        }
        for { set i 0 } { $i < $YDIM } { incr i } {
            y $i = [expr {double($i)*3.*$PI/double($YDIMM1)}]
        }

        for { set i 0 } { $i < $XDIM } { incr i } {
            for { set j 0 } { $j < $YDIM } { incr j } {
                set xx [x $i]
                set yy [y $j]
                r $i $j = [expr {sqrt($xx*$xx+$yy*$yy)+0.001}]
                set rr [r $i $j]
                z $i $j = [expr {sin($rr) / $rr}]
            }
        }

        $w cmd pllab "No an amplitude clipped \"sombrero\"" "" "Saturn?"
        $w cmd plptex 2. 2. 3. 4. 0. "Transparent image"
        $w cmd plimage z 0. [expr {2.*$PI}] 0.0 [expr {3.*$PI}] \
            0.05 1. 0. [expr {2.*$PI}]  0. [expr {3.*$PI}]

#       Save the plot
        if { $f_name != "" } {
            save_plot $w $f_name
        }

        $w cmd pladv 0
    }

#
#   Read Lena image
#   Note we try two different locations to cover the case where this
#   examples is being run from the test_c.sh script
#
    if { ![read_img "lena.pgm" img_f width height num_col] } {
        if { ![read_img "../lena.pgm" img_f width height num_col] } {
#C          $w cmd plabort "No such file"
            puts "Image could not be read"
            $w cmd plend
            return
        }
    }

#   Set gray colormap
    gray_cmap $w $num_col

#   Display Lena
    $w cmd plenv 1. $width 1. $height 1 -1

    if { !$nointeractive } {
        $w cmd pllab "Set and drag Button 1 to  re set selection Button 2 to finish." \
            "" "Lena..."
    } else {
        $w cmd pllab "" " " "Lena..."
    }

    $w cmd plimage img_f 1. $width 1. $height 0. 0. 1. $width 1. $height

#   Selection/expansion demo
    if { !$nointeractive } {
        set xi 200.0
        set xe 330.0
        set yi 280.0
        set ye 220.0<commit_msg>Update labels for tcl example 20 consistent with C version.<commit_after># $Id$
#
#      Copyright (C) 2004  <NAME>
#      Copyright (C) 2008  <NAME>
#
#
#      This file is part of PLplot.
#
#      PLplot is free software; you can redistribute it and/or modify
#      it under the terms of the GNU General Library Public License as
#      published by the Free Software Foundation; either version 2 of the
#      License, or (at your option) any later version.
#
#      PLplot is distributed in the hope that it will be useful,
#      but WITHOUT ANY WARRANTY; without even the implied warranty of
#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#      GNU Library General Public License for more details.
#
#      You should have received a copy of the GNU Library General Public
#      License along with PLplot; if not, write to the Free Software
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#
#      plimage demo
#
#

#static PLOptionTable options[] = {
#{
#    "dbg",			/* extra debugging plot */
#    NULL,
#    NULL,
#    &dbg,
#    PL_OPT_BOOL,
#    "-dbg",
#    "Extra debugging plot" },
#{
#    "nosombrero",			/* Turns on test of xor function */
#    NULL,
#    NULL,
#    &nosombrero,
#    PL_OPT_BOOL,
#    "-nosombrero",
#    "No sombrero plot" },
#{
#    "nointeractive",			/* Turns on test of xor function */
#    NULL,
#    NULL,
#    &nointeractive,
#    PL_OPT_BOOL,
#    "-nointeractive",
#    "No interactive selection" },
#{
#    "save",			/* For saving in postscript */
#    NULL,
#    NULL,
#    &f_name,
#    PL_OPT_STRING,
#    "-save filename",
#      "Save sombrero plot in color postscript `filename'" },
#{
#    NULL,			/* option */
#    NULL,			/* handler */
#    NULL,			/* client data */
#    NULL,			/* address of variable to set */
#    0,				/* mode flag */
#    NULL,			/* short syntax */
#    NULL }			/* long syntax */
#};

proc x20 {{w loopback}} {

    set PI   [expr {4.0*atan(1.0)}]

    set XDIM 260
    set YDIM 220

    matrix x f $XDIM
    matrix y f $YDIM
    matrix z f $XDIM $YDIM
    matrix r f $XDIM $YDIM

#
#     Bugs in plimage():
#      -at high magnifications, the left and right edge are ragged, try
#         ./x20c -dev xwin -wplt 0.3,0.3,0.6,0.6 -ori 0.5
#
#     Bugs in x20c.c:
#      -if the window is resized after a selection is made on 'lena', when
#       making a new selection the old one will re-appear.
#
#
#     Parse and process command line arguments
#
#      $w cmd plMergeOpts options "x20c options" NULL

    set dbg            0
    set nosombrero     0
    set nointeractive  0
    set f_name         ""

    set XDIMM1 [expr {$XDIM-1}]
    set YDIMM1 [expr {$YDIM-1}]

#   View image border pixels
    if { $dbg} {
        $w cmd plenv 1. $XDIM 1. $YDIM 1 1

        for { set i 0 } { $i < $YDIM } { incr i } {
            for { set j 0 } { $j < $YDIM } { incr j } {
                z $i $j = 0.0
            }
        }

#       Build a one pixel square border, for diagnostics

        for { set i 0 } { $i <$XDIM } { incr i } {
#           Right
            z $i $YDIMM1 = 1.0
#           Left
            z $i 0       = 1.0
        }

        for { set i 0 } { $i <$YDIM } { incr i } {
#           Top
            z 0 $i       = 1.0
#           Bottom
            z $XDIMM1 $i = 1.0
        }

        $w cmd pllab "...around a blue square." " " \
            "A red border should appear..."

        $w cmd plimage z 1. $XDIM 1. $YDIM 0. 0. 1. $XDIM 1.$YDIM

        $w cmd pladv 0
    }

#   Sombrero-like demo
    if { ! $nosombrero } {
#       draw a yellow plot box, useful for diagnostics# :(
        $w cmd plcol0 2
        $w cmd plenv 0. [expr {2.*$PI}] 0.0 [expr {3.*$PI}] 1 -1

        for { set i 0 } { $i < $XDIM } { incr i } {
            x $i = [expr {double($i)*2.*$PI/double($XDIMM1)}]
        }
        for { set i 0 } { $i < $YDIM } { incr i } {
            y $i = [expr {double($i)*3.*$PI/double($YDIMM1)}]
        }

        for { set i 0 } { $i < $XDIM } { incr i } {
            for { set j 0 } { $j < $YDIM } { incr j } {
                set xx [x $i]
                set yy [y $j]
                r $i $j = [expr {sqrt($xx*$xx+$yy*$yy)+0.001}]
                set rr [r $i $j]
                z $i $j = [expr {sin($rr) / $rr}]
            }
        }

        $w cmd pllab "No, an amplitude clipped \"sombrero\"" "" "Saturn?"
        $w cmd plptex 2. 2. 3. 4. 0. "Transparent image"
        $w cmd plimage z 0. [expr {2.*$PI}] 0.0 [expr {3.*$PI}] \
            0.05 1. 0. [expr {2.*$PI}]  0. [expr {3.*$PI}]

#       Save the plot
        if { $f_name != "" } {
            save_plot $w $f_name
        }

        $w cmd pladv 0
    }

#
#   Read Lena image
#   Note we try two different locations to cover the case where this
#   examples is being run from the test_c.sh script
#
    if { ![read_img "lena.pgm" img_f width height num_col] } {
        if { ![read_img "../lena.pgm" img_f width height num_col] } {
#C          $w cmd plabort "No such file"
            puts "Image could not be read"
            $w cmd plend
            return
        }
    }

#   Set gray colormap
    gray_cmap $w $num_col

#   Display Lena
    $w cmd plenv 1. $width 1. $height 1 -1

    if { !$nointeractive } {
        $w cmd pllab "Set and drag Button 1 to (re)set selection Button 2 to finish." \
            " " "Lena..."
    } else {
        $w cmd pllab "" " " "Lena..."
    }

    $w cmd plimage img_f 1. $width 1. $height 0. 0. 1. $width 1. $height

#   Selection/expansion demo
    if { !$nointeractive } {
        set xi 200.0
        set xe 330.0
        set yi 280.0
        set ye 220.0
{'fraction_non_alphanumeric': 0.1299254526091587, 'fraction_numerical': 0.027334043308484202, 'mean_word_length': 1.629258049463369, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6571413', 'n_tokens_mistral': 4272, 'n_tokens_neox': 4011, 'n_words': 1405}