This file is indexed.

/usr/share/xcrysden/Tcl/wnRunWIEN.tcl is in xcrysden-data 1.5.53-1.

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
#############################################################################
# Author:                                                                   #
# ------                                                                    #
#  Anton Kokalj                                  Email: Tone.Kokalj@ijs.si  #
#  Department of Physical and Organic Chemistry  Phone: x 386 1 477 3523    #
#  Jozef Stefan Institute                          Fax: x 386 1 477 3811    #
#  Jamova 39, SI-1000 Ljubljana                                             #
#  SLOVENIA                                                                 #
#                                                                           #
# Source: $XCRYSDEN_TOPDIR/Tcl/wnRunWIEN.tcl                                       
# ------                                                                    #
# Copyright (c) 1996-2003 by Anton Kokalj                                   #
#############################################################################

proc wnRun_IsERROR {} {
    global system
    if { [file size [exec $system(BINDIR)/wn_errorfile]] } {
	return 1
    }
    return 0    
}

proc wnRunWIEN {command message outf} {
    global wn runWn system xcMisc

    wnRunWIEN_DeleteOutputFile $outf

    set runWn(command) $command
    set runWn(outf) $outf
    #
    # one user has reported that "pipe" execution doesn't work on SUN;
    # provide "direct" execution as a way out
    #
    if { [info exists xcMisc(WIEN_direct_exe)] } {
	if $xcMisc(WIEN_direct_exe) {
	    cd $wn(dir)
	    ###################################################################
	    # calculation can take some time, it's needed to 
	    # give some feed back to the user.
	    set oldgrab [grab current]
	    set mw [DisplayUpdateWidget "Calculating" $message]
	    update
	    grab $mw
	    #if { [catch "exec $command" err] == 1 } 
	    catch {exec $command} err
	    if { [wnRun_IsERROR] } {
		destroy $mw
		wnRunWIENError 
		return 0
	    }
	    destroy $mw
	    return 1
	}
    }

    ###################################################################
    # calculation can take some time, it's needed to 
    # give some feed back to the user.
    set oldgrab [grab current]
    set mw [DisplayUpdateWidget "Calculating" $message]
    update
    grab $mw
    #
    # change cursor to watch, to indicate that something is going on
    #
    SetWatchCursor
	
    set runWn(outf) $outf

    cd $wn(dir)
    set command [concat | $command]

    # ================================
    # run WIENXX in background mode
    # ================================

    set runWn(command) $command
    set runWn(fileID) [open $command r]
    fconfigure $runWn(fileID) -blocking 0
    fileevent $runWn(fileID) readable wnRunWIENEvent
    
    tkwait variable runWn(event_done)
    ResetCursor
    xcSwapBuffers

    destroy $mw
    if { $oldgrab != {} } {
	grab $oldgrab
    }

    #
    # has an error occured during WIEN execution
    #
    if { $runWn(error) == 1 } {
	#if [catch {exec $command < $inp > $output_file} err]
	#C95Error $command $output_file $err
	cd $system(SCRDIR)
	unset runWn
	ResetCursor
	return 0
    } else {
	# if we have parallel execution, this will concatenate output files
	wnRunWIEN_ReadOutputFile $outf
    }
    unset runWn
    ResetCursor

    
    return 1
}
    

proc wnRunWIENEvent {} {
    global runWn
    
    if { ![eof $runWn(fileID)] } {
	append runWn(output) [gets $runWn(fileID)]\n
	xcDebug "$runWn(output)"
	return
    } else {
	xcDebug "In wnRunWIENEvent"
	set runWn(error) 0
	if { [catch {close $runWn(fileID)}] } {
	    set runWn(error) 1
	}
	
	#
	# if we have an error display tk_dialog
	#
	if { $runWn(error) } {
	    # is it really an error; check the error file !!!
	    if { [wnRun_IsERROR] } {
		wnRunWIENError
	    } else {
		set runWn(error) 0
	    }
	}
	
	set runWn(event_done) 1
    }
}


proc wnRunWIENError {} {
    global runWn
    
    set button [tk_dialog [WidgetName] ERROR "ERROR occure while executing WIEN2k command: $runWn(command)" error 0 OK Details]
    if { $button == 1} {
	set oldgrab [grab current]
	set t [xcToplevel [WidgetName] "WIEN2k ERROR" "ERROR" \
		. 100 100 1]
	grab $t

	set output [wnRunWIEN_ReadOutputFile $runWn(outf)]
	set text [DispText $t.f $output 80 20]
	set fric [lindex [$text yview] 1]
	$text yview moveto [expr 1.0 - $fric]
	$text config -state disabled
	
	proc wnRunWIENErrorClose {} {
	    global runWn
	    set runWn(error_done) 1
	}
	
	set f2 [frame $t.f2 -height 10]
	pack $f2 -side bottom -before $t.f -fill x
	set close [button $f2.cl -text "Close" \
		-command wnRunWIENErrorClose]
	pack $close -side left -expand 1 -ipadx 2 -ipady 2 -pady 10
	
	tkwait variable runWn(error_done)
	
	grab release $t
	destroy $t	
	if { $oldgrab != "" } {
	    grab $oldgrab
	}
    }
}


proc wnRunWEIN_IsParallel {} {
    global wn
    
    if { [info exists wn(parallel)] } {
	if { $wn(parallel) == 1 } {
	    return 1
	}
    }
    return 0
}

proc wnRunWIEN_DeleteOutputFile {outf} {
    global wn

    file delete $outf 
    if { [wnRunWEIN_IsParallel] } {
	file delete [glob -nocomplain ${outf}_*]
    }
}

proc wnRunWIEN_ReadOutputFile {outf} {
    global wn

    if { [wnRunWEIN_IsParallel] } {

	# it was a parallel run, concatenate output files
	
	set nproc [wnRunWIEN_NProc]
	puts stderr "wien-parallel: nproc=$nproc"
	
	if { $nproc > 0 } {
	    # check if all parallel output files exist and are larger > 0
	    set concate 1
	    for {set i 1} {$i<=$nproc} {incr i} {
		if { ! [file exists ${outf}_$i] } {
		    set concate 0
		    break
		} else {
		    if { [file size ${outf}_$i] == 0 } {
			set concate 0
			break
		    }
		    if { [file exists $outf] } {
			if { [file mtime $outf] > [file mtime ${outf}_$i] } {
			    # the $outf is newer than the ${outf}_$i, use $outf
			    set concate 0
			    break
			}
		    }
		}
	    }
	    if { $concate } {
		for {set i 1} {$i<=$nproc} {incr i} {
		    puts stderr "wien-parallel: proc=$i, output-file=${outf}_$i"
		    append output [ReadFile ${outf}_$i]
		}
		if { [info exists output] } {		
		    WriteFile $outf $output
		    return $output
		}
	    }
	}
    }

    puts stderr "wien: output-file=$outf"
    return [ReadFile $outf]    	
}


proc wnRunWIEN_NProc {} {
    global wn
    
    set pwdDir [pwd]

    cd $wn(dir)
       # try with this:
       catch {set result [exec grep -v init .processes | wc]}
    cd $pwdDir

    if { [info exists result] } {
	return [lindex $result 0]
    } else {
	return 0
    }    
}