This file is indexed.

/usr/share/elmerfront/tcl/ecif_tk_procedureEntryPanel.tcl is in elmer-common 6.1.0.svn.5396.dfsg2-4ubuntu4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
#/*****************************************************************************/
# *
# *  Elmer, A Finite Element Software for Multiphysical Problems
# *
# *  Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
# * 
# *  This program is free software; you can redistribute it and/or
# *  modify it under the terms of the GNU General Public License
# *  as published by the Free Software Foundation; either version 2
# *  of the License, or (at your option) any later version.
# * 
# *  This program is distributed in the hope that it will be useful,
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# *  GNU General Public License for more details.
# *
# *  You should have received a copy of the GNU General Public License
# *  along with this program (in file fem/GPL-2); if not, write to the 
# *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
# *  Boston, MA 02110-1301, USA.
# *
# *****************************************************************************/

#***********************************************************************
#Program:   ELMER Front 
#Module:    ecif_tk_procedureEntryPanel.tcl
#Language:  Tcl
#Date:      06.11.99
#Version:   1.00
#Author(s): Martti Verho
#Revisions: 
#
#Abstract:  Displays a panel with for a field's procedure entry
#
#************************************************************************


#==========================#
#   ProcedureEntryPanel    # 
#==========================#

# Procedure displays a dialog with entry fields for procedure names.
# Result is put into the namespace variable resultId, where Id is the
# id-number for the namespace
#
# When panel is **saved**, **callback-function** is called in the form:
# $callback $id $globArray $fld
#
# Result: delivered using variable result$id
#
proc ProcedureEntryPanel::create { globArray fld callback} {
  global Info Equation Model
  upvar #0 $globArray theArray

  # Increment (unique) id
  variable id
  incr id

  # Namespace variables with id specifier
  #
  variable applyButton$id
  variable callback$id
  variable cancelButton$id
  variable compiler$id
  variable compilerEntry$id
  variable dataChanged$id
  variable field$id
  variable fieldName$id
  variable functionName$id ""
  variable functionNameEntry$id
  variable globArray$id
  variable isMatcProc$id
  variable libraries$id
  variable librariesEntry$id
  variable libraryName$id ""
  variable libraryName$id,abs 0
  variable libraryNameEntry$id
  variable matcWidgetGroup$id
  variable result$id
  variable sourceName$id ""
  variable sourceName$id,abs 0
  variable sourceNameEntry$id
  variable updated$id 0
  variable variableName$id "none"
  variable variableNameButton$id
  variable variableNameMenu$id
  variable variableNamePrev$id
  variable window$id

  set globArray$id $globArray
  
  if { $theArray(currentProcedureDir) == "" } {
    set theArray(currentProcedureDir) $Info(lastProcedureDir)
  }

  set callback$id $callback
  set field$id $fld

  set fname [DataField::getFieldProperty $globArray $fld SifName]

  if { $fname == "" } {
    set fname [DataField::fieldNameGuiToSif $fld]
  }

  set coord_index [DataField::getFieldProperty $globArray $fld CoordinateIndex]
  if { $coord_index > 0 } {
    ;#append fname "_$coord"
  }

  set fieldName$id $fname

  set dataChanged$id 0

  if { [info exists theArray($fld,proc)] &&
       $theArray($fld,proc)
     } {
    set fieldValues [DataField::splitProcedureEntryValue [set theArray($fld)] ]
    set libraryName$id [lindex $fieldValues 0]
    set functionName$id [lindex $fieldValues 1]
    set variableName$id [lindex $fieldValues 2]
    set sourceName$id [lindex $fieldValues 3]

  } else {
    if { [info exists theArray($fld,variables)] &&
          $theArray($fld,variables) != ""
       } {
      set variableName$id $theArray($fld,variables)
    }
  }

  if { "" == [set variableName$id] } {
    set variableName$id "none"
  }

  set variableNamePrev$id [set variableName$id]

  # Do we have a Matc-proc
  #
  if { $Info(matcMarker) == [string index [set functionName$id] 0] } {
    set isMatcProc$id 1
    set functionName$id [ProcedureEntryPanel::getMatcFunctionInName $id]
  } else {
    set isMatcProc$id 0 
  }

  # Set generic compiler command
  # ----------------------------
  if { ![info exist compiler$id] || "" == [set compiler$id] } {
    set EH $Info(ELMER_HOME)
    set idir [file join $EH include]
    
    #-Win32
    if { $Info(platform) == "windows" } {
      regsub -all "/" $idir "\\" idirWIN32

      set compiler$id "f90.exe -dll -I $idirWIN32"

    #-Unix  
    } else {  
      # NOTE: verbode flag (-v) is used  cause SGI f90
      # compiler is otherwise complety silent!

      set compiler$id "f90 -v -I$idir -shared -o"
    }
  }

  # Set default libraries
  # ---------------------
  set libraries$id $Info(procedureLibraries)

  # If nothing entered yet
  if { ![info exist libraries$id] || "" == [set libraries$id] } {
    set EH $Info(ELMER_HOME)
    set ldir [file join $EH lib]
  
    #-Win32
    if { $Info(platform) == "windows" } {
      regsub -all "/" $ldir "\\" ldirWIN32
      set libraries$id "$ldirWIN32\\solver.lib"

    #-Unix  
    } else {  
      set libraries$id ""
    }
  }

  # NOTE: Only one window per panel/field can exists
  set window$id .wPEP$globArray$fld

  set w [set window$id]
  set ProcedureEntry($id,winName) $w

  # Set window title
  set fn [string toupper [set fieldName$id]]
  set title "Procedure definition for $fn"
  set ProcedureEntry($id,winTitle) $title

  set wid [winfo atom $w]
  set ProcedureEntry($id,winId) $wid

  set Info(thisWindow) $w

  if { 1 == [Util::checkPanelWindow ProcedureEntry $wid $ProcedureEntry($id,winTitle) ""] } {
    return
  }  

  toplevel $w
  wm title $w $ProcedureEntry($id,winTitle)

  # We collect Matc-proc value dependent widgets into list list
  set matcWidgetGroup ""

  # Principal frames
  frame $w.f1 ;# Library file, function, source, variable
  frame $w.f2 ;# Libraries, compiler
  frame $w.f3 ;# Edit, Compile buttons
  frame $w.f4 ;# Ok, Cancel buttons

  # Library file etc. subframes
  frame $w.f11
  frame $w.f12
  frame $w.f13
  frame $w.f14

  # Libraries,compiler subframes
  frame $w.f21
  frame $w.f22

  set lw 15
  set ew 35

  #---Entry fields and their labels

  #--Library file name 
  label $w.lLibrary -text "Library file:" -width $lw 

  set e [entry $w.eLibrary -width $ew -textvariable ProcedureEntryPanel::libraryName$id \
                          -font $Info(entryFont)]
  set libraryNameEntry$id $e
  bind $e <KeyRelease> "ProcedureEntryPanel::updated $id $e"

  lappend matcWidgetGroup $e

  # File browser button
  set browse_wdg [button $w.bbLibrary -text "..." -width 1 -height 0 \
                    -command "Util::fillFileEntry $e \
                              -array $globArray \
                              -absVar ProcedureEntryPanel::libraryName$id,abs \
                              -keepExtVar ProcedureEntryPanel::libraryName$id,abs \
                              -initDirFld currentProcedureDir \
                              -resultAbsFld currentProcedureDir" ]

  lappend matcWidgetGroup $browse_wdg

  # Abs check box
  set cb_wdg [checkbutton $w.abLibrary -text "Abs" -variable ProcedureEntryPanel::libraryName$id,abs \
                -command ""]

  lappend matcWidgetGroup $cb_wdg

  #--Function name
  label $w.lFunction -text "Function name:" -width $lw
  set e [entry $w.eFunction -width $ew -textvariable ProcedureEntryPanel::functionName$id\
                            -font $Info(entryFont)]
  set functionNameEntry$id $e
  bind $e <KeyRelease> "ProcedureEntryPanel::updated $id $e"

  # Is Matc-proc  check box
  set cb_wdg [checkbutton $w.isMatcProc -text "Is Matc proc" -variable ProcedureEntryPanel::isMatcProc$id \
                -command "ProcedureEntryPanel::checkMatcProc $id"]



  #--Variable name (an option menu)
  #
  if { [info exists theArray(targetMask)] } {
    set targetMask $theArray(targetMask)
  } else {
    set targetMask $Equation(problemMask)
  }

  label $w.lVariable -text "Variable:" -width $lw
	set accept_array 1
  set val_list [lindex [Panel::getCurrentVariables $targetMask $accept_array] 1]
  set val_list [linsert $val_list 0 "none"]

  set om [Panel::createOptionMenuWidget $w.mVariable ProcedureEntryPanel::variableName$id $val_list]
  set variableNameMenu$id $om
  set variableNameButton$id $w.mVariable

  $w.mVariable configure -width 15 -indicatoron 0 -relief raised \
                         -activebackground $Info(optionMenuBg)

  # NOTE: This seems to be the only event which is handled by the *.menu widget
  # We have to use this event to get the selection, when the menu is pulldown
  # and selection is done after that (not with a single "mouse-stroke")
  bind $om <<MenuSelect>> "ProcedureEntryPanel::checkVariable $id"

  # NOTE: ..menu widget does not respond to this event!
  #bind $om <ButtonRelease-1> "ProcedureEntryPanel::checkVariable $id $w.e4"
  # NOTE: This is not needed, when we use the <<MenuSelect>> event
  #bind $om <ButtonRelease-1> "ProcedureEntryPanel::checkVariable $id"


  #--Source name
  label $w.lSource -text "Source file:" -width $lw
  set e  [entry $w.eSource -width $ew -textvariable ProcedureEntryPanel::sourceName$id\
                           -font $Info(entryFont)]
  set sourceNameEntry$id $e
  bind $e <KeyRelease> "ProcedureEntryPanel::updated $id $e"
  bind $e <KeyPress-Return> "+ProcedureEntryPanel::editSource $id"

  lappend matcWidgetGroup $e

  # File browser button
  set browse_wdg [button $w.bbSource -text "..." -width 1 -height 0 \
                    -command "Util::fillFileEntry $e \
                                -absVar ProcedureEntryPanel::sourceName$id,abs \
                                -keepExtVar ProcedureEntryPanel::sourceName$id,abs"]

  lappend matcWidgetGroup $browse_wdg

  # Abs check box
  set cb_wdg [checkbutton $w.abSource -text "Abs" -variable ProcedureEntryPanel::sourceName$id,abs \
                -command ""]

  lappend matcWidgetGroup $cb_wdg

  #--Compiler command
  label $w.lCompiler -text "Compiler:" -width $lw
  set e  [entry $w.eCompiler -width $ew -textvariable ProcedureEntryPanel::compiler$id\
                             -font $Info(entryFont)]
  set compilerEntry$id $e

  lappend matcWidgetGroup $e

  #--Libraries
  label $w.lLibraries -text "Libraries:" -width $lw
  set e  [entry $w.eLibraries -width $ew -textvariable ProcedureEntryPanel::libraries$id\
                              -font $Info(entryFont)]
  set librariesEntry$id $e
  bind $e <KeyRelease> "ProcedureEntryPanel::updated $id $e"

  lappend matcWidgetGroup $e

  #---Button and button commands
  #-Edit, compile buttons
  eval "button $w.compileSource -text \"Compile source\" -command {ProcedureEntryPanel::compileSource $id }"
  eval "button $w.editSource -text \"Edit source\" -command {ProcedureEntryPanel::editSource $id }"
  
  lappend matcWidgetGroup $w.compileSource
  lappend matcWidgetGroup $w.editSource

  #-Ok, Cancel buttons

  set ap $Info(defaultApplyState)
  set ca $Info(defaultCancelState)
  
  set ok_btn [button $w.ok -text OK -command "ProcedureEntryPanel::ok $id"]
  set cn_btn [button $w.cancel -text Cancel -command "ProcedureEntryPanel::cancel $id" -state $ca]
  set ap_btn [button $w.apply -text Apply -command "ProcedureEntryPanel::apply $id" -state $ap]

  set applyButton$id $ap_btn
  set cancelButton$id $cn_btn

  set matcWidgetGroup$id  $matcWidgetGroup


  #---Pack widgets
  #
  pack $w.f1 $w.f2 $w.f3 $w.f4 -side top -fill y -fill x -expand 1 -anchor c -pady 10 -padx 5

  #pack $textW -side top 

  pack $w.f11 $w.f12 $w.f13 $w.f14 -side top -in $w.f1 -anchor w -fill x -padx 4 -pady 4
  pack $w.f21 $w.f22 -side top -in $w.f2 -anchor w -fill x -padx 4 -pady 4

  #-Frame 1 stuff
  pack $w.lLibrary -side left -in $w.f11 -anchor w
  pack $w.eLibrary -side left -in $w.f11 
  pack $w.bbLibrary -side left -in $w.f11 -padx 2
  pack $w.abLibrary -side left -in $w.f11

  pack $w.lFunction -side left -in $w.f12 -anchor w
  pack $w.eFunction -side left -in $w.f12 
  pack $w.isMatcProc -side left -in $w.f12 

  pack $w.lVariable -side left -in $w.f13 -anchor w
  #pack $w.eVariable -side left -in $w.f13 -fill x
  pack $w.mVariable -side left -in $w.f13 

  pack $w.lSource -side left -in $w.f14 -anchor w
  pack $w.eSource -side left -in $w.f14 
  pack $w.bbSource -side left -in $w.f14 -padx 2
  pack $w.abSource -side left -in $w.f14 

  #-Frame 2 stuff
  pack $w.lCompiler -side left -in $w.f21 -anchor w
  pack $w.eCompiler -side left -in $w.f21

  pack $w.lLibraries -side left -in $w.f22 -anchor w
  pack $w.eLibraries -side left -in $w.f22

  #-Frame 3 stuff
  pack $w.editSource -side left -in $w.f3 -expand 1 -anchor e -padx 30 
  pack $w.compileSource -side left -in $w.f3 -expand 1 -anchor w -padx 30 

  #pack $w.variable -side left -in $w.f3 -expand 1 -anchor c

  #-Frame 4 stuff
  pack $ok_btn -side left -in $w.f4 -expand 1 -anchor e
  pack $cn_btn -side left -in $w.f4 -expand 0 -anchor e -padx 30
  pack $ap_btn -side left -in $w.f4 -expand 1 -anchor w


  #--Check widget states
  #
  ProcedureEntryPanel::checkMatcProc $id

  # Return the handle to ProcedureEntrypanel instance
  focus $w
  return $id 
}


