lib/App/SeismicUnixGui/big_streams/immodpg.pm untested

filter: Statementstmt 0.0% 0 / 2264 Branchbran 0.0% 0 / 514 Conditioncond 0.0% 0 / 543 MC/DCmcdc 0.0% 0 / 283 Subroutinesub 0.0% 0 / 143 Podpod 0.0% 0 / 122 totaltotal 0.0% 0 / 3869 CC 258 SCAR 30.5
CC
258
Cov
0%
_set_control
132.0
get_control_layer
72.0
_get_control_layer
56.0
CRAP 21.2
1 package App::SeismicUnixGui::big_streams::immodpg;
2  
3 =head1 DOCUMENTATION 7985
4  
5 =head2 SYNOPSIS
6  
7 PROGRAM NAME: immodpg
8 AUTHOR: Juan Lorenzo
9 DATE: Feb 6 2020
10 DESCRIPTION:
11 Version: 0.0.1
12
13  
14 =head2 USE
15  
16 =head3 NOTES
17
18 Original Fortran code is by Emilio Vera
19 and is called mmodpg
20
21 Modeling of Traveltime (T-X) Curves
22
23 LDG:146O , 1984-1989
24 BOIGM, 1993
25 Depto. de Geofisica, U. de Chile, 1996-**
26
27 Computations are carried out for a model consisting
28 of a mixture of horizontal constant velocity, and
29 constant velocity gradient layers.Low velocity zones
30 can be included. Each layer is specified by its top
31 and bottom velocity. Rays are traced using equispaced
32 ray parameterss.
33
34 Data traces are presented as a grey scale plot.
35
36 TODO: _Vbot vs. _Vbot_current may confuse
37 key _Vbot is used only initially herein
38 _Vbot_current is the latest value in the gui
39
40 The following order of operations is needed
41 to prevent the fortran programs from quickly
42 reading the change (yes) BEFORE the options
43 and values are written out.
44
45 _setVtop( $immodpg->{_Vtop_current} );
46 _set_option($changeVtop_opt);
47 _set_change($yes);
48
49  
50 =head4
51 Examples
52  
53 =head3
54  
55 =head4 CHANGES and their DATES
56  
57 V0.2 April 4, 2021
58  
59 April 2021: controlled data input errors
60 Added model values to namespace of immodpg.pm
61  
62  
63 =cut
64  
65 use Moose;
66 our $VERSION = '0.0.2';
67  
68 use aliased 'App::SeismicUnixGui::misc::L_SU_global_constants';
69 use aliased 'App::SeismicUnixGui::configs::big_streams::Project_config';
70 use aliased 'App::SeismicUnixGui::configs::big_streams::immodpg_config';
71 use aliased 'App::SeismicUnixGui::big_streams::immodpg_global_constants';
72 use aliased 'App::SeismicUnixGui::sunix::header::header_values';
73 use aliased 'App::SeismicUnixGui::misc::manage_files_by2';
74 use App::SeismicUnixGui::misc::control '0.0.3';
75 use aliased 'App::SeismicUnixGui::misc::control';
76 use aliased 'App::SeismicUnixGui::messages::message_director';
77 use aliased 'App::SeismicUnixGui::specs::big_streams::immodpg_spec';
78 use aliased 'App::SeismicUnixGui::sunix::shell::xk';
79  
80 use Scalar::Util qw(looks_like_number);
81  
82 =pod
83 instantiate modules
84  
85 =cut
86  
87 my $Project = Project_config->new();
88 my $get_L_SU = L_SU_global_constants->new();
89 my $get_immodpg = immodpg_global_constants->new();
90 my $immodpg_config = immodpg_config->new();
91 my $immodpg_spec = immodpg_spec->new();
92  
93 my $var_L_SU = $get_L_SU->var();
94 my $var_immodpg = $get_immodpg->var();
95 my $IMMODPG = $Project->IMMODPG();
96 my $IMMODPG_INVISIBLE = $Project->IMMODPG_INVISIBLE();
97  
98 my $empty_string = $var_L_SU->{_empty_string};
99 my $yes = $var_L_SU->{_yes};
100 my $no = $var_L_SU->{_no};
101 my $on = $var_L_SU->{_on};
102 my $off = $var_L_SU->{_off};
103 my $global_libs = $get_L_SU->global_libs();
104 my $immodpg_model_file_text = $var_immodpg->{_immodpg_model_file_text};
105 my $immodpg_model = $var_immodpg->{_immodpg_model};
106  
107 =head2 private anonymous array
108  
109 =cut
110  
111 my $immodpg = {
112 _Vbot => '',
113 _VbotEntry => '',
114 _Vbot_current => '',
115 _Vbot_default => '',
116 _Vbot_multiplied => '',
117 _Vbot_prior => '',
118 _Vbot_upper_layer => '',
119 _Vbot_upper_layerEntry => '',
120 _Vbot_upper_layer_current => '',
121 _Vbot_upper_layer_default => '',
122 _Vbot_upper_layer_prior => '',
123 _Vincrement => '',
124 _VincrementEntry => '',
125 _Vincrement_current => '',
126 _Vincrement_default => '',
127 _Vincrement_prior => '',
128 _Vtop => '',
129 _Vtop_current => '',
130 _Vtop_prior => '',
131 _Vtop_lower_layer_current => '',
132 _Vtop_lower_layer => '',
133 _Vtop_lower_layer_prior => '',
134 _Vtop_multiplied => '',
135 _VbotNtop_factor => '',
136 _VbotNtop_factorEntry => '',
137 _VbotNtop_factor_current => '',
138 _VbotNtop_factor_default => '',
139 _VbotNtop_factor_prior => '',
140 _base_file_name => '',
141 _cdp => '',
142 _change_file => '',
143 _change_default => $no,
144 _clip => '',
145 _clip_file => '',
146 _clip4plot => '',
147 _clip4plotEntry => '',
148 _clip4plot_current => '',
149 _clip4plot_default => '',
150 _clip4plot_prior => '',
151 _control_value => '',
152 _data_traces => '',
153 _control_layer => '',
154 _control_layer_external => '',
155 _error_switch => '',
156 _inbound_missing => '',
157 _inVbot => '',
158 _inVbot_upper_layer => '',
159 _inVincrement => '',
160 _inVtop => '',
161 _inVtop_lower_layer => '',
162 _inVbotNtop_factor => '',
163 _in_clip => '',
164 _in_layer => '',
165 _layerEntry => '',
166 _layer_current => '',
167 _layer_default => '',
168 _layer_prior => '',
169 _in_thickness_increment_m => '',
170 _invert => '',
171 _isVbot_changed_in_gui => $no,
172 _isVbot_upper_layer_changed_in_gui => $no,
173 _isVincrement_changed_in_gui => $no,
174 _isVtop_changed_in_gui => $no,
175 _isVtop_lower_layer_changed_in_gui => $no,
176 _isVbotNtop_factor_changed_in_gui => $no,
177 _is_clip_changed_in_gui => $no,
178 _is_layer_changed_in_gui => $no,
179 _is_layer_changed_in_gui => $no,
180 _layer => '',
181 _layer_file => '',
182 _lmute => '',
183 _lower_layerLabel => '',
184 _min_t_s => '',
185 _min_x_m => '',
186 _model_file_text => $var_immodpg->{_immodpg_model_file_text},
187 _model_error => $off,
188 _model_layer_number => '',
189 _message_box_w => '',
190 _message_upper_frame => '',
191 _message_lower_frame => '',
192 _message_label_w => '',
193 _message_box_wait => '',
194 _message_ok_button => '',
195 _mw => '',
196 _new_model => '',
197 _option_default => -1,
198 _option_file => '',
199 _outsideVbot => '',
200 _outsideVbot_upper_layer => '',
201 _outsideVincrement => '',
202 _outsideVtop => '',
203 _outsideVtop_lower_layer => '',
204 _outsideVbotNtop_factor => '',
205 _outside_clip => '',
206 _outside_layer => '',
207 _outside_thickness_increment_m => '',
208 _par => '',
209 _plot_max_t_s => '',
210 _plot_max_x_m => '',
211 _plot_min_t_s => '',
212 _plot_min_x_m => '',
213 _pre_digitized_XT_pairs => '',
214 _previous_model => '',
215 _receiver_depth_m => '',
216 _reducing_vel_mps => '',
217 _refVPtop => '',
218 _refVPbot => '',
219 _ref_dz => '',
220 _replacement4missing => '',
221 _scaled_par => '',
222 _smute => '',
223 _source_depth_m => '',
224 _sscale => '',
225 _tnmo => '',
226 _upper_layerLabel => '',
227 _upward => '',
228 _vnmo => '',
229 _voutfile => '',
230 _thickness_increment_m => '',
231 _thickness_increment_mEntry => '',
232 _thickness_increment_m_current => '',
233 _thickness_increment_m_default => '',
234 _thickness_increment_m_prior => '',
235 _Step => '',
236 _note => '',
237 };
238  
239 # print("immodpg, starting, _isVtop_lower_layer_changed_in_gui: $immodpg->{_is_isVtop_lower_layer_changed_in_gui}\n");
240  
241 =head2 Define
242 private variables
243  
244 =cut
245  
246 $immodpg->{_Vbot_file} = $var_immodpg->{_Vbot_file};
247 $immodpg->{_Vbot_upper_layer_file} = $var_immodpg->{_Vbot_upper_layer_file};
248 $immodpg->{_Vincrement_file} = $var_immodpg->{_Vincrement_file};
249 $immodpg->{_Vtop_file} = $var_immodpg->{_Vtop_file};
250 $immodpg->{_Vtop_lower_layer_file} = $var_immodpg->{_Vtop_lower_layer_file};
251 $immodpg->{_VbotNtop_factor_file} = $var_immodpg->{_VbotNtop_factor_file};
252 $immodpg->{_VbotNtop_multiply_file} = $var_immodpg->{_VbotNtop_multiply_file};
253 $immodpg->{_option_file} = $var_immodpg->{_option_file};
254 $immodpg->{_change_file} = $var_immodpg->{_change_file};
255 $immodpg->{_clip_file} = $var_immodpg->{_clip_file};
256 $immodpg->{_layer_file} = $var_immodpg->{_layer_file};
257 $immodpg->{_immodpg_model} = $var_immodpg->{_immodpg_model};
258 $immodpg->{_thickness_m_file} = $var_immodpg->{_thickness_m_file};
259 $immodpg->{_thickness_increment_m_file} =
260 $var_immodpg->{_thickness_increment_m_file};
261  
262 =head2 Coded user options
263 Only used in message files
264 for communication with
265 immopg.for
266 'change*_opt' subs change values of repeatedly
267 used variables, whereas other subs change
268 values of variables frequently modified
269 by user
270  
271 =cut
272  
273 my $move_down_opt = $var_immodpg->{_move_down_opt};
274 my $move_left_opt = $var_immodpg->{_move_left_opt};
275 my $move_minus_opt = $var_immodpg->{_move_minus_opt};
276 my $move_right_opt = $var_immodpg->{_move_right_opt};
277 my $move_up_opt = $var_immodpg->{_move_up_opt};
278 my $thickness_m_plus_opt = $var_immodpg->{_thickness_m_plus_opt};
279 my $thickness_m_minus_opt = $var_immodpg->{_thickness_m_minus_opt};
280 my $zoom_minus_opt = $var_immodpg->{_zoom_minus_opt};
281 my $zoom_plus_opt = $var_immodpg->{_zoom_plus_opt};
282  
283 my $Vbot_opt = $var_immodpg->{_Vbot_opt};
284 my $Vbot_upper_layer_opt = $var_immodpg->{_Vbot_upper_layer_opt};
285 my $Vbot_minus_opt = $var_immodpg->{_Vbot_minus_opt};
286 my $Vbot_plus_opt = $var_immodpg->{_Vbot_plus_opt};
287 my $Vtop_opt = $var_immodpg->{_Vtop_opt};
288 my $Vtop_lower_layer_opt = $var_immodpg->{_Vtop_lower_layer_opt};
289 my $Vtop_minus_opt = $var_immodpg->{_Vtop_minus_opt};
290 my $Vtop_plus_opt = $var_immodpg->{_Vtop_plus_opt};
291 my $VbotNVtop_lower_layer_minus_opt =
292 $var_immodpg->{_VbotNVtop_lower_layer_minus_opt};
293 my $VbotNVtop_lower_layer_plus_opt =
294 $var_immodpg->{_VbotNVtop_lower_layer_plus_opt};
295 my $VtopNVbot_upper_layer_minus_opt =
296 $var_immodpg->{_VtopNVbot_upper_layer_minus_opt};
297 my $VtopNVbot_upper_layer_plus_opt =
298 $var_immodpg->{_VtopNVbot_upper_layer_plus_opt};
299 my $VbotNtop_multiply_opt = $var_immodpg->{_VbotNtop_multiply_opt};
300 my $VbotNtop_plus_opt = $var_immodpg->{_VbotNtop_plus_opt};
301 my $VbotNtop_minus_opt = $var_immodpg->{_VbotNtop_minus_opt};
302 my $update_opt = $var_immodpg->{_update_opt};
303  
304 my $change_clip_opt = $var_immodpg->{_clip4plot_opt};
305 my $change_layer_number_opt = $var_immodpg->{_layer_number_opt};
306 my $change_thickness_increment_m_opt =
307 $var_immodpg->{_thickness_increment_m_opt};
308 my $change_thickness_m_opt = $var_immodpg->{_thickness_m_opt};
309 my $changeVtop_opt = $var_immodpg->{_Vtop_opt};
310 my $changeVincrement_opt = $var_immodpg->{_Vincrement_opt};
311 my $changeVbotNtop_factor_opt = $var_immodpg->{_VbotNtop_factor_opt};
312 my $change_working_model_bin_opt = $var_immodpg->{_working_model_bin_opt};
313 my $change_working_model_text_opt = $var_immodpg->{_working_model_text_opt};
314  
315 =head2 sub Step
316 collects switches and assembles bash instructions
317 by adding the program name
318  
319 =cut
320  
321 sub Step {
322  
323 $immodpg->{_Step} = 'mmodpg' . $immodpg->{_Step};
324 return ( $immodpg->{_Step} );
325  
326 }
327  
328 =head2 sub note
329 collects switches and assembles bash instructions
330 by adding the program name
331  
332 =cut
333  
334 sub note {
335  
336 $immodpg->{_note} = 'mmodpg' . $immodpg->{_note};
337 return ( $immodpg->{_note} );
338  
339 }
340  
341 =head2 sub _checkVbot
342 When you use setVbot
343 check what the current Vbot value is
344 compared to former Vbot values
345  
346 =cut
347  
348 sub _checkVbot {
349  
350 my ($self) = @_;
351  
352 return _check_widget_state(
353 $self,
354 '_VbotEntry', # entry widget key
355 '_inVbot', # in state key
356 '_outsideVbot', # outside state key
357 '_Vbot_current', # current value key
358 '_Vbot_prior' # prior value key
359 );
360 }
361  
362 =head2 sub _checkVbot_upper_layer
363  
364 When you use setVbot_upper_layer
365 check what the current setVbot_upper_layer value is
366 compared to former setVbot_upper_layer values
367  
368 =cut
369  
370 sub _checkVbot_upper_layer {
371  
372 my ($self) = @_;
373  
374 return _check_widget_state(
375 $self,
376 '_Vbot_upper_layerEntry', # entry widget key
377 '_inVbot_upper_layer', # in state key
378 '_outsideVbot_upper_layer', # outside state key
379 '_Vbot_upper_layer_current', # current value key
380 '_Vbot_upper_layer_prior' # prior value key
381 );
382 }
383  
384 =head2 sub _checkVincrement
385  
386 When you use Vincrement
387 check what the current Vincrement value is
388 compared to former Vincrement values
389  
390 =cut
391  
392 sub _checkVincrement {
393  
394 my ($self) = @_;
395  
396 return _check_widget_state(
397 $self,
398 '_VincrementEntry', # entry widget key
399 '_inVincrement', # in state key
400 '_outsideVincrement', # outside state key
401 '_Vincrement_current', # current value key
402 '_Vincrement_prior' # prior value key
403 );
404 }
405  
406 =head2 sub _checkVtop
407  
408 Checks the current Vtop value compared to former Vtop values when modifying,
409 entering, or leaving the VtopEntry widget.
410  
411 Parameters:
412 $self - the object reference.
413  
414 Returns:
415 Nothing; updates internal state.
416  
417 When you modify, enter or leave VtopEntry widget
418 check what the current Vtop value is
419 compared to former Vtop values
420  
421 =cut
422  
423 sub _checkVtop {
424  
425 my ($self) = @_;
426  
427 return _check_widget_state(
428 $self,
429 '_VtopEntry', # entry widget key
430 '_inVtop', # in state key
431 '_outsideVtop', # outside state key
432 '_Vtop_current', # current value key
433 '_Vtop_prior' # prior value key
434 );
435 }
436  
437 =head2 sub _check_widget_state
438  
439 A generic subroutine to check the state of the widget, handle entry and exit, and update the current and prior values.
440  
441 =cut
442  
443 sub _check_widget_state {
444 my ($self, $entry_key, $in_key, $outside_key, $current_key, $prior_key) = @_;
445  
446 if ( defined $immodpg->{$entry_key}
447 && length $immodpg->{$entry_key}
448 && length $immodpg->{$in_key}
449 && length $immodpg->{$outside_key}
450 && length $immodpg->{$current_key}
451 && length $immodpg->{$prior_key} ) {
452  
453 # Convenience variables
454 my $in = $immodpg->{$in_key};
455 my $outside = $immodpg->{$outside_key};
456 my $current = $immodpg->{$current_key};
457 my $prior = $immodpg->{$prior_key};
458  
459 if ( $in eq $yes
460 && $outside eq $no ) {
461  
462 # CASE 1: Previously inside the widget, now leaving
463 $current = $immodpg->{$entry_key}->get();
464  
465 # Reverse conditions: leaving the widget
466 $in = $no;
467 $outside = $yes;
468  
469 # Update the module values
470 $immodpg->{$in_key} = $in;
471 $immodpg->{$outside_key} = $outside;
472 $immodpg->{$current_key} = $current;
473  
474 return ();
475  
476 } elsif ( $in eq $no
477 && $outside eq $yes ) {
478  
479 # CASE 2: Previously outside the widget, now entering
480 $prior = $current;
481 $current = $immodpg->{$entry_key}->get();
482  
483 # Reverse conditions: entering the widget
484 $in = $yes;
485 $outside = $no;
486  
487 # Update the module values
488 $immodpg->{$in_key} = $in;
489 $immodpg->{$outside_key} = $outside;
490 $immodpg->{$current_key} = $current;
491 $immodpg->{$prior_key} = $prior;
492  
493 return ();
494  
495 } else {
496 print("immodpg, $entry_key, unexpected values\n");
497 return ();
498 }
499  
500 } else {
501 print("immodpg, $entry_key, missing widget or values\n");
502 return ();
503 }
504 }
505  
506  
507 #=head2 sub _checkVbot
508 #When you use setVbot
509 #check what the current Vbot value is
510 #compared to former Vbot values
511 #
512 #=cut
513 #
514 #sub _checkVbot {
515 #
516 # my ($self) = @_;
517 #
518 # # print("immodpg, _checkVbot, $immodpg->{_VbotEntry}\n");
519 #
520 # if ( defined $immodpg->{_VbotEntry}
521 # && length $immodpg->{_VbotEntry}
522 # && length $immodpg->{_inVbot}
523 # && length $immodpg->{_outsideVbot}
524 # && length $immodpg->{_Vbot_current}
525 # && length $immodpg->{_Vbot_prior} )
526 # {
527 #
528 # # rename for convenience
529 # my $inVbot = $immodpg->{_inVbot};
530 # my $outsideVbot = $immodpg->{_outsideVbot};
531 # my $Vbot_current = $immodpg->{_Vbot_current};
532 # my $Vbot_prior = $immodpg->{_Vbot_prior};
533 #
534 # # print("immodpg,_checkVbot, inVbot:$inVbot\n");
535 # # print("immodpg,_checkVbot, outsideVbot: $outsideVbot\n");
536 # if ( $inVbot eq $yes
537 # && $outsideVbot eq $no )
538 # {
539 #
540 # # print("immodpg, _checkVbot, Leaving widget\n");
541 #
542 # # CASE 1: Previously, inside Entry widget
543 # # Now leaving Entry widget
544 # $Vbot_current = $immodpg->{_VbotEntry}->get();
545 #
546 # # print("immodpg,_checkVbot, Vbot_current:$Vbot_current\n");
547 # # reverse the conditions now
548 # # when user leaves Entry widget
549 # $inVbot = $no;
550 # $outsideVbot = $yes;
551 #
552 # # reset module values for convenience of renaming
553 # $immodpg->{_inVbot} = $inVbot;
554 # $immodpg->{_outsideVbot} = $outsideVbot;
555 # $immodpg->{_Vbot_current} = $Vbot_current;
556 #
557 # return ();
558 #
559 # }
560 # elsif ($inVbot eq $no
561 # && $outsideVbot eq $yes )
562 # {
563 #
564 # # CASE 2: Previously, outside Entry widget
565 # # Now entering Entry widget
566 # $Vbot_prior = $Vbot_current;
567 # $Vbot_current = $immodpg->{_VbotEntry}->get();
568 #
569 # # print("immodpg, _checkVbot, Entering widget\n");
570 #
571 # # reverse the conditions now
572 # # when user enters Entry widget
573 # $inVbot = $yes;
574 # $outsideVbot = $no;
575 #
576 # # reset module values for convenience of renaming
577 # $immodpg->{_inVbot} = $inVbot;
578 # $immodpg->{_outsideVbot} = $outsideVbot;
579 # $immodpg->{_Vbot_current} = $Vbot_current;
580 # $immodpg->{_Vbot_prior} = $Vbot_prior;
581 # return ();
582 #
583 # }
584 # else {
585 # print("immodpg, _checkVbot, unexpected values\n");
586 # return ();
587 # }
588 #
589 # }
590 # else {
591 # print("immodpg, _checkVbot, missing widget\n");
592 # return ();
593 # }
594 #}
595  
596 #=head2 sub _checkVbot_upper_layer
597 #
598 #When you use setVbot_upper_layer
599 #check what the current setVbot_upper_layer value is
600 #compared to former setVbot_upper_layer values
601 #
602 #=cut
603 #
604 #sub _checkVbot_upper_layer {
605 #
606 # my ($self) = @_;
607 #
608 ## print("immodpg, _checkVbot_upper_layer, $immodpg->{_Vbot_upper_layerEntry}\n");
609 #
610 # if ( length( $immodpg->{_Vbot_upper_layerEntry} )
611 # && length $immodpg->{_Vbot_upper_layerEntry}
612 # && length $immodpg->{_inVbot_upper_layer}
613 # && length $immodpg->{_outsideVbot_upper_layer}
614 # && length $immodpg->{_Vbot_upper_layer_current}
615 # && length $immodpg->{_Vbot_upper_layer_prior} )
616 # {
617 #
618 # # rename for convenience
619 # my $inVbot_upper_layer = $immodpg->{_inVbot_upper_layer};
620 # my $outsideVbot_upper_layer = $immodpg->{_outsideVbot_upper_layer};
621 # my $Vbot_upper_layer_current = $immodpg->{_Vbot_upper_layer_current};
622 # my $Vbot_upper_layer_prior = $immodpg->{_Vbot_upper_layer_prior};
623 #
624 ## print("immodpg,_checkVbot_upper_layer, inVbot_upper_layer:$inVbot_upper_layer\n");
625 ## print("immodpg,_checkVbot_upper_layer, outsideVbot_upper_layer: $outsideVbot_upper_layer\n");
626 # if ( $inVbot_upper_layer eq $yes
627 # && $outsideVbot_upper_layer eq $no )
628 # {
629 #
630 # # print("immodpg, _checkVbot_upper_layer, Leaving widget\n");
631 #
632 # # CASE 1: Previously, inside Entry widget
633 # # Now leaving Entry widget
634 # $Vbot_upper_layer_current =
635 # $immodpg->{_Vbot_upper_layerEntry}->get();
636 #
637 # # reverse the conditions now
638 # # when user leaves Entry widget
639 # $inVbot_upper_layer = $no;
640 # $outsideVbot_upper_layer = $yes;
641 #
642 # # reset module values for convenience of renaming
643 # $immodpg->{_inVbot_upper_layer} = $inVbot_upper_layer;
644 # $immodpg->{_outsideVbot_upper_layer} = $outsideVbot_upper_layer;
645 # $immodpg->{_Vbot_upper_layer_current} = $Vbot_upper_layer_current;
646 #
647 # return ();
648 #
649 # }
650 # elsif ($inVbot_upper_layer eq $no
651 # && $outsideVbot_upper_layer eq $yes )
652 # {
653 #
654 # # CASE 2: Previously, outside Entry widget
655 # # Now entering Entry widget
656 # $Vbot_upper_layer_prior = $Vbot_upper_layer_current;
657 # $Vbot_upper_layer_current =
658 # $immodpg->{_Vbot_upper_layerEntry}->get();
659 #
660 # # print("immodpg, _checkVbot_upper_layer, Entering widget\n");
661 #
662 # # reverse the conditions now
663 # # when user enters Entry widget
664 # $inVbot_upper_layer = $yes;
665 # $outsideVbot_upper_layer = $no;
666 #
667 # # reset module values for convenience of renaming
668 # $immodpg->{_inVbot_upper_layer} = $inVbot_upper_layer;
669 # $immodpg->{_outsideVbot_upper_layer} = $outsideVbot_upper_layer;
670 # $immodpg->{_Vbot_upper_layer_current} = $Vbot_upper_layer_current;
671 # $immodpg->{_Vbot_upper_layer_prior} = $Vbot_upper_layer_prior;
672 # return ();
673 #
674 # }
675 # else {
676 # print("immodpg, _checkVbot_upper_layer, unexpected values\n");
677 # return ();
678 # }
679 #
680 # }
681 # else {
682 # print("immodpg, _checkVbot_upper_layer, missing widget or values\n");
683 # return ();
684 # }
685 #}
686  
687 #=head2 sub _checkVincrement
688 #
689 #When you use Vincrement
690 #check what the current Vincrement value is
691 #compared to former Vincrement values
692 #
693 #=cut
694 #
695 #sub _checkVincrement {
696 #
697 # my ($self) = @_;
698 #
699 # # print("immodpg, _checkVincrement, $immodpg->{_VincrementEntry}\n");
700 #
701 # if ( defined $immodpg->{_VincrementEntry}
702 # && $immodpg->{_VincrementEntry} ne $empty_string
703 # && $immodpg->{_inVincrement} ne $empty_string
704 # && $immodpg->{_outsideVincrement} ne $empty_string
705 # && $immodpg->{_Vincrement} ne $empty_string )
706 # {
707 #
708 # # rename for convenience
709 # my $inVincrement = $immodpg->{_inVincrement};
710 # my $outsideVincrement = $immodpg->{_outsideVincrement};
711 # my $Vincrement_current = $immodpg->{_Vincrement_current};
712 # my $Vincrement_prior = $immodpg->{_Vincrement_prior};
713 #
714 # # print("immodpg,_checkVincrement, inVincrement:$inVincrement\n");
715 # # print("immodpg,_checkVincrement, outsideVincrement: $outsideVincrement\n");
716 # if ( $inVincrement eq $yes
717 # && $outsideVincrement eq $no )
718 # {
719 #
720 # # print("immodpg, _checkVincrement, Leaving widget\n");
721 #
722 # # CASE 1: Previously, inside Entry widget
723 # # Now leaving Entry widget
724 # $Vincrement_current = $immodpg->{_VincrementEntry}->get();
725 #
726 # # reverse the conditions now
727 # # when user leaves Entry widget
728 # $inVincrement = $no;
729 # $outsideVincrement = $yes;
730 #
731 # # reset module values for convenience of renaming
732 # $immodpg->{_inVincrement} = $inVincrement;
733 # $immodpg->{_outsideVincrement} = $outsideVincrement;
734 # $immodpg->{_Vincrement_current} = $Vincrement_current;
735 #
736 # return ();
737 #
738 # }
739 # elsif ($inVincrement eq $no
740 # && $outsideVincrement eq $yes )
741 # {
742 #
743 # # CASE 2: Previously, outside Entry widget
744 # # Now entering Entry widget
745 # $Vincrement_prior = $Vincrement_current;
746 # $Vincrement_current = $immodpg->{_VincrementEntry}->get();
747 #
748 # # print("immodpg, _checkVincrement, Entering widget\n");
749 #
750 # # reverse the conditions now
751 # # when user enters Entry widget
752 # $inVincrement = $yes;
753 # $outsideVincrement = $no;
754 #
755 # # reset module values for convenience of renaming
756 # $immodpg->{_inVincrement} = $inVincrement;
757 # $immodpg->{_outsideVincrement} = $outsideVincrement;
758 # $immodpg->{_Vincrement_current} = $Vincrement_current;
759 # $immodpg->{_Vincrement_prior} = $Vincrement_prior;
760 # return ();
761 #
762 # }
763 # else {
764 # print("immodpg, _checkVincrement, unexpected values\n");
765 # return ();
766 # }
767 #
768 # }
769 # else {
770 # print("immodpg, _checkVincrement, missing widget\n");
771 # return ();
772 # }
773 #}
774  
775 #=head2 sub _checkVtop
776 #
777 #When you modify, enter or leave VtopEntry widget
778 #check what the current Vtop value is
779 #compared to former Vtop values
780 #
781 #=cut
782 #
783 #sub _checkVtop {
784 #
785 # my ($self) = @_;
786 #
787 # # print("immodpg, _checkVtop, $immodpg->{_VtopEntry}\n");
788 #
789 # if ( defined $immodpg->{_VtopEntry}
790 # && $immodpg->{_VtopEntry} ne $empty_string
791 # && $immodpg->{_inVtop} ne $empty_string
792 # && $immodpg->{_outsideVtop} ne $empty_string
793 # && $immodpg->{_Vtop_current} ne $empty_string
794 # && $immodpg->{_Vtop_prior} ne $empty_string )
795 # {
796 #
797 # # rename for convenience
798 # my $inVtop = $immodpg->{_inVtop};
799 # my $outsideVtop = $immodpg->{_outsideVtop};
800 # my $Vtop_current = $immodpg->{_Vtop_current};
801 # my $Vtop_prior = $immodpg->{_Vtop_prior};
802 #
803 # # print("immodpg,_checkVtop, inVtop:$inVtop\n");
804 # # print("immodpg,_checkVtop, outsideVtop: $outsideVtop\n");
805 # # print("immodpg,_checkVtop, Vtop_current: $Vtop_current\n");
806 # if ( $inVtop eq $yes
807 # && $outsideVtop eq $no )
808 # {
809 #
810 # # print("immodpg, _checkVtop, Leaving widget\n");
811 #
812 # # CASE 1: Previously, inside Entry widget
813 # # Now leaving Entry widget
814 # $Vtop_current = $immodpg->{_VtopEntry}->get();
815 #
816 # # reverse the conditions now
817 # # when user leaves Entry widget
818 # $inVtop = $no;
819 # $outsideVtop = $yes;
820 #
821 # # reset module values for convenience of renaming
822 # $immodpg->{_inVtop} = $inVtop;
823 # $immodpg->{_outsideVtop} = $outsideVtop;
824 # $immodpg->{_Vtop_current} = $Vtop_current;
825 #
826 # return ();
827 #
828 # }
829 # elsif ($inVtop eq $no
830 # && $outsideVtop eq $yes )
831 # {
832 #
833 # # CASE 2: Previously, outside Entry widget
834 # # Now entering Entry widget
835 # $Vtop_prior = $Vtop_current;
836 # $Vtop_current = $immodpg->{_VtopEntry}->get();
837 #
838 # # print("immodpg, _checkVtop, Entering widget\n");
839 #
840 # # reverse the conditions now
841 # # when user enters Entry widget
842 # $inVtop = $yes;
843 # $outsideVtop = $no;
844 #
845 # # reset module values for convenience of renaming
846 # $immodpg->{_inVtop} = $inVtop;
847 # $immodpg->{_outsideVtop} = $outsideVtop;
848 # $immodpg->{_Vtop_current} = $Vtop_current;
849 # $immodpg->{_Vtop_prior} = $Vtop_prior;
850 # return ();
851 #
852 # }
853 # else {
854 # print("immodpg, _checkVtop, unexpected values\n");
855 # return ();
856 # }
857 #
858 # }
859 # else {
860 # print("immodpg, _checkVtop, missing widget\n");
861 # return ();
862 # }
863 #}
864  
865  
866 =head2 sub _checkVtop_lower_layer
867  
868 When you use Vtop_lower_layer
869 check what the current Vtop_lower_layer value is
870 compared to former Vtop_lower_layer values
871  
872 =cut
873  
874 sub _checkVtop_lower_layer {
875  
876 my ($self) = @_;
877  
878 # print("immodpg, _checkVtop_lower_layer, $immodpg->{_Vtop_lower_layerEntry}\n");
879  
880 if ( defined $immodpg->{_Vtop_lower_layerEntry}
881 && $immodpg->{_Vtop_lower_layerEntry} ne $empty_string
882 && $immodpg->{_inVtop_lower_layer} ne $empty_string
883 && $immodpg->{_outsideVtop_lower_layer} ne $empty_string
884 && $immodpg->{_Vtop_lower_layer_current} ne $empty_string
885 && $immodpg->{_Vtop_lower_layer_prior} ne $empty_string )
886 {
887  
888 # rename for convenience
889 my $inVtop_lower_layer = $immodpg->{_inVtop_lower_layer};
890 my $outsideVtop_lower_layer = $immodpg->{_outsideVtop_lower_layer};
891 my $Vtop_lower_layer_current = $immodpg->{_Vtop_lower_layer_current};
892 my $Vtop_lower_layer_prior = $immodpg->{_Vtop_lower_layer_prior};
893  
894 # print("immodpg,_checkVtop_lower_layer, inVtop_lower_layer:$inVtop_lower_layer\n");
895 # print("immodpg,_checkVtop_lower_layer, outsideVtop_lower_layer: $outsideVtop_lower_layer\n");
896 if ( $inVtop_lower_layer eq $yes
897 && $outsideVtop_lower_layer eq $no )
898 {
899  
900 # print("immodpg, _checkVtop_lower_layer, Leaving widget\n");
901  
902 # CASE 1: Previously, inside Entry widget
903 # Now leaving Entry widget
904 $Vtop_lower_layer_current =
905 $immodpg->{_Vtop_lower_layerEntry}->get();
906  
907 # reverse the conditions now
908 # when user leaves Entry widget
909 $inVtop_lower_layer = $no;
910 $outsideVtop_lower_layer = $yes;
911  
912 # reset module values for convenience of renaming
913 $immodpg->{_inVtop_lower_layer} = $inVtop_lower_layer;
914 $immodpg->{_outsideVtop_lower_layer} = $outsideVtop_lower_layer;
915 $immodpg->{_Vtop_lower_layer_current} = $Vtop_lower_layer_current;
916  
917 # print("1 _Vtop_lower_layer_current=$immodpg->{_Vtop_lower_layer_current}\n");
918 return ();
919  
920 }
921 elsif ($inVtop_lower_layer eq $no
922 && $outsideVtop_lower_layer eq $yes )
923 {
924  
925 # CASE 2: Previously, outside Entry widget
926 # Now entering Entry widget
927 $Vtop_lower_layer_prior = $Vtop_lower_layer_current;
928 $Vtop_lower_layer_current =
929 $immodpg->{_Vtop_lower_layerEntry}->get();
930  
931 # print("immodpg, _checkVtop_lower_layer, Entering widget\n");
932  
933 # reverse the conditions now
934 # when user enters Entry widget
935 $inVtop_lower_layer = $yes;
936 $outsideVtop_lower_layer = $no;
937  
938 # reset module values for convenience of renaming
939 $immodpg->{_inVtop_lower_layer} = $inVtop_lower_layer;
940 $immodpg->{_outsideVtop_lower_layer} = $outsideVtop_lower_layer;
941 $immodpg->{_Vtop_lower_layer_current} = $Vtop_lower_layer_current;
942 $immodpg->{_Vtop_lower_layer_prior} = $Vtop_lower_layer_prior;
943  
944 # print("2 _Vtop_lower_layer_current=$immodpg->{_Vtop_lower_layer_current}\n");
945 return ();
946  
947 }
948 else {
949 print("immodpg, _checkVtop_lower_layer, unexpected values\n");
950 return ();
951 }
952  
953 }
954 else {
955 print("immodpg, _checkVtop_lower_layer, missing widget\n");
956 return ();
957 }
958 }
959  
960 =head2 sub _checkVbotNtop_factor
961  
962 When you enter or leave
963 check what the current VbotNtop_factor value is
964 compared to former VbotNtop_factor values
965  
966 =cut
967  
968 sub _checkVbotNtop_factor {
969  
970 my ($self) = @_;
971  
972 # print("immodpg, _checkVbotNtop_factor, $immodpg->{_VbotNtop_factor4Entry}\n");
973  
974 if ( defined $immodpg->{_VbotNtop_factorEntry}
975 && $immodpg->{_VbotNtop_factorEntry} ne $empty_string
976 && $immodpg->{_inVbotNtop_factor} ne $empty_string
977 && $immodpg->{_outsideVbotNtop_factor} ne $empty_string
978 && $immodpg->{_VbotNtop_factor_current} ne $empty_string
979 && $immodpg->{_VbotNtop_factor_prior} ne $empty_string )
980 {
981  
982 # rename for convenience
983 my $inVbotNtop_factor = $immodpg->{_inVbotNtop_factor};
984 my $outsideVbotNtop_factor = $immodpg->{_outsideVbotNtop_factor};
985 my $VbotNtop_factor_current = $immodpg->{_VbotNtop_factor_current};
986 my $VbotNtop_factor_prior = $immodpg->{_VbotNtop_factor_prior};
987  
988 # print("immodpg,_checkVbotNtop_factor, inVbotNtop_factor:$inVbotNtop_factor\n");
989 # print("immodpg,_checkVbotNtop_factor, outsideVbotNtop_factor: $outsideVbotNtop_factor\n");
990 if ( $inVbotNtop_factor eq $yes
991 && $outsideVbotNtop_factor eq $no )
992 {
993  
994 # print("immodpg, _checkVbotNtop_factor, Leaving widget\n");
995  
996 # CASE 1: Previously, inside Entry widget
997 # Now leaving Entry widget
998 $VbotNtop_factor_current = $immodpg->{_VbotNtop_factorEntry}->get();
999  
1000 # reverse the conditions now
1001 # when user leaves Entry widget
1002 $inVbotNtop_factor = $no;
1003 $outsideVbotNtop_factor = $yes;
1004  
1005 # reset module values for convenience of renaming
1006 $immodpg->{_inVbotNtop_factor} = $inVbotNtop_factor;
1007 $immodpg->{_outsideVbotNtop_factor} = $outsideVbotNtop_factor;
1008 $immodpg->{_VbotNtop_factor_current} = $VbotNtop_factor_current;
1009  
1010 return ();
1011  
1012 }
1013 elsif ($inVbotNtop_factor eq $no
1014 && $outsideVbotNtop_factor eq $yes )
1015 {
1016  
1017 # CASE 2: Previously, outside Entry widget
1018 # Now entering Entry widget
1019 $VbotNtop_factor_prior = $VbotNtop_factor_current;
1020 $VbotNtop_factor_current = $immodpg->{_VbotNtop_factorEntry}->get();
1021  
1022 # print("immodpg, _checkVbotNtop_factor, Entering widget\n");
1023  
1024 # reverse the conditions now
1025 # when user enters Entry widget
1026 $inVbotNtop_factor = $yes;
1027 $outsideVbotNtop_factor = $no;
1028  
1029 # reset module values for convenience of renaming
1030 $immodpg->{_inVbotNtop_factor} = $inVbotNtop_factor;
1031 $immodpg->{_outsideVbotNtop_factor} = $outsideVbotNtop_factor;
1032 $immodpg->{_VbotNtop_factor_current} = $VbotNtop_factor_current;
1033 $immodpg->{_VbotNtop_factor_prior} = $VbotNtop_factor_prior;
1034 return ();
1035  
1036 }
1037 else {
1038 print("immodpg, _checkVbotNtop_factor, unexpected values\n");
1039 return ();
1040 }
1041  
1042 }
1043 else {
1044 print("immodpg, _checkVbotNtop_factor, missing widget\n");
1045 return ();
1046 }
1047 }
1048  
1049 =head2 sub _check_clip
1050  
1051 When you enter or leave
1052 check what the current clip value is
1053 compared to former clip values
1054  
1055 =cut
1056  
1057 sub _check_clip {
1058  
1059 my ($self) = @_;
1060  
1061 # print("immodpg, _check_clip, $immodpg->{_clip4plotEntry}\n");
1062  
1063 if ( defined( $immodpg->{_clip4plotEntry} )
1064 && $immodpg->{_clip4plotEntry} ne $empty_string
1065 && $immodpg->{_in_clip} ne $empty_string
1066 && $immodpg->{_outside_clip} ne $empty_string
1067 && $immodpg->{_clip4plot_current} ne $empty_string
1068 && $immodpg->{_clip4plot_prior} ne $empty_string )
1069 {
1070  
1071 # rename for convenience
1072 my $in_clip = $immodpg->{_in_clip};
1073 my $outside_clip = $immodpg->{_outside_clip};
1074 my $clip4plot_current = $immodpg->{_clip4plot_current};
1075 my $clip4plot_prior = $immodpg->{_clip4plot_prior};
1076  
1077 # print("immodpg,_check_clip, in_clip:$in_clip\n");
1078 # print("immodpg,_check_clip, outside_clip: $outside_clip\n");
1079 if ( $in_clip eq $yes
1080 && $outside_clip eq $no )
1081 {
1082  
1083 # print("immodpg, _check_clip, Leaving widget\n");
1084  
1085 # CASE 1: Previously, inside Entry widget
1086 # Now leaving Entry widget
1087 $clip4plot_current = $immodpg->{_clip4plotEntry}->get();
1088  
1089 # rint("immodpg, _check_clip, clip4plot_current:$clip4plot_current\n");
1090  
1091 # reverse the conditions now
1092 # when user leaves Entry widget
1093 $in_clip = $no;
1094 $outside_clip = $yes;
1095  
1096 # reset module values for convenience of renaming
1097 $immodpg->{_in_clip} = $in_clip;
1098 $immodpg->{_outside_clip} = $outside_clip;
1099 $immodpg->{_clip4plot_current} = $clip4plot_current;
1100  
1101 return ();
1102  
1103 }
1104 elsif ($in_clip eq $no
1105 && $outside_clip eq $yes )
1106 {
1107  
1108 # CASE 2: Previously, outside Entry widget
1109 # Now entering Entry widget
1110 $clip4plot_prior = $clip4plot_current;
1111 $clip4plot_current = $immodpg->{_clip4plotEntry}->get();
1112  
1113 # print("immodpg, _check_clip, Entering widget\n");
1114  
1115 # reverse the conditions now
1116 # when user enters Entry widget
1117 $in_clip = $yes;
1118 $outside_clip = $no;
1119  
1120 # reset module values for convenience of renaming
1121 $immodpg->{_in_clip} = $in_clip;
1122 $immodpg->{_outside_clip} = $outside_clip;
1123 $immodpg->{_clip4plot_current} = $clip4plot_current;
1124 $immodpg->{_clip4plot_prior} = $clip4plot_prior;
1125 return ();
1126  
1127 }
1128 else {
1129 print("immodpg, _check_clip, unexpected values\n");
1130 return ();
1131 }
1132  
1133 }
1134 else {
1135 print("immodpg, _check_clip, missing widget\n");
1136 return ();
1137 }
1138 }
1139  
1140 =head2 sub _check_layer
1141  
1142 When you enter or leave
1143 check what the current layer value is
1144 compared to former layer values
1145  
1146 If you enter the LayerEntry widget it will check before you change
1147 its value
1148  
1149 If you enter another widget that now has the focus you
1150 will have to recall the current and prior values of the
1151 layerEntry widget
1152  
1153 =cut
1154  
1155 sub _check_layer {
1156  
1157 my ($self) = @_;
1158  
1159 # print("immodpg, _check_layer, $immodpg->{_layerEntry}\n");
1160  
1161 if ( length( $immodpg->{_layerEntry} )
1162 && length( $immodpg->{_in_layer} )
1163 && length( $immodpg->{_outside_layer} )
1164 && length( $immodpg->{_layer_current} )
1165 && length( $immodpg->{_layer_prior} ) )
1166 {
1167  
1168 # rename for convenience
1169 my $in_layer = $immodpg->{_in_layer};
1170 my $outside_layer = $immodpg->{_outside_layer};
1171 my $layer_current = $immodpg->{_layer_current};
1172 my $layer_prior = $immodpg->{_layer_prior};
1173  
1174 # print("immodpg,_check_layer, in_layer:$in_layer\n");
1175 # print("immodpg,_check_layer, outside_layer: $outside_layer\n");
1176 if ( $in_layer eq $yes
1177 && $outside_layer eq $no )
1178 {
1179  
1180 # CASE 1: Previously, inside Entry widget
1181 # print("immodpg, _check_layer, left widget\n");
1182 # possible layer number idiosyncracies
1183 my $temp_layer_current = $immodpg->{_layerEntry}->get();
1184  
1185 # print("immodpg, _check_layer, CASE 1 temp layer number = $temp_layer_current\n");
1186 _set_layer_control($temp_layer_current);
1187 my $new_layer_current = _get_control_layer();
1188  
1189 # $new_layer_current=99;
1190 $immodpg->{_layerEntry}->delete( 0, 'end' );
1191 $immodpg->{_layerEntry}->insert( 0, $new_layer_current );
1192  
1193 # reverse the conditions now
1194 # when user leaves widget
1195 # Next will enter layerEntry widget
1196 $in_layer = $no;
1197 $outside_layer = $yes;
1198  
1199 # reset module values for convenience of renaming
1200 $immodpg->{_in_layer} = $in_layer;
1201 $immodpg->{_outside_layer} = $outside_layer;
1202 $immodpg->{_layer_current} = $new_layer_current;
1203  
1204 return ();
1205  
1206 }
1207 elsif ($in_layer eq $no
1208 && $outside_layer eq $yes )
1209 {
1210  
1211 # CASE 2: Previously, outside layerEntry widget
1212 # Now entering entering the layerEntry widget
1213 # print("immodpg, _check_layer, Entering widget\n");
1214 $layer_current = $immodpg->{_layerEntry}->get();
1215  
1216 # print("immodpg, _check_layer,prior =$immodpg->{_layer_prior} current= $layer_current\n\n");
1217  
1218 # reverse the conditions now
1219 # when user enters Entry widget
1220 $in_layer = $yes;
1221 $outside_layer = $no;
1222  
1223 # reset module values for convenience of renaming
1224 $immodpg->{_in_layer} = $in_layer;
1225 $immodpg->{_outside_layer} = $outside_layer;
1226 $immodpg->{_layer_current} = $layer_current;
1227  
1228 # $immodpg->{_layer_prior} = $new_layer_prior;
1229 return ();
1230  
1231 }
1232 else {
1233 print("immodpg, _check_layer, unexpected values\n");
1234 return ();
1235 }
1236  
1237 }
1238 else {
1239 print("immodpg, _check_layer, missing widget\n");
1240 return ();
1241 }
1242 }
1243  
1244 =head2 sub _check_thickness_m
1245  
1246 When you modify, enter or leave thickness_mEntry widget
1247 check what the current thickness_m value is
1248 compared to former thickness_m values
1249  
1250 =cut
1251  
1252 sub _check_thickness_m {
1253  
1254 my ($self) = @_;
1255  
1256 # print("immodpg, _check_thickness_m, $immodpg->{_thickness_mEntry}\n");
1257  
1258 if ( defined $immodpg->{_thickness_mEntry}
1259 && length $immodpg->{_thickness_mEntry}
1260 && length $immodpg->{_in_thickness_m}
1261 && length $immodpg->{_outside_thickness_m}
1262 && length $immodpg->{_thickness_m} )
1263 {
1264  
1265 # rename for convenience
1266 my $in_thickness_m = $immodpg->{_in_thickness_m};
1267 my $outside_thickness_m = $immodpg->{_outside_thickness_m};
1268 my $_thickness_m_current = $immodpg->{_thickness_m_current};
1269 my $_thickness_m_prior = $immodpg->{_thickness_m_prior};
1270  
1271 if ( $in_thickness_m eq $yes
1272 && $outside_thickness_m eq $no )
1273 {
1274  
1275 # CASE 1: Previously, inside Entry widget
1276 # Now leaving Entry widget
1277 $_thickness_m_current = $immodpg->{_thickness_mEntry}->get();
1278  
1279 # reverse the conditions now
1280 # when user leaves Entry widget
1281 $in_thickness_m = $no;
1282 $outside_thickness_m = $yes;
1283  
1284 # reset module values for convenience of renaming
1285 $immodpg->{_in_thickness_m} = $in_thickness_m;
1286 $immodpg->{_outside_thickness_m} = $outside_thickness_m;
1287 $immodpg->{_thickness_m_current} = $_thickness_m_current;
1288 # print("immodpg, _check_thickness_m, Leaving widget\n");
1289 # print(
1290 # "immodpg,_check_thickness_m, in_thickness_m:$in_thickness_m\n");
1291 # print(
1292 #"immodpg,_check_thickness_m, outside_thickness_m: $outside_thickness_m\n"
1293 # );
1294 # print(
1295 #"immodpg,_check_thickness_m, _thickness_m_current: $_thickness_m_current\n"
1296 # );
1297  
1298 return ();
1299  
1300 }
1301 elsif ($in_thickness_m eq $no
1302 && $outside_thickness_m eq $yes )
1303 {
1304  
1305 # CASE 2: Previously, outside Entry widget
1306 # Now entering Entry widget
1307 $_thickness_m_prior = $_thickness_m_current;
1308 $_thickness_m_current = $immodpg->{_thickness_mEntry}->get();
1309  
1310 # reverse the conditions now
1311 # when user enters Entry widget
1312 $in_thickness_m = $yes;
1313 $outside_thickness_m = $no;
1314  
1315 # reset module values for convenience of renaming
1316 $immodpg->{_in_thickness_m} = $in_thickness_m;
1317 $immodpg->{_outside_thickness_m} = $outside_thickness_m;
1318 $immodpg->{_thickness_m_current} = $_thickness_m_current;
1319 $immodpg->{_thickness_m_prior} = $_thickness_m_prior;
1320  
1321 # print("immodpg, _check_thickness_m, Entering widget\n");
1322 # print(
1323 # "immodpg,_check_thickness_m, in_thickness_m:$in_thickness_m\n");
1324 # print(
1325 #"immodpg,_check_thickness_m, outside_thickness_m: $outside_thickness_m\n"
1326 # );
1327 # print(
1328 #"immodpg,_check_thickness_m, _thickness_m_current: $_thickness_m_current\n"
1329 # );
1330  
1331 return ();
1332  
1333 }
1334 else {
1335 print("immodpg, _check_thickness_m, unexpected values\n");
1336 return ();
1337 }
1338  
1339 }
1340 else {
1341 print("immodpg, _check_thickness_m, missing widget\n");
1342 return ();
1343 }
1344 }
1345  
1346 =head2 sub _check_thickness_increment_m
1347  
1348 When you enter or leave
1349 check what the current thickness_increment_m value is
1350 compared to former thickness_increment_m values
1351  
1352 =cut
1353  
1354 sub _check_thickness_increment_m {
1355  
1356 my ($self) = @_;
1357  
1358 # print("immodpg, _check_thickness_increment_m, $immodpg->{_thickness_increment_mEntry}\n");
1359  
1360 if ( defined( $immodpg->{_thickness_increment_mEntry} )
1361 && $immodpg->{_thickness_increment_mEntry} ne $empty_string
1362 && $immodpg->{_in_thickness_increment_m} ne $empty_string
1363 && $immodpg->{_outside_thickness_increment_m} ne $empty_string
1364 && $immodpg->{_thickness_increment_m_current} ne $empty_string
1365 && $immodpg->{_thickness_increment_m_prior} ne $empty_string )
1366 {
1367  
1368 # rename for convenience
1369 my $in_thickness_increment_m = $immodpg->{_in_thickness_increment_m};
1370 my $outside_thickness_increment_m =
1371 $immodpg->{_outside_thickness_increment_m};
1372 my $thickness_increment_m_current =
1373 $immodpg->{_thickness_increment_m_current};
1374 my $thickness_increment_m_prior =
1375 $immodpg->{_thickness_increment_m_prior};
1376  
1377 # print("immodpg,_check_thickness_increment_m, in_thickness_increment_m:$in_thickness_increment_m\n");
1378 # print("immodpg,_check_thickness_increment_m, outside_thickness_increment_m: $outside_thickness_increment_m\n");
1379 if ( $in_thickness_increment_m eq $yes
1380 && $outside_thickness_increment_m eq $no )
1381 {
1382  
1383 # print("immodpg, _check_thickness_increment_m, Leaving widget\n");
1384  
1385 # CASE 1: Previously, inside Entry widget
1386 # Now leaving Entry widget
1387 $thickness_increment_m_current =
1388 $immodpg->{_thickness_increment_mEntry}->get();
1389  
1390 # reverse the conditions now
1391 # when user leaves Entry widget
1392 $in_thickness_increment_m = $no;
1393 $outside_thickness_increment_m = $yes;
1394  
1395 # reset module values for convenience of renaming
1396 $immodpg->{_in_thickness_increment_m} = $in_thickness_increment_m;
1397 $immodpg->{_outside_thickness_increment_m} =
1398 $outside_thickness_increment_m;
1399 $immodpg->{_thickness_increment_m_current} =
1400 $thickness_increment_m_current;
1401  
1402 return ();
1403  
1404 }
1405 elsif ($in_thickness_increment_m eq $no
1406 && $outside_thickness_increment_m eq $yes )
1407 {
1408  
1409 # CASE 2: Previously, outside Entry widget
1410 # Now entering Entry widget
1411 $thickness_increment_m_prior = $thickness_increment_m_current;
1412 $thickness_increment_m_current =
1413 $immodpg->{_thickness_increment_mEntry}->get();
1414  
1415 # print("immodpg, _check_thickness_increment_m, Entering widget\n");
1416  
1417 # reverse the conditions now
1418 # when user enters Entry widget
1419 $in_thickness_increment_m = $yes;
1420 $outside_thickness_increment_m = $no;
1421  
1422 # reset module values for convenience of renaming
1423 $immodpg->{_in_thickness_increment_m} = $in_thickness_increment_m;
1424 $immodpg->{_outside_thickness_increment_m} =
1425 $outside_thickness_increment_m;
1426 $immodpg->{_thickness_increment_m_current} =
1427 $thickness_increment_m_current;
1428 $immodpg->{_thickness_increment_m_prior} =
1429 $thickness_increment_m_prior;
1430 return ();
1431  
1432 }
1433 else {
1434 return ();
1435 print("immodpg, _check_thickness_increment_m, unexpected values\n");
1436 }
1437  
1438 }
1439 else {
1440 print("immodpg, _check_thickness_increment_m, missing widget\n");
1441 return ();
1442 }
1443 }
1444  
1445 =head2 sub _get_control
1446 find corrected value
1447  
1448 =cut
1449  
1450 sub _get_control {
1451 my ($self) = @_;
1452  
1453 my $result;
1454  
1455 if ( length( $immodpg->{_control_value} ) ) {
1456  
1457 $result = $immodpg->{_control_value};
1458  
1459 }
1460 else {
1461 print("immodpg, _get_control, unexpected value\n");
1462 }
1463 return ($result);
1464 }
1465  
1466 #=head2 sub _get_control_VbotNtop_factor
1467 #adjust bad VbotNtop_factor value
1468 #set defaults
1469 #
1470 #=cut
1471 #
1472 # sub _get_control_VbotNtop_factor {
1473 #
1474 # my ($self) = @_;
1475 #
1476 # my $result;
1477 #
1478 # if ( not( looks_like_number( $immodpg->{_control_VbotNtop_factor} ) ) ) {
1479 #
1480 # $immodpg->{_VbotNtop_factor_current} = $immodpg->{_VbotNtop_factor_default};
1481 # $immodpg->{_VbotNtop_factor_prior} = $immodpg->{_VbotNtop_factor_default};
1482 # $immodpg->{_VbotNtop_factorEntry}->delete( 0, 'end' );
1483 # $immodpg->{_VbotNtop_factorEntry}->insert( 0, $immodpg->{_VbotNtop_factor_current} );
1484 # $immodpg->{_isVbotNtop_factor_changed_in_gui} = $no,;
1485 #
1486 # } else {
1487 # print("immodpg, _get_control_VbotNtop_factor, bad value\n");
1488 # }
1489 #
1490 # return ();
1491 # }
1492  
1493 =head2 sub _get_control_clip
1494 adjust clip value
1495  
1496 =cut
1497  
1498 sub _get_control_clip {
1499  
1500 my ($self) = @_;
1501  
1502 my $result;
1503  
1504 if ( length( $immodpg->{_control_clip} ) ) {
1505  
1506 # print("1. immodpg, _get_control_clip, old control_clip= $immodpg->{_control_clip}\n");
1507 my $control_clip = $immodpg->{_control_clip};
1508  
1509 if ( $control_clip <= 0 ) {
1510  
1511 # case 1 layer number exceeds possible value
1512 $control_clip = 1;
1513 $result = $control_clip;
1514  
1515 }
1516 else {
1517  
1518 # print("immodpg, _get_control_clip, NADA\n");
1519 $result = $control_clip;
1520 }
1521  
1522 # print("2. immodpg, _get_control_clip, new control_clip= $control_clip\n");
1523 return ($result);
1524  
1525 }
1526 else {
1527 print("immodpg, _get_control_clip, missing clip value\n");
1528 }
1529 return ();
1530 }
1531  
1532 =head2 sub _get_control_layer
1533 adjust layer number
1534  
1535 =cut
1536  
1537 sub _get_control_layer {
1538  
1539 my ($self) = @_;
1540  
1541 my $result;
1542  
1543 if ( length( $immodpg->{_control_layer} ) ) {
1544  
1545 # print("1. immodpg, _get_control_layer, control_layer= $immodpg->{_control_layer}\n");
1546 my $control_layer = $immodpg->{_control_layer};
1547 my $number_of_layers = _get_number_of_layers();
1548  
1549 if ( $control_layer > $number_of_layers ) {
1550  
1551 # case 1 layer number exceeds possible value
1552 # print("case1: immodpg, _get_control_layer, layer number too large\n");
1553 # print("immodpg, _get_control_layer, layer_number=$control_layer}\n");
1554 $control_layer = $number_of_layers - 1;
1555  
1556 # print("immodpg, _get_control_layer, new layer_number=$control_layer}\n");
1557 $result = $control_layer;
1558  
1559 }
1560 elsif ( $control_layer < 1 ) {
1561  
1562 $control_layer = 1;
1563 $result = $control_layer;
1564  
1565 }
1566 elsif ( ( $control_layer == 1 ) ) {
1567  
1568 $control_layer = 1;
1569 $result = $control_layer;
1570  
1571 # NADA
1572  
1573 }
1574 elsif ( ( $control_layer < $number_of_layers ) ) {
1575  
1576 #print("immodpg, get_control_layer, layer=$control_layer\n");
1577 $result = $control_layer;
1578  
1579 # NADA
1580  
1581 }
1582 elsif ( ( $control_layer == $number_of_layers ) ) {
1583  
1584 # print("immodpg, get_control_layer, layer=$control_layer\n");
1585 $result = $control_layer - 1;
1586  
1587 }
1588 else {
1589  
1590 # print("immodpg, _get_control_layer, unexpected layer number\n");
1591 $result = $empty_string;
1592 }
1593  
1594 }
1595 else {
1596  
1597 # print("immodpg, _get_control_layer, empty string, result = 1\n");
1598 $result = 1;
1599 }
1600  
1601 return ($result);
1602 }
1603  
1604 =head2 sub _get_data_scale
1605  
1606 get scalco or scalel from file header
1607  
1608 =cut
1609  
1610 sub _get_data_scale {
1611 my ($self) = @_;
1612  
1613 =head2 instantiate class
1614  
1615 =cut
1616  
1617 print(
1618 "immodpg, _get_data_scale, _base_file_name=$immodpg->{_base_file_name}\n"
1619 );
1620  
1621 # ???
1622 my $header_values = header_values->new();
1623  
1624 if ( defined $immodpg->{_base_file_name}
1625 && $immodpg->{_base_file_name} ne $empty_string )
1626 {
1627  
1628 $header_values->set_base_file_name( $immodpg->{_base_file_name} );
1629 $header_values->set_header_name('scalel');
1630 my $data_scale = $header_values->get_number();
1631  
1632 my $result = $data_scale;
1633  
1634 # print("immodpg, _get_data_scale, data_scale = $data_scale\n");
1635 return ($result);
1636  
1637 }
1638 else {
1639  
1640 my $data_scale = 1;
1641 my $result = $data_scale;
1642  
1643 # print("immodpg, _get_data_scale, data_scale = 1:1\n");
1644 return ($result);
1645  
1646 }
1647 }
1648  
1649 =head2 _get_initial_model
1650  
1651 PERL PERL PROGRAM NAME: _get_initial_model
1652 AUTHOR: Juan Lorenzo
1653 DATE: May 21 2020
1654  
1655 DESCRIPTION:
1656
1657 read Fortran 77 unformatted binary model file
1658 from mmodpg
1659  
1660 =cut
1661  
1662 =head2 USE
1663  
1664 =over
1665  
1666 =item
1667  
1668 Number of layers is passed as a variable
1669 Number of layers is read from an ascii
1670 version of the model data file
1671  
1672 =item
1673  
1674  
1675 =back
1676
1677 =cut
1678  
1679 =head2 NOTES
1680  
1681
1682 =cut
1683  
1684 =head4 Examples
1685  
1686 =cut
1687  
1688 =head2 CHANGES and their DATES
1689 3.31.21
1690 Consider storing model values and
1691 their changes within this namespace
1692  
1693 =cut
1694  
1695 sub _get_initial_model {
1696  
1697 my ($self) = @_;
1698  
1699 use PDL::Core;
1700 use PDL::IO::FlexRaw;
1701  
1702 my $Project = Project_config->new();
1703 my $IMMODPG = $Project->IMMODPG();
1704 my $var = ( immodpg_global_constants->new() )->var;
1705  
1706 my ( @VPtop, @VStop, @density_top, @dz );
1707 my ( @VPbot, @VSbot, @density_bot );
1708 my ( @VP, @VS, @model );
1709 my $error_switch = $off;
1710 my $result = '';
1711  
1712 my $inbound = $IMMODPG . '/' . $var->{_immodpg_model};
1713 my $cols = 9; #default
1714 my $km2m = 1000;
1715 my $gcc2MKS = 1000;
1716  
1717 my $number_of_layers = _get_number_of_layers();
1718  
1719 # print("immodpg, _get_initial_model,number_of_layers = $number_of_layers\n");
1720  
1721 my $header = [
1722 { Type => 'f77' },
1723 {
1724 Type => 'float',
1725 NDims => 2,
1726 Dims => [ $cols, ($number_of_layers) ]
1727 }
1728 ];
1729  
1730 # does file exist?
1731 if ( -e $inbound ) {
1732  
1733 # CASE 1: file exists
1734 my $model_pdl = readflex( $inbound, $header );
1735  
1736 # print("$model_pdl\n");
1737 my $nelem = nelem($model_pdl);
1738  
1739 # print("immodpg,_get_initial_model,nelem=$nelem,#cols=$cols,#layers=$number_of_layers\n");
1740  
1741 for (
1742 my $layer_index = 0 ;
1743 $layer_index < $number_of_layers ;
1744 $layer_index++
1745 )
1746 {
1747  
1748 my $magic_number_str = '0:1';
1749 my $value_indices = $magic_number_str;
1750 my $full_indices = $value_indices . ',' . $layer_index;
1751  
1752 # pdl 2 perl
1753 @VP = ( $model_pdl->slice($full_indices) )->list;
1754 $VPtop[$layer_index] =
1755 sprintf( "$var_immodpg->{_format_dot2f}", ( $VP[0] * $km2m ) );
1756 $VPbot[$layer_index] =
1757 sprintf( "$var_immodpg->{_format_dot2f}", ( $VP[1] * $km2m ) );
1758  
1759 $value_indices = '2:6';
1760 $full_indices = $value_indices . ',' . $layer_index;
1761  
1762 # pdl 2 perl
1763 @model = ( $model_pdl->slice($full_indices) )->list;
1764 $dz[$layer_index] =
1765 sprintf( "$var_immodpg->{_format_dot3f}", ( $model[0] * $km2m ) );
1766 $VStop[$layer_index] =
1767 sprintf( "$var_immodpg->{_format_dot3f}", ( $model[1] * $km2m ) );
1768 $VSbot[$layer_index] =
1769 sprintf( "$var_immodpg->{_format_dot3f}", ( $model[2] * $km2m ) );
1770 $density_top[$layer_index] =
1771 sprintf( "$var_immodpg->{_format_dot3f}",
1772 ( $model[3] * $gcc2MKS ) );
1773 $density_bot[$layer_index] =
1774 sprintf( "$var_immodpg->{_format_dot3f}",
1775 ( $model[4] * $gcc2MKS ) );
1776  
1777 # print(
1778 # "immodpg,_get_initial_model,V,layer_index=$layer_index\n"
1779 # );
1780 # print(
1781 # "immodpg,_get_initial_model,VPtop = $VPtop[$layer_index], VPbot=$VPbot[$layer_index]\n"
1782 # );
1783  
1784 # print("VStop = $VStop[$layer_index], VSbot=$VSbot[$layer_index],layer_index=$layer_index\n");
1785 # print("dz = $dz[$layer_index], rho_top=$density_top[$layer_index],rho_bot=$density_bot[$layer_index]\n");
1786  
1787 # my $x_indices = pdl(5);
1788 # my $layer_indices = pdl(2);
1789 } # end a for loop
1790  
1791 # test for errors
1792 _set_model_control( \@VPbot, \@VPtop, \@VSbot, \@VStop, \@density_bot,
1793 \@density_top, \@dz );
1794 my $error_switch = _get_model_control();
1795  
1796 if ( $error_switch eq $on ) {
1797  
1798 # CASE 1A File exists and is corrupt
1799 _messages( 'immodpg', 1 );
1800 return ();
1801  
1802 }
1803 elsif ( $error_switch eq $off ) {
1804  
1805 # CASE 1B File exists and is OK
1806 # print("immodpg,_get_initial_model, MODEL OK ;NADA\n");
1807 return ( \@VPtop, \@VPbot, \@dz, $error_switch );
1808 }
1809 else {
1810 print("immodpg,_get_initial_model, unexpected value\n");
1811 }
1812  
1813 # print pdl(@VPtop,@VPbot,@dz,@VStop,@VSbot,@density_top,@density_bot);
1814 # print ("\n");
1815 # print $model_pdl->index2d($x_indices,$layer_indices);
1816 # print ("\n");
1817 # print $model_pdl;
1818  
1819 }
1820 elsif ( not( -e $inbound ) ) {
1821  
1822 print("immodpg,_get_initial_model,file is missing\n");
1823 use File::Copy;
1824 my $from = $global_libs->{_configs_big_streams} . '/' . $immodpg_model;
1825 my $to = $IMMODPG . '/' . $immodpg_model_file_text;
1826 copy( $from, $to );
1827  
1828 $from =
1829 $global_libs->{_configs_big_streams} . '/' . $immodpg_model_file_text;
1830 $to = $IMMODPG . '/' . $immodpg_model_file_text;
1831 copy( $from, $to );
1832  
1833 return ();
1834  
1835 }
1836 else {
1837 print("immodpg,_get_initial_model,unexpected value\n");
1838 return ();
1839 }
1840  
1841 return ();
1842 }
1843  
1844 =head2 _get_initial_model4gui
1845  
1846 PERL PERL PROGRAM NAME: _get_initial_model4gui
1847 AUTHOR: Juan Lorenzo
1848 DATE: May 21 2020
1849  
1850 DESCRIPTION:
1851
1852 read Fortran 77 unformatted binary model file
1853 from mmodpg
1854  
1855 =cut
1856  
1857 =head2 USE
1858  
1859 =over
1860  
1861 =item
1862  
1863 Number of layers is passed as a variable
1864 Number of layers is read from an ascii
1865 version of the model data file
1866  
1867 =item
1868  
1869  
1870 =back
1871
1872 =cut
1873  
1874 =head2 NOTES
1875  
1876
1877 =cut
1878  
1879 =head4 Examples
1880  
1881 =cut
1882  
1883 =head2 CHANGES and their DATES
1884 3.31.21
1885 Consider storing model values and
1886 their changes within this namespace
1887  
1888 =cut
1889  
1890 sub _get_initial_model4gui {
1891  
1892 my ($self) = @_;
1893  
1894 use PDL::Core;
1895 use PDL::IO::FlexRaw;
1896  
1897 my $Project = Project_config->new();
1898 my $IMMODPG = $Project->IMMODPG();
1899 my $var = ( immodpg_global_constants->new() )->var;
1900  
1901 my ( @VPtop, @VStop, @density_top, @dz );
1902 my ( @VPbot, @VSbot, @density_bot );
1903 my ( @VP, @VS, @model );
1904 my $error_switch = $off;
1905 my $result = '';
1906  
1907 my $inbound = $IMMODPG . '/' . $var->{_immodpg_model};
1908 my $cols = 9; #default
1909 my $km2m = 1000;
1910 my $gcc2MKS = 1000;
1911  
1912 # print("immodpg, _get_initial_model4gui,model_layer_number =$immodpg->{_model_layer_number}\n");
1913 my $number_of_layers = _get_number_of_layers();
1914  
1915 # print("immodpg, _get_initial_model4gui,number_of_layers = $number_of_layers\n");
1916  
1917 if ( $immodpg->{_model_layer_number} > 0
1918 && $immodpg->{_model_layer_number} <= $number_of_layers )
1919 {
1920  
1921 my $header = [
1922 { Type => 'f77' },
1923 {
1924 Type => 'float',
1925 NDims => 2,
1926 Dims => [ $cols, ($number_of_layers) ]
1927 }
1928 ];
1929  
1930 # does file exist?
1931 if ( -e $inbound ) {
1932  
1933 # CASE 1: file exists
1934 my $model_pdl = readflex( $inbound, $header );
1935  
1936 # print("$model_pdl\n");
1937 my $nelem = nelem($model_pdl);
1938  
1939 # print("immodpg,_get_initial_model4gui,nelem=$nelem,#cols=$cols,#layers=$number_of_layers\n");
1940 # print("immodpg,_get_initial_model4gui,=format_dot2f=$var_immodpg->{_format_dot2f}\n");
1941 for (
1942 my $layer_index = 0 ;
1943 $layer_index < $number_of_layers ;
1944 $layer_index++
1945 )
1946 {
1947  
1948 my $magic_number_str = '0:1';
1949 my $value_indices = $magic_number_str;
1950 my $full_indices = $value_indices . ',' . $layer_index;
1951  
1952 # pdl 2 perl
1953 @VP = ( $model_pdl->slice($full_indices) )->list;
1954  
1955 $VPtop[$layer_index] = sprintf( "$var_immodpg->{_format_dot2f}",
1956 ( $VP[0] * $km2m ) );
1957 $VPbot[$layer_index] = sprintf( "$var_immodpg->{_format_dot2f}",
1958 ( $VP[1] * $km2m ) );
1959  
1960 $value_indices = '2:6';
1961 $full_indices = $value_indices . ',' . $layer_index;
1962  
1963 # pdl 2 perl
1964 @model = ( $model_pdl->slice($full_indices) )->list;
1965 $dz[$layer_index] = sprintf( "$var_immodpg->{_format_dot3f}",
1966 ( $model[0] * $km2m ) );
1967 $VStop[$layer_index] = sprintf( "$var_immodpg->{_format_dot3f}",
1968 ( $model[1] * $km2m ) );
1969 $VSbot[$layer_index] = sprintf( "$var_immodpg->{_format_dot3f}",
1970 ( $model[2] * $km2m ) );
1971 $density_top[$layer_index] =
1972 sprintf( "$var_immodpg->{_format_dot3f}",
1973 ( $model[3] * $gcc2MKS ) );
1974 $density_bot[$layer_index] =
1975 sprintf( "$var_immodpg->{_format_dot3f}",
1976 ( $model[4] * $gcc2MKS ) );
1977  
1978 # print(
1979 # "immodpg,_get_initial_model4gui,VPtop = $VPtop[$layer_index], VPbot=$VPbot[$layer_index],layer_index=$layer_index\n"
1980 # );
1981  
1982 # print("VStop = $VStop[$layer_index], VSbot=$VSbot[$layer_index],layer_index=$layer_index\n");
1983 # print("dz = $dz[$layer_index], rho_top=$density_top[$layer_index],rho_bot=$density_bot[$layer_index]\n");
1984  
1985 # my $x_indices = pdl(5);
1986 # my $layer_indices = pdl(2);
1987 } # end a for loop
1988  
1989 # test for errors
1990 _set_model_control( \@VPbot, \@VPtop, \@VSbot, \@VStop,
1991 \@density_bot, \@density_top, \@dz );
1992 my $error_switch = _get_model_control();
1993  
1994 if ( $error_switch eq $on ) {
1995  
1996 # CASE 1A File exists and is corrupt
1997 _messages( 'immodpg', 1 );
1998 return ();
1999  
2000 }
2001 elsif ( $error_switch eq $off ) {
2002  
2003 # CASE 1B File exists and is OK
2004 # print("immodpg,_get_initial_model4gui, MODEL OK ;NADA\n");
2005 return ( \@VPtop, \@VPbot, \@dz, $error_switch );
2006  
2007 }
2008 else {
2009 print("immodpg,_get_initial_model4gui, unexpected value\n");
2010 }
2011  
2012 # print pdl(@VPtop,@VPbot,@dz,@VStop,@VSbot,@density_top,@density_bot);
2013 # print ("\n");
2014 # print $model_pdl->index2d($x_indices,$layer_indices);
2015 # print ("\n");
2016 # print $model_pdl;
2017  
2018 }
2019 elsif ( not( -e $inbound ) ) {
2020  
2021 print("immodpg,_get_initial_model4gui,file is missing\n");
2022 use File::Copy;
2023 my $from =
2024 $global_libs->{_configs_big_streams} . '/' . $immodpg_model;
2025 my $to = $IMMODPG . '/' . $immodpg_model_file_text;
2026 copy( $from, $to );
2027  
2028 $from = $global_libs->{_configs_big_streams} . '/'
2029 . $immodpg_model_file_text;
2030 $to = $IMMODPG . '/' . $immodpg_model_file_text;
2031 copy( $from, $to );
2032  
2033 return ();
2034 }
2035 else {
2036 print("immodpg,_get_initial_model4gui,unexpected value\n");
2037 return ();
2038 }
2039  
2040 }
2041 else {
2042 print("immodpg,_get_initial_model4gui,bad layer number\n");
2043 return ();
2044 }
2045 return ();
2046 }
2047  
2048 =head2
2049  
2050 determine number of layers
2051 from model.text file
2052  
2053 =cut
2054  
2055 sub _get_number_of_layers {
2056  
2057 my ($self) = @_;
2058 my $number_of_layers;
2059  
2060 if ( length( $immodpg->{_model_file_text} ) ) {
2061  
2062 my $count = 0;
2063 my $magic_number = 4;
2064 my $inbound_model_file_text =
2065 $IMMODPG . '/' . $immodpg->{_model_file_text};
2066  
2067 # print ("immodpg,_get_number_of_layers,inbound_model_file_text=$inbound_model_file_text\n");
2068  
2069 open( my $fh, '<', $inbound_model_file_text );
2070  
2071 while (<$fh>) {
2072  
2073 $count++;
2074  
2075 }
2076 close($fh);
2077  
2078 $number_of_layers = $count - $magic_number;
2079  
2080 # print("immodpg,_get_number_of_layers, layers = $number_of_layers \n");
2081  
2082 }
2083 else {
2084  
2085 # print("immodpg,_get_number_of_layers, missing values\n");
2086 $number_of_layers = 0;
2087 }
2088  
2089 my $result = $number_of_layers;
2090 return ($result);
2091 }
2092  
2093 =head2 sub _getVp_ref_dz_ref
2094 Collect the currently update
2095 values in the model for
2096 layers and their velocities and
2097 thicknesses
2098  
2099 =cut
2100  
2101 sub _getVp_ref_dz_ref {
2102  
2103 my ($self) = @_;
2104  
2105 my @VPtop = @{ $immodpg->{_refVPtop} };
2106 my @VPbot = @{ $immodpg->{_refVPbot} };
2107 my @dz = @{ $immodpg->{_ref_dz} };
2108 my $layer = $immodpg->{_model_layer_number};
2109  
2110 # print("immodpg,_getVp_ref_dz_ref layer_number = $layer \n");
2111  
2112 if ( looks_like_number($layer)
2113 and scalar(@VPtop)
2114 and scalar(@VPbot)
2115 and scalar(@dz) )
2116 {
2117  
2118 return ( \@VPtop, \@VPbot, \@dz );
2119  
2120 }
2121 else {
2122 print("immodpg,_getVp_ref_dz_ref , unexpected value\n");
2123 return ();
2124 }
2125  
2126 }
2127  
2128 =head2 sub _getVp_ref_dz_scalar
2129 Collect the currently update
2130 values in the model for
2131 layers and their velocities and
2132 thicknesses
2133  
2134 =cut
2135  
2136 sub _getVp_ref_dz_scalar {
2137  
2138 my ($self) = @_;
2139  
2140 if ( looks_like_number( $immodpg->{_model_layer_number} ) ) {
2141  
2142 my ( $_thickness_m_upper_layer, $Vbot_lower_layer );
2143 my ( @V, @result );
2144  
2145 my $layer = $immodpg->{_model_layer_number};
2146  
2147 # print("immodpg,_getVp_ref_dz_scalar layer_number = $layer \n");
2148  
2149 my @VPtop = @{ $immodpg->{_refVPtop} };
2150 my @VPbot = @{ $immodpg->{_refVPbot} };
2151 my @dz = @{ $immodpg->{_ref_dz} };
2152  
2153 # $error_switch = $immodpg->{_error_switch};
2154  
2155 if ( scalar(@VPtop)
2156 and scalar(@VPbot)
2157 and scalar(@dz) )
2158 {
2159  
2160 # print("immodpg,_getVp_ref_dz_scalar VPtop= $VPtop[($layer-1)]\n");
2161 # print("immodpg,_getVp_ref_dz_scalar for layer:($layer), VPbot= $VPbot[($layer-1)]\n");
2162  
2163 my $layer_index = $layer - 1;
2164 my $layer_index_upper_layer = $layer - 2;
2165 my $layer_index_lower_layer = $layer;
2166  
2167 # For all cases
2168 my $Vtop = $VPtop[$layer_index];
2169 my $Vbot = $VPbot[$layer_index];
2170 my $dz = $dz[$layer_index];
2171  
2172 if ( $layer >= 2 ) {
2173  
2174 # CASE of second of two or more layers
2175 my $Vbot_upper_layer = $VPbot[$layer_index_upper_layer];
2176 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
2177  
2178 $V[0] = $Vbot_upper_layer;
2179 $V[1] = $Vtop;
2180 $V[2] = $Vbot;
2181 $V[3] = $Vtop_lower_layer;
2182  
2183 @result = @V;
2184  
2185 # print("immodpg,_getVp_ref_dz_scalar: velocities are: @V \n");
2186 return ( \@result, $dz );
2187  
2188 # return ( \@result, $dz, $error_switch );
2189  
2190 }
2191 elsif ( $layer >= 1 ) {
2192  
2193 # CASE of first of one or more layers
2194 my $Vbot_upper_layer = $empty_string;
2195 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
2196  
2197 $V[0] = $Vbot_upper_layer;
2198 $V[1] = $Vtop;
2199 $V[2] = $Vbot;
2200 $V[3] = $Vtop_lower_layer;
2201  
2202 @result = @V;
2203  
2204 # return ( \@result, $dz, $error_switch );
2205 return ( \@result, $dz );
2206 }
2207 else {
2208 print(
2209 "immodpg, _getVp_ref_dz_scalar, unexpected layer number \n"
2210 );
2211 return ();
2212 }
2213 }
2214 else {
2215 return ();
2216 print(
2217 "immodpg,_getVp_ref_dz_scalar, _get_initial_model gives bad values\ n"
2218 );
2219 }
2220  
2221 }
2222 else {
2223 print("immodpg,_getVp_ref_dz_scalar,missing layer\n");
2224 return ();
2225 }
2226 return ();
2227  
2228 }
2229  
2230 =head2 sub _get_initialVp_dz4gui
2231  
2232 =cut
2233  
2234 sub _get_initialVp_dz4gui {
2235  
2236 my ($self) = @_;
2237  
2238 if ( looks_like_number( $immodpg->{_model_layer_number} ) ) {
2239  
2240 my ( $_thickness_m_upper_layer, $Vbot_lower_layer );
2241 my ( @V, @result );
2242  
2243 my $layer = $immodpg->{_model_layer_number};
2244 my ( $refVPtop, $refVPbot, $ref_dz, $error_switch ) =
2245 _get_initial_model4gui();
2246  
2247 if ( length($refVPtop)
2248 and length($refVPbot)
2249 and length($ref_dz)
2250 and length($error_switch) )
2251 {
2252  
2253 my @VPtop = @$refVPtop;
2254 my @VPbot = @$refVPbot;
2255 my @dz = @$ref_dz;
2256  
2257 # print("immodpg,_get_initialVp_dz4gui VPtop= @VPtop\n");
2258 # print("immodpg,_get_initialVp_dz4gui VPbot= @VPbot\n");
2259 # print("immodpg,_get_initialVp_dz4gui layer_number = $layer \n");
2260  
2261 my $layer_index = $layer - 1;
2262 my $layer_index_upper_layer = $layer - 2;
2263 my $layer_index_lower_layer = $layer;
2264  
2265 # For all cases
2266 my $Vtop = $VPtop[$layer_index];
2267 my $Vbot = $VPbot[$layer_index];
2268 my $dz = $dz[$layer_index];
2269  
2270 if ( $layer >= 2 ) {
2271  
2272 # CASE of second of two or more layers
2273 my $Vbot_upper_layer = $VPbot[$layer_index_upper_layer];
2274 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
2275  
2276 $V[0] = $Vbot_upper_layer;
2277 $V[1] = $Vtop;
2278 $V[2] = $Vbot;
2279 $V[3] = $Vtop_lower_layer;
2280  
2281 @result = @V;
2282  
2283 # print("immodpg_get_initialVp_dz4gui: velocities are: @V \n");
2284 return ( \@result, $dz, $error_switch );
2285  
2286 }
2287 elsif ( $layer >= 1 ) {
2288  
2289 # CASE of first of one or more layers
2290 my $Vbot_upper_layer = $empty_string;
2291 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
2292  
2293 $V[0] = $Vbot_upper_layer;
2294 $V[1] = $Vtop;
2295 $V[2] = $Vbot;
2296 $V[3] = $Vtop_lower_layer;
2297  
2298 @result = @V;
2299 return ( \@result, $dz, $error_switch );
2300  
2301 }
2302 else {
2303 print(
2304 "immodpg, _get_initialVp_dz4gui, unexpected layer number \n"
2305 );
2306 return ();
2307 }
2308 }
2309 else {
2310 return ();
2311 print(
2312 "immodpg,_get_initialVp_dz4gui, _get_initial_model gives bad values \n"
2313 );
2314 }
2315  
2316 }
2317 else {
2318 print("immodpg,_get_initialVp_dz4gui,missing layer\\n");
2319 return ();
2320 }
2321 return ();
2322  
2323 }
2324  
2325 =head2 sub _messages
2326 Show warnings or errors in a message box
2327 Message box is defined in main where it is
2328 also made invisible (withdraw)
2329 Here we turn on the message box (deiconify, raise)
2330 The message does not release the program
2331 until OK is clicked and wait variable changes from yes
2332 to no.
2333  
2334 =cut
2335  
2336 sub _messages {
2337  
2338 my ( $run_name, $number ) = @_;
2339  
2340 my $run_name_message = message_director->new();
2341 my $message = $run_name_message->immodpg($number);
2342  
2343 my $message_box = $immodpg->{_message_box_w};
2344 my $message_label = $immodpg->{_message_label_w};
2345 my $message_box_wait = $immodpg->{_message_box_wait};
2346 my $message_ok_button = $immodpg->{_message_ok_button};
2347  
2348 # print("1 immodpg,_messages, message_box=$message_box\n");
2349  
2350 $message_box->title($run_name);
2351  
2352 $message_label->configure( -textvariable => \$message, );
2353  
2354 $message_box->deiconify();
2355 $message_box->raise();
2356 $message_ok_button->waitVariable( \$message_box_wait );
2357 return ();
2358 }
2359  
2360 =head2 sub _setVbot
2361  
2362 Verify another lock file does not exist and
2363 only then:
2364  
2365 Create another lock file
2366 while change file is written
2367 that prevents fortran file from reading.
2368 Then, delete the lock file
2369 Avoids crash between asynchronous
2370 reading (fortran) and
2371 writing (Perl) of files
2372  
2373 =cut
2374  
2375 sub _setVbot {
2376 my ($Vbot) = @_;
2377  
2378 if ( looks_like_number($Vbot)
2379 && $immodpg->{_isVbot_changed_in_gui} eq $yes )
2380 {
2381  
2382 =head2 instantiate classes
2383  
2384 =cut
2385  
2386 my $files = manage_files_by2->new();
2387 my $control = control->new();
2388  
2389 =head2 Define local
2390 variables
2391  
2392 =cut
2393  
2394 my @X;
2395 my $Vbot_file = $immodpg->{_Vbot_file};
2396  
2397 my $test = $no;
2398 my $outbound = $IMMODPG_INVISIBLE . '/' . $Vbot_file;
2399 my $outbound_locked = $outbound . '_locked';
2400  
2401 for ( my $i = 0 ; $test eq $no ; $i++ ) {
2402  
2403 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
2404 my $format = $var_immodpg->{_format_string};
2405 $X[0] = $empty_string;
2406 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
2407  
2408 $X[0] = $Vbot;
2409 $format = $var_immodpg->{_format_real};
2410 $files->write_1col_aref( \@X, \$outbound, \$format );
2411  
2412 unlink($outbound_locked);
2413 $test = $yes;
2414  
2415 } # if
2416 } # for
2417  
2418 }
2419 elsif ( $immodpg->{_isVbot_changed_in_gui} eq $no ) {
2420  
2421 # NADA
2422  
2423 }
2424 else {
2425 print("immodpg, _setVbot, unexpected answer\n");
2426 }
2427  
2428 return ();
2429 }
2430  
2431 =head2 sub _setVbot_upper_layer
2432  
2433 Verify another lock file does not exist and
2434 only then:
2435  
2436 Create another lock file
2437 while change file is written
2438 that prevents fortran file from reading.
2439 Then, delete the lock file
2440 Avoids crash between asynchronous
2441 reading (fortran) and
2442 writing (Perl) of files
2443 _setVbot_upper_layer
2444  
2445 =cut
2446  
2447 sub _setVbot_upper_layer {
2448 my ($Vbot_upper_layer) = @_;
2449  
2450 if ( $Vbot_upper_layer ne $empty_string
2451 && $immodpg->{_isVbot_upper_layer_changed_in_gui} eq $yes )
2452 {
2453  
2454 =head2 instantiate classes
2455  
2456 =cut
2457  
2458 my $files = manage_files_by2->new();
2459 my $control = control->new();
2460  
2461 =head2 Define local
2462 variables
2463  
2464 =cut
2465  
2466 my @X;
2467 my $Vbot_upper_layer_file = $immodpg->{_Vbot_upper_layer_file};
2468  
2469 my $test = $no;
2470 my $outbound = $IMMODPG_INVISIBLE . '/' . $Vbot_upper_layer_file;
2471 my $outbound_locked = $outbound . '_locked';
2472  
2473 for ( my $i = 0 ; $test eq $no ; $i++ ) {
2474  
2475 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
2476  
2477 my $format = $var_immodpg->{_format_string};
2478 $X[0] = $empty_string;
2479 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
2480  
2481 $X[0] = $Vbot_upper_layer;
2482 $format = $var_immodpg->{_format_real};
2483 $files->write_1col_aref( \@X, \$outbound, \$format );
2484  
2485 unlink($outbound_locked);
2486 $test = $yes;
2487  
2488 } # if
2489 } # for
2490  
2491 }
2492 elsif ( $immodpg->{_isVbot_upper_layer_changed_in_gui} eq $no ) {
2493  
2494 # NADA
2495  
2496 }
2497 else {
2498 print("immodpg, _setVbot_upper_layer, unexpected answer\n");
2499 }
2500  
2501 return ();
2502 }
2503  
2504 =head2 sub _setVbotNtop_factor
2505  
2506 Verify another lock file does not exist and
2507 only then:
2508  
2509 Create another lock file
2510 while change file is written
2511 that prevents fortran file from reading.
2512 Then, delete the lock file
2513 Avoids crash between asynchronous
2514 reading (fortran) and
2515 writing (Perl) of files
2516 _setVbotNtop_factor
2517  
2518 =cut
2519  
2520 sub _setVbotNtop_factor {
2521 my ($VbotNtop_factor) = @_;
2522  
2523 if ( $VbotNtop_factor ne $empty_string
2524 && $immodpg->{_isVbotNtop_factor_changed_in_gui} eq $yes )
2525 {
2526  
2527 =head2 instantiate classes
2528  
2529 =cut
2530  
2531 my $files = manage_files_by2->new();
2532 my $control = control->new();
2533  
2534 =head2 Define local
2535 variables
2536  
2537 =cut
2538  
2539 my @X;
2540 my $VbotNtop_factor_file = $immodpg->{_VbotNtop_factor_file};
2541  
2542 my $test = $no;
2543 my $outbound = $IMMODPG_INVISIBLE . '/' . $VbotNtop_factor_file;
2544 my $outbound_locked = $outbound . '_locked';
2545  
2546 for ( my $i = 0 ; $test eq $no ; $i++ ) {
2547  
2548 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
2549 my $format = $var_immodpg->{_format_string};
2550 $X[0] = $empty_string;
2551 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
2552  
2553 $X[0] = $VbotNtop_factor;
2554 $format = ' 0.0';
2555 $files->write_1col_aref( \@X, \$outbound, \$format );
2556  
2557 unlink($outbound_locked);
2558 $test = $yes;
2559  
2560 } # if
2561 } # for
2562  
2563 }
2564 elsif ( $immodpg->{_isVbotNtop_factor_changed_in_gui} eq $no ) {
2565  
2566 # NADA
2567  
2568 }
2569 else {
2570 print("immodpg, _setVbotNtop_factor, unexpected answer\n");
2571 }
2572  
2573 return ();
2574 }
2575  
2576 =head2 sub _setVbotNtop_multiply
2577 Verify another lock file does not exist and
2578 only then:
2579 Create another lock file
2580 while change file is written
2581 that prevents fortran file from reading.
2582 Then, delete the lock file
2583 Avoids crash between asynchronous
2584 reading (fortran) and
2585 writing (Perl) of files
2586 _setVbotNtop_multiply
2587  
2588 =cut
2589  
2590 sub _setVbotNtop_multiply {
2591 my ($self) = @_;
2592  
2593 if ( looks_like_number( $immodpg->{_Vbot_multiplied} )
2594 && looks_like_number( $immodpg->{_Vtop_multiplied} )
2595 && looks_like_number( $immodpg->{_Vbot_current} )
2596 && looks_like_number( $immodpg->{_Vtop_current} ) )
2597 {
2598  
2599 =head2 instantiate classes
2600  
2601 =cut
2602  
2603 my $files = manage_files_by2->new();
2604 my $control = control->new();
2605  
2606 =head2 Define local
2607 variables
2608  
2609 =cut
2610  
2611 my @X;
2612 my $file = $immodpg->{_VbotNtop_multiply_file};
2613  
2614 my $test = $no;
2615 my $outbound = $IMMODPG_INVISIBLE . '/' . $file;
2616 my $outbound_locked = $outbound . '_locked';
2617  
2618 for ( my $i = 0 ; $test eq $no ; $i++ ) {
2619  
2620 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
2621 my $format = $var_immodpg->{_format_string};
2622 $X[0] = $empty_string;
2623 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
2624  
2625 $X[0] = $immodpg->{_Vbot_multiplied};
2626 $X[1] = $immodpg->{_Vtop_multiplied};
2627 $format = $var_immodpg->{_format_real};
2628 $files->write_1col_aref( \@X, \$outbound, \$format );
2629  
2630 unlink($outbound_locked);
2631 $test = $yes;
2632  
2633 } # if
2634 } # for
2635  
2636 }
2637 else {
2638 print("immodpg, _setVbotNtop_multiply, unexpected answer\n");
2639 }
2640  
2641 return ();
2642 }
2643  
2644 =head2 sub _setVincrement
2645  
2646 Verify another lock file does not exist and
2647 only then:
2648  
2649 Create another lock file
2650 while change file is written
2651 that prevents fortran file from reading.
2652 Then, delete the lock file
2653 Avoids crash between asynchronous
2654 reading (fortran) and
2655 writing (Perl) of files
2656  
2657 =cut
2658  
2659 sub _setVincrement {
2660 my ($Vincrement) = @_;
2661  
2662
2663 if ( $Vincrement ne $empty_string
2664 && $immodpg->{_isVincrement_changed_in_gui} eq $yes )
2665 {
2666  
2667 =head2 instantiate classes
2668  
2669 =cut
2670  
2671 my $files = manage_files_by2->new();
2672 my $control = control->new();
2673  
2674 =head2 Define local
2675 variables
2676  
2677 =cut
2678  
2679 my @X;
2680 my $Vincrement_file = $immodpg->{_Vincrement_file};
2681  
2682 my $test = $no;
2683 my $outbound = $IMMODPG_INVISIBLE . '/' . $Vincrement_file;
2684 my $outbound_locked = $outbound . '_locked';
2685  
2686 for ( my $i = 0 ; $test eq $no ; $i++ ) {
2687  
2688 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
2689
2690 my $format = $var_immodpg->{_format_string};
2691 $X[0] = $empty_string;
2692 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
2693  
2694 $X[0] = $Vincrement;
2695
2696 $format = $var_immodpg->{_format51f};
2697 $files->write_1col_aref( \@X, \$outbound, \$format );
2698  
2699 unlink($outbound_locked);
2700 $test = $yes;
2701  
2702 } # if
2703 } # for
2704  
2705 }
2706 elsif ( $immodpg->{_isVincrement_changed_in_gui} eq $no ) {
2707  
2708 # NADA
2709  
2710 }
2711 else {
2712 print("immodpg, _setVincrement, unexpected answer\n");
2713 }
2714  
2715 return ();
2716 }
2717  
2718  
2719 =head2 sub _set_control
2720 Correct improper values
2721 =cut
2722  
2723 sub _set_control {
2724 my ( $name, $value ) = @_;
2725  
2726 if ( length($name) && length($value) ) {
2727  
2728 # print("immodpg, _set_control, name=$name, value=$value\n");
2729  
2730 if ( $name eq 'Vtop' or $name eq 'Vbot' or $name eq 'Vbot_upper_layer' or $name eq 'Vtop_lower_layer' ) {
2731 $immodpg->{_control_value} = ($value < 0) ? 10 : $value;
2732 }
2733 elsif ( $name eq 'VbotNtop_factor' ) {
2734 $immodpg->{_control_value} = ($value < 0) ? 1 : $value;
2735 }
2736 elsif ( $name eq 'Vincrement' ) {
2737 # Vincrement can be any value (including negative)
2738 $immodpg->{_control_value} = $value;
2739 }
2740 elsif ( $name eq 'clip4plot' or $name eq 'thickness_m' ) {
2741 $immodpg->{_control_value} = ($value < 0) ? 0.1 : $value;
2742 }
2743 elsif ( $name eq 'thickness_increment_m' ) {
2744 $immodpg->{_control_value} = ($value < 0) ? 1 : $value;
2745 }
2746 else {
2747 print("immodpg, _set_control, unexpected name: $name\n");
2748 }
2749 }
2750 else {
2751 print("immodpg, _set_control, missing variable\n");
2752 print("immodpg, _set_control, name=$name\n");
2753 print("immodpg, _set_control, value=$value\n");
2754 }
2755 return ();
2756 }
2757 #=head2 sub _set_control
2758 #Correct improper values
2759 #
2760 #=cut
2761 #
2762 #sub _set_control {
2763 #
2764 # my ( $name, $value ) = @_;
2765 #
2766 # if ( length($name)
2767 # && length($value) )
2768 # {
2769 #
2770 # # print("immodpg, _set_control, name=$name, value=$value\n");
2771 #
2772 # if ( $name eq 'Vtop' ) {
2773 # if ( $value < 0 ) {
2774 #
2775 # $immodpg->{_control_value} = 10;
2776 #
2777 ## print("immodpg, _set_control, new corrected Vtop=$immodpg->{_control_value}\n");
2778 #
2779 # }
2780 # else {
2781 # $immodpg->{_control_value} = $value;
2782 # }
2783 #
2784 # }
2785 # elsif ( $name eq 'Vbot' ) {
2786 # if ( $value < 0 ) {
2787 #
2788 # $immodpg->{_control_value} = 10;
2789 #
2790 ## print("immodpg, _set_control, new corrected Vbot=$immodpg->{_control_value}\n");
2791 #
2792 # }
2793 # else {
2794 # $immodpg->{_control_value} = $value;
2795 # }
2796 #
2797 # }
2798 # elsif ( $name eq 'Vbot_upper_layer' ) {
2799 # if ( $value < 0 ) {
2800 #
2801 # $immodpg->{_control_value} = 10;
2802 #
2803 ## print("immodpg, _set_control, corrected Vbot_upper_layer=$immodpg->{_control_value}\n");
2804 #
2805 # }
2806 # else {
2807 # $immodpg->{_control_value} = $value;
2808 #
2809 ## print("immodpg, _set_control, uncorrected Vbot_upper_layer=$immodpg->{_control_value}\n");
2810 # }
2811 #
2812 # }
2813 # elsif ( $name eq 'VbotNtop_factor' ) {
2814 # if ( $value < 0 ) {
2815 #
2816 # $immodpg->{_control_value} = 1;
2817 #
2818 ## print("immodpg, _set_control, new corrected VbotNtop_factor=$immodpg->{_control_value}\n");
2819 #
2820 # }
2821 # else {
2822 # $immodpg->{_control_value} = $value;
2823 #
2824 ## print("immodpg, _set_control, uncorrected VbotNtop_factor=$immodpg->{_control_value}\n");
2825 # }
2826 # }
2827 # elsif ( $name eq 'Vincrement' ) {
2828 # if ( $value < 0 ) {
2829 #
2830 # # Vincrement is wild
2831 # $immodpg->{_control_value} = $value;
2832 #
2833 ## print("immodpg, _set_control, new corrected Vincrement=$immodpg->{_control_value}\n");
2834 #
2835 # }
2836 # else {
2837 # $immodpg->{_control_value} = $value;
2838 #
2839 ## print("immodpg, _set_control, uncorrected VbotNtop_factor=$immodpg->{_control_value}\n");
2840 # }
2841 #
2842 # }
2843 # elsif ( $name eq 'Vtop_lower_layer' ) {
2844 # if ( $value < 0 ) {
2845 #
2846 # $immodpg->{_control_value} = 10;
2847 #
2848 ## print("immodpg, _set_control, new corrected Vtop_lower_layer=$immodpg->{_control_value}\n");
2849 #
2850 # }
2851 # else {
2852 # $immodpg->{_control_value} = $value;
2853 # }
2854 #
2855 # }
2856 # elsif ( $name eq 'clip4plot' ) {
2857 # if ( $value < 0 ) {
2858 #
2859 # $immodpg->{_control_value} = 0.1;
2860 #
2861 ## print("immodpg, _set_control, new corrected clip4plot=$immodpg->{_control_value}\n");
2862 #
2863 # }
2864 # else {
2865 # $immodpg->{_control_value} = $value;
2866 #
2867 ## print("immodpg, _set_control, uncorrected clip4plot=$immodpg->{_control_value}\n");
2868 # }
2869 #
2870 # }
2871 # elsif ( $name eq 'thickness_m' ) {
2872 # if ( $value < 0 ) {
2873 #
2874 # $immodpg->{_control_value} = 0.1;
2875 #
2876 ## print("immodpg, _set_control, new corrected thickness_m=$immodpg->{_control_value}\n");
2877 #
2878 # }
2879 # else {
2880 # $immodpg->{_control_value} = $value;
2881 # }
2882 #
2883 # }
2884 # elsif ( $name eq 'thickness_increment_m' ) {
2885 # if ( $value < 0 ) {
2886 #
2887 # $immodpg->{_control_value} = 1;
2888 #
2889 ## print("immodpg, _set_control, new corrected thicknessincrement_m=$immodpg->{_control_value}\n");
2890 #
2891 # }
2892 # else {
2893 # $immodpg->{_control_value} = $value;
2894 # }
2895 # }
2896 # else {
2897 # print("immodpg,_setVp_dz, unexpected name \n");
2898 # }
2899 #
2900 # }
2901 # else {
2902 # print("immodpg, _setVp_dz, missing variable\n");
2903 # print("immodpg, _setVp_dz, name=$name\n");
2904 # print("immodpg, _setVp_dz, value=$value\n");
2905 # }
2906 # return ();
2907 #}
2908  
2909 =head2 sub _set_initialVp_dz
2910 Establish the initial values
2911 from the model that will
2912 be used in the gui
2913 initially
2914  
2915 =cut
2916  
2917 sub _set_initialVp_dz {
2918  
2919 my ( $refVPtop, $refVPbot, $ref_dz, $error_switch ) = @_;
2920  
2921 if ( length($refVPtop)
2922 && length($refVPbot)
2923 && length($ref_dz)
2924 && length($error_switch) )
2925 {
2926  
2927 if ( $error_switch eq $on ) {
2928  
2929 print("immodpg, _set_initialVp_dz, corrupt model\n");
2930  
2931 }
2932 elsif ( $error_switch eq $off ) {
2933  
2934 $immodpg->{_refVPtop} = $refVPtop;
2935 $immodpg->{_refVPbot} = $refVPbot;
2936 $immodpg->{_ref_dz} = $ref_dz;
2937 $immodpg->{_error_switch} = $error_switch;
2938  
2939 }
2940 else {
2941 print(
2942 "immodpg, _set_initialVp_dz, unexpected error switch value\n");
2943 }
2944 }
2945 else {
2946 print("immodpg, _set_initialVp_dz, unexpected model values \n");
2947 }
2948 return ();
2949 }
2950  
2951 =head2 sub _setVp_dz
2952 Dynamically collect
2953 values layers, layer velocities and
2954 thicknesses
2955 during interaction with user
2956  
2957 =cut
2958  
2959 sub _setVp_dz {
2960  
2961 my ( $name, $value ) = @_;
2962  
2963 if ( length($name)
2964 && length($value)
2965 && length( $immodpg->{_refVPtop} )
2966 && length( $immodpg->{_refVPbot} )
2967 && length( $immodpg->{_ref_dz} ) )
2968 {
2969  
2970 my $layer_index = $immodpg->{_layer_current} - 1;
2971  
2972 if ( $name eq 'Vtop' ) {
2973  
2974 my $refVPtop = $immodpg->{_refVPtop};
2975 my @VPtop = @$refVPtop;
2976 $VPtop[$layer_index] = $value;
2977  
2978 # print("immodpg, _setVp_dz,Vtop,VPtop[$layer_index]=$VPtop[$layer_index]\n");
2979 $immodpg->{_refVPtop} = \@VPtop;
2980  
2981 }
2982 elsif ( $name eq 'Vtop_lower_layer' ) {
2983  
2984 my $refVPtop = $immodpg->{_refVPtop};
2985 my @VPtop = @$refVPtop;
2986 $VPtop[ ( $layer_index + 1 ) ] = $value;
2987  
2988 # print("immodpg, _setVp_dz,Vtop_lower_layer, VPtop[($layer_index+1)]=$VPtop[($layer_index+1)]\n");
2989 $immodpg->{_refVPtop} = \@VPtop;
2990  
2991 }
2992 elsif ( $name eq 'Vbot' ) {
2993  
2994 # print("immodpg, _setVp_dz,immodpg->{_Vbot_current}= $immodpg->{_Vbot_current}\n");
2995 # print("immodpg, _setVp_dz,immodpg->{_layer_current}= $immodpg->{_layer_current}\n");
2996 my $refVPbot = $immodpg->{_refVPbot};
2997 my @VPbot = @$refVPbot;
2998 $VPbot[$layer_index] = $value;
2999  
3000 # print("immodpg, _setVp_dz,Vbot,VPbot[$layer_index]=$VPbot[$layer_index]\n");
3001 $immodpg->{_refVPbot} = \@VPbot;
3002  
3003 }
3004 elsif ( $name eq 'Vbot_upper_layer' ) {
3005  
3006 my $refVPbot = $immodpg->{_refVPbot};
3007 my @VPbot = @$refVPbot;
3008 $VPbot[ ( $layer_index - 1 ) ] = $value;
3009  
3010 # print("immodpg, _setVp_dz,Vbot_upper_layer,VPbot[($layer_index-1)]=$VPbot[($layer_index-1)]\n");
3011 $immodpg->{_refVPbot} = \@VPbot;
3012  
3013 }
3014 elsif ( $name eq 'thickness_m' ) {
3015  
3016 my $ref_dz = $immodpg->{_ref_dz};
3017 my @dz = @$ref_dz;
3018 $dz[$layer_index] = $value;
3019  
3020 # print("immodpg, _setVp_dz, dz: dz[$layer_index]=$dz[$layer_index]\n");
3021 $immodpg->{_ref_dz} = \@dz;
3022  
3023 }
3024 else {
3025 print("immodpg,_setVp_dz, unexpected name \n");
3026 }
3027 }
3028 else {
3029 print("immodpg, _setVp_dz, missing variable\n");
3030 print("immodpg, _setVp_dz, name=$name\n");
3031 print("immodpg, _setVp_dz, value = $value\n");
3032 print("immodpg, _setVp_dz, _refVPtop = @{$immodpg->{_refVPtop}}\n");
3033 print("immodpg, _setVp_dz, _refVPbot = @{$immodpg->{_refVPbot}}\n");
3034 print("immodpg, _setVp_dz, _dz = $immodpg->{_dz}\n");
3035 }
3036  
3037 return ();
3038 }
3039  
3040 =head2 sub _setVtop
3041  
3042 Verify another lock file does not exist and
3043 only then:
3044  
3045 Create another lock file
3046 while change file is written
3047 that prevents fortran file from reading.
3048 Then, delete the lock file
3049 Avoids crash between asynchronous
3050 reading (fortran) and
3051 writing (Perl) of files
3052  
3053 =cut
3054  
3055 sub _setVtop {
3056  
3057 my ($Vtop) = @_;
3058  
3059 if ( looks_like_number($Vtop)
3060 && $immodpg->{_isVtop_changed_in_gui} eq $yes )
3061 {
3062  
3063 # print("immodpg,_setVtop,write out fortran value of Vtop\n");
3064  
3065 =head2 instantiate classes
3066  
3067 =cut
3068  
3069 my $files = manage_files_by2->new();
3070 my $control = control->new();
3071  
3072 =head2 Define local
3073 variables
3074  
3075 =cut
3076  
3077 my @X;
3078 my $Vtop_file = $immodpg->{_Vtop_file};
3079  
3080 my $test = $no;
3081 my $outbound = $IMMODPG_INVISIBLE . '/' . $Vtop_file;
3082 my $outbound_locked = $outbound . '_locked';
3083  
3084 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3085  
3086 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3087 my $format = $var_immodpg->{_format_string};
3088 $X[0] = $empty_string;
3089 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3090  
3091 $X[0] = $Vtop;
3092 $format = $var_immodpg->{_format_real};
3093 $files->write_1col_aref( \@X, \$outbound, \$format );
3094  
3095 unlink($outbound_locked);
3096 $test = $yes;
3097  
3098 } # if
3099 } # for
3100  
3101 }
3102 elsif ( $immodpg->{_isVtop_changed_in_gui} eq $no ) {
3103  
3104 # NADA
3105 print("immodpg, _setVtop, no change\n");
3106  
3107 }
3108 else {
3109 print("immodpg, _setVtop, unexpected answer\n");
3110 }
3111  
3112 return ();
3113 }
3114  
3115 =head2 sub _setVtop_lower_layer
3116  
3117 Verify another lock file does not exist and
3118 only then:
3119  
3120 Create another lock file
3121 while change file is written
3122 that prevents fortran file from reading.
3123 Then, delete the lock file
3124 Avoids crash between asynchronous
3125 reading (fortran) and
3126 writing (Perl) of files
3127  
3128 =cut
3129  
3130 sub _setVtop_lower_layer {
3131 my ($Vtop_lower_layer) = @_;
3132  
3133 if ( looks_like_number($Vtop_lower_layer)
3134 && $immodpg->{_isVtop_lower_layer_changed_in_gui} eq $yes )
3135 {
3136  
3137 =head2 instantiate classes
3138  
3139 =cut
3140  
3141 my $files = manage_files_by2->new();
3142 my $control = control->new();
3143  
3144 =head2 Define local
3145 variables
3146  
3147 =cut
3148  
3149 my @X;
3150 my $Vtop_lower_layer_file = $immodpg->{_Vtop_lower_layer_file};
3151  
3152 my $test = $no;
3153 my $outbound = $IMMODPG_INVISIBLE . '/' . $Vtop_lower_layer_file;
3154 my $outbound_locked = $outbound . '_locked';
3155  
3156 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3157  
3158 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3159 my $format = $var_immodpg->{_format_string};
3160 $X[0] = $empty_string;
3161 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3162  
3163 $X[0] = $Vtop_lower_layer;
3164 $format = $var_immodpg->{_format_real};
3165 $files->write_1col_aref( \@X, \$outbound, \$format );
3166  
3167 unlink($outbound_locked);
3168 $test = $yes;
3169  
3170 } # if
3171 } # for
3172  
3173 }
3174 elsif ( $immodpg->{_isVtop_lower_layer_changed_in_gui} eq $no ) {
3175  
3176 # NADA
3177  
3178 }
3179 else {
3180 print("immodpg, _setVtop_lower_layer, unexpected answer\n");
3181 }
3182  
3183 return ();
3184 }
3185  
3186 =head2 sub _set_change
3187  
3188 Verify another lock file does not exist and
3189 only then:
3190  
3191 Create another lock file
3192 while change file is written
3193 that prevents fortran file from reading.
3194 Then, delete the lock file
3195 Avoids crash between asynchronous
3196 reading (fortran) and
3197 writing (Perl) of files
3198  
3199 =cut
3200  
3201 sub _set_change {
3202  
3203 my ($yes_or_no) = @_;
3204  
3205 if ( length($yes_or_no)
3206 && length( $immodpg->{_change_file} ) )
3207 {
3208  
3209 # print("immodpg, _set_change, yes_or_no:$yes_or_no\n");
3210  
3211 =head2 instantiate classes
3212  
3213 =cut
3214  
3215 my $files = manage_files_by2->new();
3216 my $control = control->new();
3217  
3218 =head2 Define local
3219 variables
3220  
3221 =cut
3222  
3223 my @X;
3224 my $test = $yes;
3225 my $change = $immodpg->{_change_file};
3226  
3227 my $outbound = $IMMODPG_INVISIBLE . '/' . $change;
3228 my $outbound_locked = $outbound . '_locked';
3229 my $format = $var_immodpg->{_format_string};
3230  
3231 my $count = 0;
3232 my $max_counts = 1000;
3233 for (
3234 my $i = 0 ;
3235 ( $test eq $yes ) and ( $count < $max_counts ) ;
3236 $i++
3237 )
3238 {
3239  
3240 # print("1. immodpg,_set_change, in loop count=$count \n");
3241  
3242 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3243  
3244 $X[0] = $empty_string;
3245 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3246  
3247 # print("immodpg, _set_change, outbound_locked=$outbound_locked\n");
3248 # print("immodpg, _set_change, IMMODPG_INVISIBLE=$IMMODPG_INVISIBLE\n");
3249 # print("immodpg, _set_change, created empty locked file=$X[0]\n");
3250  
3251 # print("immodpg, _set_change, outbound=$outbound\n");
3252 # print("immodpg, _set_change, IMMODPG_INVISIBLE=$IMMODPG_INVISIBLE\n");
3253  
3254 # do not overwrite a waiting change (= yes)
3255 my $response_aref = $files->read_1col_aref( \$outbound );
3256 my $ans = @{$response_aref}[0];
3257  
3258 if ( $ans eq $yes ) {
3259  
3260 # do not overwrite a waiting change (= yes)
3261 # print("2. immodpg, _set_change, SKIP\n");
3262 # print("immodpg, _set_change,do not overwrite change_file\n");
3263  
3264 unlink($outbound_locked);
3265  
3266 }
3267 elsif ( $ans eq $no ) {
3268  
3269 # overwrite change_file(=no) with no or yes
3270 $X[0] = $yes_or_no;
3271 $files->write_1col_aref( \@X, \$outbound, \$format );
3272  
3273 # print("immodpg, _set_change, overwrite change file with $X[0]\n");
3274  
3275 unlink($outbound_locked);
3276  
3277 # print("3. immodpg, _set_change, delete locked file\n");
3278 # print("4. immodpg, _set_change, yes_or_no=$X[0]\n");
3279  
3280 $test = $no;
3281  
3282 }
3283 else {
3284 print("immodpg, _set_change, unexpected result \n");
3285 } # test change_file's content
3286  
3287 }
3288 else {
3289  
3290 # print("immodpg,_set_change, locked change file\n");
3291 $count++; # governor on finding an unlocked change_file
3292 } # if unlocked file is missing and change_file is free
3293  
3294 $count++; # governor on checking for a change_file = yes
3295 } # for
3296  
3297 }
3298 else {
3299 print("immodpg, _set_change, missing values\n");
3300 }
3301 return ();
3302 }
3303  
3304 =head2 sub _set_clip
3305  
3306 Verify another lock file does not exist and
3307 only then:
3308  
3309 Create another lock file
3310 while change file is written
3311 that prevents fortran file from reading.
3312 Then, delete the lock file
3313 Avoids crash between asynchronous
3314 reading (fortran) and
3315 writing (Perl) of files
3316  
3317 =cut
3318  
3319 sub _set_clip {
3320 my ($clip) = @_;
3321  
3322 if ( $clip ne $empty_string
3323 && $immodpg->{_is_clip_changed_in_gui} eq $yes )
3324 {
3325  
3326 =head2 instantiate classes
3327  
3328 =cut
3329  
3330 my $files = manage_files_by2->new();
3331 my $control = control->new();
3332  
3333 =head2 Define local
3334 variables
3335  
3336 =cut
3337  
3338 my @X;
3339 my $clip_file = $immodpg->{_clip_file};
3340  
3341 my $test = $no;
3342 my $outbound = $IMMODPG_INVISIBLE . '/' . $clip_file;
3343 my $outbound_locked = $outbound . '_locked';
3344  
3345 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3346  
3347 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3348 my $format = $var_immodpg->{_format_string};
3349 $X[0] = $empty_string;
3350 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3351  
3352 $X[0] = $clip;
3353 $format = $var_immodpg->{_format51f};
3354 $files->write_1col_aref( \@X, \$outbound, \$format );
3355  
3356 # print("immodpg, _set_clip, output clip = $clip\n");
3357 unlink($outbound_locked);
3358 $test = $yes;
3359  
3360 } # if
3361 } # for
3362  
3363 }
3364 elsif ( $immodpg->{_is_clip_changed_in_gui} eq $no ) {
3365  
3366 # NADA
3367  
3368 }
3369 else {
3370 print("immodpg, _set_clip, unexpected answer\n");
3371 }
3372  
3373 return ();
3374 }
3375  
3376 =head2 sub _set_thickness_m
3377  
3378 Verify another lock file does not exist and
3379 only then:
3380  
3381 Create another lock file
3382 while change file is written
3383 that prevents fortran file from reading.
3384 Then, delete the lock file
3385 Avoids crash between asynchronous
3386 reading (fortran) and
3387 writing (Perl) of files
3388  
3389 =cut
3390  
3391 sub _set_thickness_m {
3392 my ($thickness_m) = @_;
3393  
3394 if ( $thickness_m ne $empty_string
3395 && $immodpg->{_is_thickness_m_changed_in_gui} eq $yes )
3396 {
3397  
3398 =head2 instantiate classes
3399  
3400 =cut
3401  
3402 my $files = manage_files_by2->new();
3403 my $control = control->new();
3404  
3405 =head2 Define local
3406 variables
3407  
3408 =cut
3409  
3410 my @X;
3411 my $thickness_m_file = $immodpg->{_thickness_m_file};
3412  
3413 my $test = $no;
3414 my $outbound = $IMMODPG_INVISIBLE . '/' . $thickness_m_file;
3415 my $outbound_locked = $outbound . '_locked';
3416  
3417 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3418  
3419 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3420 my $format = $var_immodpg->{_format_string};
3421 $X[0] = $empty_string;
3422 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3423  
3424 $X[0] = $thickness_m;
3425 $format = $var_immodpg->{_format51f};
3426 $files->write_1col_aref( \@X, \$outbound, \$format );
3427  
3428 unlink($outbound_locked);
3429 $test = $yes;
3430  
3431 } # if
3432 } # for
3433  
3434 }
3435 elsif ( $immodpg->{_is_thickness_m_changed_in_gui} eq $no ) {
3436  
3437 # NADA
3438  
3439 }
3440 else {
3441 print("immodpg, _set_thickness_m, unexpected answer\n");
3442 }
3443  
3444 return ();
3445 }
3446  
3447 =head2 sub _set_thickness_increment_m
3448  
3449 Verify another lock file does not exist and
3450 only then:
3451  
3452 Create another lock file
3453 while change file is written
3454 that prevents fortran file from reading.
3455 Then, delete the lock file
3456 Avoids crash between asynchronous
3457 reading (fortran) and
3458 writing (Perl) of files
3459  
3460 =cut
3461  
3462 sub _set_thickness_increment_m {
3463 my ($thickness_increment_m) = @_;
3464  
3465 if ( $thickness_increment_m ne $empty_string
3466 && $immodpg->{_is_layer_changed_in_gui} eq $yes )
3467 {
3468  
3469 =head2 instantiate classes
3470  
3471 =cut
3472  
3473 my $files = manage_files_by2->new();
3474 my $control = control->new();
3475  
3476 =head2 Define local
3477 variables
3478  
3479 =cut
3480  
3481 my @X;
3482 my $thickness_increment_m_file =
3483 $immodpg->{_thickness_increment_m_file};
3484  
3485 my $test = $no;
3486 my $outbound = $IMMODPG_INVISIBLE . '/' . $thickness_increment_m_file;
3487 my $outbound_locked = $outbound . '_locked';
3488  
3489 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3490  
3491 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3492 my $format = $var_immodpg->{_format_string};
3493 $X[0] = $empty_string;
3494 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3495  
3496 $X[0] = $thickness_increment_m;
3497 print("thickness_increment_m=$thickness_increment_m\n");
3498 $format = $var_immodpg->{_format51f};
3499 $files->write_1col_aref( \@X, \$outbound, \$format );
3500  
3501 unlink($outbound_locked);
3502 $test = $yes;
3503  
3504 } # if
3505 } # for
3506  
3507 }
3508 elsif ( $immodpg->{_is_layer_changed_in_gui} eq $no ) {
3509  
3510 # NADA
3511  
3512 }
3513 else {
3514 print("immodpg, _set_thickness_increment_m, unexpected answer\n");
3515 }
3516  
3517 return ();
3518 }
3519  
3520 =head2 sub _fortran_layer
3521  
3522 set layer
3523 Verify another lock file does not exist and
3524 only then:
3525  
3526 Create another lock file
3527 while change file is written
3528 that prevents fortran file from reading.
3529 Then, delete the lock file
3530 Avoids crash between asynchronous
3531 reading (fortran) and
3532 writing (Perl) of files
3533  
3534  
3535 =cut
3536  
3537 sub _fortran_layer {
3538 my ($layer) = @_;
3539  
3540 if ( $layer ne $empty_string
3541 && $immodpg->{_is_layer_changed_in_gui} eq $yes )
3542 {
3543  
3544 =head2 instantiate classes
3545  
3546 =cut
3547  
3548 my $files = manage_files_by2->new();
3549 my $control = control->new();
3550  
3551 =head2 Define local
3552 variables
3553  
3554 =cut
3555  
3556 my @X;
3557 my $layer_file = $immodpg->{_layer_file};
3558  
3559 my $test = $no;
3560 my $outbound = $IMMODPG_INVISIBLE . '/' . $layer_file;
3561 my $outbound_locked = $outbound . '_locked';
3562  
3563 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3564  
3565 # print("in loop \n");
3566  
3567 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3568 my $format = $var_immodpg->{_format_string};
3569 $X[0] = $empty_string;
3570 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3571  
3572 $X[0] = $layer;
3573 $format = $var_immodpg->{_format_integer};
3574 $files->write_1col_aref( \@X, \$outbound, \$format );
3575 unlink($outbound_locked);
3576  
3577 $test = $yes;
3578 } # if
3579 } # for
3580  
3581 }
3582 elsif ( $immodpg->{_is_layer_changed_in_gui} eq $no ) {
3583  
3584 # NADA
3585  
3586 }
3587 else {
3588 print("immodpg, _fortran_layer, unexpected answer\n");
3589 }
3590  
3591 return ();
3592  
3593 }
3594  
3595 =head2 sub set_working_model_bin
3596  
3597 =cut
3598  
3599 sub _set_working_model_bin {
3600 my ($self) = @_;
3601  
3602 # print("l3171 $immodpg->{_working_model_bin_opt} \n");
3603 _set_option($change_working_model_bin_opt);
3604 _set_change($yes);
3605  
3606 return ();
3607 }
3608  
3609 =head2 sub set_working_model_text
3610  
3611 =cut
3612  
3613 sub _set_working_model_text {
3614  
3615 _set_option($change_working_model_text_opt);
3616 _set_change($yes);
3617  
3618 return ();
3619 }
3620  
3621 =head2 sub _set_clip_control
3622 value adjusts to current
3623 clip value in use
3624  
3625 =cut
3626  
3627 sub _set_clip_control {
3628  
3629 my ($control_clip) = @_;
3630  
3631 my $result;
3632  
3633 if ( length($control_clip) ) {
3634  
3635 $immodpg->{_control_clip} = $control_clip;
3636  
3637 # print("immodpg,_set_clip_control, control_clip=$immodpg->{_control_clip}\n");
3638  
3639 }
3640 elsif ( not( length($control_clip) ) ) {
3641  
3642 # print("immodpg,_set_clip_control, empty string\n");
3643 $immodpg->{_control_clip} = $control_clip;
3644  
3645 }
3646 else {
3647 print("immodpg,_set_clip_control, missing value\n");
3648 }
3649  
3650 return ();
3651 }
3652  
3653 =head2 sub _set_layer_control
3654 value adjusts to current
3655 layer number in use
3656  
3657 =cut
3658  
3659 sub _set_layer_control {
3660  
3661 my ($control_layer) = @_;
3662  
3663 my $result;
3664  
3665 if ( length($control_layer) ) {
3666  
3667 $immodpg->{_control_layer} = $control_layer;
3668  
3669 # print("immodpg,_set_layer_control, control_layer=$immodpg->{_control_layer}\n");
3670  
3671 }
3672 elsif ( not( length($control_layer) ) ) {
3673  
3674 # print("immodpg,_set_layer_control, empty string\n");
3675 $immodpg->{_control_layer} = $control_layer;
3676  
3677 }
3678 else {
3679 print("immodpg,_set_layer_control, missing value\n");
3680 }
3681  
3682 return ();
3683 }
3684  
3685 =head2 sub _get_model_control
3686 is there an error with the model?
3687  
3688 =cut
3689  
3690 sub _get_model_control {
3691  
3692 my ($self) = @_;
3693  
3694 my $result = $off;
3695  
3696 if ( length( $immodpg->{_model_error} ) ) {
3697  
3698 $result = $immodpg->{_model_error};
3699  
3700 }
3701 else {
3702 print(
3703 "immodpg,get_model_control,num_layers=unexpected missing value\n");
3704 }
3705  
3706 return ($result);
3707  
3708 }
3709  
3710 =head2 sub set_model_control
3711 find out if there is an error in the binary
3712 fortran model
3713  
3714 =cut
3715  
3716 sub _set_model_control {
3717  
3718 my ( $refVPbot, $refVPtop, $ref_VSbot, $ref_VStop, $ref_density_bot,
3719 $ref_density_top, $ref_dz )
3720 = @_;
3721  
3722 my $result = '';
3723 my $error_switch = $off;
3724  
3725 if ( length($refVPbot)
3726 and length($refVPtop)
3727 and length($ref_VSbot)
3728 and length($ref_VStop)
3729 and length($ref_density_bot)
3730 and length($ref_density_top)
3731 and length($ref_dz) )
3732 {
3733  
3734 my @VSbot = @$ref_VSbot;
3735 my @VStop = @$ref_VStop;
3736 my @VPbot = @$refVPbot;
3737 my @VPtop = @$refVPtop;
3738 my @density_bot = @$ref_density_bot;
3739 my @density_top = @$ref_density_top;
3740 my @dz = @$ref_dz;
3741 my $number_of_layers = scalar @$refVPbot;
3742  
3743 # print("immodpg,set_model_control,num_layers=$number_of_layers\n");
3744 if ( $number_of_layers > 1 ) {
3745  
3746 for (
3747 my $layer_index = 0 ;
3748 $layer_index < $number_of_layers ;
3749 $layer_index++
3750 )
3751 {
3752  
3753 if ( $VStop[$layer_index] < 0
3754 or $VSbot[$layer_index] < 0
3755 or $VPtop[$layer_index] < 0
3756 or $VPbot[$layer_index] < 0
3757 or $density_bot[$layer_index] < 0
3758 or $density_top[$layer_index] < 0
3759 or $dz[$layer_index] < 0 )
3760 {
3761  
3762 $error_switch = $on;
3763  
3764 }
3765 else {
3766  
3767 # print("immodpg,_get_initial_model, TEST OK NADA\n");
3768 }
3769 } # end for loop
3770  
3771 if ( $error_switch eq $on ) {
3772  
3773 # print("immodpg,set_model_control, CORRUPT MODEL\n");
3774 $immodpg->{_model_error} = $error_switch;
3775 }
3776  
3777 return ($result);
3778  
3779 }
3780 else {
3781 print("immodpg, _set_model_control, error with layer number\n");
3782 return ($result);
3783 }
3784  
3785 }
3786 else {
3787 print("immodpg, _set_model_control, unexpected model error\n");
3788 return ($result);
3789 }
3790  
3791 }
3792  
3793 =head2 _set_model_layer
3794 Set the number of layers in
3795 mmodpg
3796  
3797 =cut
3798  
3799 sub _set_model_layer {
3800  
3801 my ($model_layer_number) = @_;
3802  
3803 if ( $model_layer_number != 0
3804 && length($model_layer_number) )
3805 {
3806  
3807 $immodpg->{_model_layer_number} = $model_layer_number;
3808  
3809 }
3810 else {
3811 print("immodpg, _set_model_layer, unexpected layer# \n");
3812 }
3813  
3814 # print("immodpg, _set_model_layer,model layer# =$immodpg->{_model_layer_number}\n");
3815  
3816 return ();
3817 }
3818  
3819 =head2 sub _set_option
3820  
3821 Verify another lock file does not exist and
3822 only then:
3823  
3824 Create another lock file
3825 while change file is written
3826 that prevents fortran file from reading.
3827 Then, delete the lock file
3828 Avoids crash between asynchronous
3829 reading (fortran) and
3830 writing (Perl) of files
3831  
3832  
3833 =cut
3834  
3835 sub _set_option {
3836  
3837 my ($option) = @_;
3838  
3839 # print("1.immodpg,_set_option,option:$option\n");
3840  
3841 if ( defined($option)
3842 && $immodpg->{_option_file} ne $empty_string )
3843 {
3844  
3845 =head2 instantiate classes
3846  
3847 =cut
3848  
3849 my $files = manage_files_by2->new();
3850 my $control = control->new();
3851  
3852 =head2 Define local variables
3853  
3854 =cut
3855  
3856 my @X;
3857 my $option_file = $immodpg->{_option_file};
3858  
3859 my $test = $no;
3860 my $outbound = $IMMODPG_INVISIBLE . '/' . $option_file;
3861 my $outbound_locked = $outbound . '_locked';
3862  
3863 for ( my $i = 0 ; $test eq $no ; $i++ ) {
3864  
3865 # print("immodpg,_set_option, in loop \n");
3866  
3867 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
3868 my $format = $var_immodpg->{_format_string};
3869 $X[0] = $empty_string;
3870 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
3871  
3872 $X[0] = $option;
3873 $format = $var_immodpg->{_format2i};
3874  
3875 # print("2.immodpg,_set_option,option:$option\n");
3876 $files->write_1col_aref( \@X, \$outbound, \$format );
3877  
3878 unlink($outbound_locked);
3879  
3880 $test = $yes;
3881 } # if
3882 } # for
3883  
3884 }
3885 elsif ( $immodpg->{_is_option_changed} eq $no ) {
3886 # NADA
3887 }
3888 else {
3889 print("immodpg, _set_option, unexpected answer\n");
3890 }
3891 return ();
3892 }
3893  
3894 =head2 sub _updateVbot
3895  
3896 keep tabs on Vbot values
3897 and changes in the values in the
3898 GUI
3899 Also updates an shared copy
3900 of the model properties
3901  
3902 use App::SeismicUnixGui::misc::control '0.0.3' method to check for bad values;
3903  
3904 =cut
3905  
3906 sub _updateVbot {
3907  
3908 my ($self) = @_;
3909  
3910 if ( looks_like_number( $immodpg->{_Vbot_current} )
3911 and looks_like_number( $immodpg->{_Vbot_prior} )
3912 && $immodpg->{_Vbot_current} != $immodpg->{_Vbot_prior} )
3913 {
3914  
3915 # CASE Vbot has changed
3916 $immodpg->{_isVbot_changed_in_gui} = $yes;
3917 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
3918  
3919 # print("immodpg, _updateVbot, has changed\n");
3920 # print("1. immodpg,_updateVbot,Vbot_current=$immodpg->{_Vbot_current}\n");
3921 # print("1. immodpg,_updateVbot,Vbot_prior=$immodpg->{_Vbot_prior}\n");
3922  
3923 _set_control( 'Vbot', $immodpg->{_Vbot_current} );
3924 $immodpg->{_Vbot_current} = _get_control('Vbot');
3925  
3926 _setVp_dz( 'Vbot', $immodpg->{_Vbot_current} );
3927  
3928 return ();
3929  
3930 }
3931 elsif ( $immodpg->{_Vbot_current} == $immodpg->{_Vbot_prior} ) {
3932  
3933 # CASE Vbot is unchanged
3934 # print("immodpg, _updateVbot, unchanged\n");
3935 $immodpg->{_isVbot_changed_in_gui} = $no;
3936  
3937 # print("2. immodpg,_updateVbot,Vbot_current=$immodpg->{_Vbot_current}\n");
3938 # print("2. immodpg,_updateVbot,Vbot_prior=$immodpg->{_Vbot_prior}\n");
3939 return ();
3940  
3941 }
3942 else {
3943 print("immodpg, _updateVbot, unexpected\n");
3944 return ();
3945 }
3946 }
3947  
3948 =head2 sub _updateVbot_upper_layer
3949  
3950 keep tabs on upper layer Vbottom values
3951 and changes in the values in the
3952 GUI
3953 current layer must >0
3954  
3955 =cut
3956  
3957 sub _updateVbot_upper_layer {
3958  
3959 my ($self) = @_;
3960  
3961 # print("mmodpg, _updateVbot_upper_layer, Vbot_upper_layer_current=..$immodpg->{_Vbot_upper_layer_current}..\n");
3962 if ( looks_like_number( $immodpg->{_Vbot_upper_layer_current} )
3963 && $immodpg->{_layer_current} > 0
3964 && $immodpg->{_Vbot_upper_layer_current} !=
3965 $immodpg->{_Vbot_upper_layer_prior} )
3966 {
3967  
3968 # CASE Vbot_upper_layer changed
3969 $immodpg->{_isVbot_upper_layer_changed_in_gui} = $yes;
3970 $immodpg->{_Vbot_upper_layer_prior} =
3971 $immodpg->{_Vbot_upper_layer_current};
3972  
3973 # print("immodpg, _updateVbot_upper_layer, updated to $immodpg->{_Vbot_upper_layer_current}\n");
3974 # print("immodpg,_updateVbot_upper_layer,Vbot_upper_layer_current=$immodpg->{_Vbot_upper_layer_current}\n");
3975 # print("immodpg,_updateVbot_upper_layer,Vbot_upper_layer_prior=$immodpg->{_Vbot_upper_layer_prior}\n");
3976 _set_control( 'Vbot_upper_layer',
3977 $immodpg->{_Vbot_upper_layer_current} );
3978 $immodpg->{_Vbot_upper_layer_current} =
3979 _get_control('Vbot_upper_layer');
3980  
3981 _setVp_dz( 'Vbot_upper_layer', $immodpg->{_Vbot_upper_layer_current} );
3982 return ();
3983  
3984 }
3985 elsif ( looks_like_number( $immodpg->{_Vbot_upper_layer_current} )
3986 && $immodpg->{_Vbot_upper_layer_current} ==
3987 $immodpg->{_Vbot_upper_layer_prior} )
3988 {
3989  
3990 # CASE Vbot_upper_layer is unchanged
3991 # print("immodpg, _updateVbot_upper_layer, unchanged\n");
3992 $immodpg->{_isVbot_upper_layer_changed_in_gui} = $no;
3993  
3994 # print("immodpg,_updateVbot_upper_layer,Vbot_upper_layer_prior=$immodpg->{_Vbot_upper_layer_prior}\n");
3995 return ();
3996  
3997 }
3998 elsif ( not( looks_like_number( $immodpg->{_Vbot_upper_layer_current} ) ) )
3999 {
4000  
4001 # CASE Vbot_upper_layer is unchanged
4002 # print("immodpg, _updateVbot_upper_layer, no value in Vbot_upper_layer NADA\n");
4003 # print("immodpg,_updateVbot_upper_layer,Vbot_upper_layer_prior=$immodpg->{_Vbot_upper_layer_prior}\n");
4004 return ();
4005  
4006 }
4007 else {
4008 print("immodpg, _updateVbot_upper_layer, unexpected\n");
4009  
4010 # print("immodpg,_updateVbot_upper_layer,Vbot_upper_layer_current=$immodpg->{_Vbot_upper_layer_current}\n");
4011 return ();
4012 }
4013 }
4014  
4015 =head2 sub _update_Vincrement
4016  
4017 keep tabs on Vincrement values
4018 and changes in the values in the
4019 GUI
4020  
4021 =cut
4022  
4023 sub _updateVincrement {
4024  
4025 my ($self) = @_;
4026  
4027 if ( looks_like_number( $immodpg->{_Vincrement_current} )
4028 && $immodpg->{_Vincrement_current} != $immodpg->{_Vincrement_prior} )
4029 {
4030  
4031 # CASE Vincrement changed
4032 $immodpg->{_Vincrement_current} = $immodpg->{_Vincrement_current};
4033 $immodpg->{_isVincrement_changed_in_gui} = $yes;
4034  
4035 # print("immodpg, _updateVincrement, updated to $immodpg->{_Vincrement_current}\n");
4036  
4037 # print("immodpg,_updateVincrement,Vincrement_current=$immodpg->{_Vincrement_current}\n");
4038 # print("immodpg,_updateVincrement,Vincrement_prior=$immodpg->{_Vincrement_prior}\n");
4039 return ();
4040  
4041 }
4042 elsif ( $immodpg->{_Vincrement_current} == $immodpg->{_Vincrement_prior} ) {
4043  
4044 # CASE Vincrement is unchanged
4045 # print("immodpg, _updateVincrement, unchanged\n");
4046 $immodpg->{_isVincrement_changed_in_gui} = $no;
4047  
4048 # print("immodpg,_updateVincrement,Vincrement_current=$immodpg->{_Vincrement_current}\n");
4049 # print("immodpg,_updateVincrement,Vincrement_prior=$immodpg->{_Vincrement_prior}\n");
4050 return ();
4051  
4052 }
4053 else {
4054 print("immodpg, _updateVincrement, unexpected\n");
4055 return ();
4056 }
4057 }
4058  
4059 =head2 sub _updateVtop
4060  
4061 keep tabs on Vtop values
4062 and changes in the values in the
4063 GUI
4064 Also updates an shared copy
4065 of the model properties
4066  
4067 =cut
4068  
4069 sub _updateVtop {
4070  
4071 my ($self) = @_;
4072  
4073 if ( looks_like_number( $immodpg->{_Vtop_current} )
4074 && $immodpg->{_Vtop_current} != $immodpg->{_Vtop_prior} )
4075 {
4076  
4077 # CASE Vtop changed
4078 $immodpg->{_isVtop_changed_in_gui} = $yes;
4079 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
4080  
4081 # print("immodpg, _updateVtop, updated to $immodpg->{_Vtop_current}\n");
4082 # print("immodpg,_updateVtop,Vtop_current=$immodpg->{_Vtop_current}\n");
4083 # print("immodpg,_updateVtop,Vtop_prior=$immodpg->{_Vtop_prior}\n");
4084  
4085 _set_control( 'Vtop', $immodpg->{_Vtop_current} );
4086 $immodpg->{_Vtop_current} = _get_control('Vtop');
4087 _setVp_dz( 'Vtop', $immodpg->{_Vtop_current} );
4088  
4089 return ();
4090  
4091 }
4092 elsif ( $immodpg->{_Vtop_current} == $immodpg->{_Vtop_prior} ) {
4093  
4094 # CASE Vtop is unchanged
4095 # print("immodpg, _updateVtop, unchanged\n");
4096 $immodpg->{_isVtop_changed_in_gui} = $no;
4097  
4098 # print("immodpg,_updateVtop,Vtop_current=$immodpg->{_Vtop_current}\n");
4099 # print("immodpg,_updateVtop,Vtop_prior=$immodpg->{_Vtop_prior}\n");
4100 return ();
4101  
4102 }
4103 else {
4104 print("immodpg, _updateVtop, unexpected\n");
4105 return ();
4106 }
4107 }
4108  
4109 =head2 sub _updateVtop_lower_layer
4110  
4111 keep tabs on Vtop_lower_layer values
4112 and changes in the values in the
4113 GUI
4114 Also updates an shared copy
4115 of the model properties
4116  
4117 =cut
4118  
4119 sub _updateVtop_lower_layer {
4120  
4121 my ($self) = @_;
4122  
4123 if ( looks_like_number( $immodpg->{_Vtop_lower_layer_current} )
4124 && $immodpg->{_Vtop_lower_layer_current} !=
4125 $immodpg->{_Vtop_lower_layer_prior} )
4126 {
4127  
4128 # CASE Vtop changed
4129 # print("immodpg, _updateVtop_lower_layer, Vcurrent=$immodpg->{_Vtop_lower_layer_current}\n");
4130 $immodpg->{_isVtop_lower_layer_changed_in_gui} = $yes;
4131 $immodpg->{_Vtop_lower_layer_prior} =
4132 $immodpg->{_Vtop_lower_layer_current};
4133  
4134 # print("immodpg, _updateVtop_lower_layer, changed\n");
4135 _set_control( 'Vtop_lower_layer',
4136 $immodpg->{_Vtop_lower_layer_current} );
4137 $immodpg->{_Vtop_lower_layer_current} =
4138 _get_control('Vtop_lower_layer');
4139  
4140 _setVp_dz( 'Vtop_lower_layer', $immodpg->{_Vtop_lower_layer_current} );
4141  
4142 return ();
4143  
4144 }
4145 elsif ( $immodpg->{_Vtop_lower_layer_current} ==
4146 $immodpg->{_Vtop_lower_layer_prior} )
4147 {
4148  
4149 # CASE Vtop_lower_layer is unchanged
4150 # print("immodpg, _updateVtop_lower_layer, unchanged\n");
4151 # print("immodpg, _updateVtop_lower_layer, Vcurrent=$immodpg->{_Vtop_lower_layer_current}\n");
4152 $immodpg->{_isVtop_lower_layer_changed_in_gui} = $no;
4153  
4154 return ();
4155  
4156 }
4157 else {
4158 print("immodpg, _updateVtop_lower_layer, unexpected\n");
4159 return ();
4160 }
4161 }
4162  
4163 =head2 sub _updateVbotNtop_factor
4164  
4165 keep tabs on VbotNtop_factor values
4166 and changes in the values in the
4167 GUI
4168  
4169 =cut
4170  
4171 sub _updateVbotNtop_factor {
4172  
4173 my ($self) = @_;
4174  
4175 if ( looks_like_number( $immodpg->{_VbotNtop_factor_current} )
4176 && $immodpg->{_VbotNtop_factor_current} !=
4177 $immodpg->{_VbotNtop_factor_prior} )
4178 {
4179  
4180 # CASE VbotNtop_factor changed
4181 # $immodpg->{_VbotNtop_factor_current} = $immodpg->{_VbotNtop_factor_current};
4182 _set_control( 'VbotNtop_factor', $immodpg->{_VbotNtop_factor_current} );
4183 $immodpg->{_VbotNtop_factor_current} = _get_control('VbotNtop_factor');
4184 $immodpg->{_isVbotNtop_factor_changed_in_gui} = $yes;
4185  
4186 # print("immodpg, _updateVbotNtop_factor, updated to $immodpg->{_VbotNtop_factor_current}\n");
4187 # print("immodpg,_updateVbotNtop_factor,VbotNtop_factor_current=$immodpg->{_VbotNtop_factor_current}\n");
4188 # print("immodpg,_updateVbotNtop_factor,VbotNtop_factor_prior=$immodpg->{_VbotNtop_factor_prior}\n");
4189 return ();
4190  
4191 }
4192 elsif ( $immodpg->{_VbotNtop_factor_current} ==
4193 $immodpg->{_VbotNtop_factor_prior} )
4194 {
4195  
4196 # CASE VbotNtop_factor is unchanged
4197 # print("immodpg, _updateVbotNtop_factor, unchanged\n");
4198 $immodpg->{_isVbotNtop_factor_changed_in_gui} = $no;
4199  
4200 # print("immodpg,_updateVbotNtop_factor,VbotNtop_factor_current=$immodpg->{_VbotNtop_factor_current}\n");
4201 # print("immodpg,_updateVbotNtop_factor,VbotNtop_factor_prior=$immodpg->{_VbotNtop_factor_prior}\n");
4202 return ();
4203  
4204 }
4205 else {
4206 print("immodpg, _updateVbotNtop_factor, unexpected\n");
4207 return ();
4208 }
4209 }
4210  
4211 =head2 sub _updateVbotNtop_multiply
4212  
4213 keep tabs on Vbot AND Vtop values together
4214 and changes in the values in the
4215 GUI
4216 Also updates an shared copy
4217 of the model properties
4218  
4219 =cut
4220  
4221 sub _updateVbotNtop_multiply {
4222  
4223 my ($self) = @_;
4224  
4225 if ( looks_like_number( $immodpg->{_Vbot_current} )
4226 && looks_like_number( $immodpg->{_Vtop_current} )
4227 && looks_like_number( $immodpg->{_Vbot_multiplied} )
4228 && looks_like_number( $immodpg->{_Vtop_multiplied} ) )
4229 {
4230  
4231 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
4232 $immodpg->{_Vbot_current} = $immodpg->{_Vbot_multiplied};
4233  
4234 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
4235 $immodpg->{_Vtop_current} = $immodpg->{_Vtop_multiplied};
4236  
4237 _set_control( 'Vbot', $immodpg->{_Vbot_current} );
4238 $immodpg->{_Vbot_current} = _get_control('Vbot');
4239  
4240 _set_control( 'Vtop', $immodpg->{_Vtop_current} );
4241 $immodpg->{_Vtop_current} = _get_control('Vtop');
4242  
4243 # conveniently short variable names
4244 my $Vtop_current = $immodpg->{_Vtop_current};
4245 my $Vbot_current = $immodpg->{_Vbot_current};
4246  
4247 $immodpg->{_VtopEntry}->delete( 0, 'end' );
4248 $immodpg->{_VtopEntry}->insert( 0, $Vtop_current );
4249 $immodpg->{_VbotEntry}->delete( 0, 'end' );
4250 $immodpg->{_VbotEntry}->insert( 0, $Vbot_current );
4251  
4252 # print("immodpg, _updateVbotNtop_multiply, updated to $immodpg->{_VbotNtop_multiply_current}\n");
4253 # print("immodpg,_updateVbotNtop_multiply,VbotNtop_multiply_current=$immodpg->{_VbotNtop_multiply_current}\n");
4254 # print("immodpg,_updateVbotNtop_multiply,VbotNtop_multiply_prior=$immodpg->{_VbotNtop_multiply_prior}\n");
4255 # _checkVbot(); #todo
4256 _updateVbot();
4257  
4258 # _checkVtop(); #todo
4259 _updateVtop();
4260  
4261 }
4262 else {
4263 print("immodpg, _updateVbotNtop_factor, unexpected\n");
4264 return ();
4265 }
4266 }
4267  
4268 =head2 sub _update_clip
4269  
4270 keep tabs on clip values
4271 and changes in the values in the
4272 GUI
4273  
4274 =cut
4275  
4276 sub _update_clip {
4277  
4278 my ($self) = @_;
4279  
4280 if ( looks_like_number( $immodpg->{_clip4plot_current} )
4281 && $immodpg->{_clip4plot_current} != $immodpg->{_clip4plot_prior} )
4282 {
4283  
4284 # CASE clip changed
4285 $immodpg->{_clip4plot_current} = $immodpg->{_clip4plot_current};
4286 $immodpg->{_is_clip_changed_in_gui} = $yes;
4287  
4288 # print("immodpg, _update_clip, updated to $immodpg->{_clip4plot_current}\n");
4289 # print("immodpg,_update_clip,clip4plot_current=$immodpg->{_clip4plot_current}\n");
4290 # print("immodpg,_update_clip,clip4plot_prior=$immodpg->{_clip4plot_prior}\n");
4291 return ();
4292  
4293 }
4294 elsif ( $immodpg->{_clip4plot_current} == $immodpg->{_clip4plot_prior} ) {
4295  
4296 # CASE clip4plot is unchanged
4297 # print("immodpg, _update_clip, unchanged\n");
4298 $immodpg->{_is_clip_changed_in_gui} = $no;
4299  
4300 # print("immodpg,_update_clip,clip4plot_current=$immodpg->{_clip4plot_current}\n");
4301 # print("immodpg,_update_clip,clip4plot_prior=$immodpg->{_clip4plot_prior}\n");
4302 return ();
4303  
4304 }
4305 else {
4306 print("immodpg, _update_clip, unexpected\n");
4307 return ();
4308 }
4309 }
4310  
4311 =head2 sub _update_thickness_m
4312  
4313 keep tabs on thickness_m values
4314 and changes in the values in the
4315 GUI
4316 Also updates an shared copy
4317 of the model properties
4318  
4319 =cut
4320  
4321 sub _update_thickness_m {
4322  
4323 my ($self) = @_;
4324  
4325 if ( looks_like_number( $immodpg->{_thickness_m_current} )
4326 && $immodpg->{_thickness_m_current} != $immodpg->{_thickness_m_prior} )
4327 {
4328  
4329 # CASE _thickness_m changed
4330 $immodpg->{_is_thickness_m_changed_in_gui} = $yes;
4331  
4332 # print("immodpg, _update_thickness_m, updated to $immodpg->{_thickness_m_current}\n");
4333 # print("immodpg,_update_thickness_m,_thickness_m_current=$immodpg->{_thickness_m_current}\n");
4334 # print("immodpg,_update_thickness_m,_thickness_m_prior=$immodpg->{_thickness_m_prior}\n");
4335  
4336 _set_control( 'thickness_m', $immodpg->{_thickness_m_current} );
4337 $immodpg->{_thickness_m_current} = _get_control('thickness_m');
4338 _setVp_dz( 'thickness_m', $immodpg->{_thickness_m_current} );
4339  
4340 return ();
4341  
4342 }
4343 elsif ( $immodpg->{_thickness_m_current} == $immodpg->{_thickness_m_prior} )
4344 {
4345  
4346 # CASE _thickness_m is unchanged
4347 # print("immodpg, _update_thickness_m, unchanged\n");
4348 $immodpg->{_is_thickness_m_changed_in_gui} = $no;
4349  
4350 # print("immodpg,_update_thickness_m,_thickness_m_current=$immodpg->{_thickness_m_current}\n");
4351 # print("immodpg,_update_thickness_m,_thickness_m_prior=$immodpg->{_thickness_m_prior}\n");
4352 return ();
4353  
4354 }
4355 else {
4356 print("immodpg, _update_thickness_m, unexpected\n");
4357 return ();
4358 }
4359 }
4360  
4361 =head2 sub _update_thickness_increment_m_in_gui
4362  
4363 keep tabs on thickness_increment_m values
4364 and changes in the values in the
4365 GUI
4366  
4367 =cut
4368  
4369 sub _update_thickness_increment_m_in_gui {
4370  
4371 my ($self) = @_;
4372  
4373 if ( looks_like_number( $immodpg->{_thickness_increment_m_current} )
4374 && $immodpg->{_thickness_increment_m_current} !=
4375 $immodpg->{_thickness_increment_m_prior} )
4376 {
4377  
4378 # CASE thickness changed
4379 $immodpg->{_thickness_increment_m_prior} =
4380 $immodpg->{_thickness_increment_m_current};
4381 $immodpg->{_is_layer_changed_in_gui} = $yes;
4382  
4383 # print("immodpg, _update_thickness_increment_m_in_gui, updated to $immodpg->{_thickness_increment_m_current}\n");
4384 # print("immodpg,_update_thickness_increment_m_in_gui,thickness_increment_m_current=$immodpg->{_thickness_increment_m_current}\n");
4385 # print("immodpg,_update_thickness_increment_m_in_gui,thickness_increment_m_prior=$immodpg->{_thickness_increment_m_prior}\n");
4386 return ();
4387  
4388 }
4389 elsif ( $immodpg->{_thickness_increment_m_current} ==
4390 $immodpg->{_thickness_increment_m_prior} )
4391 {
4392  
4393 # CASE thickness_increment_m is unchanged
4394 # print("immodpg, _update_thickness_increment_m_in_gui, unchanged\n");
4395 $immodpg->{_is_layer_changed_in_gui} = $no;
4396  
4397 # print("immodpg,_update_thickness_increment_m_in_gui,thickness_increment_m_current=$immodpg->{_thickness_increment_m_current}\n");
4398 # print("immodpg,_update_thickness_increment_m_in_gui,thickness_increment_m_prior=$immodpg->{_thickness_increment_m_prior}\n");
4399 return ();
4400  
4401 }
4402 else {
4403 print("immodpg, _update_thickness_increment_m_in_gui, unexpected\n");
4404 return ();
4405 }
4406 }
4407  
4408 =head2 sub _update_layer_in_gui
4409  
4410 keep tabs on layer values
4411 and changes in the values in the
4412 GUI
4413  
4414 update prior in advance of _check_layer
4415  
4416 =cut
4417  
4418 sub _update_layer_in_gui {
4419  
4420 my ($self) = @_;
4421  
4422 if (
4423 looks_like_number( $immodpg->{_layer_current} )
4424 and length(
4425 $immodpg->{_layer_prior} and length( $immodpg->{_layerEntry} )
4426 )
4427 and ( $immodpg->{_layer_current} != $immodpg->{_layer_prior} )
4428 )
4429 {
4430  
4431 # CASE layer changed
4432 $immodpg->{_is_layer_changed_in_gui} = $yes;
4433 my $layer_current = $immodpg->{_layer_current};
4434 my $new_layer_prior = $immodpg->{_layer_current};
4435  
4436 $immodpg->{_layerEntry}->delete( 0, 'end' );
4437 $immodpg->{_layerEntry}->insert( 0, $layer_current );
4438  
4439 $immodpg->{_layer_prior} = $new_layer_prior;
4440  
4441 # print("immodpg, _update_layer_in_gui, prior=$immodpg->{_layer_prior}current= $immodpg->{_layer_current}\n");
4442  
4443 return ();
4444  
4445 }
4446 elsif ( looks_like_number( $immodpg->{_layer_current} )
4447 and looks_like_number( $immodpg->{_layer_prior} )
4448 and ( $immodpg->{_layer_current} == $immodpg->{_layer_prior} ) )
4449 {
4450  
4451 # CASE layer has not changed
4452 # print("immodpg, _update_layer_in_gui, unchanged\n");
4453 $immodpg->{_is_layer_changed_in_gui} = $no;
4454  
4455 $immodpg->{_layerEntry}->delete( 0, 'end' );
4456 $immodpg->{_layerEntry}->insert( 0, $immodpg->{_layer_current} );
4457  
4458 # print("immodpg,_update_layer_in_gui, prior=$immodpg->{_layer_prior},current=$immodpg->{_layer_current}\n");
4459 return ();
4460  
4461 }
4462 else {
4463 print("immodpg, _update_layer_in_gui, unexpected\n");
4464 return ();
4465 }
4466 return ();
4467 }
4468  
4469 =head2 sub _update_lower_layer_in_gui
4470  
4471 keep tabs on lower_layer values
4472 and changes in the values in the
4473 GUI
4474  
4475 =cut
4476  
4477 sub _update_lower_layer_in_gui {
4478  
4479 my ($self) = @_;
4480  
4481 if ( $immodpg->{_is_layer_changed_in_gui} eq $yes
4482 && $immodpg->{_layer_current} >= 1 )
4483 {
4484  
4485 # CASE layer changed
4486 my $lower_layer = $immodpg->{_layer_current} + 1;
4487 my $layer_current = ( $immodpg->{_lower_layerLabel} )
4488 ->configure( -textvariable => \$lower_layer, );
4489  
4490 return ();
4491  
4492 }
4493 elsif ( $immodpg->{_is_layer_changed_in_gui} eq $no ) {
4494  
4495 # CASE layer is unchanged
4496 # print("immodpg, _update_lower_layer_in_gui, unchanged\n");
4497 return ();
4498  
4499 }
4500 else {
4501 print("immodpg, _update_lower_layer_in_gui, unexpected\n");
4502 return ();
4503 }
4504 }
4505  
4506 =head2 sub _update_upper_layer_in_gui
4507  
4508 keep tabs on upper_layer values
4509 and changes in the values in the
4510 GUI
4511  
4512 =cut
4513  
4514 sub _update_upper_layer_in_gui {
4515  
4516 my ($self) = @_;
4517  
4518 if ( $immodpg->{_is_layer_changed_in_gui} eq $yes
4519 && $immodpg->{_layer_current} >= 1 )
4520 {
4521  
4522 # CASE layer changed
4523 my $upper_layer = $immodpg->{_layer_current} - 1;
4524  
4525 if ( $upper_layer == 0 ) {
4526  
4527 # control output
4528 $upper_layer = $empty_string;
4529 }
4530 my $layer_current = ( $immodpg->{_upper_layerLabel} )
4531 ->configure( -textvariable => \$upper_layer, );
4532 return ();
4533  
4534 }
4535 elsif ( $immodpg->{_is_layer_changed_in_gui} eq $no ) {
4536  
4537 # CASE layer is unchanged
4538 # print("immodpg, _update_upper_layer_in_gui, unchanged\n");
4539 return ();
4540  
4541 }
4542 else {
4543 return ();
4544 print("immodpg, _update_upper_layer_in_gui, unexpected\n");
4545 }
4546 }
4547  
4548 =head2 sub _writeVincrement
4549  
4550 write out Vincrement
4551  
4552 =cut
4553  
4554 sub _writeVincrement {
4555 my ($self) = @_;
4556  
4557 if ( $immodpg->{_isVincrement_changed_in_gui} eq $yes ) {
4558 _write_config();
4559  
4560 }
4561 elsif ( $immodpg->{_isVincrement_changed_in_gui} eq $no ) {
4562  
4563 #NADA
4564  
4565 }
4566 else {
4567 print("immodpg, _writeVincrement, unexpected\n");
4568 }
4569 return ();
4570 }
4571  
4572 =head2 sub _writeVbotNtop_factor
4573  
4574 write out VbotNtop_factor
4575  
4576 =cut
4577  
4578 sub _writeVbotNtop_factor {
4579 my ($self) = @_;
4580  
4581 if ( $immodpg->{_isVbotNtop_factor_changed_in_gui} eq $yes ) {
4582 _write_config();
4583  
4584 }
4585 elsif ( $immodpg->{_isVbotNtop_factor_changed_in_gui} eq $no ) {
4586  
4587 #NADA
4588  
4589 }
4590 else {
4591 print("immodpg, _writeVbotNtop_factor, unexpected\n");
4592 }
4593 return ();
4594 }
4595  
4596 =head2 sub _write_clip
4597  
4598 write out clip
4599  
4600 =cut
4601  
4602 sub _write_clip {
4603 my ($self) = @_;
4604  
4605 if ( $immodpg->{_is_clip_changed_in_gui} eq $yes ) {
4606 _write_config();
4607  
4608 }
4609 elsif ( $immodpg->{_is_clip_changed_in_gui} eq $no ) {
4610  
4611 #NADA
4612  
4613 }
4614 else {
4615 print("immodpg, _write_clip, unexpected\n");
4616 }
4617 return ();
4618 }
4619  
4620 =head2 sub _write_thickness_increment_m
4621  
4622 write out thickness_increment_m
4623  
4624 =cut
4625  
4626 sub _write_thickness_increment_m {
4627 my ($self) = @_;
4628  
4629 if ( $immodpg->{_is_layer_changed_in_gui} eq $yes ) {
4630 _write_config();
4631  
4632 }
4633 elsif ( $immodpg->{_is_layer_changed_in_gui} eq $no ) {
4634  
4635 #NADA
4636  
4637 }
4638 else {
4639 print("immodpg, _write_thickness_increment_m, unexpected\n");
4640 }
4641 return ();
4642 }
4643  
4644 =head2 sub _write_config
4645  
4646 write out the new values
4647 as well as old values and their
4648 names to the configuration file
4649 called immodpg.config
4650 External parameter names do not
4651 agree always with variable names
4652 used inside the programs
4653 e.g., starting_layer versus layer
4654 or data_x_inc_m_m versus thickness_increment_m
4655  
4656 =cut
4657  
4658 sub _write_config {
4659  
4660 my ($self) = @_;
4661  
4662 =pod import private variables
4663  
4664 =cut
4665  
4666 my $variables = $immodpg_spec->variables();
4667 my $format_clip = $var_immodpg->{_config_file_format_clip};
4668 my $format_string = $var_immodpg->{_config_file_format};
4669 my $format_real = $var_immodpg->{_config_file_format_real};
4670 my $format_signed_integer =
4671 $var_immodpg->{_config_file_format_signed_integer};
4672  
4673 =head2 correct errors
4674  
4675 =cut
4676  
4677 #print("immodpg, _write_config,base_file_name:$immodpg->{_base_file_name}\n");
4678  
4679 =pod
4680 declare private variables
4681  
4682 =cut
4683  
4684 my $file = 'immodpg.config';
4685 my $outbound = $variables->{_CONFIG} . '/' . $file;
4686  
4687 open( OUT, ">$outbound" );
4688  
4689 printf OUT $format_string . "\n", "base_file_name ", "= ",
4690 $immodpg->{_base_file_name};
4691 printf OUT $format_string . "\n", "pre_digitized_XT_pairs ", "= ",
4692 $immodpg->{_pre_digitized_XT_pairs};
4693 printf OUT $format_string . "\n", "data_traces ", "= ",
4694 $immodpg->{_data_traces};
4695 printf OUT $format_clip . "\n", "clip ", "= ",
4696 $immodpg->{_clip4plot_current};
4697 printf OUT $format_real . "\n", "min_t_s ", "= ", $immodpg->{_min_t_s};
4698 printf OUT $format_real . "\n", "min_x_m ", "= ", $immodpg->{_min_x_m};
4699 printf OUT $format_real . "\n", "data_x_inc_m ", "= ",
4700 $immodpg->{_data_x_inc_m};
4701 printf OUT $format_real . "\n", "source_depth_m ", "= ",
4702 $immodpg->{_source_depth_m};
4703 printf OUT $format_real . "\n", "receiver_depth_m ", "= ",
4704 $immodpg->{_receiver_depth_m};
4705 printf OUT $format_real . "\n", "reducing_vel_mps ", "= ",
4706 $immodpg->{_reducing_vel_mps};
4707 printf OUT $format_real . "\n", "plot_min_x_m ", "= ",
4708 $immodpg->{_plot_min_x_m};
4709 printf OUT $format_real . "\n", "plot_max_x_m ", "= ",
4710 $immodpg->{_plot_max_x_m};
4711 printf OUT $format_real . "\n", "plot_min_t_s ", "= ",
4712 $immodpg->{_plot_min_t_s};
4713 printf OUT $format_real . "\n", "plot_max_t_s ", "= ",
4714 $immodpg->{_plot_max_t_s};
4715 printf OUT $format_string . "\n", "previous_model ", "= ",
4716 $immodpg->{_previous_model};
4717 printf OUT $format_string . "\n", "new_model ", "= ",
4718 $immodpg->{_new_model};
4719 printf OUT $format_signed_integer . "\n", "starting_layer ", "= ",
4720 $immodpg->{_layer_current};
4721 printf OUT $format_real . "\n", "VbotNtop_factor ", "= ",
4722 $immodpg->{_VbotNtop_factor_current};
4723 printf OUT $format_real . "\n", "Vincrement_mps", "= ",
4724 $immodpg->{_Vincrement_current};
4725 printf OUT $format_real . "\n", "thickness_increment_m ", "= ",
4726 $immodpg->{_thickness_increment_m_current};
4727  
4728 close(OUT);
4729  
4730 }
4731  
4732 =head2 sub _set_simple_model_text
4733  
4734 write out the model in ASCII
4735 format
4736  
4737 =cut
4738  
4739 sub _set_simple_model_text {
4740  
4741 my ($self) = @_;
4742  
4743 =pod import private variables
4744  
4745 =cut
4746  
4747 my $variables = $immodpg_spec->variables();
4748 my $format_title = $var_immodpg->{_model_text_file_format_title};
4749 my $format_values = $var_immodpg->{_model_text_file_format_values};
4750 my $simple_model_txt = $var_immodpg->{_simple_model_txt};
4751 my $number_of_layers = _get_number_of_layers();
4752  
4753 # print("$simple_model_txt \n");
4754  
4755 if ( length($variables)
4756 && length($format_title)
4757 && length($format_values)
4758 && length($simple_model_txt)
4759 && length($number_of_layers) )
4760 {
4761  
4762 =pod
4763 declare private variables
4764  
4765 =cut
4766  
4767 my ( @Vtop, @Vbot, @dz );
4768 my $file = $simple_model_txt;
4769 my $outbound = $variables->{_CONFIG} . '/' . $file;
4770  
4771 my ( $Vtop_ref, $Vbot_ref, $dz_ref ) = _getVp_ref_dz_ref();
4772 @Vtop = @$Vtop_ref;
4773 @Vbot = @$Vbot_ref;
4774 @dz = @$dz_ref;
4775  
4776 # print("immodpg,_getVp_ref_dz_ref; VPtop,VPbot,dz= @Vtop,@Vbot,@dz\n");
4777  
4778 open( OUT, ">$outbound" );
4779 printf OUT $format_title . "\n",
4780 " VPtop VPbottom thickness(m)";
4781  
4782 for ( my $i = 0 ; $i < $number_of_layers ; $i++ ) {
4783 print OUT (" $Vtop[$i] \t$Vbot[$i]\t\t$dz[$i]\n");
4784 }
4785  
4786 close(OUT);
4787  
4788 # print("immodpg,_write_simple_model_txt\n");
4789  
4790 }
4791 else {
4792 print("immodpg,_write_simple_model_txt, no output\n");
4793 print("variables = $immodpg_spec->variables()\n");
4794 print(
4795 "format_title = $var_immodpg->{_model_text_file_format_title}\n"
4796 );
4797 print(
4798 "format_values = $var_immodpg->{_model_text_file_format_values}\n"
4799 );
4800 print("simple_model_txt = $var_immodpg->{_simple_model_txt}\n");
4801 print("number_of_layers = _get_number_of_layers()\n");
4802 }
4803 }
4804  
4805 =head2 sub get_initialVp_dz4gui
4806  
4807 =cut
4808  
4809 sub get_initialVp_dz4gui {
4810  
4811 my ($self) = @_;
4812  
4813 if ( looks_like_number( $immodpg->{_model_layer_number} ) ) {
4814  
4815 my ( $_thickness_m_upper_layer, $Vbot_lower_layer );
4816 my ( @V, @result );
4817  
4818 my $layer = $immodpg->{_model_layer_number};
4819  
4820 my ( $refVPtop, $refVPbot, $ref_dz, $error_switch ) =
4821 _get_initial_model();
4822  
4823 if ( length($refVPtop)
4824 and length($refVPbot)
4825 and length($ref_dz)
4826 and length($error_switch) )
4827 {
4828  
4829 my @VPtop = @$refVPtop;
4830 my @VPbot = @$refVPbot;
4831 my @dz = @$ref_dz;
4832  
4833 # print("immodpg,get_initialVp_dz4gui VPtop= @VPtop\n");
4834 # print("immodpg,get_initialVp_dz4gui VPbot= @VPbot\n");
4835 # print("immodpg,get_initialVp_dz4gui dz= @dz\n");
4836 # print("immodpg,get_initialVp_dz4gui layer_number = $layer \n");
4837  
4838 my $layer_index = $layer - 1;
4839 my $layer_index_upper_layer = $layer - 2;
4840 my $layer_index_lower_layer = $layer;
4841  
4842 # For all cases
4843 my $Vtop = $VPtop[$layer_index];
4844 my $Vbot = $VPbot[$layer_index];
4845 my $dz = $dz[$layer_index];
4846  
4847 if ( $layer >= 2 ) {
4848  
4849 # CASE of second of two or more layers
4850 my $Vbot_upper_layer = $VPbot[$layer_index_upper_layer];
4851 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
4852  
4853 $V[0] = $Vbot_upper_layer;
4854 $V[1] = $Vtop;
4855 $V[2] = $Vbot;
4856 $V[3] = $Vtop_lower_layer;
4857  
4858 @result = @V;
4859  
4860 # print("immodpg, get_initialVp_dz4gui: velocities are: @V \n");
4861 return ( \@result, $dz, $error_switch );
4862  
4863 }
4864 elsif ( $layer >= 1 ) {
4865  
4866 # CASE of first of one or more layers
4867 my $Vbot_upper_layer = $empty_string;
4868 my $Vtop_lower_layer = $VPtop[$layer_index_lower_layer];
4869  
4870 $V[0] = $Vbot_upper_layer;
4871 $V[1] = $Vtop;
4872 $V[2] = $Vbot;
4873 $V[3] = $Vtop_lower_layer;
4874  
4875 @result = @V;
4876 return ( \@result, $dz, $error_switch );
4877  
4878 }
4879 else {
4880 print(
4881 "immodpg, get_initialVp_dz4gui, unexpected layer number \n"
4882 );
4883 return ();
4884 }
4885  
4886 }
4887 else {
4888 print(
4889 "immodpg,get_initialVp_dz4gui, _get_initial_model gives bad values \n"
4890 );
4891 return ();
4892 }
4893  
4894 }
4895 else {
4896 print("immodpg,get_initialVp_dz4gui,missing layer\\n");
4897 return ();
4898 }
4899 return ();
4900 }
4901  
4902 =head2 set_defaults
4903 1. Get starting configuration
4904 parameters from configuration file
4905 directly and independently of main
4906  
4907 =cut
4908  
4909 sub set_defaults {
4910  
4911 my ($self) = @_;
4912  
4913 my ( $CFG_h, $CFG_aref ) = $immodpg_config->get_values();
4914  
4915 $immodpg->{_base_file_name} = $CFG_h->{immodpg}{1}{base_file_name};
4916 $immodpg->{_pre_digitized_XT_pairs} =
4917 $CFG_h->{immodpg}{1}{pre_digitized_XT_pairs};
4918 $immodpg->{_data_traces} = $CFG_h->{immodpg}{1}{data_traces};
4919 $immodpg->{_clip} = $CFG_h->{immodpg}{1}{clip};
4920 $immodpg->{_min_t_s} = $CFG_h->{immodpg}{1}{min_t_s};
4921 $immodpg->{_min_x_m} = $CFG_h->{immodpg}{1}{min_x_m};
4922 $immodpg->{_data_x_inc_m} = $CFG_h->{immodpg}{1}{data_x_inc_m};
4923 $immodpg->{_source_depth_m} = $CFG_h->{immodpg}{1}{source_depth_m};
4924 $immodpg->{_receiver_depth_m} = $CFG_h->{immodpg}{1}{receiver_depth_m};
4925 $immodpg->{_reducing_vel_mps} = $CFG_h->{immodpg}{1}{reducing_vel_mps};
4926 $immodpg->{_plot_min_x_m} = $CFG_h->{immodpg}{1}{plot_min_x_m};
4927 $immodpg->{_plot_max_x_m} = $CFG_h->{immodpg}{1}{plot_max_x_m};
4928 $immodpg->{_plot_min_t_s} = $CFG_h->{immodpg}{1}{plot_min_t_s};
4929 $immodpg->{_plot_max_t_s} = $CFG_h->{immodpg}{1}{plot_max_t_s};
4930 $immodpg->{_previous_model} = $CFG_h->{immodpg}{1}{previous_model};
4931 $immodpg->{_new_model} = $CFG_h->{immodpg}{1}{new_model};
4932 $immodpg->{_layer} = $CFG_h->{immodpg}{1}{layer};
4933 $immodpg->{_VbotNtop_factor} = $CFG_h->{immodpg}{1}{VbotNtop_factor};
4934 $immodpg->{_Vincrement} = $CFG_h->{immodpg}{1}{Vincrement_mps};
4935 $immodpg->{_thickness_increment_m} =
4936 $CFG_h->{immodpg}{1}{thickness_increment_m};
4937  
4938 # print("immodpg,set_defaults,data_x_inc_m=$immodpg->{_data_x_inc_m}\n");
4939  
4940 =head2 Error control
4941 - clip ( ne 0)
4942 - layer number can be no smaller than 1
4943 or greater than max-1
4944
4945 clip >=0
4946
4947 =cut
4948  
4949 _set_clip_control( $immodpg->{_clip} );
4950 $immodpg->{_clip} = _get_control_clip();
4951  
4952 _set_layer_control( $immodpg->{_layer} );
4953 $immodpg->{_layer} = _get_control_layer();
4954  
4955 _set_model_layer( $immodpg->{_layer} );
4956 my ( $Vp_ref, $dz ) = _get_initialVp_dz4gui();
4957 my @V = @$Vp_ref;
4958 $immodpg->{_thickness_m} = $dz;
4959  
4960 my $Vbot_upper_layer = $V[0];
4961 my $Vtop = $V[1];
4962 my $Vbot = $V[2];
4963 my $Vtop_lower_layer = $V[3];
4964  
4965 $immodpg->{_Vbot} = $Vbot;
4966 $immodpg->{_Vbot_upper_layer} = $Vbot_upper_layer;
4967 $immodpg->{_Vtop} = $Vtop;
4968 $immodpg->{_Vtop_lower_layer} = $Vtop_lower_layer;
4969  
4970 # default values for Vbot-related variables
4971 $immodpg->{_Vbot_default} = $immodpg->{_Vbot};
4972 $immodpg->{_Vbot_current} = $immodpg->{_Vbot_default};
4973 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_default};
4974 $immodpg->{_inVbot} = $no;
4975 $immodpg->{_outsideVbot} = $yes;
4976  
4977 # default values for Vbot_upper_layer-related variables
4978 $immodpg->{_Vbot_upper_layer_default} = $immodpg->{_Vbot_upper_layer};
4979 $immodpg->{_Vbot_upper_layer_current} =
4980 $immodpg->{_Vbot_upper_layer_default};
4981 $immodpg->{_Vbot_upper_layer_prior} = $immodpg->{_Vbot_upper_layer_default};
4982 $immodpg->{_inVbot_upper_layer} = $no;
4983 $immodpg->{_outsideVbot_upper_layer} = $yes;
4984  
4985 # default values for Vincrement-related variables
4986 $immodpg->{_Vincrement_default} = $immodpg->{_Vincrement};
4987 $immodpg->{_Vincrement_current} = $immodpg->{_Vincrement_default};
4988 $immodpg->{_Vincrement_prior} = $immodpg->{_Vincrement_default};
4989 $immodpg->{_inVincrement} = $no;
4990 $immodpg->{_outsideVincrement} = $yes;
4991  
4992 # default values for Vtop-related variables
4993 $immodpg->{_Vtop_default} = $immodpg->{_Vtop};
4994 $immodpg->{_Vtop_current} = $immodpg->{_Vtop_default};
4995 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_default};
4996 $immodpg->{_inVtop} = $no;
4997 $immodpg->{_outsideVtop} = $yes;
4998  
4999 # default values for Vtop_lower_layer-related variables
5000 $immodpg->{_Vtop_lower_layer_default} = $immodpg->{_Vtop_lower_layer};
5001 $immodpg->{_Vtop_lower_layer_current} =
5002 $immodpg->{_Vtop_lower_layer_default};
5003 $immodpg->{_Vtop_lower_layer_prior} = $immodpg->{_Vtop_lower_layer_default};
5004 $immodpg->{_inVtop_lower_layer} = $no;
5005 $immodpg->{_outsideVtop_lower_layer} = $yes;
5006  
5007 # default values for VbotNtop_factor-related variables
5008 $immodpg->{_VbotNtop_factor_default} = $immodpg->{_VbotNtop_factor};
5009 $immodpg->{_VbotNtop_factor_current} = $immodpg->{_VbotNtop_factor_default};
5010 $immodpg->{_VbotNtop_factor_prior} = $immodpg->{_VbotNtop_factor_default};
5011 $immodpg->{_inVbotNtop_factor} = $no;
5012 $immodpg->{_outsideVbotNtop_factor} = $yes;
5013  
5014 # default values for clip-related variables
5015 $immodpg->{_clip4plot_default} = $immodpg->{_clip};
5016 $immodpg->{_clip4plot_current} = $immodpg->{_clip4plot_default};
5017 $immodpg->{_clip4plot_prior} = $immodpg->{_clip4plot_default};
5018 $immodpg->{_clip4plot} = $immodpg->{_clip4plot_default};
5019 $immodpg->{_in_clip} = $no;
5020 $immodpg->{_outside_clip} = $yes;
5021  
5022 # default values for layer-related variables
5023 $immodpg->{_layer_default} = $immodpg->{_layer};
5024 $immodpg->{_layer_current} = $immodpg->{_layer_default};
5025 $immodpg->{_layer_prior} = $immodpg->{_layer_default};
5026 $immodpg->{_in_layer} = $no;
5027 $immodpg->{_outside_layer} = $yes;
5028  
5029 # default values for thickness_m-related variables
5030 $immodpg->{_thickness_m_default} = $immodpg->{_thickness_m};
5031 $immodpg->{_thickness_m_current} = $immodpg->{_thickness_m_default};
5032 $immodpg->{_thickness_m_prior} = $immodpg->{_thickness_m_default};
5033 $immodpg->{_in_thickness_m} = $no;
5034 $immodpg->{_outside_thickness_m} = $yes;
5035  
5036 # default values for thickness_increment_m-related variables
5037 $immodpg->{_thickness_increment_m_default} =
5038 $immodpg->{_thickness_increment_m};
5039 $immodpg->{_thickness_increment_m_current} =
5040 $immodpg->{_thickness_increment_m_default};
5041 $immodpg->{_thickness_increment_m_prior} =
5042 $immodpg->{_thickness_increment_m_default};
5043 $immodpg->{_in_thickness_increment_m} = $no;
5044 $immodpg->{_outside_thickness_increment_m} = $yes;
5045  
5046 }
5047  
5048 =head2 sub setVbot_minus
5049  
5050 update Vbot value in gui
5051 update private value in this module
5052  
5053 output option for immodpg.for
5054  
5055 =cut
5056  
5057 sub setVbot_minus {
5058  
5059 my ($self) = @_;
5060  
5061 if ( length( $immodpg->{_VbotEntry} )
5062 and looks_like_number( $immodpg->{_Vincrement_current} ) )
5063 {
5064  
5065 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
5066  
5067 if ( looks_like_number($Vbot) ) {
5068  
5069 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
5070 my $newVbot = $Vbot - $Vincrement;
5071 _set_control( 'Vbot', $newVbot );
5072 $newVbot = _get_control('Vbot');
5073  
5074 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
5075 $immodpg->{_Vbot_current} = $newVbot;
5076  
5077 $immodpg->{_VbotEntry}->delete( 0, 'end' );
5078 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
5079  
5080 # $immodpg->{_isVbot_changed_in_gui} = $yes;
5081 # _checkVbot(); # todo
5082 _updateVbot();
5083  
5084 if ( $immodpg->{_isVbot_changed_in_gui} eq $yes ) {
5085  
5086 # for fortran program to read
5087 _set_option($Vbot_minus_opt);
5088 _set_change($yes);
5089  
5090 # print("immodpg, setVbot_minus, Vbot is changed: $yes \n");
5091 # print("immodpg, setVbot_minus,option:$Vbot_minus_opt\n");
5092 # print("immodpg, setVbot_minus, V=$immodpg->{_Vbot_current}\n");
5093  
5094 }
5095 else {
5096  
5097 # negative cases are reset by fortran program
5098 # and so eliminate need to read locked files
5099 # while use of locked files helps most of the time
5100 # creation and deletion of locked files in perl are not
5101 # failsafe
5102 #
5103 # print("immodpg, setVbot_minus, same Vbot NADA\n");
5104 }
5105  
5106 }
5107 else {
5108 print("immodpg, setVbot_minus, Vbot value missing\n");
5109 }
5110  
5111 }
5112 else {
5113 print("immodpg, setVbot_minus, missing widget or Vincrement\n");
5114  
5115 # print("immodpg, setVbot_minus, VbotEntry=$immodpg->{_VbotEntry}\n");
5116 # print("immodpg, setVbot_minus, Vincrement=$immodpg->{_Vincrement_current}\n");
5117 }
5118 return ();
5119 }
5120  
5121 =head2 sub setVbot_plus
5122  
5123 update Vbot value in gui
5124 update private value in this module
5125 output option for immodpg.for
5126  
5127 =cut
5128  
5129 sub setVbot_plus {
5130  
5131 my ($self) = @_;
5132  
5133 if ( length( $immodpg->{_VbotEntry} )
5134 && looks_like_number( $immodpg->{_Vincrement_current} ) )
5135 {
5136  
5137 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
5138  
5139 if ( looks_like_number($Vbot) ) {
5140  
5141 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
5142 my $newVbot = $Vbot + $Vincrement;
5143  
5144 _set_control( 'Vbot', $newVbot );
5145 $newVbot = _get_control('Vbot');
5146  
5147 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
5148 $immodpg->{_Vbot_current} = $newVbot;
5149  
5150 $immodpg->{_VbotEntry}->delete( 0, 'end' );
5151 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
5152  
5153 # $immodpg->{_isVbot_changed_in_gui} = $yes;
5154 # _checkVbot(); #todo
5155 _updateVbot();
5156  
5157 # print("immodpg, setVbot_plus, new Vbot= $newVbot\n");
5158  
5159 # print("immodpg, setVbot_plus, Vincrement= $Vincrement\n");
5160  
5161 if ( $immodpg->{_isVbot_changed_in_gui} eq $yes ) {
5162  
5163 # for fortran program to read
5164 _set_option($Vbot_plus_opt);
5165 _set_change($yes);
5166  
5167 # print("immodpg, setVbot_plus, Vbot_plus_opt:$Vbot_plus_opt \n");
5168  
5169 }
5170 else {
5171  
5172 # negative cases are reset by fortran program
5173 # and so eliminate need to read locked files
5174 # while use of locked files helps most of the time
5175 # creation and deletion of locked files in perl are not
5176 # failsafe
5177 #
5178 # print("immodpg, setVbot_plus, same Vbot NADA\n");
5179 }
5180  
5181 }
5182 else {
5183 print("immodpg, setVbot_plus, Vbot value missing\n");
5184 }
5185  
5186 }
5187 else {
5188 print("immodpg, setVbot_plus, missing widget or Vincrement\n");
5189  
5190 # print("immodpg, setVbot_plus, VbotEntry=$immodpg->{_VbotEntry}\n");
5191 # print("immodpg, setVbot_plus, Vincrement=$immodpg->{_Vincrement}\n");
5192 }
5193 return ();
5194 }
5195  
5196 =head2 sub setVtop_minus
5197  
5198 update Vtop value in gui
5199 update private value in this module
5200  
5201 output option for immodpg.for
5202  
5203 =cut
5204  
5205 sub setVtop_minus {
5206  
5207 my ($self) = @_;
5208  
5209 if ( length( $immodpg->{_VtopEntry} )
5210 && looks_like_number( $immodpg->{_Vincrement_current} ) )
5211 {
5212  
5213 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
5214  
5215 if ( looks_like_number($Vtop) ) {
5216  
5217 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
5218 my $newVtop = $Vtop - $Vincrement;
5219  
5220 _set_control( 'Vtop', $newVtop );
5221 $newVtop = _get_control('Vtop');
5222  
5223 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
5224 $immodpg->{_Vtop_current} = $newVtop;
5225  
5226 $immodpg->{_VtopEntry}->delete( 0, 'end' );
5227 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
5228  
5229 # $immodpg->{_isVtop_changed_in_gui} = $yes;
5230 # _checkVtop(); #todo
5231 _updateVtop();
5232  
5233 if ( $immodpg->{_isVtop_changed_in_gui} eq $yes ) {
5234  
5235 # for fortran program to read
5236 _set_option($Vtop_minus_opt);
5237 _set_change($yes);
5238  
5239 # print("immodpg, setVtop_minus,option:$Vtop_minus_opt\n");
5240 # print("immodpg, setVtop_minus, V=$immodpg->{_Vtop_current}\n");
5241  
5242 }
5243 else {
5244  
5245 # negative cases are reset by fortran program
5246 # and so eliminate need to read locked files
5247 # while use of locked files helps most of the time
5248 # creation and deletion of locked files in perl are not
5249 # failsafe
5250 #
5251 print("immodpg, setVtop_minus, same Vtop NADA\n");
5252 }
5253  
5254 }
5255 else {
5256 print("immodpg, setVtop_minus, Vtop value missing\n");
5257 }
5258  
5259 }
5260 else {
5261 print("immodpg, setVtop_minus, missing widget or Vincrement\n");
5262 print("immodpg, setVtop_minus, VtopEntry=$immodpg->{_VtopEntry}\n");
5263 print(
5264 "immodpg, setVtop_minus, Vincrement=$immodpg->{_Vincrement_current}\n"
5265 );
5266 }
5267 return ();
5268 }
5269  
5270 =head2 sub setVtop_plus
5271  
5272 update Vtop value in gui
5273 update private value in this module
5274  
5275 output option for immodpg.for
5276  
5277 =cut
5278  
5279 sub setVtop_plus {
5280  
5281 my ($self) = @_;
5282  
5283 # print("0. immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5284 if ( length( $immodpg->{_VtopEntry} )
5285 && length( $immodpg->{_VincrementEntry} ) )
5286 {
5287  
5288 # print("1. immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5289 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
5290  
5291 if ( looks_like_number($Vtop) ) {
5292  
5293 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
5294 my $newVtop = $Vtop + $Vincrement;
5295  
5296 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
5297 $immodpg->{_Vtop_current} = $newVtop;
5298  
5299 _set_control( 'Vtop', $immodpg->{_Vtop_current} );
5300 $immodpg->{_Vtop_current} = _get_control('Vtop');
5301 $newVtop = $immodpg->{_Vtop_current};
5302  
5303 $immodpg->{_VtopEntry}->delete( 0, 'end' );
5304 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
5305  
5306 # $immodpg->{_isVtop_changed_in_gui} = $yes;
5307 # _checkVtop(); #todo
5308 _updateVtop();
5309  
5310 # print("immodpg, setVtop_plus, $immodpg->{_Vtop_current}= $immodpg->{_Vtop_current}\n");
5311 # print("immodpg, setVtop_plus, Vincrement= $Vincrement\n");
5312 # print("2. immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5313 if ( $immodpg->{_isVtop_changed_in_gui} eq $yes ) {
5314  
5315 # for fortran program to read
5316 _set_option($Vtop_plus_opt);
5317 _set_change($yes);
5318  
5319 # print("immodpg, setVtop_plus,option:$Vtop_plus_opt\n");
5320 # print("immodpg, setVtop_plus, V=$immodpg->{_Vtop_current}\n");
5321  
5322 }
5323 else {
5324  
5325 # print("immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5326 # print("immodpg, setVtop_plus, Vincrement=$immodpg->{_Vincrement_current}\n");
5327  
5328 # negative cases are reset by fortran program
5329 # and so eliminate need to read locked files
5330 # while use of locked files helps most of the time
5331 # creation and deletion of locked files in perl are not
5332 # failsafe
5333 #
5334 # print("immodpg, setVtop_plus, same Vtop NADA\n");
5335 }
5336  
5337 }
5338 else {
5339 print("immodpg, setVtop_plus, Vtop value missing\n");
5340  
5341 # print("immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5342 # print("immodpg, setVtop_plus, Vincrement=$immodpg->{_Vincrement_current}\n");
5343 }
5344  
5345 }
5346 else {
5347 print("immodpg, setVtop_plus, missing widget or Vincrement\n");
5348 print("immodpg, setVtop_plus, VtopEntry=$immodpg->{_VtopEntry}\n");
5349 print(
5350 "immodpg, setVtop_plus, Vincrement=$immodpg->{_Vincrement_current}\n"
5351 );
5352 }
5353 return ();
5354 }
5355  
5356 =head2 sub cdp
5357  
5358  
5359 =cut
5360  
5361 sub cdp {
5362  
5363 my ( $self, $cdp ) = @_;
5364 if ($cdp) {
5365  
5366 $immodpg->{_cdp} = $cdp;
5367 $immodpg->{_note} = $immodpg->{_note} . ' cdp=' . $immodpg->{_cdp};
5368 $immodpg->{_Step} = $immodpg->{_Step} . ' cdp=' . $immodpg->{_cdp};
5369  
5370 }
5371 else {
5372 print("immodpg, cdp, missing cdp,\n");
5373 }
5374 }
5375  
5376 =head2 sub clean_trash
5377 delete remaining locked files
5378 reset default files as well
5379  
5380 =cut
5381  
5382 sub clean_trash {
5383 my ($self) = @_;
5384 use File::stat;
5385  
5386 my $xk = xk->new();
5387 my $files = manage_files_by2->new();
5388 my ( $outbound_locked, $outbound );
5389  
5390 my @X;
5391 my $Vbot_file = $immodpg->{_Vbot_file};
5392 my $VbotNtop_factor_file = $immodpg->{_VbotNtop_factor_file};
5393 my $Vbot_upper_layer_file = $immodpg->{_Vbot_upper_layer_file};
5394 my $Vincrement_file = $immodpg->{_Vincrement_file};
5395 my $Vtop_file = $immodpg->{_Vtop_file};
5396 my $Vtop_lower_layer_file = $immodpg->{_Vtop_lower_layer_file};
5397 my $change_file = $immodpg->{_change_file};
5398 my $clip_file = $immodpg->{_clip_file};
5399 my $immodpg_model = $immodpg->{_immodpg_model};
5400 my $layer_file = $immodpg->{_layer_file};
5401 my $option_file = $immodpg->{_option_file};
5402 my $thickness_m_file = $immodpg->{_thickness_m_file};
5403 my $thickness_increment_m_file = $immodpg->{_thickness_increment_m_file};
5404  
5405 # kill previous processes
5406 $xk->set_process('immodpg1.1');
5407 $xk->kill_process();
5408  
5409 $xk->set_process('pgxwin_server');
5410  
5411 # print("immodpg,exit: kill pgxwin_server\n");
5412 $xk->kill_process();
5413  
5414 # deleted lock files
5415 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $Vbot_file . '_locked';
5416 unlink($outbound_locked);
5417 $outbound_locked =
5418 $IMMODPG_INVISIBLE . '/' . $VbotNtop_factor_file . '_locked';
5419 unlink($outbound_locked);
5420 $outbound_locked =
5421 $IMMODPG_INVISIBLE . '/' . $Vbot_upper_layer_file . '_locked';
5422 unlink($outbound_locked);
5423 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $Vincrement_file . '_locked';
5424 unlink($outbound_locked);
5425 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $Vtop_file . '_locked';
5426 unlink($outbound_locked);
5427 $outbound_locked =
5428 $IMMODPG_INVISIBLE . '/' . $Vtop_lower_layer_file . '_locked';
5429 unlink($outbound_locked);
5430 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $change_file . '_locked';
5431  
5432 # print("immodpg, clean_trash, delete $outbound_locked\n");
5433 unlink($outbound_locked);
5434 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $clip_file . '_locked';
5435 unlink($outbound_locked);
5436 $outbound_locked = $IMMODPG . '/' . $immodpg_model . '_locked';
5437 unlink($outbound_locked);
5438 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $layer_file . '_locked';
5439 unlink($outbound_locked);
5440 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $option_file . '_locked';
5441 unlink($outbound_locked);
5442 $outbound_locked = $IMMODPG_INVISIBLE . '/' . $thickness_m_file . '_locked';
5443 unlink($outbound_locked);
5444 $outbound_locked =
5445 $IMMODPG_INVISIBLE . '/' . $thickness_increment_m_file . '_locked';
5446 unlink($outbound_locked);
5447  
5448 # reset files to their default options
5449 $outbound = $IMMODPG_INVISIBLE . '/' . $change_file;
5450 unlink($outbound);
5451 my $format = $var_immodpg->{_format_string};
5452 $X[0] = $immodpg->{_change_default};
5453 $files->write_1col_aref( \@X, \$outbound, \$format );
5454  
5455 _fortran_layer( $immodpg->{_layer_default} );
5456 _set_option( $immodpg->{_option_default} );
5457 _set_change( $immodpg->{_change_default} );
5458  
5459 # delete empty files (including surviving lock files)
5460 # remove weird, locked files from the current directory
5461 my $CD = `pwd`;
5462 $files->set_directory($CD);
5463 $files->clear_empty_files();
5464  
5465 # remove weird lock files from the main directory
5466 $files->set_directory($IMMODPG);
5467 $files->clear_empty_files();
5468  
5469 # remove weird lock files from the IMMODPG_INVISIBLE
5470 $files->set_directory($IMMODPG_INVISIBLE);
5471 $files->clear_empty_files();
5472  
5473 return ();
5474 }
5475  
5476 =head2 sub clear
5477  
5478 =cut
5479  
5480 sub clear {
5481 $immodpg->{_base_file_name} = '';
5482 $immodpg->{_cdp} = '';
5483 $immodpg->{_invert} = '';
5484 $immodpg->{_lmute} = '';
5485 $immodpg->{_smute} = '';
5486 $immodpg->{_sscale} = '';
5487 $immodpg->{_scaled_par} = '';
5488 $immodpg->{_tnmo} = '';
5489 $immodpg->{_upward} = '';
5490 $immodpg->{_vnmo} = '';
5491 $immodpg->{_voutfile} = '';
5492 $immodpg->{_Step} = '';
5493 $immodpg->{_note} = '';
5494 }
5495  
5496 =head2 subroutine exit
5497  
5498 =cut
5499  
5500 sub exit {
5501  
5502 my $xk = xk->new();
5503  
5504 $xk->set_process('pgxwin_server');
5505  
5506 # print("immodpg,exit: kill pgxwin_server\n");
5507 $xk->kill_process();
5508  
5509 $xk->set_process('immodpg1.1');
5510  
5511 # print("immodpg,exit: kill immodpg1.1\n");
5512 $xk->kill_process();
5513  
5514 $xk->set_process('immodpg');
5515 $xk->kill_process();
5516  
5517 # print("immodpg,exit: Goodbye!\n");
5518  
5519 return ();
5520  
5521 }
5522  
5523 =head2 sub get_control_clip
5524 adjust clip value
5525  
5526 =cut
5527  
5528 sub get_control_clip {
5529  
5530 my ($self) = @_;
5531  
5532 my $result;
5533  
5534 if ( length( $immodpg->{_control_clip} ) ) {
5535  
5536 # print("1. immodpg, get_control_clip, old control_clip= $immodpg->{_control_clip}\n");
5537 my $control_clip = $immodpg->{_control_clip};
5538  
5539 if ( $control_clip <= 0 ) {
5540  
5541 # case 1 layer number exceeds possible value
5542 $control_clip = 1;
5543 $result = $control_clip;
5544  
5545 }
5546 else {
5547  
5548 # print("immodpg, get_control_clip, NADA\n");
5549 $result = $control_clip;
5550 }
5551  
5552 # print("2. immodpg, get_control_clip, new control_clip= $control_clip\n");
5553 return ($result);
5554  
5555 }
5556 else {
5557 print("immodpg, get_control_clip, missing clip value\n");
5558 }
5559 return ();
5560 }
5561  
5562 =head2 sub get_control_layer
5563 Layer value is adjustable
5564 Working layer
5565 number must be
5566 >= 1
5567  
5568 =cut
5569  
5570 sub get_control_layer {
5571  
5572 my ($self) = @_;
5573  
5574 my $result;
5575  
5576 # print("1. immodpg, get_control_layer, control_layer_external= $immodpg->{_control_layer_external}\n");
5577  
5578 if ( length( $immodpg->{_control_layer_external} ) ) {
5579  
5580 # CASE 1
5581 # print("CASE 1: immodpg, get_control_layer, control_layer_external= $immodpg->{_control_layer_external}\n");
5582  
5583 my $layer_current = $immodpg->{_control_layer_external};
5584 my $number_of_layers = _get_number_of_layers();
5585  
5586 # print("2. immodpg, get_control_layer, number_of_layers= $number_of_layers\n");
5587  
5588 if ( $layer_current > $number_of_layers ) {
5589  
5590 # case 1A layer number exceeds possible value
5591 # print("case1A: immodpg, get_control_layer, layer number too large\n");
5592 # print("immodpg, get_control_layer, layer_number=$layer_current}\n");
5593 $layer_current = $number_of_layers - 1;
5594  
5595 # print("immodpg, get_control_layer, new layer_number=$layer_current}\n");
5596 $result = $layer_current;
5597  
5598 }
5599 elsif ( $layer_current < 1 ) {
5600  
5601 $layer_current = 1;
5602 $result = $layer_current;
5603  
5604 # print("CASE 1B immodpg, get_control_layer, layer_number=$layer_current}\n");
5605  
5606 }
5607 elsif ( $layer_current == 1 ) {
5608  
5609 $layer_current = 1;
5610 $result = $layer_current;
5611  
5612 # print("CASE 1 C immodpg, get_control_layer, layer=$layer_current\n");
5613  
5614 }
5615 elsif ( ( $layer_current < $number_of_layers ) ) {
5616  
5617 $result = $layer_current;
5618  
5619 # print("CASE 1 D immodpg, get_control_layer, layer=$layer_current\n");
5620  
5621 # NADA
5622  
5623 }
5624 elsif ( ( $layer_current == $number_of_layers ) ) {
5625  
5626 $result = $layer_current - 1;
5627  
5628 # print("iCASE 1 E mmodpg, get_control_layer, layer=$layer_current\n");
5629 # NADA
5630  
5631 }
5632 else {
5633 print("immodpg, get_control_layer, unexpected layer number\n");
5634 $result = $empty_string;
5635 }
5636  
5637 }
5638 elsif ( length( $immodpg->{_control_layer_external} ) == 0 ) {
5639  
5640 $result = 1;
5641  
5642 # print("CASE 2immodpg, get_control_layer, empty string layer updated to $result\n");
5643  
5644 }
5645 else {
5646 print("immodpg, get_control_layer, unexpected value\n");
5647 }
5648  
5649 return ($result);
5650 }
5651  
5652 =head2 sub get_max_index
5653
5654 max index = number of input variables -1
5655
5656 =cut
5657  
5658 sub get_max_index {
5659 my ($self) = @_;
5660 my $max_index = 14;
5661  
5662 return ($max_index);
5663 }
5664  
5665 =head2 sub initialize_messages
5666  
5667 Create widgets that show messages
5668 Show warnings or errors in a message box
5669 Message box is defined in main where it is
5670 also made invisible (withdraw)
5671 Here we turn on the message box (deiconify, raise)
5672 The message does not release the program
5673 until OK is clicked and wait variable changes from yes
5674 to no.
5675  
5676 =cut
5677  
5678 sub initialize_messages {
5679  
5680 my ($self) = @_;
5681  
5682 my $arial_14_b = ( $immodpg->{_mw} )->fontCreate(
5683 'arial_14_b',
5684 -family => 'arial',
5685 -weight => 'bold',
5686 -size => -14
5687 );
5688  
5689 =head2 message box
5690  
5691 Withdraw temporarily while filling
5692 with widgets
5693  
5694 =cut
5695  
5696 $immodpg->{_message_box_w} =
5697 $immodpg->{_mw}->Toplevel( -background => $var_L_SU->{_my_yellow}, );
5698 $immodpg->{_message_box_w}->withdraw;
5699  
5700 $immodpg->{_message_box_w}->geometry( $var_L_SU->{_message_box_geometry} );
5701  
5702 $immodpg->{_message_upper_frame} = $immodpg->{_message_box_w}->Frame(
5703 -borderwidth => $var_L_SU->{_no_borderwidth},
5704 -background => $var_L_SU->{_my_yellow},
5705 );
5706 $immodpg->{_message_lower_frame} = $immodpg->{_message_box_w}->Frame(
5707 -borderwidth => $var_L_SU->{_no_borderwidth},
5708 -background => $var_L_SU->{_my_yellow},
5709 -height => '10',
5710 );
5711 $immodpg->{_message_label_w} = $immodpg->{_message_upper_frame}->Label(
5712 -background => $var_L_SU->{_my_yellow},
5713 -font => $arial_14_b,
5714 -justify => 'left',
5715 );
5716  
5717 $immodpg->{_message_box_wait} = $var_L_SU->{_yes};
5718 $immodpg->{_message_ok_button} = $immodpg->{_message_box_w}->Button(
5719 -text => "ok",
5720 -font => $arial_14_b,
5721 -command => sub {
5722 $immodpg->{_message_box_w}->grabRelease;
5723 $immodpg->{_message_box_w}->withdraw;
5724 },
5725 );
5726  
5727 =head2 Pack message box
5728  
5729 This Toplevel window has
5730 geometry that is independent
5731 of the main window widget.
5732 Upper frame contains message.
5733 Lower frame contains ok button.
5734  
5735 =cut
5736  
5737 $immodpg->{_message_upper_frame}->pack();
5738 $immodpg->{_message_label_w}->pack( -side => 'top', );
5739 $immodpg->{_message_lower_frame}->pack( -side => 'top', );
5740  
5741 $immodpg->{_message_ok_button}->pack(
5742 -side => "top",
5743 -fill => 'none',
5744 -expand => 0,
5745 );
5746  
5747 return ();
5748 }
5749  
5750 =head2 sub initialize_model
5751  
5752 Load into namespace the immodpg model to
5753 establish the first set of layers
5754 their velocities and thickness
5755  
5756 =cut
5757  
5758 sub initialize_model {
5759 my ($self) = @_;
5760  
5761 my ( $refVPtop, $refVPbot, $ref_dz, $error_switch ) = _get_initial_model();
5762  
5763 if ( length($refVPtop)
5764 && length($refVPbot)
5765 && length($ref_dz)
5766 && length($error_switch) )
5767 {
5768  
5769 _set_initialVp_dz( $refVPtop, $refVPbot, $ref_dz, $error_switch );
5770  
5771 }
5772 else {
5773 print(" immodpg, L5046, missing or corrupt variables \n");
5774 }
5775  
5776 return ();
5777  
5778 }
5779  
5780 =head2 sub get_number_of_layers
5781  
5782 Determine number of layers
5783 from model.text file
5784  
5785 =cut
5786  
5787 sub get_number_of_layers {
5788  
5789 my ($self) = @_;
5790 my $number_of_layers;
5791  
5792 if ( length( $immodpg->{_model_file_text} ) ) {
5793  
5794 my $count = 0;
5795 my $magic_number = 4;
5796 my $inbound_model_file_text =
5797 $IMMODPG_INVISIBLE . '/' . $immodpg->{_model_file_text};
5798  
5799 # print ("immodpg,_get_number_of_layers,inbound_model_file_text=$inbound_model_file_text\n");
5800  
5801 open( my $fh, '<', $inbound_model_file_text );
5802  
5803 while (<$fh>) {
5804  
5805 $count++;
5806  
5807 }
5808 close($fh);
5809  
5810 $number_of_layers = $count - $magic_number;
5811  
5812 # print("immodpg,_get_number_of_layers, layers = $number_of_layers \n");
5813  
5814 }
5815 else {
5816  
5817 # print("immodpg,_get_number_of_layers, missing values\n");
5818 $number_of_layers = 0;
5819 }
5820  
5821 my $result = $number_of_layers;
5822 return ($result);
5823 }
5824  
5825 =head2 sub get_replacement4missing
5826  
5827  
5828 =cut
5829  
5830 sub get_replacement4missing {
5831  
5832 my ($self) = @_;
5833  
5834 if ( length( $immodpg->{_replacement4missing} )
5835 and length( $immodpg->{_inbound_missing} ) )
5836 {
5837  
5838 my $inbound = $immodpg->{_inbound_missing};
5839 my $replacement = $immodpg->{_replacement4missing};
5840  
5841 if ( not( -e $inbound ) ) {
5842  
5843 # print("immodpg,get_replacement4missing ,file is missing\n");
5844 use File::Copy;
5845 my $from = $replacement;
5846 my $to = $inbound;
5847 copy( $from, $to );
5848  
5849 }
5850 elsif ( -e $inbound ) {
5851  
5852 # print("immodpg,get_replacement4missing,OK-NADA \n");
5853  
5854 }
5855 else {
5856 print("immodpg,get_replacement4missing,unexpected value\n");
5857 }
5858  
5859 }
5860 else {
5861 print("immodpg, get_replacement4missing, missing replacement\n");
5862 }
5863  
5864 return ();
5865 }
5866  
5867 =head2 sub setVbot
5868  
5869 When you enter or leave
5870 check what the current Vbot value is
5871 compared to former Vbot values.
5872  
5873 Vtop value is updated for immodpg.for
5874 through a message in file= "Vbot"
5875  
5876 =cut
5877  
5878 sub setVbot {
5879  
5880 my ($self) = @_;
5881  
5882 if ( length( $immodpg->{_VbotEntry} ) ) {
5883  
5884 $immodpg->{_Vbot_current} = ( $immodpg->{_VbotEntry} )->get();
5885  
5886 _set_control( 'Vbot', $immodpg->{_Vbot_current} );
5887 $immodpg->{_Vbot_current} = _get_control('Vbot');
5888 my $newVbot = $immodpg->{_Vbot_current};
5889  
5890 $immodpg->{_VbotEntry}->delete( 0, 'end' );
5891 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
5892  
5893 _checkVbot();
5894 _updateVbot();
5895  
5896 if ( length( $immodpg->{_isVbot_changed_in_gui} )
5897 && $immodpg->{_isVbot_changed_in_gui} eq $yes )
5898 {
5899  
5900 # for fortran program to read
5901 # print("immodpg, set_Vbot, Vbot is changed: $yes \n");
5902 # print("immodpg, setVbot,option:$Vbot_opt\n");
5903 # print("immodpg, setVbot, V=$immodpg->{_Vbot_current}\n");
5904  
5905 _setVbot( $immodpg->{_Vbot_current} );
5906 _set_option($Vbot_opt);
5907 _set_change($yes);
5908  
5909 }
5910 else {
5911  
5912 # negative cases are reset by fortran program
5913 # and so eliminate need to read locked files
5914 # while use of locked files helps most of the time
5915 # creation and deletion of locked files in perl are not
5916 # failsafe
5917  
5918 # print("immodpg, setVbot, same Vbot NADA\n");
5919 }
5920  
5921 }
5922 else {
5923  
5924 }
5925 }
5926  
5927 =head2 sub setVbot_upper_layer
5928  
5929 When you enter or leave a field,
5930 check what the current Vbot_upper_layer value is
5931 compared to former Vbot_upper_layer values
5932 Vtop value is updated in immodpg.for
5933 through a message in file= "Vbot_lower"
5934 (&_setVbot_upper_layer)
5935  
5936 =cut
5937  
5938 sub setVbot_upper_layer {
5939  
5940 my ($self) = @_;
5941  
5942 # for convenience
5943 my $layer_current = $immodpg->{_layer_current};
5944 my $newVbot_upper_layer;
5945  
5946 if ( length( $immodpg->{_Vbot_upper_layerEntry} ) ) {
5947  
5948 $immodpg->{_Vbot_upper_layer_current} =
5949 ( $immodpg->{_Vbot_upper_layerEntry} )->get();
5950 my $Vbot_upper_layer_current = $immodpg->{_Vbot_upper_layer_current};
5951  
5952 # print("1. immodpg, setVbot_upper_layer, immodpg->{_Vbot_upper_layer_current}=$Vbot_upper_layer_current\n");
5953 if ( length $Vbot_upper_layer_current
5954 and looks_like_number($Vbot_upper_layer_current)
5955 and $layer_current > 0 )
5956 {
5957  
5958 # print("immodpg, setVbot_upper_layer, immodpg->{_Vbot_upper_layer_current}=$immodpg->{_Vbot_upper_layer_current}\n");
5959  
5960 _set_control( 'Vbot_upper_layer',
5961 $immodpg->{_Vbot_upper_layer_current} );
5962 $immodpg->{_Vbot_upper_layer_current} =
5963 _get_control('Vbot_upper_layer');
5964 $newVbot_upper_layer = $immodpg->{_Vbot_upper_layer_current};
5965  
5966 # print("2. immodpg, setVbot_upper_layer, newVbot_upper_layer=$newVbot_upper_layer\n");
5967  
5968 $immodpg->{_Vbot_upper_layerEntry}->delete( 0, 'end' );
5969 $immodpg->{_Vbot_upper_layerEntry}
5970 ->insert( 0, $newVbot_upper_layer );
5971  
5972 _checkVbot_upper_layer();
5973 _updateVbot_upper_layer();
5974  
5975 if ( $immodpg->{_isVbot_upper_layer_changed_in_gui} eq $yes ) {
5976  
5977 # for fortran program to read
5978  
5979 _setVbot_upper_layer( $immodpg->{_Vbot_upper_layer_current} );
5980 _set_option($Vbot_upper_layer_opt);
5981 _set_change($yes);
5982  
5983 # print("immodpg, setVbot_upper_layer,option:$Vbot_upper_layer_opt\n");
5984 # print("immodpg, setVbot_upper_layer,V= $immodpg->{_Vbot_upper_layer_current}\n");
5985  
5986 }
5987 else {
5988  
5989 # negative cases are reset by fortran program
5990 # and so eliminate need to read locked files
5991 # while use of locked files helps most of the time
5992 # creation and deletion of locked files in perl are not
5993 # failsafe
5994  
5995 # print("immodpg, setVbot_upper_layer, same Vbot NADA\n");
5996 }
5997  
5998 }
5999 else {
6000  
6001 # print("immodpg, setVbot_upper_layer, Velocity is empty in non-layer NADA\n");
6002 }
6003  
6004 }
6005 else {
6006  
6007 }
6008 }
6009  
6010 =head2 setVbotNVtop_lower_layer_minus
6011 update Vbot value in gui
6012 update Vtop_lower_layer value in gui
6013 update private value in this module
6014  
6015 output option for immodpg.for
6016  
6017 =cut
6018  
6019 sub setVbotNVtop_lower_layer_minus {
6020  
6021 my ($self) = @_;
6022  
6023 if ( looks_like_number( $immodpg->{_Vincrement_current} )
6024 && length( $immodpg->{_Vtop_lower_layerEntry} )
6025 && length( $immodpg->{_VbotEntry} ) )
6026 {
6027  
6028 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
6029 my $Vtop_lower_layer = ( $immodpg->{_Vtop_lower_layerEntry} )->get();
6030 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
6031  
6032 if ( looks_like_number($Vtop_lower_layer)
6033 && looks_like_number($Vbot) )
6034 {
6035  
6036 my $newVtop_lower_layer = $Vtop_lower_layer - $Vincrement;
6037 my $newVbot = $Vbot - $Vincrement;
6038  
6039 _set_control( 'Vtop', $newVtop_lower_layer );
6040 $newVtop_lower_layer = _get_control('Vtop');
6041 _set_control( 'Vbot', $newVbot );
6042 $newVbot = _get_control('Vbot');
6043  
6044 $immodpg->{_Vtop_lower_layer_prior} =
6045 $immodpg->{_Vtop_lower_layer_current};
6046 $immodpg->{_Vtop_lower_layer_current} = $newVtop_lower_layer;
6047  
6048 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
6049 $immodpg->{_Vbot_current} = $newVbot;
6050  
6051 $immodpg->{_Vtop_lower_layerEntry}->delete( 0, 'end' );
6052 $immodpg->{_Vtop_lower_layerEntry}
6053 ->insert( 0, $newVtop_lower_layer );
6054  
6055 $immodpg->{_VbotEntry}->delete( 0, 'end' );
6056 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
6057  
6058 # $immodpg->{_isVtop_lower_layer_changed_in_gui} = $yes;
6059 # $immodpg->{_isVbot_changed_in_gui} = $yes;
6060 # _checkVbot(); #todo
6061 _updateVbot();
6062  
6063 # _checkVtop_lower_layer(); #todo
6064 _updateVtop_lower_layer();
6065  
6066 if ( $immodpg->{_isVtop_lower_layer_changed_in_gui} eq $yes
6067 && $immodpg->{_isVbot_changed_in_gui} eq $yes )
6068 {
6069  
6070 # for fortran program to read
6071 # print("immodpg, setVbotNVtop_lower_layer_minus, Vbot is changed: $yes \n");
6072  
6073 _set_option($VbotNVtop_lower_layer_minus_opt);
6074 _set_change($yes);
6075  
6076 # print("immodpg, setVbotNVtop_lower_layer_minus,option:$VbotNVtop_lower_layer_minus_opt\n");
6077 # print("immodpg, setVbotNVtop_lower_layer_minus, V=$immodpg->{_Vtop_lower_layer_current}\n");
6078  
6079 }
6080 else {
6081  
6082 # negative cases are reset by fortran program
6083 # and so eliminate need to read locked files
6084 # while use of locked files helps most of the time
6085 # creation and deletion of locked files in perl are not
6086 # failsafe
6087 #
6088 # print("immodpg, setVbotNVtop_lower_layer_minus, same Vbot and Vtop_lower_layer; NADA\n");
6089 }
6090  
6091 }
6092 else {
6093 print(
6094 "immodpg, setVbotNVtop_lower_layer_minus, Vbot or Vtop_lower_layer value missing\n"
6095 );
6096 }
6097  
6098 }
6099 else {
6100 print(
6101 "immodpg, setVbotNVtop_lower_layer_minus, missing widget or Vincrement\n"
6102 );
6103  
6104 # print("immodpg, setVtopNVtop_lower_layer_minus, Vtop_lower_layerEntry=$immodpg->{_Vtop_lower_layerEntry}\n");
6105 # print("immodpg, setVtopNVtop_lower_layer_minus, Vincrement=$immodpg->{_Vincrement_current}\n");
6106 }
6107 return ();
6108 }
6109  
6110 =head2 setVbotNVtop_lower_layer_plus
6111 update Vbot value in gui
6112 update Vtop_lower_layer value in gui
6113 update private value in this module
6114  
6115 output option for immodpg.for
6116  
6117 =cut
6118  
6119 sub setVbotNVtop_lower_layer_plus {
6120  
6121 my ($self) = @_;
6122  
6123 if ( looks_like_number( $immodpg->{_Vincrement_current} )
6124 && length( $immodpg->{_Vtop_lower_layerEntry} )
6125 && length( $immodpg->{_VbotEntry} ) )
6126 {
6127  
6128 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
6129 my $Vtop_lower_layer = ( $immodpg->{_Vtop_lower_layerEntry} )->get();
6130 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
6131  
6132 if ( looks_like_number($Vtop_lower_layer)
6133 && looks_like_number($Vbot) )
6134 {
6135  
6136 my $newVtop_lower_layer = $Vtop_lower_layer + $Vincrement;
6137 my $newVbot = $Vbot + $Vincrement;
6138  
6139 _set_control( 'Vbot', $newVbot );
6140 $newVbot = _get_control('Vbot');
6141 _set_control( 'Vtop', $newVtop_lower_layer );
6142 $newVtop_lower_layer = _get_control('Vtop');
6143  
6144 $immodpg->{_Vtop_lower_layer_prior} =
6145 $immodpg->{_Vtop_lower_layer_current};
6146 $immodpg->{_Vtop_lower_layer_current} = $newVtop_lower_layer;
6147  
6148 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
6149 $immodpg->{_Vbot_current} = $newVbot;
6150  
6151 $immodpg->{_Vtop_lower_layerEntry}->delete( 0, 'end' );
6152 $immodpg->{_Vtop_lower_layerEntry}
6153 ->insert( 0, $newVtop_lower_layer );
6154  
6155 $immodpg->{_VbotEntry}->delete( 0, 'end' );
6156 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
6157  
6158 # $immodpg->{_isVtop_lower_layer_changed_in_gui} = $yes;
6159 # $immodpg->{_isVbot_changed_in_gui} = $yes;
6160  
6161 _checkVbot(); # todo
6162 _updateVbot();
6163 _checkVtop_lower_layer(); # todo
6164 _updateVtop_lower_layer();
6165  
6166 # print("immodpg, setVbotNVtop_lower_layer_plus, new Vtop_lower_layer= $newVtop_lower_layer\n");
6167 # print("immodpg, setVbotNVtop_lower_layer_plus, Vincrement= $Vincrement\n");
6168  
6169 if ( $immodpg->{_isVtop_lower_layer_changed_in_gui} eq $yes
6170 && $immodpg->{_isVbot_changed_in_gui} eq $yes )
6171 {
6172  
6173 # for fortran program to read
6174 # print("immodpg, setVbotNVtop_lower_layer_plus, Vbot is changed: $yes \n");
6175  
6176 _set_option($VbotNVtop_lower_layer_plus_opt);
6177 _set_change($yes);
6178  
6179 # print("immodpg, setVbotNVtop_lower_layer_plus,option:$VbotNVtop_lower_layer_plus_opt\n");
6180 # print("immodpg, setVbotNVtop_lower_layer_plus, V=$immodpg->{_Vtop_lower_layer_current}\n");
6181  
6182 }
6183 else {
6184  
6185 # negative cases are reset by fortran program
6186 # and so eliminate need to read locked files
6187 # while use of locked files helps most of the time
6188 # creation and deletion of locked files in perl are not
6189 # failsafe
6190 #
6191 # print("immodpg, setVbotNVtop_lower_layer_plus, same Vbot and Vtop_lower_layer; NADA\n");
6192 }
6193  
6194 }
6195 else {
6196 print(
6197 "immodpg, setVbotNVtop_lower_layer_plus, Vbot or Vtop_lower_layer value missing\n"
6198 );
6199 }
6200  
6201 }
6202 else {
6203 print(
6204 "immodpg, setVbotNVtop_lower_layer_plus, missing widget or Vincrement\n"
6205 );
6206  
6207 # print("immodpg, setVtopNVtop_lower_layer_plus, Vtop_lower_layerEntry=$immodpg->{_Vtop_lower_layerEntry}\n");
6208 print(
6209 "immodpg, setVtopNVtop_lower_layer_plus, Vincrement=$immodpg->{_Vincrement_current}\n"
6210 );
6211 }
6212 return ();
6213 }
6214  
6215 =head2 sub setVtopNVbot_upper_layer_minus
6216 update Vtop value in gui
6217 update Vbot_upper_layer value in gui
6218 update private value in this module
6219  
6220 output option for immodpg.for
6221  
6222 =cut
6223  
6224 sub setVtopNVbot_upper_layer_minus {
6225  
6226 my ($self) = @_;
6227  
6228 # print("layer_current = $immodpg->{_layer_current};\n");
6229 if (
6230 looks_like_number( $immodpg->{_Vincrement_current} )
6231 && length( $immodpg->{_Vbot_upper_layerEntry} )
6232 && length( $immodpg->{_VtopEntry} )
6233  
6234 )
6235 {
6236  
6237 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
6238 my $Vbot_upper_layer = ( $immodpg->{_Vbot_upper_layerEntry} )->get();
6239 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
6240 my $layer_current = $immodpg->{_layer_current};
6241  
6242 if ( looks_like_number($Vbot_upper_layer) && looks_like_number($Vtop)
6243 and $layer_current > 1 )
6244 {
6245  
6246 my $newVbot_upper_layer = $Vbot_upper_layer - $Vincrement;
6247 my $newVtop = $Vtop - $Vincrement;
6248  
6249 _set_control( 'Vbot', $newVbot_upper_layer );
6250 $newVbot_upper_layer = _get_control('Vbot');
6251  
6252 _set_control( 'Vtop', $newVtop );
6253 $newVtop = _get_control('Vtop');
6254  
6255 $immodpg->{_Vbot_upper_layer_prior} =
6256 $immodpg->{_Vbot_upper_layer_current};
6257 $immodpg->{_Vbot_upper_layer_current} = $newVbot_upper_layer;
6258  
6259 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
6260 $immodpg->{_Vtop_current} = $newVtop;
6261  
6262 $immodpg->{_Vbot_upper_layerEntry}->delete( 0, 'end' );
6263 $immodpg->{_Vbot_upper_layerEntry}
6264 ->insert( 0, $newVbot_upper_layer );
6265  
6266 $immodpg->{_VtopEntry}->delete( 0, 'end' );
6267 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6268  
6269 # $immodpg->{_isVbot_upper_layer_changed_in_gui} = $yes;
6270 # $immodpg->{_isVtop_changed_in_gui} = $yes;
6271  
6272 # print("immodpg, setVtopNVbot_upper_layer_minus, new Vbot_upper_layer= $newVbot_upper_layer\n");
6273 # print("immodpg, setVtopNVbot_upper_layer_minus, Vincrement= $Vincrement\n");
6274  
6275 # _checkVtop(); #todo
6276 _updateVtop();
6277  
6278 # _checkVbot_upper_layer(); #todo
6279 _updateVbot_upper_layer();
6280  
6281 if ( $immodpg->{_isVbot_upper_layer_changed_in_gui} eq $yes
6282 && $immodpg->{_isVtop_changed_in_gui} eq $yes )
6283 {
6284  
6285 # for fortran program to read
6286 # print("immodpg, setVtopNVbot_upper_layer_minus, Vbot is changed: $yes \n");
6287  
6288 _set_option($VtopNVbot_upper_layer_minus_opt);
6289 _set_change($yes);
6290  
6291 # print("immodpg, setVtopNVbot_upper_layer_minus,option:$VtopNVbot_upper_layer_minus_opt\n");
6292 # print("immodpg, setVtopNVbot_upper_layer_minus, V=$immodpg->{_Vbot_upper_layer_current}\n");
6293  
6294 }
6295 else {
6296  
6297 # negative cases are reset by fortran program
6298 # and so eliminate need to read locked files
6299 # while use of locked files helps most of the time
6300 # creation and deletion of locked files in perl are not
6301 # failsafe
6302 #
6303 # print("immodpg, setVtopNVbot_upper_layer_minus, same Vtop and Vbot_upper_layer; NADA\n");
6304 }
6305  
6306 }
6307 else {
6308  
6309 # print("immodpg, setVtopNVbot_upper_layer_minus, Vtop or Vbot_upper_layer value missing-NADA\n");
6310 }
6311  
6312 }
6313 else {
6314 print(
6315 "immodpg, setVtopNVbot_upper_layer_minus, missing widget or Vincrement\n"
6316 );
6317  
6318 # print("immodpg, setVtopNVbot_upper_layer_minus, Vbot_upper_layerEntry=$immodpg->{_Vbot_upper_layerEntry}\n");
6319 # print("immodpg, setVtopNVbot_upper_layer_minus, Vincrement=$immodpg->{_Vincrement_current}\n");
6320 }
6321 return ();
6322 }
6323  
6324 =head2 sub setVtopNVbot_upper_layer_plus
6325  
6326 update Vtop value in gui
6327 update Vbot_upper_layer value in gui
6328 update private value in this module
6329  
6330 output option for immodpg.for
6331  
6332 =cut
6333  
6334 sub setVtopNVbot_upper_layer_plus {
6335  
6336 my ($self) = @_;
6337  
6338 if (
6339 looks_like_number( $immodpg->{_Vincrement_current} )
6340 && length( $immodpg->{_Vbot_upper_layerEntry} )
6341 && length( $immodpg->{_VtopEntry} )
6342  
6343 )
6344 {
6345  
6346 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
6347 my $Vbot_upper_layer = ( $immodpg->{_Vbot_upper_layerEntry} )->get();
6348 my $Vincrement = ( $immodpg->{_VincrementEntry} )->get();
6349 my $layer_current = $immodpg->{_layer_current};
6350  
6351 if ( looks_like_number($Vbot_upper_layer) && looks_like_number($Vtop)
6352 and $layer_current > 1 )
6353 {
6354  
6355 my $newVbot_upper_layer = $Vbot_upper_layer + $Vincrement;
6356 my $newVtop = $Vtop + $Vincrement;
6357  
6358 _set_control( 'Vbot', $newVbot_upper_layer );
6359 $newVbot_upper_layer = _get_control('Vbot');
6360  
6361 _set_control( 'Vtop', $newVtop );
6362 $newVtop = _get_control('Vtop');
6363  
6364 $immodpg->{_Vbot_upper_layer_prior} =
6365 $immodpg->{_Vbot_upper_layer_current};
6366 $immodpg->{_Vbot_upper_layer_current} = $newVbot_upper_layer;
6367  
6368 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
6369 $immodpg->{_Vtop_current} = $newVtop;
6370  
6371 $immodpg->{_Vbot_upper_layerEntry}->delete( 0, 'end' );
6372 $immodpg->{_Vbot_upper_layerEntry}
6373 ->insert( 0, $newVbot_upper_layer );
6374  
6375 $immodpg->{_VtopEntry}->delete( 0, 'end' );
6376 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6377  
6378 # $immodpg->{_isVbot_upper_layer_changed_in_gui} = $yes;
6379 # $immodpg->{_isVtop_changed_in_gui} = $yes;
6380 # _checkVtop(); #todo
6381 _updateVtop();
6382  
6383 # _checkVbot_upper_layer(); # todo
6384 _updateVbot_upper_layer();
6385  
6386 # print("immodpg, setVtopNVbot_upper_layer_plus, new Vbot_upper_layer= $newVbot_upper_layer\n");
6387 # print("immodpg, setVtopNVbot_upper_layer_plus, Vincrement= $Vincrement\n");
6388  
6389 if ( $immodpg->{_isVbot_upper_layer_changed_in_gui} eq $yes
6390 && $immodpg->{_isVtop_changed_in_gui} eq $yes )
6391 {
6392  
6393 # for fortran program to read
6394 # print("immodpg, setVtopNVbot_upper_layer_plus, Vbot is changed: $yes \n");
6395  
6396 _set_option($VtopNVbot_upper_layer_plus_opt);
6397 _set_change($yes);
6398  
6399 # print("immodpg, setVtopNVbot_upper_layer_plus,option:$VtopNVbot_upper_layer_plus_opt\n");
6400 # print("immodpg, setVtopNVbot_upper_layer_plus, V=$immodpg->{_Vbot_upper_layer_current}\n");
6401  
6402 }
6403 else {
6404  
6405 # negative cases are reset by fortran program
6406 # and so eliminate need to read locked files
6407 # while use of locked files helps most of the time
6408 # creation and deletion of locked files in perl are not
6409 # failsafe
6410 #
6411 # print("immodpg, setVtopNVbot_upper_layer_plus, same Vtop and Vbot_upper_layer; NADA\n");
6412 }
6413  
6414 }
6415 else {
6416  
6417 # print("immodpg, setVtopNVbot_upper_layer_plus, Vtop or Vbot_upper_layer value missing NADA\n");
6418 }
6419  
6420 }
6421 else {
6422 print(
6423 "immodpg, setVtopNVbot_upper_layer_plus, missing widget or Vincrement\n"
6424 );
6425  
6426 # print("immodpg, setVtopNVbot_upper_layer_plus, Vbot_upper_layerEntry=$immodpg->{_Vbot_upper_layerEntry}\n");
6427 # print("immodpg, setVtopNVbot_upper_layer_plus, Vincrement=$immodpg->{_Vincrement}\n");
6428 }
6429 return ();
6430 }
6431  
6432 =head2 sub setVincrement
6433  
6434 When you enter or leave
6435 check what the current Vincrement value is
6436 compared to former Vincrement values
6437  
6438 =cut
6439  
6440 sub setVincrement {
6441  
6442 my ($self) = @_;
6443  
6444 if ( length( $immodpg->{_VincrementEntry} ) ) {
6445  
6446 $immodpg->{_Vincrement_current} = $immodpg->{_VincrementEntry}->get();
6447  
6448 # print("1. immodpg, setVincrement ,immodpg->{_Vincrement_current}:$immodpg->{_Vincrement_current}\n");
6449  
6450 _set_control( 'Vincrement', $immodpg->{_Vincrement_current} );
6451 $immodpg->{_Vincrement_current} = _get_control('Vincrement');
6452 my $newVincrement = $immodpg->{_Vincrement_current};
6453  
6454 # print("2. immodpg, setVincrement,immodpg->{_Vincrement_current}:$immodpg->{_Vincrement_current}\n");
6455  
6456 $immodpg->{_VincrementEntry}->delete( 0, 'end' );
6457 $immodpg->{_VincrementEntry}->insert( 0, $newVincrement );
6458  
6459 _checkVincrement();
6460 _updateVincrement();
6461 _write_config();
6462  
6463 if ( $immodpg->{_isVincrement_changed_in_gui} eq $yes ) {
6464  
6465 # for fortran program to read
6466 # print("immodpg, setVincrement, Vincrement is changed: $yes \n");
6467 # print("immodpg, setVincrement,option:$changeVincrement_opt\n");
6468 # print("immodpg, setVincrement, $immodpg->{_Vincrement_current}\n");
6469  
6470 _setVincrement( $immodpg->{_Vincrement_current} );
6471 _set_option($changeVincrement_opt);
6472 _set_change($yes);
6473  
6474 }
6475 else {
6476  
6477 # negative cases are reset by fortran program
6478 # and so eliminate need to read locked files
6479 # while use of locked files helps most of the time
6480 # creation and deletion of locked files in perl are not
6481 # failsafe
6482  
6483 # print("immodpg, setVincrement, same Vincrement NADA\n");
6484 }
6485  
6486 }
6487 else {
6488 print("immodpg, setVincrement, missing value\n");
6489 }
6490  
6491 }
6492  
6493 =head2 sub setVtop
6494  
6495 When you enter or leave,
6496 check what the current Vtop value is
6497 compared to former Vtop values
6498  
6499 Vtop value is updated in immodpg.for
6500 through a message in file= "Vtop"
6501 (&_setVtop)
6502  
6503 =cut
6504  
6505 sub setVtop {
6506  
6507 my ($self) = @_;
6508  
6509 if ( length( $immodpg->{_VtopEntry} ) ) {
6510  
6511 $immodpg->{_Vtop_current} = ( $immodpg->{_VtopEntry} )->get();
6512  
6513 _set_control( 'Vtop', $immodpg->{_Vtop_current} );
6514 $immodpg->{_Vtop_current} = _get_control('Vtop');
6515 my $newVtop = $immodpg->{_Vtop_current};
6516  
6517 $immodpg->{_VtopEntry}->delete( 0, 'end' );
6518 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6519  
6520 _checkVtop();
6521 _updateVtop();
6522  
6523 if ( $immodpg->{_isVtop_changed_in_gui} eq $yes ) {
6524  
6525 # for fortran program to read
6526 # print("immodpg, set_Vtop, Vtop is changed: $yes \n");
6527  
6528 # $immodpg->{_VtopEntry}->delete( 0, 'end');
6529 # $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6530  
6531 _setVtop( $immodpg->{_Vtop_current} );
6532 _set_option($changeVtop_opt);
6533 _set_change($yes);
6534  
6535 # print("immodpg, setVtop,option:$changeVtop_opt\n");
6536 # print("immodpg, setVtop, V=$immodpg->{_Vtop_current}\n");
6537  
6538 }
6539 else {
6540  
6541 # negative cases are reset by fortran program
6542 # and so eliminate need to read locked files
6543 # while use of locked files helps most of the time
6544 # creation and deletion of locked files in perl are not
6545 # failsafe
6546  
6547 # print("immodpg, setVtop, same Vtop NADA\n");
6548 }
6549  
6550 }
6551 else {
6552 print("immodpg, setVtop, _Vtop value missing\n");
6553 print("immodpg, setVtop, Vtop=$immodpg->{_Vtop}\n");
6554 }
6555 }
6556  
6557 =head2 sub setVtop_lower_layer
6558  
6559 When you enter or leave
6560 check what the current Vtop_lower_layer value is
6561 compared to former Vtop_lower_layer values
6562 Vtop value is updated in immodpg.for
6563 through a message in file= "Vtop_lower_layer"
6564 (&_setVtop_lower_layer)
6565  
6566 =cut
6567  
6568 sub setVtop_lower_layer {
6569  
6570 my ($self) = @_;
6571  
6572 my $newVtop_lower_layer;
6573  
6574 # my $isVtop_lower_layer_changed = $immodpg->{_isVtop_lower_layer_changed_in_gui};
6575  
6576 if ( length( $immodpg->{_Vtop_lower_layerEntry} ) ) {
6577  
6578 $immodpg->{_Vtop_lower_layer} =
6579 ( $immodpg->{_Vtop_lower_layerEntry} )->get();
6580  
6581 _set_control( 'Vtop_lower_layer', $immodpg->{_Vtop_lower_layer} );
6582 $immodpg->{_Vtop_lower_layer} = _get_control('Vtop_lower_layer');
6583 $newVtop_lower_layer = $immodpg->{_Vtop_lower_layer};
6584  
6585 $immodpg->{_Vtop_lower_layerEntry}->delete( 0, 'end' );
6586 $immodpg->{_Vtop_lower_layerEntry}->insert( 0, $newVtop_lower_layer );
6587  
6588 _checkVtop_lower_layer();
6589 _updateVtop_lower_layer();
6590  
6591 if ( $immodpg->{_isVtop_lower_layer_changed_in_gui} eq $yes ) {
6592  
6593 # for fortran program to read
6594 # print(" immodpg, set_Vtop_lower_layer, newVtop_lower_layer = $newVtop_lower_layer\n");
6595  
6596 # $immodpg->{_Vtop_lower_layerEntry}->delete( 0, 'end' );
6597 # $immodpg->{_Vtop_lower_layerEntry}->insert( 0, $newVtop_lower_layer);
6598  
6599 _setVtop_lower_layer( $immodpg->{_Vtop_lower_layer_current} );
6600 _set_option($Vtop_lower_layer_opt);
6601 _set_change($yes);
6602  
6603 # print("immodpg, setVtop_lower_layer,option:$Vtop_lower_layer_opt\n");
6604  
6605 }
6606 else {
6607  
6608 # negative cases are reset by fortran program
6609 # and so eliminate need to read locked files
6610 # while use of locked files helps most of the time
6611 # creation and deletion of locked files in perl are not
6612 # failsafe
6613  
6614 # print("immodpg, setVtop_lower_layer, same Vtop_lower_layer NADA\n");
6615 }
6616  
6617 }
6618 else {
6619 ("immodpg, setVtop_lower_layer, missing widget\n");
6620 }
6621 }
6622  
6623 =head2 sub setVbotNtop_factor
6624  
6625 When you enter or leave
6626 check what the current VbotNtop_factor value is
6627 compared to former VbotNtop_factor values
6628  
6629 =cut
6630  
6631 sub setVbotNtop_factor {
6632  
6633 my ($self) = @_;
6634  
6635 if ( length( $immodpg->{_VbotNtop_factorEntry} ) ) {
6636  
6637 $immodpg->{_VbotNtop_factor_current} =
6638 $immodpg->{_VbotNtop_factorEntry}->get();
6639  
6640 # print("1, immodpg, setVbotNtop_factor,immodpg->{_VbotNtop_factor_current}: $immodpg->{_VbotNtop_factor_current} \n");
6641 _set_control( 'VbotNtop_factor', $immodpg->{_VbotNtop_factor_current} );
6642 $immodpg->{_VbotNtop_factor_current} = _get_control('VbotNtop_factor');
6643 my $newVbotNtop_factor = $immodpg->{_VbotNtop_factor_current};
6644  
6645 # print("2. immodpg, setVbotNtop_factor,newVbotNtop_factor:$newVbotNtop_factor\n");
6646  
6647 $immodpg->{_VbotNtop_factorEntry}->delete( 0, 'end' );
6648 $immodpg->{_VbotNtop_factorEntry}->insert( 0, $newVbotNtop_factor );
6649  
6650 _checkVbotNtop_factor();
6651 _updateVbotNtop_factor();
6652 _write_config();
6653  
6654 if ( $immodpg->{_isVbotNtop_factor_changed_in_gui} eq $yes ) {
6655  
6656 _setVbotNtop_factor( $immodpg->{_VbotNtop_factor_current} );
6657 _set_option($changeVbotNtop_factor_opt);
6658 _set_change($yes);
6659  
6660 # print("immodpg, setVbotNtop_factor,option:$changeVbotNtop_factor_opt\n");
6661  
6662 }
6663 else {
6664 _set_change($no);
6665  
6666 # print("immodpg, setVbotNtop_factor, same VbotNtop_factor_opt NADA\n");
6667 }
6668  
6669 }
6670 else {
6671 print("immodpg, setVbotNtop_factor, bad factor or widget\n");
6672  
6673 # correct for bad typing
6674 # _set_control('VbotNtop_factor',)
6675 # _set_VbotNtop_factor_control();
6676 # _get_control_VbotNtop_factor();
6677 }
6678 }
6679  
6680 #
6681  
6682 =head2 sub setVbotNtop_multiply
6683 Multiply Vbot and Vtop with factor
6684  
6685 _updateVbotNtop_multiply
6686 gui values for widgets
6687 VbotEntry and VtopEntry
6688
6689 output option for immodpg.for
6690  
6691 =cut
6692  
6693 sub setVbotNtop_multiply {
6694  
6695 my ($self) = @_;
6696  
6697 if ( looks_like_number( $immodpg->{_VbotNtop_factor_current} )
6698 && length( $immodpg->{_VbotEntry}->get() )
6699 && length( $immodpg->{_VtopEntry}->get() ) )
6700 {
6701  
6702 my $factor = $immodpg->{_VbotNtop_factorEntry}->get();
6703 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
6704 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
6705 my $Vbot_multiplied = $Vbot * $factor;
6706 my $Vtop_multiplied = $Vtop * $factor;
6707 $immodpg->{_Vbot_multiplied} = $Vbot_multiplied;
6708 $immodpg->{_Vtop_multiplied} = $Vtop_multiplied;
6709  
6710 # print("immodpg, setVbotNtop_multiply, Vbot=$Vbot_multiplied=, Vtop= $Vtop_multiplied\n");
6711  
6712 _updateVbotNtop_multiply();
6713 _set_option($VbotNtop_multiply_opt);
6714 _set_change($yes);
6715  
6716 }
6717 else {
6718 print("immodpg, setVbotNtop_multiply, missing value\n");
6719 }
6720  
6721 return ();
6722  
6723 }
6724  
6725 =head2 sub setVbotNtop_minus
6726  
6727 update Vbot and Vtop values in gui
6728 update private svalue in this module
6729 output option for immodpg.for
6730  
6731 =cut
6732  
6733 sub setVbotNtop_minus {
6734  
6735 my ($self) = @_;
6736  
6737 if ( length( $immodpg->{_VbotEntry} )
6738 && length( $immodpg->{_VtopEntry} ) )
6739 {
6740  
6741 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
6742 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
6743 my $Vincrement = $immodpg->{_VincrementEntry}->get();
6744  
6745 if ( looks_like_number($Vbot)
6746 && looks_like_number($Vtop)
6747 && looks_like_number($Vincrement) )
6748 {
6749  
6750 my $newVbot = $Vbot - $Vincrement;
6751  
6752 _set_control( 'Vbot', $newVbot );
6753 $newVbot = _get_control('Vbot');
6754  
6755 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
6756 $immodpg->{_Vbot_current} = $newVbot;
6757  
6758 $immodpg->{_VbotEntry}->delete( 0, 'end' );
6759 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
6760  
6761 _updateVbot();
6762  
6763 my $newVtop = $Vtop - $Vincrement;
6764 _set_control( 'Vtop', $newVtop );
6765 $newVtop = _get_control('Vtop');
6766  
6767 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
6768 $immodpg->{_Vtop_current} = $newVtop;
6769  
6770 $immodpg->{_VtopEntry}->delete( 0, 'end' );
6771 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6772  
6773 _updateVtop();
6774  
6775 # print("immodpg, setVbotNtop_minus, new Vbot= $newVbot\n");
6776 # print("immodpg, setVbotNtop_minus, new Vtop= $newVtop\n");
6777 # print("immodpg, setVbotNtop_minus, Vincrement= $Vincrement\n");
6778  
6779 if ( $immodpg->{_isVbot_changed_in_gui} eq $yes
6780 && $immodpg->{_isVtop_changed_in_gui} eq $yes )
6781 {
6782  
6783 # for fortran program to read
6784 _set_option($VbotNtop_minus_opt);
6785 _set_change($yes);
6786  
6787 # print("immodpg, setVbotNtop_minus, VbotNtop_minus_opt:$VbotNtop_minus_opt \n");
6788  
6789 }
6790 else {
6791  
6792 # negative cases are reset by fortran program
6793 # and so eliminate need to read locked files
6794 # while use of locked files helps most of the time
6795 # creation and deletion of locked files in perl are not
6796 # failsafe
6797 #
6798 # print("immodpg, setVbotNtop_minus, same VbotNtop NADA\n");
6799 }
6800  
6801 }
6802 else {
6803 print("immodpg, setVbotNtop_minus, VbotNtop value missing\n");
6804 }
6805  
6806 }
6807 else {
6808 print("immodpg, setVbotNtop_minus, missing widget or Vincrement\n");
6809 # print("immodpg, setVbotNtop_minus, Vincrement=$immodpg->{_Vincrement}\n");
6810 }
6811 return ();
6812 }
6813  
6814 =head2 sub setVbotNtop_plus
6815  
6816 update Vbot and Vtop values in gui
6817 update private svalue in this module
6818 output option for immodpg.for
6819  
6820 =cut
6821  
6822 sub setVbotNtop_plus {
6823  
6824 my ($self) = @_;
6825  
6826 if ( length( $immodpg->{_VbotEntry} )
6827 && length( $immodpg->{_VtopEntry} ) )
6828 {
6829  
6830 my $Vbot = ( $immodpg->{_VbotEntry} )->get();
6831 my $Vtop = ( $immodpg->{_VtopEntry} )->get();
6832 my $Vincrement = $immodpg->{_VincrementEntry}->get();
6833  
6834 if ( looks_like_number($Vbot)
6835 && looks_like_number($Vtop)
6836 && looks_like_number($Vincrement) )
6837 {
6838  
6839 my $newVbot = $Vbot + $Vincrement;
6840  
6841 _set_control( 'Vbot', $newVbot );
6842 $newVbot = _get_control('Vbot');
6843  
6844 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
6845 $immodpg->{_Vbot_current} = $newVbot;
6846  
6847 $immodpg->{_VbotEntry}->delete( 0, 'end' );
6848 $immodpg->{_VbotEntry}->insert( 0, $newVbot );
6849  
6850 _updateVbot();
6851  
6852 my $newVtop = $Vtop + $Vincrement;
6853 _set_control( 'Vtop', $newVtop );
6854 $newVtop = _get_control('Vtop');
6855  
6856 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
6857 $immodpg->{_Vtop_current} = $newVtop;
6858  
6859 $immodpg->{_VtopEntry}->delete( 0, 'end' );
6860 $immodpg->{_VtopEntry}->insert( 0, $newVtop );
6861  
6862 _updateVtop();
6863  
6864 # print("immodpg, setVbotNtop_plus, new Vbot= $newVbot\n");
6865 # print("immodpg, setVbotNtop_plus, new Vtop= $newVtop\n");
6866 # print("immodpg, setVbotNtop_plus, Vincrement= $Vincrement\n");
6867  
6868 if ( $immodpg->{_isVbot_changed_in_gui} eq $yes
6869 && $immodpg->{_isVtop_changed_in_gui} eq $yes )
6870 {
6871  
6872 # for fortran program to read
6873 _set_option($VbotNtop_plus_opt);
6874 _set_change($yes);
6875  
6876 # print("immodpg, setVbotNtop_plus, VbotNtop_plus_opt:$VbotNtop_plus_opt \n");
6877  
6878 }
6879 else {
6880  
6881 # negative cases are reset by fortran program
6882 # and so eliminate need to read locked files
6883 # while use of locked files helps most of the time
6884 # creation and deletion of locked files in perl are not
6885 # failsafe
6886 #
6887 # print("immodpg, setVbotNtop_plus, same VbotNtop NADA\n");
6888 }
6889  
6890 }
6891 else {
6892 print("immodpg, setVbotNtop_plus, VbotNtop value missing\n");
6893 }
6894  
6895 }
6896 else {
6897 print("immodpg, setVbotNtop_plus, missing widget or Vincrement\n");
6898 print("immodpg, setVbotNtop_plus, Vincrement=$immodpg->{_Vincrement}\n");
6899 }
6900 return ();
6901 }
6902  
6903 =head2 sub invert
6904  
6905  
6906 =cut
6907  
6908 sub invert {
6909  
6910 my ( $self, $invert ) = @_;
6911 if ( $invert ne $empty_string ) {
6912  
6913 $immodpg->{_invert} = $invert;
6914 $immodpg->{_note} =
6915 $immodpg->{_note} . ' invert=' . $immodpg->{_invert};
6916 $immodpg->{_Step} =
6917 $immodpg->{_Step} . ' invert=' . $immodpg->{_invert};
6918  
6919 }
6920 else {
6921 print("immodpg, invert, missing invert,\n");
6922 }
6923 }
6924  
6925 =head2 sub lmute
6926  
6927  
6928 =cut
6929  
6930 sub lmute {
6931  
6932 my ( $self, $lmute ) = @_;
6933 if ($lmute) {
6934  
6935 $immodpg->{_lmute} = $lmute;
6936 $immodpg->{_note} = $immodpg->{_note} . ' lmute=' . $immodpg->{_lmute};
6937 $immodpg->{_Step} = $immodpg->{_Step} . ' lmute=' . $immodpg->{_lmute};
6938  
6939 }
6940 else {
6941 print("immodpg, lmute, missing lmute,\n");
6942 }
6943 }
6944  
6945 =head2 sub premmod
6946  
6947 prepare su file as a binary file for (i)mmodpg
6948 This program read a SU file, and creates the file:
6949 datammod
6950 which is a binary fortran file containing the SU file with
6951 no headers, and that
6952 can be read by program mmodpg. It also create the ascii
6953 file: parmmod
6954 containing
6955 basic parameters of the SU file (ntr,ns,dt) also used by mmodpg.
6956  
6957 =cut
6958  
6959 sub premmod {
6960 my ($self) = @_;
6961  
6962 # _set_inbound;
6963 # my $inbound = _get_inbound();
6964 my $inbound;
6965  
6966 if ( $inbound ne $empty_string ) {
6967  
6968 }
6969 else {
6970 print("immodpg,premmod, unexpected result\n");
6971 }
6972  
6973 }
6974  
6975 =head2 sub set_clip
6976  
6977 When you enter or leave
6978 check what the current clip value is
6979 compared to former clip values
6980  
6981 =cut
6982  
6983 sub set_clip {
6984  
6985 my ($self) = @_;
6986  
6987 if ( length( $immodpg->{_clip4plotEntry} ) ) {
6988  
6989 $immodpg->{_clip4plot_current} = $immodpg->{_clip4plotEntry}->get();
6990  
6991 # print("1. immodpg, set_clip,immodpg->{_clip4plot_current}:$immodpg->{_clip4plot_current}\n");
6992  
6993 _set_control( 'clip4plot', $immodpg->{_clip4plot_current} );
6994 $immodpg->{_clip4plot_current} = _get_control('clip4plot');
6995 my $new_clip4plot = $immodpg->{_clip4plot_current};
6996  
6997 # print("2. immodpg, set_clip,immodpg->{_clip4plot_current}:$immodpg->{_clip4plot_current}\n");
6998  
6999 $immodpg->{_clip4plotEntry}->delete( 0, 'end' );
7000 $immodpg->{_clip4plotEntry}->insert( 0, $new_clip4plot );
7001  
7002 _check_clip();
7003 _update_clip();
7004 _write_config();
7005  
7006 if ( $immodpg->{_is_clip_changed_in_gui} eq $yes ) {
7007  
7008 _set_clip( $immodpg->{_clip4plot_current} );
7009 _set_option($change_clip_opt);
7010 _set_change($yes);
7011  
7012 # print("immodpg, set_clip,immodpg->{_clip4plot_current}=$immodpg->{_clip4plot_current}\n");
7013  
7014 }
7015 else {
7016 _set_change($no);
7017  
7018 # print("immodpg, set_clip, same clip NADA\n");
7019 }
7020  
7021 }
7022 else {
7023  
7024 }
7025 }
7026  
7027 =head2 sub set_layer
7028 When you enter or leave
7029 check what the current layer value is
7030 compared to former layer values
7031  
7032 =cut
7033  
7034 sub set_layer {
7035 my ($self) = @_;
7036  
7037 # print("immodpg, set_layer, $immodpg->{_layerEntry}\n");
7038  
7039 if ( length( $immodpg->{_layerEntry} )
7040 && looks_like_number( $immodpg->{_layer_current} )
7041 && length $immodpg->{_VbotEntry}
7042 && length $immodpg->{_VtopEntry}
7043 && length $immodpg->{_Vbot_upper_layerEntry}
7044 && length $immodpg->{_Vtop_lower_layerEntry}
7045 && length( $immodpg->{_thickness_mEntry} )
7046 && looks_like_number( $immodpg->{_thickness_m_current} ) )
7047 {
7048  
7049 _check_layer();
7050 _update_layer_in_gui();
7051 _update_upper_layer_in_gui();
7052 _update_lower_layer_in_gui();
7053  
7054 # _write_config(); TODO
7055  
7056 if ( $immodpg->{_is_layer_changed_in_gui} eq $yes ) {
7057  
7058 =head3 Get model values from
7059 immodpg.out for initial settings
7060 in GUI
7061 If the layer changes, also change associated
7062 velocity values and thickness values of the new layer
7063  
7064 =cut
7065  
7066 # print("immodpg, set_layer, layer is changed to: $immodpg->{_layer_current}\n");
7067 _set_model_layer( $immodpg->{_layer_current} );
7068  
7069 my ( $Vp_ref, $dz ) = _getVp_ref_dz_scalar();
7070 my @V = @$Vp_ref;
7071 my $thickness_m = $dz;
7072  
7073 # print("immodpg,set_layer,thickness=$thickness_m \n");
7074  
7075 my $Vbot_upper_layer = $V[0];
7076 my $Vtop = $V[1];
7077 my $Vbot = $V[2];
7078 my $Vtop_lower_layer = $V[3];
7079  
7080 # print("immodpg, set_layer, Vbot=$Vbot for layer=$immodpg->{_layer_current} \n");
7081 $immodpg->{_thickness_mEntry}->delete( 0, 'end' );
7082 $immodpg->{_thickness_mEntry}->insert( 0, $thickness_m );
7083  
7084 # print("immodpg, set_layer, Vbot=$Vbot\n");
7085 $immodpg->{_VbotEntry}->delete( 0, 'end' );
7086 $immodpg->{_VbotEntry}->insert( 0, $Vbot );
7087  
7088 # print("immodpg, set_layer, Vtop=$Vtop\n");
7089 $immodpg->{_VtopEntry}->delete( 0, 'end' );
7090 $immodpg->{_VtopEntry}->insert( 0, $Vtop );
7091  
7092 # print("immodpg, set_layer, Vbot_upper_layer=$Vbot_upper_layer\n");
7093 $immodpg->{_Vbot_upper_layerEntry}->delete( 0, 'end' );
7094 $immodpg->{_Vbot_upper_layerEntry}->insert( 0, $Vbot_upper_layer );
7095  
7096 # print("immodpg, set_layer, Vtop_lower_layer=$Vtop_lower_layer\n");
7097 $immodpg->{_Vtop_lower_layerEntry}->delete( 0, 'end' );
7098 $immodpg->{_Vtop_lower_layerEntry}->insert( 0, $Vtop_lower_layer );
7099  
7100 # update stored values
7101 $immodpg->{_Vtop_prior} = $immodpg->{_Vtop_current};
7102 $immodpg->{_Vtop_current} = $Vtop;
7103 $immodpg->{_Vbot_prior} = $immodpg->{_Vbot_current};
7104 $immodpg->{_Vbot_current} = $Vbot;
7105 $immodpg->{_Vbot_upper_layer_prior} =
7106 $immodpg->{_Vbot_upper_layer_current};
7107 $immodpg->{_Vbot_upper_layer_current} = $Vbot_upper_layer;
7108 $immodpg->{_Vtop_lower_layer_prior} =
7109 $immodpg->{_Vtop_lower_layer_current};
7110 $immodpg->{_Vtop_lower_layer_current} = $Vtop_lower_layer;
7111 $immodpg->{_thickness_m_prior} = $immodpg->{_thickness_m_current};
7112 $immodpg->{_thickness_m_current} = $thickness_m;
7113  
7114 # affects immodpg.for
7115 # print("3. immodpg, set_layer, layer is changed: $yes \n");
7116 _fortran_layer( $immodpg->{_layer_current} );
7117 _set_option($change_layer_number_opt);
7118 _set_change($yes);
7119  
7120 # print("immodpg, set_layer,option:$change_layer_number_opt\n");
7121  
7122 }
7123 else {
7124 _set_change($no);
7125  
7126 # print("immodpg, layer, same layer NADA\n");
7127 }
7128  
7129 }
7130 else {
7131  
7132 }
7133 }
7134  
7135 =head2 sub set_layer_control
7136 Value adjusts to current
7137 layer number in use
7138  
7139 =cut
7140  
7141 sub set_layer_control {
7142  
7143 my ( $self, $control_layer_external ) = @_;
7144  
7145 my $result;
7146  
7147 if ( length($control_layer_external) ) {
7148  
7149 $immodpg->{_control_layer_external} = $control_layer_external;
7150  
7151 # print("immodpg,set_layer_control,control_layer_external = $control_layer_external \n");
7152  
7153 }
7154 elsif ( not( length($control_layer_external) ) ) {
7155  
7156 # print("immodpg,set_layer_control, empty string\n");
7157 $immodpg->{_control_layer_external} = $control_layer_external;
7158  
7159 }
7160 else {
7161 print("immodpg,set_layer_control, missing value\n");
7162 }
7163  
7164 return ();
7165 }
7166  
7167 =head2 sub set_missing
7168  
7169  
7170 =cut
7171  
7172 sub set_missing {
7173  
7174 my ( $self, $inbound_missing ) = @_;
7175  
7176 if ( length($inbound_missing) ) {
7177  
7178 $immodpg->{_inbound_missing} = $inbound_missing;
7179  
7180 }
7181 else {
7182 print("immodpg, missing, missing file,\n");
7183 }
7184 return ();
7185 }
7186  
7187 =head2 set_model_layer
7188 Set the number of layers in
7189 mmodpg
7190  
7191 =cut
7192  
7193 sub set_model_layer {
7194  
7195 my ( $self, $model_layer_number ) = @_;
7196  
7197 if ( $model_layer_number != 0
7198 && length($model_layer_number) )
7199 {
7200  
7201 $immodpg->{_model_layer_number} = $model_layer_number;
7202  
7203 }
7204 else {
7205 print("immodpg, set_model_layer, unexpected layer# \n");
7206 }
7207  
7208 # print("immodpg, set_model_layer,modellayer# =$immodpg->{_model_layer_number}\n");
7209  
7210 return ();
7211 }
7212  
7213 =head2 sub set_replacement4missing
7214  
7215  
7216 =cut
7217  
7218 sub set_replacement4missing {
7219  
7220 my ( $self, $replacement4missing ) = @_;
7221  
7222 if ( length($replacement4missing) ) {
7223  
7224 $immodpg->{_replacement4missing} = $replacement4missing;
7225  
7226 }
7227 else {
7228 print("immodpg, set_replacement4missing, missing replacement\n");
7229 }
7230 return ();
7231 }
7232  
7233 =head2 sub set_thickness_m_minus
7234  
7235 update _thickness_m value in gui
7236 update private value in this module
7237  
7238 output option for immodpg.for
7239  
7240 =cut
7241  
7242 sub set_thickness_m_minus {
7243  
7244 my ($self) = @_;
7245  
7246 if ( length( $immodpg->{_thickness_mEntry} )
7247 && looks_like_number( $immodpg->{_thickness_increment_m} ) )
7248 {
7249  
7250 my $thickness_m = ( $immodpg->{_thickness_mEntry} )->get();
7251  
7252 if ( looks_like_number($thickness_m) ) {
7253  
7254 my $thickness_increment_m =
7255 ( $immodpg->{_thickness_increment_mEntry} )->get();
7256 my $new_thickness_m = $thickness_m - $thickness_increment_m;
7257 _set_control( 'thickness_m', $new_thickness_m );
7258 $new_thickness_m = _get_control('thickness_m');
7259  
7260 $immodpg->{_thickness_m_prior} = $immodpg->{_thickness_m_current};
7261 $immodpg->{_thickness_m_current} = $new_thickness_m;
7262  
7263 $immodpg->{_thickness_mEntry}->delete( 0, 'end' );
7264 $immodpg->{_thickness_mEntry}->insert( 0, $new_thickness_m );
7265  
7266 # print("immodpg, set new _thickness_m= $new_thickness_m\n");
7267 # print("immodpg, set_thickness_m_minus, thickness_increment_m= $thickness_increment_m\n");
7268  
7269 # _check_thickness_m(); #todo
7270 _update_thickness_m();
7271  
7272 $immodpg->{_is_thickness_m_changed_in_gui} = $yes;
7273  
7274 if ( $immodpg->{_is_thickness_m_changed_in_gui} eq $yes ) {
7275  
7276 # for fortran program to read
7277 # print("immodpg, set_thickness_m_minus, _thickness_m is changed: $yes \n");
7278  
7279 # _set_thickness_m( $immodpg->{_thickness_m_current} );
7280 _set_option($thickness_m_minus_opt);
7281 _set_change($yes);
7282  
7283 # print("immodpg, set_thickness_m_minus,option:$thickness_m_minus_opt\n");
7284 # print("immodpg, set_thickness_m_minus, V=$immodpg->{_thickness_m_current}\n");
7285  
7286 }
7287 else {
7288  
7289 # negative cases are reset by fortran program
7290 # and so eliminate need to read locked files
7291 # while use of locked files helps most of the time
7292 # creation and deletion of locked files in perl are not
7293 # failsafe
7294 #
7295 # print("immodpg, set_thickness_m_minus, same _thickness_m NADA\n");
7296 }
7297  
7298 }
7299 else {
7300 print(
7301 "immodpg, set_thickness_m_minus, _thickness_m value missing\n");
7302  
7303 # print("immodpg, set_thickness_m_minus, _thickness_mEntry=$immodpg->{_thickness_mEntry}\n");
7304 # print("immodpg, set_thickness_m_minus, thickness_increment_m=$immodpg->{_thickness_increment_m}\n");
7305 }
7306  
7307 }
7308 else {
7309 print(
7310 "immodpg, set_thickness_m_minus, missing widget or thickness_increment_m\n"
7311 );
7312 }
7313 return ();
7314 }
7315  
7316 =head2 sub set_thickness_m_plus
7317  
7318 update _thickness_m value in gui
7319 update private value in this module
7320  
7321 output option for immodpg.for
7322  
7323 =cut
7324  
7325 sub set_thickness_m_plus {
7326  
7327 my ($self) = @_;
7328  
7329 if ( length( $immodpg->{_thickness_mEntry} )
7330 && looks_like_number( $immodpg->{_thickness_increment_m} ) )
7331 {
7332  
7333 my $thickness_m = ( $immodpg->{_thickness_mEntry} )->get();
7334  
7335 if ( looks_like_number($thickness_m) ) {
7336  
7337 my $thickness_increment_m =
7338 ( $immodpg->{_thickness_increment_mEntry} )->get();
7339 my $new_thickness_m = $thickness_m + $thickness_increment_m;
7340 _set_control( 'thickness_m', $new_thickness_m );
7341 $new_thickness_m = _get_control('thickness_m');
7342  
7343 $immodpg->{_thickness_m_prior} = $immodpg->{_thickness_m_current};
7344 $immodpg->{_thickness_m_current} = $new_thickness_m;
7345  
7346 $immodpg->{_thickness_mEntry}->delete( 0, 'end' );
7347 $immodpg->{_thickness_mEntry}->insert( 0, $new_thickness_m );
7348  
7349 # print("immodpg, set_thickness_m_plus, set new _thickness_m= $new_thickness_m\n");
7350 _check_thickness_m(); #todo
7351 _update_thickness_m();
7352  
7353 $immodpg->{_is_thickness_m_changed_in_gui} = $yes;
7354  
7355 if ( $immodpg->{_is_thickness_m_changed_in_gui} eq $yes ) {
7356  
7357 # for fortran program to read
7358 # print("immodpg, set_thickness_m_plus, _thickness_m is changed: $yes \n");
7359  
7360 # _set_thickness_m( $immodpg->{_thickness_m_current} );
7361 _set_option($thickness_m_plus_opt);
7362 _set_change($yes);
7363  
7364 # print("immodpg, set_thickness_m_plus,option:$_thickness_m_plus_opt\n");
7365 # print("immodpg, set_thickness_m_plus, dz=$immodpg->{_thickness_m_current}\n");
7366  
7367 }
7368 else {
7369  
7370 # print("immodpg, set_thickness_m_plus, _thickness_mEntry=$immodpg->{_thickness_mEntry}\n");
7371 # print("immodpg, set_thickness_m_plus, thickness_increment_m=$immodpg->{_thickness_increment_m}\n");
7372  
7373 # negative cases are reset by fortran program
7374 # and so eliminate need to read locked files
7375 # while use of locked files helps most of the time
7376 # creation and deletion of locked files in perl are not
7377 # failsafe
7378 #
7379 # print("immodpg, set_thickness_m_plus, same _thickness_m NADA\n");
7380 }
7381  
7382 }
7383 else {
7384 print(
7385 "immodpg, set_thickness_m_plus, _thickness_m value missing\n");
7386  
7387 # print("immodpg, set_thickness_m_plus, _thickness_mEntry=$immodpg->{_thickness_mEntry}\n");
7388 # print("immodpg, set_thickness_m_plus, thickness_increment_m=$immodpg->{_thickness_increment_m}\n");
7389 }
7390  
7391 }
7392 else {
7393 print(
7394 "immodpg, set_thickness_m_plus, missing widget or thickness_increment_m\n"
7395 );
7396 }
7397 return ();
7398 }
7399  
7400 =head2 sub set_update
7401 Save all values in the immodpg
7402 gui to immodpg.config
7403  
7404 =cut
7405  
7406 sub set_update {
7407 my ($self) = @_;
7408  
7409 print("immodpg, set_update\n");
7410  
7411 setVincrement();
7412 set_thickness_increment_m();
7413 set_thickness_m();
7414 setVbotNtop_factor();
7415 set_clip();
7416  
7417 setVbot();
7418 setVtop();
7419 setVbot_upper_layer();
7420 setVtop_lower_layer();
7421 set_layer();
7422 _set_simple_model_text();
7423 _set_working_model_bin();
7424 _set_working_model_text();
7425  
7426 }
7427  
7428 sub set_widgets {
7429  
7430 my ( $self, $widget_h ) = @_;
7431  
7432 if ($widget_h) {
7433  
7434 # print("immodpg, set_widgets, widget_ ->{_mw}: $widget_h ->{_mw}\n");
7435 $immodpg->{_VbotEntry} = $widget_h->{_VbotEntry};
7436 $immodpg->{_Vbot_upper_layerEntry} =
7437 $widget_h->{_Vbot_upper_layerEntry};
7438 $immodpg->{_VincrementEntry} = $widget_h->{_VincrementEntry};
7439 $immodpg->{_VtopEntry} = $widget_h->{_VtopEntry};
7440 $immodpg->{_Vtop_lower_layerEntry} =
7441 $widget_h->{_Vtop_lower_layerEntry};
7442 $immodpg->{_VbotNtop_factorEntry} = $widget_h->{_VbotNtop_factorEntry};
7443 $immodpg->{_clip4plotEntry} = $widget_h->{_clip4plotEntry};
7444 $immodpg->{_layerEntry} = $widget_h->{_layerEntry};
7445 $immodpg->{_thickness_mEntry} = $widget_h->{_thickness_mEntry};
7446 $immodpg->{_thickness_increment_mEntry} =
7447 $widget_h->{_thickness_increment_mEntry};
7448 $immodpg->{_upper_layerLabel} = $widget_h->{_upper_layerLabel};
7449 $immodpg->{_lower_layerLabel} = $widget_h->{_lower_layerLabel};
7450 $immodpg->{_mw} = $widget_h->{_mw};
7451  
7452 # $immodpg->{_message_box_w} = $widget_h->{_message_box_w};
7453 # $immodpg->{_message_upper_frame} = $widget_h->{_message_upper_frame};
7454 # $immodpg->{_message_lower_frame} = $widget_h->{_message_lower_frame};
7455 # $immodpg->{_message_label_w} = $widget_h->{_message_label_w};
7456 # $immodpg->{_message_box_wait} = $widget_h->{_message_box_wait};
7457 # $immodpg->{_message_ok_button} = $widget_h->{_message_ok_button};
7458  
7459 # print("immodpg, set_widgets, immodpg->{_message_box_w}: $immodpg->{_message_box_w}\n");
7460 # print("immodpg, set_widgets, OK\n");
7461  
7462 return ();
7463  
7464 }
7465 else {
7466 print("immodpg, set_widgets, unexpected\n");
7467 }
7468  
7469 }
7470  
7471 =head2 sub set_base_file_name
7472  
7473 =cut
7474  
7475 sub set_base_file_name {
7476  
7477 my ( $self, $base_file_name ) = @_;
7478  
7479 if ( $base_file_name ne $empty_string ) {
7480  
7481 $immodpg->{_base_file_name} = $base_file_name;
7482  
7483 print("header_values,set_base_file_name,$immodpg->{_base_file_name}\n");
7484  
7485 }
7486 else {
7487 print("header_values,set_base_file_name, missing base file name\n");
7488 }
7489  
7490 return ();
7491  
7492 }
7493  
7494 =head2 sub set_change
7495 verify another lock file does not exist and
7496 only then:
7497  
7498 create another lock file
7499 while change file is written.
7500 that revents fortran file from reading
7501 Then delete lock file
7502 Aavoids crash between asynchronous
7503 reading (fortran) and
7504 writing (Perl) of files
7505  
7506 =cut
7507  
7508 sub set_change {
7509  
7510 my ( $self, $yes_or_no ) = @_;
7511  
7512 # print("immodpg, set_change, yes_or_no:$yes_or_no\n");
7513  
7514 if ( defined($yes_or_no)
7515 && $immodpg->{_change_file} ne $empty_string )
7516 {
7517  
7518 =head2 instantiate classes
7519  
7520 =cut
7521  
7522 my $files = manage_files_by2->new();
7523 my $control = control->new();
7524  
7525 =head2 Define local
7526 variables
7527  
7528 =cut
7529  
7530 my @X;
7531 my $change = $immodpg->{_change_file};
7532  
7533 my $test = $yes;
7534 my $outbound = $IMMODPG_INVISIBLE . '/' . $change;
7535 my $outbound_locked = $outbound . '_locked';
7536 my $format = $var_immodpg->{_format_string};
7537  
7538 my $count = 0;
7539 my $max_counts = $var_immodpg->{_loop_limit};
7540 for (
7541 my $i = 0 ;
7542 ( $test eq $yes ) and ( $count < $max_counts ) ;
7543 $i++
7544 )
7545 {
7546  
7547 # print("1. immodpg,set_change, in loop count=$count \n");
7548  
7549 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
7550  
7551 $X[0] = $empty_string;
7552 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
7553  
7554 # print("immodpg, set_change, outbound_locked=$outbound_locked\n");
7555 # print("immodpg, set_change, IMMODPG_INVISIBLE=$IMMODPG_INVISIBLE\n");
7556 # print("immodpg, set_change, created empty locked file=$X[0]\n");
7557  
7558 # print("immodpg, set_change, outbound=$outbound\n");
7559 # print("immodpg, set_change, IMMODPG_INVISIBLE=$IMMODPG_INVISIBLE\n");
7560  
7561 # do not overwrite a waiting change (= yes)
7562 my $response_aref = $files->read_1col_aref( \$outbound );
7563 my $ans = @{$response_aref}[0];
7564  
7565 if ( $ans eq $yes ) {
7566  
7567 # do not overwrite a waiting change (= yes)
7568 # print("2. immodpg, set_change, SKIP\n");
7569 # print("immodpg, set_change,do not overwrite change_file\n");
7570  
7571 unlink($outbound_locked);
7572  
7573 }
7574 elsif ( $ans eq $no ) {
7575  
7576 # overwrite change_file(=no) with no or yes
7577 $X[0] = $yes_or_no;
7578 $files->write_1col_aref( \@X, \$outbound, \$format );
7579  
7580 # print("immodpg, set_change, overwrite change file with $X[0]\n");
7581  
7582 unlink($outbound_locked);
7583  
7584 # print("3. immodpg, set_change, delete locked file\n");
7585 # print("4. immodpg, set_change, yes_or_no=$X[0]\n");
7586  
7587 $test = $no;
7588  
7589 }
7590 else {
7591 print("immodpg, set_change, unexpected result \n");
7592 } # test change_file's content
7593  
7594 }
7595 else {
7596  
7597 # print("immodpg,_set_change, locked change file\n");
7598 $count++; # governor on finding an unlocked change_file
7599 } # if unlocked file is missing and change_file is free
7600  
7601 $count++; # governor on checking for a change_file = yes
7602 } # for
7603  
7604 }
7605 else {
7606 print("immodpg, set_change, missing values\n");
7607 }
7608 return ();
7609  
7610 } # sub
7611  
7612 =head2 sub set_clip_control
7613 value adjusts to current
7614 clip value in use
7615  
7616 =cut
7617  
7618 sub set_clip_control {
7619  
7620 my ( $self, $control_clip ) = @_;
7621  
7622 my $result;
7623  
7624 if ( length($control_clip)
7625 && $control_clip > 0 )
7626 {
7627  
7628 $immodpg->{_control_clip} = $control_clip;
7629  
7630 # print("immodpg,set_clip_control, control_clip=$immodpg->{_control_clip}\n");
7631  
7632 }
7633 elsif ( not( length($control_clip) ) ) {
7634  
7635 # print("immodpg,_set_clip_control, empty string\n");
7636 $immodpg->{_control_clip} = $control_clip;
7637  
7638 }
7639 else {
7640 print("immodpg,set_clip_control, missing value\n");
7641 }
7642  
7643 return ();
7644 }
7645  
7646 =head2 sub set_option
7647 Verify another lock file does not exist and
7648 only then:
7649  
7650 Create another lock file
7651 while change file is written
7652 that prevents fortran file from reading.
7653 Then, delete the lock file
7654 Avoids crash between asynchronous
7655 reading (fortran) and
7656 writing (Perl) of files
7657  
7658 =cut
7659  
7660 sub set_option {
7661  
7662 my ( $self, $option ) = @_;
7663  
7664 if ( looks_like_number($option)
7665 && $immodpg->{_option_file} ne $empty_string )
7666 {
7667  
7668 =head2 instantiate classes
7669  
7670 =cut
7671  
7672 my $files = manage_files_by2->new();
7673 my $control = control->new();
7674  
7675 =head2 Define local
7676 variables
7677  
7678 =cut
7679  
7680 my @X;
7681 my $option_file = $immodpg->{_option_file};
7682  
7683 my $test = $no;
7684 my $outbound = $IMMODPG_INVISIBLE . '/' . $option_file;
7685 my $outbound_locked = $outbound . '_locked';
7686  
7687 for ( my $i = 0 ; $test eq $no ; $i++ ) {
7688  
7689 if ( not( $files->does_file_exist( \$outbound_locked ) ) ) {
7690
7691 my $format = $var_immodpg->{_format_string};
7692 $X[0] = $empty_string;
7693 $files->write_1col_aref( \@X, \$outbound_locked, \$format );
7694  
7695 $X[0] = $option;
7696 $format = $var_immodpg->{_format_integer};
7697  
7698 # print("immodpg,set_option,option=$option\n");
7699 $files->write_1col_aref( \@X, \$outbound, \$format );
7700  
7701 unlink($outbound_locked);
7702  
7703 $test = $yes;
7704 } # if
7705 } # for
7706  
7707 }
7708 elsif ( $immodpg->{_is_option_changed} eq $no ) {
7709  
7710 # NADA
7711 }
7712 else {
7713 print("immodpg, set_option, unexpected answer\n");
7714 }
7715  
7716 return ();
7717 }
7718  
7719 =head2 sub smute
7720  
7721  
7722 =cut
7723  
7724 sub smute {
7725  
7726 my ( $self, $smute ) = @_;
7727 if ($smute) {
7728  
7729 $immodpg->{_smute} = $smute;
7730 $immodpg->{_note} = $immodpg->{_note} . ' smute=' . $immodpg->{_smute};
7731 $immodpg->{_Step} = $immodpg->{_Step} . ' smute=' . $immodpg->{_smute};
7732  
7733 }
7734 else {
7735 print("immodpg, smute, missing smute,\n");
7736 }
7737 }
7738  
7739 =head2 sub sscale
7740  
7741  
7742 =cut
7743  
7744 sub sscale {
7745  
7746 my ( $self, $sscale ) = @_;
7747 if ($sscale) {
7748  
7749 $immodpg->{_sscale} = $sscale;
7750 $immodpg->{_note} =
7751 $immodpg->{_note} . ' sscale=' . $immodpg->{_sscale};
7752 $immodpg->{_Step} =
7753 $immodpg->{_Step} . ' sscale=' . $immodpg->{_sscale};
7754  
7755 }
7756 else {
7757 print("immodpg, sscale, missing sscale,\n");
7758 }
7759 }
7760  
7761 =head2 sub set_thickness_m
7762  
7763 When you enter or leave,
7764 check what the current thickness_m value is
7765 compared to former thickness_m values
7766  
7767 thickness_m value is updated in immodpg.for
7768 through a message in file="thickness_m"
7769 ($_set_thickness_m)
7770  
7771 =cut
7772  
7773 sub set_thickness_m {
7774  
7775 my ($self) = @_;
7776  
7777 if ( looks_like_number( $immodpg->{_thickness_m_current} ) ) {
7778  
7779 _set_control( 'thickness_m', $immodpg->{_thickness_m_current} );
7780 $immodpg->{_thickness_m_current} = _get_control('thickness_m');
7781  
7782 _check_thickness_m();
7783 _update_thickness_m();
7784  
7785 if ( length( $immodpg->{_is_thickness_m_changed_in_gui} )
7786 && $immodpg->{_is_thickness_m_changed_in_gui} eq $yes )
7787 {
7788  
7789 # for fortran program to read
7790 # print("immodpg, set_thickness_m, thickness_m is changed: $yes \n");
7791  
7792 _set_thickness_m( $immodpg->{_thickness_m_current} );
7793 _set_option($change_thickness_m_opt);
7794 _set_change($yes);
7795  
7796 }
7797 else {
7798  
7799 # negative cases are reset by fortran program
7800 # and so eliminate need to read locked files
7801 # while use of locked files helps most of the time
7802 # creation and deletion of locked files in perl are not
7803 # failsafe
7804  
7805 # print("immodpg, set_thickness_m, same thickness_m NADA\n");
7806 }
7807  
7808 }
7809 else {
7810 print("immodpg, set_thickness_m, _thickness_m value missing\n");
7811 print(
7812 "immodpg, set_thickness_m, thickness_m=$immodpg->{_thickness_m}\n");
7813 }
7814 }
7815  
7816 =head2 sub set_thickness_increment_m
7817 When you enter or leave
7818 check what the current thickness_increment_m value is
7819 compared to former thickness_increment_m values
7820  
7821 thickness_increment_m value is updated in immodpg.for
7822 through a message in file= "thickness_increment_m"
7823 (&_set_thickness_increment_m)
7824  
7825 =cut
7826  
7827 sub set_thickness_increment_m {
7828  
7829 my ($self) = @_;
7830  
7831 # print("immodpg, set_thickness_increment_m, self, $self\n");
7832  
7833 if ( length( $immodpg->{_thickness_increment_mEntry} ) ) {
7834  
7835 $immodpg->{_thickness_increment_m_current} =
7836 ( $immodpg->{_thickness_increment_mEntry} )->get();
7837 _set_control( 'thickness_increment_m',
7838 $immodpg->{_thickness_increment_m_current} );
7839 $immodpg->{_thickness_increment_m_current} =
7840 _get_control('thickness_increment_m');
7841 my $new_thickness_increment_m =
7842 $immodpg->{_thickness_increment_m_current};
7843  
7844 $immodpg->{_thickness_increment_mEntry}->delete( 0, 'end' );
7845 $immodpg->{_thickness_increment_mEntry}
7846 ->insert( 0, $new_thickness_increment_m );
7847  
7848 # print("immodpg, set_thickness_increment_m, $immodpg->{_thickness_increment_mEntry}\n");
7849 _check_thickness_increment_m();
7850 _update_thickness_increment_m_in_gui();
7851 _write_config();
7852  
7853 if ( $immodpg->{_is_layer_changed_in_gui} eq $yes ) {
7854  
7855 print(
7856 "immodpg, set_thickness_increment_m, thickness_increment_m is changed: $yes \n"
7857 );
7858  
7859 _set_thickness_increment_m(
7860 $immodpg->{_thickness_increment_m_current} );
7861 _set_option($change_thickness_increment_m_opt);
7862 _set_change($yes);
7863  
7864 # print("immodpg, set_thickness_increment_m,option:$change_thickness_increment_m_opt\n");
7865 # print(
7866 # "immodpg, set_thickness_increment_m,immodpg->{_thickness_increment_m_current}=$immodpg->{_thickness_increment_m_current}\n"
7867 # );
7868  
7869 }
7870 else {
7871 _set_change($no);
7872  
7873 # print("immodpg, set_thickness_increment_m, same thickness_increment_m NADA\n");
7874 }
7875  
7876 }
7877 else {
7878  
7879 }
7880 }
7881  
7882 =head2 sub tnmo
7883  
7884  
7885 =cut
7886  
7887 sub tnmo {
7888  
7889 my ( $self, $tnmo ) = @_;
7890 if ( $tnmo ne $empty_string ) {
7891  
7892 $immodpg->{_tnmo} = $tnmo;
7893 $immodpg->{_note} = $immodpg->{_note} . ' tnmo=' . $immodpg->{_tnmo};
7894 $immodpg->{_Step} = $immodpg->{_Step} . ' tnmo=' . $immodpg->{_tnmo};
7895  
7896 }
7897 else {
7898 print("immodpg, tnmo, missing tnmo,\n");
7899 }
7900 }
7901  
7902 =head2 sub upward
7903  
7904  
7905 =cut
7906  
7907 sub upward {
7908  
7909 my ( $self, $upward ) = @_;
7910 if ( $upward ne $empty_string ) {
7911  
7912 $immodpg->{_upward} = $upward;
7913 $immodpg->{_note} =
7914 $immodpg->{_note} . ' upward=' . $immodpg->{_upward};
7915 $immodpg->{_Step} =
7916 $immodpg->{_Step} . ' upward=' . $immodpg->{_upward};
7917  
7918 }
7919 else {
7920 print("immodpg, upward, missing upward,\n");
7921 }
7922 }
7923  
7924 =head2 sub vnmo
7925  
7926  
7927 =cut
7928  
7929 sub vnmo {
7930  
7931 my ( $self, $vnmo ) = @_;
7932 if ($vnmo) {
7933  
7934 $immodpg->{_vnmo} = $vnmo;
7935 $immodpg->{_note} = $immodpg->{_note} . ' vnmo=' . $immodpg->{_vnmo};
7936 $immodpg->{_Step} = $immodpg->{_Step} . ' vnmo=' . $immodpg->{_vnmo};
7937  
7938 }
7939 else {
7940 print("immodpg, vnmo, missing vnmo,\n");
7941 }
7942 }
7943  
7944 =head2 sub vnmo_mps
7945  
7946  
7947 =cut
7948  
7949 sub vnmo_mps {
7950  
7951 my ( $self, $vnmo ) = @_;
7952 if ($vnmo) {
7953  
7954 $immodpg->{_vnmo} = $vnmo;
7955 $immodpg->{_note} = $immodpg->{_note} . ' vnmo=' . $immodpg->{_vnmo};
7956 $immodpg->{_Step} = $immodpg->{_Step} . ' vnmo=' . $immodpg->{_vnmo};
7957  
7958 }
7959 else {
7960 print("immodpg, vnmo, missing vnmo,\n");
7961 }
7962 }
7963  
7964 =head2 sub voutfile
7965  
7966  
7967 =cut
7968  
7969 sub voutfile {
7970  
7971 my ( $self, $voutfile ) = @_;
7972 if ($voutfile) {
7973  
7974 $immodpg->{_voutfile} = $voutfile;
7975 $immodpg->{_note} =
7976 $immodpg->{_note} . ' voutfile=' . $immodpg->{_voutfile};
7977 $immodpg->{_Step} =
7978 $immodpg->{_Step} . ' voutfile=' . $immodpg->{_voutfile};
7979  
7980 }
7981 else {
7982 print("immodpg, voutfile, missing voutfile,\n");
7983 }
7984 }
7985  
7986 1;