why I cannot delete the temp file in openSees?

Forum for OpenSees users to post questions, comments, etc. on the use of the OpenSees interpreter, OpenSees.exe

Moderators: silvia, selimgunay, Moderators

Post Reply
kengawk
Posts: 103
Joined: Wed Oct 31, 2007 11:55 pm
Location: Beijing JIaotong University
Contact:

why I cannot delete the temp file in openSees?

Post by kengawk » Thu Dec 22, 2016 7:18 am

The program checks the temp file in every loop, and fails to delete the temp file when the loop is finished.

I checks the reture variable of the file operation to make sure the program closes the file.

How can I delete the file "./temp_rec.txt" near the end of code ?



Thanks
Last edited by kengawk on Thu Dec 29, 2016 2:16 am, edited 2 times in total.
Kai Zhang
------------------------------
PH.D. candidate
School of Civil Engineering&Architecture
Beijing Jiaotong University

kengawk
Posts: 103
Joined: Wed Oct 31, 2007 11:55 pm
Location: Beijing JIaotong University
Contact:

Re: why I cannot delete the temp file in openSees?

Post by kengawk » Thu Dec 22, 2016 7:38 am

# ModelD.tcl: generic input shell for use with dynamic models
# Units: kip, in
# Kevin Mackie, 2001/08/01
# mackie@ce.berkeley.edu
# Parameters.tcl Parameters1.tcl
# Takes ground motion and structural input parameters from higher
# level procedure and outputs data to files for computation of UCSD
# output quantities. Performs dynamic excitation only

proc ModelD {param_group directory sf skew L LoH fy fc rho_s DcDs ksoil wt rhos_trans deck abut ida} {

wipe
set directory1 "motion/nga_info/"
set g 386.4
set IDAMIN 0.50 ; #ida_level line46
set IDAMAX 3.70 ; #line 66
set ida_incr 0.16 ;# line 64

# -----------------------------------------------------
# set up earthquake files and parameters


set indxfile [open [format "%sIndex.tcl" $directory] "r"]

set total_eqks 0
while {-1 != [gets $indxfile line] } {

if {[string length $line]<4} {

puts "no string,break in ModelD.tcl!!!"
break
}
set total_eqks [expr $total_eqks+1]

scan $line "%s %s %s" eqk_fp($total_eqks) eqk_fn($total_eqks) eqk_fv($total_eqks)
#puts "eqk_fp($total_eqks):$eqk_fp($total_eqks)\n"
#puts "eqk_fn($total_eqks):$eqk_fn($total_eqks)\n"
#puts "eqk_fv($total_eqks):$eqk_fv($total_eqks)\n"
}
close $indxfile
# ok
#

# -----------------------------------------------------
# begin loop of analysis for each ground motion triplet above
for {set loop_var 1} {$loop_var<=$total_eqks} {incr loop_var} {

###### "
if [catch {open ./temp_rec.txt r} field] {
#puts "field: $field"

set field [open ./temp_rec.txt w]
#set count1_0 0
puts $field $loop_var
close $field
} else {

set analysis_seq [read $field]
if {$loop_var < $analysis_seq} {

continue
} else {

}

close $field
}
#########



if { $ida == 1 } {

# perform ida before moving onto next record
while { $ida_stop==0 } {


if [catch {open ./temp_scl.txt r} field] {
#puts "field: $field"

set field [open ./temp_scl.txt w]
#set count1_0 0
puts $field $ida_cnt

close $field

} else {

set scale_seq [read $field]
if {$ida_cnt < $scale_seq} {

set ida_level [expr $ida_level+$ida_incr] ;#
set ida_cnt [expr $ida_cnt + 1]

continue
} else {


}

close $field
}
#end of if temp_scl.txt exists or not
#########
#----------------------------------------------





if { $ida_level > $IDAMAX } {
set ida_stop 1 ;
##
} else {

#
#-----------------------------------------------------
#########
#-----------------------------------------------------

set fileId [open ./temp_scl.txt w+]
if {$fileId ==0} {

#puts $fileId [temp_rec $count1 ]
#close $fileId
} else {

#set count1_0 [expr $loop_var + 1 ]



puts $fileId [expr $ida_cnt + 1 ]
# invalid command name "temp_rec"
close $fileId

}
#########
#----------------------------------------------

###########################
set ida_level [expr $ida_level+$ida_incr] ;
set ida_cnt [expr $ida_cnt + 1]



}
# end of if ida_level> IDAMAX
}


#-----------------------------------------
#########

file delete "./temp_scl.txt"
#########
#-----------------------------------------

} else {

}
# end of if IDA or not
#-----------------------------------------
#########
set fileId [open ./temp_rec.txt w+]
if {$fileId ==0} {

#puts $fileId [temp_rec $count1 ]
#close $fileId
} else {


#set count1_0 [expr $loop_var + 1 ]



puts $fileId [expr $loop_var + 1 ]
# invalid command name "temp_rec"
close $fileId
}
#########
} ;


#-----------------------------------------
######### PROBLEM HERE

file delete "./temp_rec.txt"
#########
#-----------------------------------------

puts ""

return $Tret
}
Kai Zhang
------------------------------
PH.D. candidate
School of Civil Engineering&Architecture
Beijing Jiaotong University

kengawk
Posts: 103
Joined: Wed Oct 31, 2007 11:55 pm
Location: Beijing JIaotong University
Contact:

Re: why I cannot delete the temp file in openSees?

Post by kengawk » Thu Dec 22, 2016 2:19 pm

forgot to close the file before continue!!!
Kai Zhang
------------------------------
PH.D. candidate
School of Civil Engineering&Architecture
Beijing Jiaotong University

Post Reply