proc ProcedureEntryPanel::delete {id} {
}


# Proc parses each inputline when the procedure stab file
# is read in
#
proc ProcedureEntryPanel::lineParser {id datalines } {

  set lines [split $datalines "\n"]

  set ln [set ProcedureEntryPanel::libraryName$id]
  set fn [set ProcedureEntryPanel::functionName$id]
  
	set arr [set ProcedureEntryPanel::globArray$id]
	set var [DataField::fieldNameSifToGui [set ProcedureEntryPanel::variableName$id]]
	set var_sz [lindex [lindex [DataField::getFieldSize Variables $var] 0] end]

  set new_lines ""

  foreach line $lines {
  
    # Skip stub "comment" lines (= line starting with "!#")
    #
    if { [regexp "^!#" $line] } {
      continue
    }
  
    # Replace:
    # patterns #library-name# with the acual library-name
    # patterns #function-name# with the acual function-name
    #
    regsub -all "#library-name#" $line $ln line
    regsub -all "#function-name#" $line $fn line

    if { "none" != [string tolower [set ProcedureEntryPanel::variableName$id]] } {
      regsub -all "#,n#" $line ",n" line
      regsub -all "#,X#" $line ",X" line
			if { $var_sz > 1 } {
				regsub -all "#,XX#" $line ",X($var_sz)" line
			} else {
				regsub -all "#,XX#" $line ",X" line
			}
    } else {
      regsub -all "#,n#" $line "" line
      regsub -all "#,X#" $line "" line
      regsub -all "#,XX#" $line "" line
    }

    append new_lines $line
    append new_lines "\n"
  }

  return [string trim $new_lines "\n"]
}


