In these days, a finite element model consists of several INCLUDE files either relative or absolute. When collaborating with other people, it is very difficult to remember sending the included files and also if we do remember, it is cumbersome if not difficult to find them and zip them as one file. I recently encountered this problem and wrote a simple utility in PYTHON to make this a little easier. Once you download this file, you simply invoke this using “pack_dyna main_input_file.k” and it handles all the rest of packing to give you one BZIP2 file to send to your contacts. In some cases, you may want to ignore absolutely references files (/some/path/to/a/include/file.k). To enable this, you can set the variable RELATIVE_FILES_ONLY to 1 which will cause the program to include only relatively included files (path/to/a/relative/file.k).
I must credit Dr. Brian Wainscott who was kind to guide me into using Python.
Download Link: pack_dyna.py
#!/usr/bin/python
# Utility to pack files for a LS-DYNA run
# Author: Suri Bala
import os,sys
RELATIVE_FILES_ONLY=0
if len(sys.argv) == 1:
print "Usage %s main_file.k" % sys.argv[0]
sys.exit()
MAIN_FILE=sys.argv[1]
if os.path.exists(MAIN_FILE)==0:
print " File %s does not exist" % MAIN_FILE
print " Exiting ...."
sys.exit()
JOB_NAME = MAIN_FILE.split(".").pop(0)
FILES=[]
FILES.append(MAIN_FILE)
def process_file (NAME):
file=open(NAME)
for line in file:
nline=line.strip("n")
if len(nline)>0 and nline[0]=="*" and nline[0:4]=="*inc" or nline[0:4]=="*INC":
line=file.next().strip("n")
if os.path.exists(line):
if RELATIVE_FILES_ONLY and line[0]!="/":
FILES.append(line)
else:
FILES.append(line)
process_file(line)
process_file(MAIN_FILE)
FILE_NAME=""
for f in FILES:
FILE_NAME+=" "+f
os.system("tar -cf "+JOB_NAME+".tar "+FILE_NAME)
os.system("bzip2 "+JOB_NAME+".tar")