| 1 | package Lab::XPRESS::Data::XPRESS_plotter; | ||
| 2 | #ABSTRACT: XPRESS plotting module | ||
| 3 | $Lab::XPRESS::Data::XPRESS_plotter::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Time::HiRes qw/gettimeofday tv_interval/; | ||
| 8 | use Time::HiRes qw/usleep/, qw/time/; | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my $proto = shift; | ||
| 12 | my $class = ref($proto) || $proto; | ||
| 13 | my $filename = shift; | ||
| 14 | my $plot; | ||
| 15 | |||
| 16 | if ( ref( @_[0] ) eq 'HASH' ) { | ||
| 17 | $plot = @_[0]; | ||
| 18 | } | ||
| 19 | else { | ||
| 20 | $plot = shift; | ||
| 21 | } | ||
| 22 | |||
| 23 | my $self = bless { | ||
| 24 | filename => $filename, | ||
| 25 | plot => $plot | ||
| 26 | }, $class; | ||
| 27 | |||
| 28 | my %plot = %$plot; | ||
| 29 | |||
| 30 | $self->{PAUSE} = -1 | ||
| 31 | ; # negative value ==> pause disabled, positive value ==> pause enabled | ||
| 32 | |||
| 33 | if ( $self->{plot}->{refresh} eq 'block' ) { | ||
| 34 | $self->{PAUSE} = 1; | ||
| 35 | } | ||
| 36 | |||
| 37 | $self->{gpipe} = $self->get_gnuplot_pipe(); | ||
| 38 | |||
| 39 | return $self; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub prepair_plot_config_data { | ||
| 43 | my $self = shift; | ||
| 44 | |||
| 45 | # prepair y-axis: | ||
| 46 | if ( ref( $self->{plot}->{'y-axis'} ) ne 'ARRAY' ) { | ||
| 47 | $self->{plot}->{'y-axis'} = [ $self->{plot}->{'y-axis'} ]; | ||
| 48 | } | ||
| 49 | |||
| 50 | # prepair y2-axis: | ||
| 51 | if ( ref( $self->{plot}->{'y2-axis'} ) ne 'ARRAY' ) { | ||
| 52 | $self->{plot}->{'y2-axis'} = [ $self->{plot}->{'y2-axis'} ]; | ||
| 53 | } | ||
| 54 | |||
| 55 | # replace columnames by columnumbers: | ||
| 56 | if ( exists $self->{COLUMN_NAMES}{ $self->{plot}->{'x-axis'} } ) { | ||
| 57 | $self->{plot}->{'x-axis'} | ||
| 58 | = $self->{COLUMN_NAMES}{ $self->{plot}->{'x-axis'} }; | ||
| 59 | } | ||
| 60 | |||
| 61 | my $temp = (); | ||
| 62 | foreach my $axis ( @{ $self->{plot}->{'y-axis'} } ) { | ||
| 63 | if ( exists $self->{COLUMN_NAMES}{$axis} ) { | ||
| 64 | push( @{$temp}, $self->{COLUMN_NAMES}{$axis} ); | ||
| 65 | } | ||
| 66 | elsif ( $axis <= $self->{NUMBER_OF_COLUMNS} ) { | ||
| 67 | push( @{$temp}, $axis ); | ||
| 68 | } | ||
| 69 | else { | ||
| 70 | print "$axis does not exist\n"; | ||
| 71 | } | ||
| 72 | $self->{plot}->{'y-axis'} = $temp; | ||
| 73 | } | ||
| 74 | |||
| 75 | my $temp = (); | ||
| 76 | foreach my $axis ( @{ $self->{plot}->{'y2-axis'} } ) { | ||
| 77 | if ( exists $self->{COLUMN_NAMES}{$axis} ) { | ||
| 78 | push( @{$temp}, $self->{COLUMN_NAMES}{$axis} ); | ||
| 79 | } | ||
| 80 | elsif ( $axis <= $self->{NUMBER_OF_COLUMNS} ) { | ||
| 81 | push( @{$temp}, $axis ); | ||
| 82 | } | ||
| 83 | $self->{plot}->{'y2-axis'} = $temp; | ||
| 84 | } | ||
| 85 | |||
| 86 | if ( exists $self->{COLUMN_NAMES}{ $self->{plot}->{'z-axis'} } ) { | ||
| 87 | $self->{plot}->{'z-axis'} | ||
| 88 | = $self->{COLUMN_NAMES}{ $self->{plot}->{'z-axis'} }; | ||
| 89 | } | ||
| 90 | |||
| 91 | if ( exists $self->{COLUMN_NAMES}{ $self->{plot}->{'cb-axis'} } ) { | ||
| 92 | $self->{plot}->{'cb-axis'} | ||
| 93 | = $self->{COLUMN_NAMES}{ $self->{plot}->{'cb-axis'} }; | ||
| 94 | } | ||
| 95 | |||
| 96 | } | ||
| 97 | |||
| 98 | sub get_gnuplot_pipe { | ||
| 99 | my $self = shift; | ||
| 100 | my $gpname; | ||
| 101 | if ( $^O =~ /MSWin32/ ) { | ||
| 102 | $gpname = "gnuplot"; | ||
| 103 | } | ||
| 104 | else { | ||
| 105 | $gpname = "gnuplot -noraise"; | ||
| 106 | } | ||
| 107 | if ( open my $GP, "| $gpname" ) { | ||
| 108 | my $oldfh = select($GP); | ||
| 109 | $| = 1; | ||
| 110 | select($oldfh); | ||
| 111 | return $GP; | ||
| 112 | } | ||
| 113 | return undef; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub init_gnuplot { | ||
| 117 | my $self = shift; | ||
| 118 | |||
| 119 | $self->prepair_plot_config_data(); | ||
| 120 | |||
| 121 | my %plot = %{ $self->{plot} }; | ||
| 122 | my $gp; | ||
| 123 | my $gpipe = $self->{gpipe}; | ||
| 124 | |||
| 125 | $gp .= "set title font 'arial,18'\n"; | ||
| 126 | $gp .= "set xlabel font 'arial,12'\n"; | ||
| 127 | $gp .= "set ylabel font 'arial,12'\n"; | ||
| 128 | $gp .= "set zlabel font 'arial,12'\n"; | ||
| 129 | $gp .= "set cblabel font 'arial,12'\n"; | ||
| 130 | $gp .= "set xtics font 'arial,10'\n"; | ||
| 131 | $gp .= "set ytics font 'arial,10'\n"; | ||
| 132 | $gp .= "set ztics font 'arial,10'\n"; | ||
| 133 | $gp .= "set cbtics font 'arial,7'\n"; | ||
| 134 | $gp .= "set format cb '%.4e'\n"; | ||
| 135 | $gp .= "set key font 'arial,8' at graph 1,1.15\n"; | ||
| 136 | $gp .= "set title offset -32,0.6\n"; | ||
| 137 | |||
| 138 | # store column_names and axis index to gnuplot terminal: | ||
| 139 | my $i = 1; | ||
| 140 | while ( my ( $column, $index ) = each %{ $self->{COLUMN_NAMES} } ) { | ||
| 141 | $column =~ s/\s+/_/g; #replace all whitespaces by '_' | ||
| 142 | $column =~ s/\+/_/; #replace '+' by '_' | ||
| 143 | $column =~ s/-/_/; #replace '-' by '_' | ||
| 144 | $column =~ s/\//_/; #replace '/' by '_' | ||
| 145 | $column =~ s/\*/_/; #replace '*' by '_' | ||
| 146 | |||
| 147 | $gp .= "COLUMN_$index = '" . $column . "'; "; | ||
| 148 | $i++; | ||
| 149 | } | ||
| 150 | print $gpipe $gp; | ||
| 151 | $gp = ""; | ||
| 152 | |||
| 153 | my $i = 1; | ||
| 154 | foreach my $y ( @{ $self->{plot}->{'y-axis'} } ) { | ||
| 155 | if ( not defined $y ) { next; } | ||
| 156 | $gp .= "Y1$i = $y; "; | ||
| 157 | $i++; | ||
| 158 | } | ||
| 159 | print $gpipe $gp; | ||
| 160 | $gp = ""; | ||
| 161 | |||
| 162 | my $i = 1; | ||
| 163 | foreach my $y ( @{ $self->{plot}->{'y2-axis'} } ) { | ||
| 164 | if ( not defined $y ) { next; } | ||
| 165 | $gp .= "Y2$i = $y; "; | ||
| 166 | $i++; | ||
| 167 | } | ||
| 168 | print $gpipe $gp; | ||
| 169 | $gp = ""; | ||
| 170 | |||
| 171 | $gp .= "X1 = " . $self->{plot}->{'x-axis'} . "; "; | ||
| 172 | |||
| 173 | # prepair data selection: | ||
| 174 | |||
| 175 | if ( not defined $self->{plot}->{LineIncrement} ) { | ||
| 176 | $self->{plot}->{LineIncrement} = 1; | ||
| 177 | } | ||
| 178 | $gp .= "LineIncrement = " . $self->{plot}->{LineIncrement} . "; "; | ||
| 179 | |||
| 180 | if ( not defined $self->{plot}->{BlockIncrement} ) { | ||
| 181 | $self->{plot}->{BlockIncrement} = 1; | ||
| 182 | } | ||
| 183 | $gp .= "BlockIncrement = " . $self->{plot}->{BlockIncrement} . "; "; | ||
| 184 | |||
| 185 | if ( not defined $self->{plot}->{LineFrom} ) { | ||
| 186 | $self->{plot}->{LineFrom} = 0; | ||
| 187 | } | ||
| 188 | $gp .= "LineFrom = " . $self->{plot}->{LineFrom} . "; "; | ||
| 189 | |||
| 190 | if ( not defined $self->{plot}->{BlockFrom} ) { | ||
| 191 | $self->{plot}->{BlockFrom} = 0; | ||
| 192 | } | ||
| 193 | $gp .= "BlockFrom = " . $self->{plot}->{BlockFrom} . "; "; | ||
| 194 | |||
| 195 | if ( not defined $self->{plot}->{LineTo} ) { | ||
| 196 | $self->{plot}->{LineTo} = $self->{LINE_NUM}; | ||
| 197 | } | ||
| 198 | $gp .= "LineTo = " . $self->{plot}->{LineTo} . "; "; | ||
| 199 | |||
| 200 | if ( not defined $self->{plot}->{BlockTo} ) { | ||
| 201 | $self->{plot}->{BlockTo} = $self->{BLOCK_NUM}; | ||
| 202 | } | ||
| 203 | $gp .= "BlockTo = " . $self->{plot}->{BlockTo} . "; "; | ||
| 204 | |||
| 205 | $gp .= "BLOCK_NUM = " . $self->{BLOCK_NUM} . "; "; | ||
| 206 | $gp .= "LINE_NUM = " . $self->{LINE_NUM} . "; "; | ||
| 207 | |||
| 208 | #$gp .= "show variables;\n"; | ||
| 209 | print $gpipe $gp; | ||
| 210 | $gp = ""; | ||
| 211 | |||
| 212 | if ( defined $plot{'title'} ) { | ||
| 213 | $gp .= "set title '$plot{'title'}'\n"; | ||
| 214 | |||
| 215 | #print $gp."\n"; | ||
| 216 | } | ||
| 217 | |||
| 218 | if ( defined $plot{'y2-axis'}[0] ) { | ||
| 219 | $gp .= "set y2tics\n"; | ||
| 220 | $gp .= "set ytics nomirror\n"; | ||
| 221 | } | ||
| 222 | |||
| 223 | if ( defined $plot{'x-min'} or defined $plot{'x-max'} ) { | ||
| 224 | $gp .= "set xrange [$plot{'x-min'}:$plot{'x-max'}]\n"; | ||
| 225 | |||
| 226 | #print $gp."\n"; | ||
| 227 | } | ||
| 228 | |||
| 229 | if ( defined $plot{'y-min'} or defined $plot{'y-max'} ) { | ||
| 230 | $gp .= "set yrange [$plot{'y-min'}:$plot{'y-max'}]\n"; | ||
| 231 | |||
| 232 | #print $gp."\n"; | ||
| 233 | } | ||
| 234 | |||
| 235 | if ( defined $plot{'z-min'} or defined $plot{'z-max'} ) { | ||
| 236 | $gp .= "set zrange [$plot{'z-min'}:$plot{'z-max'}]\n"; | ||
| 237 | |||
| 238 | #print $gp."\n"; | ||
| 239 | } | ||
| 240 | |||
| 241 | if ( defined $plot{'cb-min'} or defined $plot{'cb-max'} ) { | ||
| 242 | $gp .= "set cbrange [$plot{'cb-min'}:$plot{'cb-max'}]\n"; | ||
| 243 | |||
| 244 | #print $gp."\n"; | ||
| 245 | } | ||
| 246 | |||
| 247 | if ( defined $plot{'x-format'} ) { | ||
| 248 | $gp .= "set format x '" . $plot{'x-format'} . "'\n"; | ||
| 249 | } | ||
| 250 | |||
| 251 | if ( defined $plot{'y-format'} ) { | ||
| 252 | $gp .= "set format y '" . $plot{'y-format'} . "'\n"; | ||
| 253 | } | ||
| 254 | |||
| 255 | if ( defined $plot{'y2-format'} ) { | ||
| 256 | $gp .= "set format y2 '" . $plot{'y2-format'} . "'\n"; | ||
| 257 | } | ||
| 258 | |||
| 259 | if ( defined $plot{'z-format'} ) { | ||
| 260 | $gp .= "set format z '" . $plot{'z-format'} . "'\n"; | ||
| 261 | } | ||
| 262 | |||
| 263 | if ( defined $plot{'cb-format'} ) { | ||
| 264 | $gp .= "set format cb '" . $plot{'cb-format'} . "'\n"; | ||
| 265 | } | ||
| 266 | |||
| 267 | if ( defined $plot{'x-label'} ) { | ||
| 268 | $gp .= "set xlabel '$plot{'x-label'}'\n"; | ||
| 269 | } | ||
| 270 | elsif ( defined $plot{'x-axis'} ) { | ||
| 271 | my $i = $plot{'x-axis'}; | ||
| 272 | $gp .= "set xlabel COLUMN_$i\n"; | ||
| 273 | } | ||
| 274 | |||
| 275 | if ( defined $plot{'y-label'} ) { | ||
| 276 | $gp .= "set ylabel '$plot{'y-label'}'\n"; | ||
| 277 | } | ||
| 278 | elsif ( defined $plot{'y-axis'} ) { | ||
| 279 | my $i = $plot{'y-axis'}[0]; | ||
| 280 | if ( $i ne "" ) { $gp .= "set ylabel COLUMN_$i\n"; }; | ||
| 281 | } | ||
| 282 | |||
| 283 | if ( defined $plot{'y2-label'} ) { | ||
| 284 | $gp .= "set y2label '$plot{'y2-label'}'\n"; | ||
| 285 | } | ||
| 286 | elsif ( defined $plot{'y2-axis'} ) { | ||
| 287 | my $i = $plot{'y2-axis'}[0]; | ||
| 288 | if ( $i ne "" ) { $gp .= "set y2label COLUMN_$i\n"; }; | ||
| 289 | } | ||
| 290 | |||
| 291 | if ( defined $plot{'z-label'} ) { | ||
| 292 | $gp .= "set zlabel '$plot{'z-label'}'\n"; | ||
| 293 | } | ||
| 294 | elsif ( defined $plot{'z-axis'} ) { | ||
| 295 | my $i = $plot{'z-axis'}; | ||
| 296 | $gp .= "set zlabel COLUMN_$i\n"; | ||
| 297 | } | ||
| 298 | |||
| 299 | if ( defined $plot{'cb-label'} ) { | ||
| 300 | $gp .= "set cblabel '$plot{'cb-label'}'\n"; | ||
| 301 | } | ||
| 302 | elsif ( defined $plot{'cb-axis'} ) { | ||
| 303 | my $i = $plot{'cb-axis'}; | ||
| 304 | $gp .= "set cblabel COLUMN_$i\n"; | ||
| 305 | } | ||
| 306 | |||
| 307 | if ( defined $plot{'grid'} ) { | ||
| 308 | $gp .= "set grid $plot{'grid'}\n"; | ||
| 309 | } | ||
| 310 | |||
| 311 | if ( not defined $plot{'x-axis'} ) { | ||
| 312 | die "Error while plotting data. x-axis is not defined."; | ||
| 313 | } | ||
| 314 | |||
| 315 | if ( not defined $plot{'y-axis'} ) { | ||
| 316 | die "Error while plotting data. y-axis is not defined."; | ||
| 317 | } | ||
| 318 | |||
| 319 | if ( not defined $plot{'z-axis'} | ||
| 320 | and not defined $plot{'cb-axis'} | ||
| 321 | and $plot{'type'} eq 'pm3d' ) { | ||
| 322 | die | ||
| 323 | "Error while plotting data. Plot type = pm3d: z-axis and/or cb-axis are not defined."; | ||
| 324 | } | ||
| 325 | |||
| 326 | %{ $self->{plot} } = %plot; | ||
| 327 | |||
| 328 | print $gpipe $gp; | ||
| 329 | usleep(1e4); | ||
| 330 | |||
| 331 | return $gpipe; | ||
| 332 | |||
| 333 | } | ||
| 334 | |||
| 335 | sub init_gnuplot_bindings { | ||
| 336 | my $self = shift; | ||
| 337 | |||
| 338 | $self->bind_s(); | ||
| 339 | $self->bind_x(); | ||
| 340 | $self->bind_y(); | ||
| 341 | |||
| 342 | if ( defined $self->{plot}->{'z-axis'} ) { | ||
| 343 | $self->bind_z(); | ||
| 344 | } | ||
| 345 | |||
| 346 | if ( defined $self->{plot}->{'cb-axis'} ) { | ||
| 347 | $self->bind_c(); | ||
| 348 | } | ||
| 349 | |||
| 350 | } | ||
| 351 | |||
| 352 | sub toggle_pause { | ||
| 353 | my $self = shift; | ||
| 354 | |||
| 355 | $self->{PAUSE} *= -1; | ||
| 356 | |||
| 357 | return; | ||
| 358 | } | ||
| 359 | |||
| 360 | sub start_plot { | ||
| 361 | my $self = shift; | ||
| 362 | my $block_num = shift; | ||
| 363 | my $filename = $self->{filename}; | ||
| 364 | my $gp; | ||
| 365 | my $gpipe = $self->{gpipe}; | ||
| 366 | |||
| 367 | print "Starting plot\n"; | ||
| 368 | |||
| 369 | # if plot mode == pm3d, then change to other start routine: | ||
| 370 | if ( $self->{plot}->{'type'} eq 'pm3d' and $block_num <= 1 ) { | ||
| 371 | return 1; | ||
| 372 | } | ||
| 373 | elsif ( $self->{plot}->{'type'} eq 'pm3d' and $block_num > 1 ) { | ||
| 374 | $self->start_plot_pm3d($block_num); | ||
| 375 | return 1; | ||
| 376 | } | ||
| 377 | |||
| 378 | my $gpipe = $self->{gpipe}; | ||
| 379 | print $gpipe $gp; | ||
| 380 | |||
| 381 | # create PLOT-command: | ||
| 382 | |||
| 383 | #-------------------------------------------------------------------------------------------------# | ||
| 384 | #---- y1-axis ------------------------------------------------------------------------------------# | ||
| 385 | #-------------------------------------------------------------------------------------------------# | ||
| 386 | my $i = 1; | ||
| 387 | $gp = "plot "; | ||
| 388 | foreach my $y ( @{ $self->{plot}->{'y-axis'} } ) { | ||
| 389 | if ( not defined $y ) { | ||
| 390 | next; | ||
| 391 | } | ||
| 392 | |||
| 393 | if ( not defined $self->{plot}->{'type'} ) { | ||
| 394 | $self->{plot}->{'type'} = 'point'; | ||
| 395 | } | ||
| 396 | |||
| 397 | if ( $self->{plot}->{'type'} | ||
| 398 | =~ /\b(line|lines|LINE|LINES|L|l|ln|LN)\b/ ) { | ||
| 399 | if ( $block_num > 1 ) { | ||
| 400 | |||
| 401 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 402 | my $old_blocks = $block_num - 2; | ||
| 403 | my $current_block = $block_num - 1; | ||
| 404 | $gp | ||
| 405 | .= "'$filename' using X1:Y1$i every :::0::$old_blocks with lines,"; | ||
| 406 | $gp .= "'$filename' using X1:Y1$i every :::$current_block" | ||
| 407 | . "::$current_block with lines,"; | ||
| 408 | } | ||
| 409 | else { | ||
| 410 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 411 | $gp .= "'$filename' using X1:Y1$i with lines,"; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | elsif ( $self->{plot}->{'type'} | ||
| 415 | =~ /\b(linetrace|LINETRACE|trace|TRACE)\b/ ) { | ||
| 416 | |||
| 417 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 418 | my $block_old | ||
| 419 | = ( $block_num - 2 < 0 ) ? $block_num - 1 : $block_num - 2; | ||
| 420 | my $block_new | ||
| 421 | = ( $block_num - 1 < 0 ) ? $block_num : $block_num - 1; | ||
| 422 | $gp .= "'$filename' using X1:Y1$i every :::$block_old" | ||
| 423 | . "::$block_old with lines,"; | ||
| 424 | $gp .= "'$filename' using X1:Y1$i every :::$block_new" | ||
| 425 | . "::$block_new with points"; | ||
| 426 | } | ||
| 427 | elsif ( $self->{plot}->{'type'} =~ /\b(single|SINGLE)\b/ ) { | ||
| 428 | if ( $block_num > 1 ) { | ||
| 429 | |||
| 430 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 431 | my $current_block = $block_num - 1; | ||
| 432 | $gp .= "'$filename' using X1:Y1$i every :::$current_block" | ||
| 433 | . "::$current_block with lines,"; | ||
| 434 | } | ||
| 435 | else { | ||
| 436 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 437 | $gp .= "'$filename' using X1:Y1$i with lines,"; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | elsif ( $self->{plot}->{'type'} =~ /\b(rainbow|RAINBOW)\b/ ) { | ||
| 441 | if ( $block_num > 1 ) { | ||
| 442 | |||
| 443 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 444 | foreach my $block ( 0 .. $block_num - 1 ) { | ||
| 445 | $gp .= "'$filename' using X1:Y1$i every :::$block" | ||
| 446 | . "::$block with lines lt $block ti 'M_$block',"; | ||
| 447 | } | ||
| 448 | } | ||
| 449 | else { | ||
| 450 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 451 | $gp .= "'$filename' using X1:Y1$i with lines,"; | ||
| 452 | } | ||
| 453 | } | ||
| 454 | elsif ( $self->{plot}->{'type'} | ||
| 455 | =~ /\b(points|point|POINTS|POINT|P|p|pt|PT)\b/ ) { | ||
| 456 | if ( $block_num > 1 ) { | ||
| 457 | |||
| 458 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 459 | my $old_blocks = $block_num - 2; | ||
| 460 | my $current_block = $block_num - 1; | ||
| 461 | $gp | ||
| 462 | .= "'$filename' using X1:Y1$i every :::0::$old_blocks with lines,"; | ||
| 463 | $gp .= "'$filename' using X1:Y1$i every :::$current_block" | ||
| 464 | . "::$current_block with points,"; | ||
| 465 | } | ||
| 466 | else { | ||
| 467 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 468 | $gp .= "'$filename' using X1:Y1$i with points,"; | ||
| 469 | } | ||
| 470 | } | ||
| 471 | elsif ( $self->{plot}->{'type'} =~ /\b(man|MAN|empty|EMPTY)\b/ ) { | ||
| 472 | $gp .= "'$filename',"; | ||
| 473 | } | ||
| 474 | elsif ( $self->{plot}->{'type'} eq 'PlotterGUI' ) { | ||
| 475 | $gp .= "'$self->{plot}->{filename}' "; | ||
| 476 | $gp .= "using X1:Y1$i axis x1y1 "; | ||
| 477 | $gp | ||
| 478 | .= "every LineIncrement:BlockIncrement:LineFrom:BlockFrom:LineTo:BlockTo "; | ||
| 479 | $gp .= "with @{$self->{plot}->{y_LineStyle}}[$i] "; | ||
| 480 | if ( @{ $self->{plot}->{y_LineStyle} }[$i] =~ /lines/ ) { | ||
| 481 | $gp .= "linecolor '@{$self->{plot}->{y_LineColor}}[$i]' "; | ||
| 482 | $gp .= "linewidth '@{$self->{plot}->{y_LineSize}}[$i]' "; | ||
| 483 | } | ||
| 484 | if ( @{ $self->{plot}->{y1_style} }[$i] =~ /points/ ) { | ||
| 485 | $gp .= "pointtype 13 "; | ||
| 486 | $gp .= "pointsize '@{$self->{plot}->{y_LineSize}}[$i]' "; | ||
| 487 | } | ||
| 488 | $gp .= "ti '@{$self->{plot}->{y_ColumnLabel}}[$i]' "; | ||
| 489 | |||
| 490 | } | ||
| 491 | $i++; | ||
| 492 | } | ||
| 493 | |||
| 494 | #-------------------------------------------------------------------------------------------------# | ||
| 495 | #---- y2-axis ------------------------------------------------------------------------------------# | ||
| 496 | #-------------------------------------------------------------------------------------------------# | ||
| 497 | my $i = 1; | ||
| 498 | foreach my $y ( @{ $self->{plot}->{'y2-axis'} } ) { | ||
| 499 | if ( not defined $y ) { | ||
| 500 | next; | ||
| 501 | } | ||
| 502 | if ( $self->{plot}->{'type'} | ||
| 503 | =~ /\b(line|lines|LINE|LINES|L|l|ln|LN)\b/ ) { | ||
| 504 | if ( $block_num > 1 ) { | ||
| 505 | |||
| 506 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 507 | my $old_blocks = $block_num - 2; | ||
| 508 | my $current_block = $block_num - 1; | ||
| 509 | $gp | ||
| 510 | .= "'$filename' using X1:Y2$i axis x1y2 every :::0::$old_blocks with lines,"; | ||
| 511 | $gp | ||
| 512 | .= "'$filename' using X1:Y2$i axis x1y2 every :::$current_block" | ||
| 513 | . "::$current_block with lines,"; | ||
| 514 | } | ||
| 515 | else { | ||
| 516 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 517 | $gp .= "'$filename' using X1:Y2$i axis x1y2 with lines,"; | ||
| 518 | } | ||
| 519 | } | ||
| 520 | elsif ( $self->{plot}->{'type'} | ||
| 521 | =~ /\b(linetrace|LINETRACE|trace|TRACE)\b/ ) { | ||
| 522 | |||
| 523 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 524 | my $block_old | ||
| 525 | = ( $block_num - 2 < 0 ) ? $block_num - 1 : $block_num - 2; | ||
| 526 | my $block_new | ||
| 527 | = ( $block_num - 1 < 0 ) ? $block_num : $block_num - 1; | ||
| 528 | $gp .= "'$filename' using X1:Y1$i axis x1y2 every :::$block_old" | ||
| 529 | . "::$block_old with lines,"; | ||
| 530 | $gp .= "'$filename' using X1:Y1$i axis x1y2 every :::$block_new" | ||
| 531 | . "::$block_new with points"; | ||
| 532 | } | ||
| 533 | elsif ( $self->{plot}->{'type'} =~ /\b(single|SINGLE)\b/ ) { | ||
| 534 | if ( $block_num > 1 ) { | ||
| 535 | |||
| 536 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 537 | my $current_block = $block_num - 1; | ||
| 538 | $gp | ||
| 539 | .= "'$filename' using X1:Y2$i axis x1y2 every :::$current_block" | ||
| 540 | . "::$current_block with lines,"; | ||
| 541 | } | ||
| 542 | else { | ||
| 543 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 544 | $gp .= "'$filename' using X1:Y2$i axis x1y2 with lines,"; | ||
| 545 | } | ||
| 546 | } | ||
| 547 | elsif ( $self->{plot}->{'type'} =~ /\b(rainbow|RAINBOW)\b/ ) { | ||
| 548 | if ( $block_num > 1 ) { | ||
| 549 | |||
| 550 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 551 | foreach my $block ( 0 .. $block_num - 1 ) { | ||
| 552 | $gp | ||
| 553 | .= "'$filename' using X1:Y2$i axis x1y2 every :::$block" | ||
| 554 | . "::$block with lines lt $block ti 'M_$block',"; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | else { | ||
| 558 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 559 | $gp .= "'$filename' using X1:Y2$i axis x1y2 with lines,"; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | elsif ( $self->{plot}->{'type'} | ||
| 563 | =~ /\b(points|point|POINTS|POINT|P|p|pt|PT)\b/ ) { | ||
| 564 | if ( $block_num > 1 ) { | ||
| 565 | |||
| 566 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 567 | my $old_blocks = $block_num - 2; | ||
| 568 | my $current_block = $block_num - 1; | ||
| 569 | $gp | ||
| 570 | .= "'$filename' using X1:Y2$i axis x1y2 every :::0::$old_blocks with lines,"; | ||
| 571 | $gp | ||
| 572 | .= "'$filename' using X1:Y2$i axis x1y2 every :::$current_block" | ||
| 573 | . "::$current_block with points,"; | ||
| 574 | } | ||
| 575 | else { | ||
| 576 | #my $parameter = $self->{plot}->{'x-axis'}; | ||
| 577 | $gp .= "'$filename' using X1:Y2$i axis x1y2 with points,"; | ||
| 578 | } | ||
| 579 | } | ||
| 580 | elsif ( $self->{plot}->{'type'} =~ /\b(man|MAN|empty|EMPTY)\b/ ) { | ||
| 581 | $gp .= "'$filename',"; | ||
| 582 | } | ||
| 583 | $i++; | ||
| 584 | } | ||
| 585 | chop $gp; | ||
| 586 | $gp .= "\n"; | ||
| 587 | my $gpipe = $self->{gpipe}; | ||
| 588 | print $gpipe $gp; | ||
| 589 | |||
| 590 | $self->{plot}->{started} = 'started'; | ||
| 591 | |||
| 592 | $self->bind_s(); | ||
| 593 | |||
| 594 | return $self; | ||
| 595 | |||
| 596 | } | ||
| 597 | |||
| 598 | sub start_plot_pm3d { | ||
| 599 | my $self = shift; | ||
| 600 | my $block_num = shift; | ||
| 601 | |||
| 602 | my $filename = $self->{filename}; | ||
| 603 | my $gp; | ||
| 604 | |||
| 605 | my $gpipe = $self->get_gnuplot_pipe(); | ||
| 606 | |||
| 607 | $gp .= "#\n# Set color plot\n"; | ||
| 608 | $gp .= "set pm3d map corners2color c1\n"; | ||
| 609 | $gp .= "set view map\n"; | ||
| 610 | $gp .= "set key font 'arial,8' at graph 1,1.15 \n"; | ||
| 611 | |||
| 612 | #$gp.="set palette ".$self->{meta}->plot_palette($plot)."\n"; | ||
| 613 | |||
| 614 | $gp .= "set border 4095 front linetype -1 linewidth 1.000\n"; | ||
| 615 | $gp .= "set style data pm3d\n"; | ||
| 616 | $gp .= "set style function pm3d\n"; | ||
| 617 | $gp .= "set ticslevel 0\n"; | ||
| 618 | $gp .= "set size 0.95,1\n"; | ||
| 619 | |||
| 620 | $gp .= "set title offset -23,0.2\n"; | ||
| 621 | |||
| 622 | if ( ref( $self->{plot}->{'x-axis'} ) eq 'ARRAY' ) { | ||
| 623 | $self->{plot}->{'x-axis'} = $self->{plot}->{'x-axis'}[0]; | ||
| 624 | } | ||
| 625 | if ( ref( $self->{plot}->{'y-axis'} ) eq 'ARRAY' ) { | ||
| 626 | $self->{plot}->{'y-axis'} = $self->{plot}->{'y-axis'}[0]; | ||
| 627 | } | ||
| 628 | if ( ref( $self->{plot}->{'z-axis'} ) eq 'ARRAY' ) { | ||
| 629 | $self->{plot}->{'z-axis'} = $self->{plot}->{'z-axis'}[0]; | ||
| 630 | } | ||
| 631 | if ( ref( $self->{plot}->{'cb-axis'} ) eq 'ARRAY' ) { | ||
| 632 | $self->{plot}->{'cb-axis'} = $self->{plot}->{'cb-axis'}[0]; | ||
| 633 | } | ||
| 634 | |||
| 635 | $gp .= "X1 = " . $self->{plot}->{'x-axis'} . ";"; | ||
| 636 | $gp .= "Y11 = " . $self->{plot}->{'y-axis'} . ";"; | ||
| 637 | if ( defined $self->{plot}->{'z-axis'} ) { | ||
| 638 | $gp .= "Z = " . $self->{plot}->{'z-axis'} . ";"; | ||
| 639 | } | ||
| 640 | if ( defined $self->{plot}->{'cb-axis'} ) { | ||
| 641 | $gp .= "CB = " . $self->{plot}->{'cb-axis'} . ";"; | ||
| 642 | } | ||
| 643 | |||
| 644 | $gp .= "\n"; | ||
| 645 | my $gpipe = $self->{gpipe}; | ||
| 646 | print $gpipe $gp; | ||
| 647 | $gp = ""; | ||
| 648 | |||
| 649 | if ( defined $self->{plot}->{'z-axis'} ) { | ||
| 650 | $gp = ""; | ||
| 651 | $gp .= "splot '$filename' using X1:Y11:Z ; \n"; | ||
| 652 | } | ||
| 653 | elsif ( defined $self->{plot}->{'cb-axis'} ) { | ||
| 654 | $gp = ""; | ||
| 655 | $gp .= "splot '$filename' using X1:Y11:CB ; \n"; | ||
| 656 | } | ||
| 657 | |||
| 658 | #print $gp."\n"; | ||
| 659 | print $gpipe $gp; | ||
| 660 | $self->{plot}->{started} = 1; | ||
| 661 | |||
| 662 | return 1; | ||
| 663 | |||
| 664 | } | ||
| 665 | |||
| 666 | sub _stop_live_plot { | ||
| 667 | my $self = shift; | ||
| 668 | |||
| 669 | return unless ( defined $self->{gpipe} ); | ||
| 670 | |||
| 671 | close $self->{gpipe}; | ||
| 672 | undef $self->{plot}; | ||
| 673 | } | ||
| 674 | |||
| 675 | sub replot { | ||
| 676 | my $self = shift; | ||
| 677 | |||
| 678 | if ( $self->{PAUSE} > 0 ) { | ||
| 679 | return 1; | ||
| 680 | } | ||
| 681 | else { | ||
| 682 | my $gpipe = $self->{gpipe}; | ||
| 683 | print $gpipe "replot\n"; | ||
| 684 | return 1; | ||
| 685 | } | ||
| 686 | } | ||
| 687 | |||
| 688 | sub gnuplot_cmd { | ||
| 689 | my $self = shift; | ||
| 690 | my $cmd = shift; | ||
| 691 | my $gp; | ||
| 692 | my $gpipe = $self->{gpipe}; | ||
| 693 | |||
| 694 | $gp = "$cmd\n"; | ||
| 695 | |||
| 696 | print $gpipe $gp; | ||
| 697 | return $self; | ||
| 698 | |||
| 699 | } | ||
| 700 | |||
| 701 | sub bind_x { | ||
| 702 | my $self = shift; | ||
| 703 | my $gp; | ||
| 704 | |||
| 705 | # covert hash of columns to an array: | ||
| 706 | my @columns = (); | ||
| 707 | |||
| 708 | while ( my ( $column, $index ) = each %{ $self->{COLUMN_NAMES} } ) { | ||
| 709 | $column =~ s/\s+/_/g; #replace all whitespaces by '_' | ||
| 710 | $column =~ s/\+/_/; #replace '+' by '_' | ||
| 711 | $column =~ s/-/_/; #replace '-' by '_' | ||
| 712 | $column =~ s/\//_/; #replace '/' by '_' | ||
| 713 | $column =~ s/\*/_/; #replace '*' by '_' | ||
| 714 | |||
| 715 | $columns[$index] = $column; | ||
| 716 | } | ||
| 717 | shift @columns; | ||
| 718 | |||
| 719 | # foreach my $k ( keys %{$self->{COLUMN}}) | ||
| 720 | # { | ||
| 721 | # push (@columns, $k); | ||
| 722 | # } | ||
| 723 | |||
| 724 | my $gpipe = $self->{gpipe}; | ||
| 725 | usleep(1e4); | ||
| 726 | print $gpipe $gp; | ||
| 727 | |||
| 728 | $gp = ""; | ||
| 729 | |||
| 730 | # bind x key: | ||
| 731 | $gp .= 'bind x "'; | ||
| 732 | |||
| 733 | # draw background: | ||
| 734 | $gp | ||
| 735 | .= "set obj 1001 rect from graph 0, graph 0 to graph 1, graph 1 front fc rgb 'grey' fs transparent solid 0.8; "; | ||
| 736 | $gp .= "set label 1001 '';\\\n"; | ||
| 737 | print $gpipe $gp; | ||
| 738 | usleep(1e4); | ||
| 739 | $gp = ""; | ||
| 740 | |||
| 741 | # draw 'buttons' for each column: | ||
| 742 | my $m = 0; | ||
| 743 | my $n = 0; | ||
| 744 | foreach my $column (@columns) { | ||
| 745 | $gp | ||
| 746 | .= "set obj 100" | ||
| 747 | . ( $m * 4 + $n + 2 ) | ||
| 748 | . " rect from graph (0.05+$n*(0.23)), graph ((1-0.05)-$m*(0.12)) to graph (0.05+$n*(0.23)+0.21), graph ((1-0.05)-$m*(0.12) - 0.1) front fc rgb '#2F3239'; "; | ||
| 749 | $gp | ||
| 750 | .= "set label 100" | ||
| 751 | . ( $m * 4 + $n + 2 ) . " '" | ||
| 752 | . $column | ||
| 753 | . "' at graph (0.05+$n*(0.23) + 0.1), graph ((1-0.05)-$m*(0.12)-0.05) front center tc rgb 'white'; \\\n"; | ||
| 754 | print $gpipe $gp; | ||
| 755 | usleep(2e4); | ||
| 756 | $gp = ""; | ||
| 757 | $n++; | ||
| 758 | if ( $n >= 4 ) { | ||
| 759 | $n = 0; | ||
| 760 | $m++; | ||
| 761 | } | ||
| 762 | } | ||
| 763 | $gp .= "replot; \\\n"; | ||
| 764 | print $gpipe $gp; | ||
| 765 | usleep(1e4); | ||
| 766 | $gp = ""; | ||
| 767 | |||
| 768 | # check for mouseclicks: | ||
| 769 | $m = 0; | ||
| 770 | $n = 0; | ||
| 771 | $gp .= "RANGE_X = GPVAL_X_MAX - GPVAL_X_MIN; "; | ||
| 772 | $gp .= "RANGE_Y = GPVAL_Y_MAX - GPVAL_Y_MIN; "; | ||
| 773 | $gp .= "LOOP = 1; "; | ||
| 774 | $gp .= "while(LOOP){"; | ||
| 775 | $gp .= "pause mouse 'Click Mouse';"; | ||
| 776 | $gp .= "if (exists('MOUSE_X') && exists('MOUSE_Y')) {\\\n"; | ||
| 777 | print $gpipe $gp; | ||
| 778 | usleep(2e4); | ||
| 779 | $gp = ""; | ||
| 780 | |||
| 781 | foreach my $column (@columns) { | ||
| 782 | $gp | ||
| 783 | .= "if (( MOUSE_X < ( GPVAL_X_MIN + RANGE_X * " | ||
| 784 | . ( 0.05 + $n * 0.23 + 0.21 ) | ||
| 785 | . " )) && ( MOUSE_X > ( GPVAL_X_MIN + RANGE_X * " | ||
| 786 | . ( 0.05 + $n * 0.23 ) | ||
| 787 | . " )) && ( MOUSE_Y < ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 788 | . ( ( 1 - 0.05 ) - $m * 0.12 ) | ||
| 789 | . " )) && ( MOUSE_Y > ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 790 | . ( ( 1 - 0.05 ) - $m * 0.12 - 0.1 ) | ||
| 791 | . " ))) {"; | ||
| 792 | $gp .= "LOOP = 0;"; | ||
| 793 | $gp .= "X1 = " . ( $m * 4 + $n + 1 ) . "; "; | ||
| 794 | $gp .= "set xlabel COLUMN_" . ( $m * 4 + $n + 1 ) . "; "; | ||
| 795 | $gp .= "show variables; "; | ||
| 796 | $gp .= "}; \\\n"; | ||
| 797 | print $gpipe $gp; | ||
| 798 | usleep(2e4); | ||
| 799 | $gp = ""; | ||
| 800 | $n++; | ||
| 801 | |||
| 802 | if ( $n >= 4 ) { | ||
| 803 | $n = 0; | ||
| 804 | $m++; | ||
| 805 | } | ||
| 806 | } | ||
| 807 | $gp .= "}"; | ||
| 808 | $gp .= "}; \\\n"; | ||
| 809 | print $gpipe $gp; | ||
| 810 | usleep(1e4); | ||
| 811 | $gp = ""; | ||
| 812 | |||
| 813 | foreach ( 1 .. ( my $length = @columns + 1 ) ) { | ||
| 814 | $gp .= "unset obj 100" . $_ . "; "; | ||
| 815 | $gp .= "unset label 100" . $_ . "; "; | ||
| 816 | } | ||
| 817 | $gp .= "replot; "; | ||
| 818 | |||
| 819 | $gp .= "\n"; | ||
| 820 | |||
| 821 | print $gpipe $gp; | ||
| 822 | usleep(5e5); | ||
| 823 | print $gpipe "\n"; | ||
| 824 | |||
| 825 | } | ||
| 826 | |||
| 827 | sub bind_y { | ||
| 828 | my $self = shift; | ||
| 829 | my $gp; | ||
| 830 | |||
| 831 | # covert hash of columns to an array: | ||
| 832 | my @columns = (); | ||
| 833 | while ( my ( $column, $index ) = each %{ $self->{COLUMN_NAMES} } ) { | ||
| 834 | $column =~ s/\s+/_/g; #replace all whitespaces by '_' | ||
| 835 | $column =~ s/\+/_/; #replace '+' by '_' | ||
| 836 | $column =~ s/-/_/; #replace '-' by '_' | ||
| 837 | $column =~ s/\//_/; #replace '/' by '_' | ||
| 838 | $column =~ s/\*/_/; #replace '*' by '_' | ||
| 839 | |||
| 840 | $columns[$index] = $column; | ||
| 841 | } | ||
| 842 | shift @columns; | ||
| 843 | |||
| 844 | my $gpipe = $self->{gpipe}; | ||
| 845 | usleep(1e4); | ||
| 846 | print $gpipe $gp; | ||
| 847 | |||
| 848 | $gp = ""; | ||
| 849 | |||
| 850 | # bind x key: | ||
| 851 | $gp .= 'bind y "'; | ||
| 852 | |||
| 853 | # draw background: | ||
| 854 | $gp | ||
| 855 | .= "set obj 2001 rect from graph 0, graph 0 to graph 1, graph 1 front fc rgb 'grey' fs transparent solid 0.8; "; | ||
| 856 | $gp .= "set label 2001 '';\\\n"; | ||
| 857 | print $gpipe $gp; | ||
| 858 | usleep(1e4); | ||
| 859 | $gp = ""; | ||
| 860 | |||
| 861 | # draw 'buttons' for each column: | ||
| 862 | my $m = 0; | ||
| 863 | my $n = 0; | ||
| 864 | foreach my $column (@columns) { | ||
| 865 | $gp | ||
| 866 | .= "set obj 200" | ||
| 867 | . ( $m * 4 + $n + 2 ) | ||
| 868 | . " rect from graph (0.05+$n*(0.23)), graph ((1-0.05)-$m*(0.12)) to graph (0.05+$n*(0.23)+0.21), graph ((1-0.05)-$m*(0.12) - 0.1) front fc rgb '#2F3239'; "; | ||
| 869 | $gp | ||
| 870 | .= "set label 200" | ||
| 871 | . ( $m * 4 + $n + 2 ) . " '" | ||
| 872 | . $column | ||
| 873 | . "' at graph (0.05+$n*(0.23) + 0.1), graph ((1-0.05)-$m*(0.12)-0.05) front center tc rgb 'white'; \\\n"; | ||
| 874 | print $gpipe $gp; | ||
| 875 | usleep(2e4); | ||
| 876 | $gp = ""; | ||
| 877 | $n++; | ||
| 878 | if ( $n >= 4 ) { | ||
| 879 | $n = 0; | ||
| 880 | $m++; | ||
| 881 | } | ||
| 882 | } | ||
| 883 | $gp .= "replot; \\\n"; | ||
| 884 | print $gpipe $gp; | ||
| 885 | usleep(1e4); | ||
| 886 | $gp = ""; | ||
| 887 | |||
| 888 | # check for mouseclicks: | ||
| 889 | $m = 0; | ||
| 890 | $n = 0; | ||
| 891 | $gp .= "RANGE_X = GPVAL_X_MAX - GPVAL_X_MIN; "; | ||
| 892 | $gp .= "RANGE_Y = GPVAL_Y_MAX - GPVAL_Y_MIN; "; | ||
| 893 | $gp .= "LOOP = 1; "; | ||
| 894 | $gp .= "while(LOOP){"; | ||
| 895 | $gp .= "pause mouse 'Click Mouse';"; | ||
| 896 | $gp .= "if (exists('MOUSE_X') && exists('MOUSE_Y')) {\\\n"; | ||
| 897 | print $gpipe $gp; | ||
| 898 | usleep(2e4); | ||
| 899 | $gp = ""; | ||
| 900 | |||
| 901 | foreach my $column (@columns) { | ||
| 902 | $gp | ||
| 903 | .= "if (( MOUSE_X < ( GPVAL_X_MIN + RANGE_X * " | ||
| 904 | . ( 0.05 + $n * 0.23 + 0.21 ) | ||
| 905 | . " )) && ( MOUSE_X > ( GPVAL_X_MIN + RANGE_X * " | ||
| 906 | . ( 0.05 + $n * 0.23 ) | ||
| 907 | . " )) && ( MOUSE_Y < ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 908 | . ( ( 1 - 0.05 ) - $m * 0.12 ) | ||
| 909 | . " )) && ( MOUSE_Y > ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 910 | . ( ( 1 - 0.05 ) - $m * 0.12 - 0.1 ) | ||
| 911 | . " ))) {"; | ||
| 912 | $gp .= "LOOP = 0;"; | ||
| 913 | $gp .= "Y11 = " . ( $m * 4 + $n + 1 ) . "; "; | ||
| 914 | $gp .= "set ylabel COLUMN_" . ( $m * 4 + $n + 1 ) . "; "; | ||
| 915 | $gp .= "show variables; "; | ||
| 916 | $gp .= "}; \\\n"; | ||
| 917 | print $gpipe $gp; | ||
| 918 | usleep(2e4); | ||
| 919 | $gp = ""; | ||
| 920 | $n++; | ||
| 921 | |||
| 922 | if ( $n >= 4 ) { | ||
| 923 | $n = 0; | ||
| 924 | $m++; | ||
| 925 | } | ||
| 926 | } | ||
| 927 | $gp .= "}"; | ||
| 928 | $gp .= "}; \\\n"; | ||
| 929 | print $gpipe $gp; | ||
| 930 | usleep(1e4); | ||
| 931 | $gp = ""; | ||
| 932 | |||
| 933 | foreach ( 1 .. ( my $length = @columns + 1 ) ) { | ||
| 934 | $gp .= "unset obj 200" . $_ . "; "; | ||
| 935 | $gp .= "unset label 200" . $_ . "; "; | ||
| 936 | } | ||
| 937 | $gp .= "replot; "; | ||
| 938 | |||
| 939 | $gp .= "\n"; | ||
| 940 | |||
| 941 | print $gpipe $gp; | ||
| 942 | usleep(5e5); | ||
| 943 | print $gpipe "\n"; | ||
| 944 | |||
| 945 | } | ||
| 946 | |||
| 947 | sub bind_z { | ||
| 948 | my $self = shift; | ||
| 949 | my $gp; | ||
| 950 | |||
| 951 | # covert hash of columns to an array: | ||
| 952 | my @columns = (); | ||
| 953 | while ( my ( $column, $index ) = each %{ $self->{COLUMN_NAMES} } ) { | ||
| 954 | $column =~ s/\s+/_/g; #replace all whitespaces by '_' | ||
| 955 | $column =~ s/\+/_/; #replace '+' by '_' | ||
| 956 | $column =~ s/-/_/; #replace '-' by '_' | ||
| 957 | $column =~ s/\//_/; #replace '/' by '_' | ||
| 958 | $column =~ s/\*/_/; #replace '*' by '_' | ||
| 959 | |||
| 960 | $columns[$index] = $column; | ||
| 961 | } | ||
| 962 | shift @columns; | ||
| 963 | |||
| 964 | my $gpipe = $self->{gpipe}; | ||
| 965 | usleep(1e4); | ||
| 966 | print $gpipe $gp; | ||
| 967 | |||
| 968 | $gp = ""; | ||
| 969 | |||
| 970 | # bind x key: | ||
| 971 | $gp .= 'bind z "'; | ||
| 972 | |||
| 973 | # draw background: | ||
| 974 | $gp | ||
| 975 | .= "set obj 3001 rect from graph 0, graph 0 to graph 1, graph 1 front fc rgb 'grey' fs transparent solid 0.8; "; | ||
| 976 | $gp .= "set label 3001 '';\\\n"; | ||
| 977 | print $gpipe $gp; | ||
| 978 | usleep(1e4); | ||
| 979 | $gp = ""; | ||
| 980 | |||
| 981 | # draw 'buttons' for each column: | ||
| 982 | my $m = 0; | ||
| 983 | my $n = 0; | ||
| 984 | foreach my $column (@columns) { | ||
| 985 | $gp | ||
| 986 | .= "set obj 300" | ||
| 987 | . ( $m * 4 + $n + 2 ) | ||
| 988 | . " rect from graph (0.05+$n*(0.23)), graph ((1-0.05)-$m*(0.12)) to graph (0.05+$n*(0.23)+0.21), graph ((1-0.05)-$m*(0.12) - 0.1) front fc rgb '#2F3239'; "; | ||
| 989 | $gp | ||
| 990 | .= "set label 300" | ||
| 991 | . ( $m * 4 + $n + 2 ) . " '" | ||
| 992 | . $column | ||
| 993 | . "' at graph (0.05+$n*(0.23) + 0.1), graph ((1-0.05)-$m*(0.12)-0.05) front center tc rgb 'white'; \\\n"; | ||
| 994 | print $gpipe $gp; | ||
| 995 | usleep(2e4); | ||
| 996 | $gp = ""; | ||
| 997 | $n++; | ||
| 998 | if ( $n >= 4 ) { | ||
| 999 | $n = 0; | ||
| 1000 | $m++; | ||
| 1001 | } | ||
| 1002 | } | ||
| 1003 | $gp .= "replot; \\\n"; | ||
| 1004 | print $gpipe $gp; | ||
| 1005 | usleep(1e4); | ||
| 1006 | $gp = ""; | ||
| 1007 | |||
| 1008 | # check for mouseclicks: | ||
| 1009 | $m = 0; | ||
| 1010 | $n = 0; | ||
| 1011 | $gp .= "RANGE_X = GPVAL_X_MAX - GPVAL_X_MIN; "; | ||
| 1012 | $gp .= "RANGE_Y = GPVAL_Y_MAX - GPVAL_Y_MIN; "; | ||
| 1013 | $gp .= "LOOP = 1; "; | ||
| 1014 | $gp .= "while(LOOP){"; | ||
| 1015 | $gp .= "pause mouse 'Click Mouse';"; | ||
| 1016 | $gp .= "if (exists('MOUSE_X') && exists('MOUSE_Y')) {\\\n"; | ||
| 1017 | print $gpipe $gp; | ||
| 1018 | usleep(2e4); | ||
| 1019 | $gp = ""; | ||
| 1020 | |||
| 1021 | foreach my $column (@columns) { | ||
| 1022 | $gp | ||
| 1023 | .= "if (( MOUSE_X < ( GPVAL_X_MIN + RANGE_X * " | ||
| 1024 | . ( 0.05 + $n * 0.23 + 0.21 ) | ||
| 1025 | . " )) && ( MOUSE_X > ( GPVAL_X_MIN + RANGE_X * " | ||
| 1026 | . ( 0.05 + $n * 0.23 ) | ||
| 1027 | . " )) && ( MOUSE_Y < ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 1028 | . ( ( 1 - 0.05 ) - $m * 0.12 ) | ||
| 1029 | . " )) && ( MOUSE_Y > ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 1030 | . ( ( 1 - 0.05 ) - $m * 0.12 - 0.1 ) | ||
| 1031 | . " ))) {"; | ||
| 1032 | $gp .= "LOOP = 0;"; | ||
| 1033 | $gp .= "Z = " . ( $m * 4 + $n + 1 ) . "; "; | ||
| 1034 | $gp .= "set zlabel COLUMN_" . ( $m * 4 + $n + 1 ) . "; "; | ||
| 1035 | $gp .= "show variables; "; | ||
| 1036 | $gp .= "}; \\\n"; | ||
| 1037 | print $gpipe $gp; | ||
| 1038 | usleep(2e4); | ||
| 1039 | $gp = ""; | ||
| 1040 | $n++; | ||
| 1041 | |||
| 1042 | if ( $n >= 4 ) { | ||
| 1043 | $n = 0; | ||
| 1044 | $m++; | ||
| 1045 | } | ||
| 1046 | } | ||
| 1047 | $gp .= "}"; | ||
| 1048 | $gp .= "}; \\\n"; | ||
| 1049 | print $gpipe $gp; | ||
| 1050 | usleep(1e4); | ||
| 1051 | $gp = ""; | ||
| 1052 | |||
| 1053 | foreach ( 1 .. ( my $length = @columns + 1 ) ) { | ||
| 1054 | $gp .= "unset obj 300" . $_ . "; "; | ||
| 1055 | $gp .= "unset label 300" . $_ . "; "; | ||
| 1056 | } | ||
| 1057 | $gp .= "replot; "; | ||
| 1058 | |||
| 1059 | $gp .= "\n"; | ||
| 1060 | |||
| 1061 | print $gpipe $gp; | ||
| 1062 | usleep(5e5); | ||
| 1063 | print $gpipe "\n"; | ||
| 1064 | |||
| 1065 | } | ||
| 1066 | |||
| 1067 | sub bind_c { | ||
| 1068 | my $self = shift; | ||
| 1069 | my $gp; | ||
| 1070 | |||
| 1071 | # covert hash of columns to an array: | ||
| 1072 | my @columns = (); | ||
| 1073 | while ( my ( $column, $index ) = each %{ $self->{COLUMN_NAMES} } ) { | ||
| 1074 | $column =~ s/\s+/_/g; #replace all whitespaces by '_' | ||
| 1075 | $column =~ s/\+/_/; #replace '+' by '_' | ||
| 1076 | $column =~ s/-/_/; #replace '-' by '_' | ||
| 1077 | $column =~ s/\//_/; #replace '/' by '_' | ||
| 1078 | $column =~ s/\*/_/; #replace '*' by '_' | ||
| 1079 | |||
| 1080 | $columns[$index] = $column; | ||
| 1081 | } | ||
| 1082 | shift @columns; | ||
| 1083 | |||
| 1084 | my $gpipe = $self->{gpipe}; | ||
| 1085 | usleep(1e4); | ||
| 1086 | print $gpipe $gp; | ||
| 1087 | |||
| 1088 | $gp = ""; | ||
| 1089 | |||
| 1090 | # bind x key: | ||
| 1091 | $gp .= 'bind c "'; | ||
| 1092 | |||
| 1093 | # draw background: | ||
| 1094 | $gp | ||
| 1095 | .= "set obj 4001 rect from graph 0, graph 0 to graph 1, graph 1 front fc rgb 'grey' fs transparent solid 0.8; "; | ||
| 1096 | $gp .= "set label 4001 '';\\\n"; | ||
| 1097 | print $gpipe $gp; | ||
| 1098 | usleep(1e4); | ||
| 1099 | $gp = ""; | ||
| 1100 | |||
| 1101 | # draw 'buttons' for each column: | ||
| 1102 | my $m = 0; | ||
| 1103 | my $n = 0; | ||
| 1104 | foreach my $column (@columns) { | ||
| 1105 | $gp | ||
| 1106 | .= "set obj 400" | ||
| 1107 | . ( $m * 4 + $n + 2 ) | ||
| 1108 | . " rect from graph (0.05+$n*(0.23)), graph ((1-0.05)-$m*(0.12)) to graph (0.05+$n*(0.23)+0.21), graph ((1-0.05)-$m*(0.12) - 0.1) front fc rgb '#2F3239'; "; | ||
| 1109 | $gp | ||
| 1110 | .= "set label 400" | ||
| 1111 | . ( $m * 4 + $n + 2 ) . " '" | ||
| 1112 | . $column | ||
| 1113 | . "' at graph (0.05+$n*(0.23) + 0.1), graph ((1-0.05)-$m*(0.12)-0.05) front center tc rgb 'white'; \\\n"; | ||
| 1114 | print $gpipe $gp; | ||
| 1115 | usleep(2e4); | ||
| 1116 | $gp = ""; | ||
| 1117 | $n++; | ||
| 1118 | if ( $n >= 4 ) { | ||
| 1119 | $n = 0; | ||
| 1120 | $m++; | ||
| 1121 | } | ||
| 1122 | } | ||
| 1123 | $gp .= "replot; \\\n"; | ||
| 1124 | print $gpipe $gp; | ||
| 1125 | usleep(1e4); | ||
| 1126 | $gp = ""; | ||
| 1127 | |||
| 1128 | # check for mouseclicks: | ||
| 1129 | $m = 0; | ||
| 1130 | $n = 0; | ||
| 1131 | $gp .= "RANGE_X = GPVAL_X_MAX - GPVAL_X_MIN; "; | ||
| 1132 | $gp .= "RANGE_Y = GPVAL_Y_MAX - GPVAL_Y_MIN; "; | ||
| 1133 | $gp .= "LOOP = 1; "; | ||
| 1134 | $gp .= "while(LOOP){"; | ||
| 1135 | $gp .= "pause mouse 'Click Mouse';"; | ||
| 1136 | $gp .= "if (exists('MOUSE_X') && exists('MOUSE_Y')) {\\\n"; | ||
| 1137 | print $gpipe $gp; | ||
| 1138 | usleep(2e4); | ||
| 1139 | $gp = ""; | ||
| 1140 | |||
| 1141 | foreach my $column (@columns) { | ||
| 1142 | $gp | ||
| 1143 | .= "if (( MOUSE_X < ( GPVAL_X_MIN + RANGE_X * " | ||
| 1144 | . ( 0.05 + $n * 0.23 + 0.21 ) | ||
| 1145 | . " )) && ( MOUSE_X > ( GPVAL_X_MIN + RANGE_X * " | ||
| 1146 | . ( 0.05 + $n * 0.23 ) | ||
| 1147 | . " )) && ( MOUSE_Y < ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 1148 | . ( ( 1 - 0.05 ) - $m * 0.12 ) | ||
| 1149 | . " )) && ( MOUSE_Y > ( GPVAL_Y_MIN + RANGE_Y * " | ||
| 1150 | . ( ( 1 - 0.05 ) - $m * 0.12 - 0.1 ) | ||
| 1151 | . " ))) {"; | ||
| 1152 | $gp .= "LOOP = 0;"; | ||
| 1153 | $gp .= "CB = " . ( $m * 4 + $n + 1 ) . "; "; | ||
| 1154 | $gp .= "set cblabel COLUMN_" . ( $m * 4 + $n + 1 ) . "; "; | ||
| 1155 | $gp .= "show variables; "; | ||
| 1156 | $gp .= "}; \\\n"; | ||
| 1157 | print $gpipe $gp; | ||
| 1158 | usleep(2e4); | ||
| 1159 | $gp = ""; | ||
| 1160 | $n++; | ||
| 1161 | |||
| 1162 | if ( $n >= 4 ) { | ||
| 1163 | $n = 0; | ||
| 1164 | $m++; | ||
| 1165 | } | ||
| 1166 | } | ||
| 1167 | $gp .= "}"; | ||
| 1168 | $gp .= "}; \\\n"; | ||
| 1169 | print $gpipe $gp; | ||
| 1170 | usleep(1e4); | ||
| 1171 | $gp = ""; | ||
| 1172 | |||
| 1173 | foreach ( 1 .. ( my $length = @columns + 1 ) ) { | ||
| 1174 | $gp .= "unset obj 400" . $_ . "; "; | ||
| 1175 | $gp .= "unset label 400" . $_ . "; "; | ||
| 1176 | } | ||
| 1177 | $gp .= "replot; "; | ||
| 1178 | |||
| 1179 | $gp .= "\n"; | ||
| 1180 | |||
| 1181 | print $gpipe $gp; | ||
| 1182 | usleep(5e5); | ||
| 1183 | print $gpipe "\n"; | ||
| 1184 | |||
| 1185 | } | ||
| 1186 | |||
| 1187 | sub bind_s { | ||
| 1188 | my $self = shift; | ||
| 1189 | my $gp; | ||
| 1190 | |||
| 1191 | # split directory/filname .. | ||
| 1192 | if ( $self->{FILENAME} =~ /(.+)(\/|\/\/|\\|\\\\)(.+)\b/ ) { | ||
| 1193 | my $directory = $1; | ||
| 1194 | my $filename = $3; | ||
| 1195 | my $filenameextension = ".dat"; | ||
| 1196 | if ( $filename =~ /(.+)(\..+)\b/ ) { | ||
| 1197 | $filename = $1; | ||
| 1198 | $filenameextension = $2; | ||
| 1199 | } | ||
| 1200 | |||
| 1201 | #print "$directory $filename $filenameextension\n"; | ||
| 1202 | |||
| 1203 | # create directory if it doesn't exist: | ||
| 1204 | if ( not -d $directory ) { | ||
| 1205 | warn | ||
| 1206 | "directory given by $self->{FILENAME} doesn't exist. Create directory $directory"; | ||
| 1207 | mkdir $directory; | ||
| 1208 | } | ||
| 1209 | |||
| 1210 | # look for existing files: | ||
| 1211 | opendir( DIR, $directory ); | ||
| 1212 | my @files = readdir(DIR); | ||
| 1213 | my $max_index = 0; | ||
| 1214 | foreach my $file (@files) { | ||
| 1215 | my $temp_filename = $filename; | ||
| 1216 | $temp_filename =~ s/\(/\\\(/g; | ||
| 1217 | $temp_filename =~ s/\)/\\\)/g; | ||
| 1218 | if ( $file =~ /($temp_filename)_(\d+)(\.*)\b/ ) { | ||
| 1219 | if ( $2 > $max_index ) { | ||
| 1220 | $max_index = $2; | ||
| 1221 | } | ||
| 1222 | } | ||
| 1223 | } | ||
| 1224 | closedir(DIR); | ||
| 1225 | $max_index++; | ||
| 1226 | |||
| 1227 | # create filename for saving plot as eps-file: | ||
| 1228 | my $filename = $self->{FILENAME}; | ||
| 1229 | $filename =~ /(.+)\.(.+)\b/; | ||
| 1230 | $filename = sprintf( "%s_%02d", $1, $self->{ID} + 1 ); | ||
| 1231 | |||
| 1232 | $gp .= "FILENAME = '" . $filename . "'; "; | ||
| 1233 | $gp .= "FILE_INDEX = " . $max_index . "; \n"; | ||
| 1234 | my $gpipe = $self->{gpipe}; | ||
| 1235 | print $gpipe $gp; | ||
| 1236 | $gp = ""; | ||
| 1237 | |||
| 1238 | $gp .= "bind s \""; | ||
| 1239 | $gp .= "print 'save...'; "; | ||
| 1240 | $gp .= "set term png size 1024,600; "; | ||
| 1241 | $gp .= "set output sprintf('%s_%02d.png', FILENAME, FILE_INDEX); "; | ||
| 1242 | $gp .= "replot; "; | ||
| 1243 | $gp .= "set term wxt; "; | ||
| 1244 | $gp .= "FILE_INDEX = FILE_INDEX + 1; "; | ||
| 1245 | $gp .= "\"; \n"; | ||
| 1246 | my $gpipe = $self->{gpipe}; | ||
| 1247 | print $gpipe $gp; | ||
| 1248 | usleep(1e5); | ||
| 1249 | print $gpipe "\n"; | ||
| 1250 | } | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | sub save_plot { | ||
| 1254 | my $self = shift; | ||
| 1255 | my $type = shift; | ||
| 1256 | my $filename = shift; | ||
| 1257 | |||
| 1258 | if ( not defined $type ) { | ||
| 1259 | $type = 'png'; | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | if ( not defined $filename ) { | ||
| 1263 | $filename = "undefined.$type"; | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | if ( $type eq 'eps' ) { | ||
| 1267 | $self->_save_eps($filename); | ||
| 1268 | } | ||
| 1269 | elsif ( $type eq 'png' ) { | ||
| 1270 | $self->_save_png($filename); | ||
| 1271 | } | ||
| 1272 | else { | ||
| 1273 | warn | ||
| 1274 | "in function 'save_plot': file type $type not defined. Possible types are 'png' and 'eps'."; | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | return $self; | ||
| 1278 | |||
| 1279 | } | ||
| 1280 | |||
| 1281 | sub _save_eps { | ||
| 1282 | my $self = shift; | ||
| 1283 | my $filename = shift; | ||
| 1284 | $filename .= '.eps'; | ||
| 1285 | my %plot = $self->{plot}; | ||
| 1286 | |||
| 1287 | #my %plot = %$plot; | ||
| 1288 | my $gp; | ||
| 1289 | |||
| 1290 | # set output to eps: | ||
| 1291 | $gp .= "#\n# Output to file\n"; | ||
| 1292 | $gp .= "set terminal postscript eps color size 13,9.75\n"; | ||
| 1293 | $gp .= "set terminal postscript eps color enhanced\n"; | ||
| 1294 | $gp .= "set output '$filename'\n"; | ||
| 1295 | $gp .= "replot\n"; | ||
| 1296 | |||
| 1297 | my $gpipe = $self->{gpipe}; | ||
| 1298 | print $gpipe $gp; | ||
| 1299 | |||
| 1300 | return 1; | ||
| 1301 | |||
| 1302 | } | ||
| 1303 | |||
| 1304 | sub _save_png { | ||
| 1305 | my $self = shift; | ||
| 1306 | my $filename = shift; | ||
| 1307 | $filename .= '.png'; | ||
| 1308 | my %plot = $self->{plot}; | ||
| 1309 | |||
| 1310 | #my %plot = %$plot; | ||
| 1311 | my $gp; | ||
| 1312 | |||
| 1313 | # set output to eps: | ||
| 1314 | $gp .= "#\n# Output to file\n"; | ||
| 1315 | $gp .= "set terminal png\n"; | ||
| 1316 | $gp .= "set output '$filename'\n"; | ||
| 1317 | $gp .= "replot\n"; | ||
| 1318 | |||
| 1319 | my $gpipe = $self->{gpipe}; | ||
| 1320 | print $gpipe $gp; | ||
| 1321 | |||
| 1322 | return 1; | ||
| 1323 | |||
| 1324 | } | ||
| 1325 | |||
| 1326 | sub datazone { | ||
| 1327 | my $self = shift; | ||
| 1328 | my $x_min = shift; | ||
| 1329 | my $x_max = shift; | ||
| 1330 | my $y_min = shift; | ||
| 1331 | my $y_max = shift; | ||
| 1332 | my $left = shift; | ||
| 1333 | my $center = shift; | ||
| 1334 | my $right = shift; | ||
| 1335 | |||
| 1336 | my $gpipe = $self->{gpipe}; | ||
| 1337 | |||
| 1338 | # info bar: | ||
| 1339 | my $gp = "set style rect fc lt -1 fs solid 0.15 noborder\n"; | ||
| 1340 | $gp | ||
| 1341 | .= "set object 1 rect from " | ||
| 1342 | . $x_min . "," | ||
| 1343 | . ( $y_min + 0.03 * ( $y_max - $y_min ) ) . " to " | ||
| 1344 | . $x_max . "," | ||
| 1345 | . ( $y_min + 0.1 * ( $y_max - $y_min ) ) | ||
| 1346 | . " behind\n"; | ||
| 1347 | |||
| 1348 | $gp | ||
| 1349 | .= "set label 1 at " | ||
| 1350 | . ( $x_min + 0.025 * ( $x_max - $x_min ) ) . "," | ||
| 1351 | . ( $y_min + 0.06 * ( $y_max - $y_min ) ) | ||
| 1352 | . " left\n"; | ||
| 1353 | $gp .= "set label 1 '$left'\n"; | ||
| 1354 | |||
| 1355 | $gp | ||
| 1356 | .= "set label 3 at " | ||
| 1357 | . ( $x_min + 0.5 * ( $x_max - $x_min ) ) . "," | ||
| 1358 | . ( $y_min + 0.06 * ( $y_max - $y_min ) ) | ||
| 1359 | . " center\n"; | ||
| 1360 | $gp .= "set label 3 '$center'\n"; | ||
| 1361 | |||
| 1362 | $gp | ||
| 1363 | .= "set label 2 at " | ||
| 1364 | . ( $x_min + 0.975 * ( $x_max - $x_min ) ) . "," | ||
| 1365 | . ( $y_min + 0.06 * ( $y_max - $y_min ) ) | ||
| 1366 | . " right\n"; | ||
| 1367 | $gp .= "set label 2 '$right'\n"; | ||
| 1368 | |||
| 1369 | print $gpipe $gp; | ||
| 1370 | |||
| 1371 | return $self; | ||
| 1372 | |||
| 1373 | } | ||
| 1374 | |||
| 1375 | 1; | ||
| 1376 | |||
| 1377 | __END__ |