proc ProcedureEntryPanel::save {id} {
  global Info
  upvar #0 [set ProcedureEntryPanel::globArray$id] theArray


  # Store results
  # =============
  set result ""
  set sep $Info(dataListSeparator)

  set is_matc [set ProcedureEntryPanel::isMatcProc$id]
  
  if { $is_matc } {
    append result ""
    append result $sep
    append result [ProcedureEntryPanel::getMatcFunctionOutName $id]
    append result $sep
    append result [set ProcedureEntryPanel::variableName$id]
    append result $sep
    append result ""

  } else {
    append result [set ProcedureEntryPanel::libraryName$id]
    append result $sep
    append result [set ProcedureEntryPanel::functionName$id]
    append result $sep
    append result [set ProcedureEntryPanel::variableName$id]
    append result $sep
    append result [set ProcedureEntryPanel::sourceName$id]
  }

  set ProcedureEntryPanel::dataChanged$id 0
  set ProcedureEntryPanel::updated$id 1

  set ProcedureEntryPanel::result$id $result

  [set ProcedureEntryPanel::libraryNameEntry$id]    configure $Info(en_mod_option) $Info(en_nmod_color)
  [set ProcedureEntryPanel::functionNameEntry$id]   configure $Info(en_mod_option) $Info(en_nmod_color)
  [set ProcedureEntryPanel::sourceNameEntry$id]     configure $Info(en_mod_option) $Info(en_nmod_color)
  [set ProcedureEntryPanel::librariesEntry$id]      configure $Info(en_mod_option) $Info(en_nmod_color)
  [set ProcedureEntryPanel::variableNameButton$id]  configure $Info(om_mod_option) $Info(om_nmod_color)

  [set ProcedureEntryPanel::applyButton$id] configure -state disabled
  [set ProcedureEntryPanel::cancelButton$id] configure -state disabled

  set Info(procedureLibraries) [set ProcedureEntryPanel::libraries$id]
  set Info(lastProcedureDir) $theArray(currentProcedureDir) 


  # Call CallBack function
  # ======================
  set cb [set ProcedureEntryPanel::callback$id] 
  set ga [set ProcedureEntryPanel::globArray$id]
  set fld [set ProcedureEntryPanel::field$id]
  $cb $id $ga $fld

}


proc ProcedureEntryPanel::ok { id  {do_exit 1} } {
  global Info

  # If no changes
  if { ![set ProcedureEntryPanel::dataChanged$id] } {

    if {$do_exit} {
      ProcedureEntryPanel::cancel $id
    }

    return
  }


  # Check data
  if { ![ProcedureEntryPanel::checkData $id] } {
    return
  }

  ProcedureEntryPanel::save $id

  if { $do_exit } {
    Panel::cancel [set ProcedureEntryPanel::window$id]
  }
}


proc ProcedureEntryPanel::apply {id} {

  ProcedureEntryPanel::ok $id 0
}


proc ProcedureEntryPanel::cancel {id} {

  if { ![info exists ProcedureEntryPanel::window$id] } {
    return
  }

  set ProcedureEntryPanel::updated$id 0
  set ProcedureEntryPanel::result$id ""

  set ga [set ProcedureEntryPanel::globArray$id]
  set fld [set ProcedureEntryPanel::field$id]
  upvar #0 $ga theArray

  if { [info exist theArray($fld)] &&
       $theArray($fld) == "" &&
       [info exist theArray($fld,proc)]
     } {
    set theArray($fld,proc) 0
    Panel::procedureCheckBoxCommandProc $ga
  }

  Panel::cancel [set ProcedureEntryPanel::window$id]

  ProcedureEntryPanel::delete $id
}


# Check data, return possible error message
#
proc ProcedureEntryPanel::checkData {id} {
  global Info ModelProperty

  set ln [Util::stringTRQ [set ProcedureEntryPanel::libraryName$id]]
  set ln_abs [set ProcedureEntryPanel::libraryName$id,abs]

  set fn [Util::stringTRQ [set ProcedureEntryPanel::functionName$id]]

  set sn [Util::stringTRQ [set ProcedureEntryPanel::sourceName$id]]
  set sn_abs [set ProcedureEntryPanel::sourceName$id,abs]

  set is_matc [set ProcedureEntryPanel::isMatcProc$id]
  
  if { $is_matc } {
    set ln ""
    set needs [list 0 1]
  } else {
    set needs [list 1 1]
  }

  set msg ""

  foreach var  {ln fn} \
          type {Library Function} \
          name {Library Function} \
          need $needs {

    set val [set $var]

    if { $val == "" && $need } {
        set msg "ERROR: $name name missing!"
        Message::dispOkMessage $msg
        return 0
    }

    set check_proc "check"
    append check_proc $type
    append check_proc "Name"

    DataField::$check_proc $val "" msg
  
    if { $msg != "" } {
      Message::dispOkMessage $msg
      return 0
    }
  }

  # WIN32 .dll extension!
  # ======================
  if { $Info(platform) == "windows" } {
    if { $ln != "" } {
      if { ".dll" != [file extension $ln] } {
        append ln ".dll"
      }
    }
  }

  # Add model directory to the library-name and source paths if they are 
  # still relative
  set mdir $ModelProperty(MODEL_DIRECTORY,absolute)

  if { $ln != "" && "relative" == [file pathtype $ln] && $ln_abs } {
    set ln [ file join $mdir $ln ]
  }

  if { $sn != "" &&  "relative" == [file pathtype $sn] && $sn_abs} {
    set sn [ file join $mdir $sn ]
  }

  set ProcedureEntryPanel::libraryName$id $ln
  set ProcedureEntryPanel::sourceName$id $sn

  return 1
}


# Procedure set widget states when Matc-proc checkbox is turned on/off
#
proc ProcedureEntryPanel::checkMatcProc {id} {
  global Info

  if { [set ProcedureEntryPanel::isMatcProc$id] } {
    set state disabled
    set bg $Info(nonActiveBg)
  } else {
    set state normal
    set bg white
  }

  foreach wdg [set ProcedureEntryPanel::matcWidgetGroup$id] {

    if { [string equal -nocase "Entry" [winfo class $wdg]] } {
      Widget::configureSB $wdg $state $bg
    } else {
      Widget::configureS $wdg $state
    }
  }
}


# Procedure checks if the variablename entryfield in the Procedure definition
# panel should be updated
#
proc ProcedureEntryPanel::checkVariable {id} {
  global Info

  # Let option menu widget to update
  Util::doWait 50

  # Pick previous and current Variable name values
  #
  set var [set ProcedureEntryPanel::variableName$id]
  set var_prev [set ProcedureEntryPanel::variableNamePrev$id]

  # NOTE: We should not clear the variable entry field if "User defined"
  # is selected twice, otherwise we could delete laborously entered
  # data!!!
  #
  if { $var_prev != "" && $var == $var_prev } {
    return
  }

  set wdg [set ProcedureEntryPanel::variableNameButton$id]
  $wdg configure $Info(om_mod_option) $Info(om_mod_color)

  [set ProcedureEntryPanel::applyButton$id] configure -state normal
  [set ProcedureEntryPanel::cancelButton$id] configure -state normal
  
  set ProcedureEntryPanel::dataChanged$id 1
  set ProcedureEntryPanel::updated$id 1

  # Update previous variable name to be current name
  set ProcedureEntryPanel::variableNamePrev$id $var
}


proc ProcedureEntryPanel::compileSource {id} {
  global Info Model ModelProperty ProcessTable UserSetting

  if { ![ProcedureEntryPanel::checkData $id] } {
    return
  }

  set sn [set ProcedureEntryPanel::sourceName$id]
  set ln [set ProcedureEntryPanel::libraryName$id]
  set fn [set ProcedureEntryPanel::functionName$id]

  if { $sn ==  "" } {
    set msg [list "No source file name given!"]

    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return
  }
  
  # Test source existence
  set msg ""
  set rc [catch {set sn_ch [open $sn "r"] } msg]

  if { $rc != 0} {
    set msg [list "Cannot find source file!"]

    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return

  } else {
    close $sn_ch
  }

  if { $ln ==  "" } {
    set msg [list "No library name given!"]

    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return
  }

  if { $fn ==  "" } {
    set msg [list "No function name given!"]

    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return
  }

  set compiler [set ProcedureEntryPanel::compiler$id]
  set libs [set ProcedureEntryPanel::libraries$id]

  #--System specific call name specifier
  if { $Info(platform) == "windows" } {
    set sys WIN32
  } else {
    set sys UNIX
  }

  set use_eval 1
  set priority $Info(bgPriorityLevel)
  set add_to_process_table 1
  set show_in_process_list 1
  set browse_mode [string tolower $UserSetting(BROWSE_MODE_PROCEDURE_COMPILER)]
  set browse_delay $Info(browser,smallDelay)
  set process_name $Info(F90,processName)
  set process_tag $Info(F90,processTag)
  set logfile [file join $ModelProperty(LOG_DIRECTORY) $Info(F90,logfile)]
  set exec_name $Info(F90,proc,$sys)

  set EH $Info(ELMER_HOME)

  #-Win32
  if { $sys == "WIN32" } {
    #regsub -all "/" $compiler "\\" compiler
    regsub -all "/" $libs "\\" libs
    regsub -all "/" $sn "\\" sn
    regsub -all "/" $ln "\\" ln

    set exec_cmd $compiler
    set arg "$sn $libs /link /out:$ln"

  #-Unix
  } else {  
    set exec_cmd $compiler
    set arg "$ln $sn $libs"
  }

  #--Changedir to model's directory (store current)
  set Info(currentDirectory) [pwd]

  Util::cpp_exec setCurrentDirectory $ModelProperty(MODEL_DIRECTORY,absolute)

  set runnumber [MenuExec::do_elmer_exec \
    $process_name \
    $use_eval $exec_cmd $arg \
    $priority \
    $add_to_process_table \
    $show_in_process_list \
    $browse_mode \
    $exec_name \
    $process_tag \
    $logfile]

  # If call succesful
  # =================
  if { $runnumber != -1 } {

    set ProcessTable($runnumber,browserDelay) $Info(browser,smallDelay)

    if { $browse_mode == "logfile" } {
      MenuExec::browseProcessLog $runnumber
    }
  }

  #--Restore current directoy
  Util::cpp_exec setCurrentDirectory $Info(currentDirectory)

}


proc ProcedureEntryPanel::editSource {id} {
  global Info Model

  if { ![ProcedureEntryPanel::checkData $id] } {
    return
  }

  set sn [set ProcedureEntryPanel::sourceName$id]

  if { $sn ==  "" } {
    set msg [list "Give source file name!"]

    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return
  }

	set can_delete_cancelled 0
  
  # If not exist, copy stub to the file  
  if { ![file exists $sn] } {

		set can_delete_cancelled 1

    set stub [file join $Info(ELMER_FRONT_HOME) lib "procedure.stub.txt"]

    if { [file exists $stub] } {
      file copy $stub $sn
		
    } else {
      set msg [list "Cannot find stub file:\n\n" \
                    "$stub \n\n" \
                    "for the procedure source file!\n\n" \
                    "Press Ok to create the file and continue"]

      if { "cancel" == [Message::dispOkCancelMessage $msg] } {
        return
      }
      
      # Create the source file
      set ch_id [open $sn "w"]
      close $ch_id 

    }
  }

  set must_exist 0
  set can_edit 1
  set line_parser_cmd [list "ProcedureEntryPanel::lineParser $id"]
  set process_nbr 0
  set can_use_external 0

  set channel_id 0
  set textW [FileBrowser::browse .procedureEditor$id $sn \
                        $must_exist $can_edit $can_delete_cancelled \
												$line_parser_cmd $channel_id \
                        $process_nbr $can_use_external ]

  if { $textW == "" } {
    return
  }

  #$textW configure -font $Info(tableFont)
  set im $ProcedureEntryPanel::insertMarker
  set ii [$textW search -backwards $im end]

  if { $ii != "" } {
    $textW mark set insert $ii
  }

  focus $textW
  $textW configure -state normal

}


proc ProcedureEntryPanel::updated {id wdg} {
  global Info

  $wdg configure $Info(en_mod_option) $Info(en_mod_color)

  [set ProcedureEntryPanel::applyButton$id] configure -state normal
  [set ProcedureEntryPanel::cancelButton$id] configure -state normal

  set ProcedureEntryPanel::dataChanged$id 1
  set ProcedureEntryPanel::updated$id 1
}


proc ProcedureEntryPanel::getMatcFunctionInName {id} {

  set fn [Util::stringTRQ [set ProcedureEntryPanel::functionName$id]]

  set fn [string map {"$MATC" "" "(tx)" ""} $fn]

  set fn [Util::stringTRQ $fn]

  return $fn
}


proc ProcedureEntryPanel::getMatcFunctionOutName {id} {

  set fn "\$MATC "
  append fn [Util::stringTRQ [set ProcedureEntryPanel::functionName$id]]
  append fn "(tx)"

  return $fn
}


# end ecif_tk_procedureEntryPanel.tcl
# ********************