"""
Modal post-processing of a single Abaqus job

This script extracts the eigenfrequencies stored in the ODB of the current job
and writes them to a text file.

Parameter interface
-------------------
g_Jobname : str
    Abaqus job name provided by a calling batch script. A trailing line break is
    tolerated.

Output
------
test.txt : extracted eigenfrequency values, one row per entry

Author
------
F. Birk
Revised for readability and portability.
"""

odb_name = g_Jobname.strip() + '.odb'
myOdb = openOdb(odb_name, readOnly=True)
odb = session.odbs[odb_name]

xy1 = xyPlot.XYDataFromHistory(
    odb=odb,
    outputVariableName='Eigenfrequency: EIGFREQ for Whole Model',
    suppressQuery=True,
    __linkedVpName__='Viewport: 1'
)
c1 = session.Curve(xyData=xy1)
xyp = session.xyPlots['XYPlot-1']
chartName = xyp.charts.keys()[0]
chart = xyp.charts[chartName]
chart.setValues(curvesToPlot=(c1,))
session.charts[chartName].autoColor(lines=True, symbols=True)
session.viewports['Viewport: 1'].setValues(displayedObject=xyp)
session.xyDataObjects.changeKey(fromName='_temp_1', toName='Eigenvalues')

Eigenwerte = session.xyDataObjects['Eigenvalues']
filename = 'test.txt'

paramsFile = open(filename, 'w')
for i in range(0, len(Eigenwerte), 1):
    string = str(Eigenwerte[i])[1:-1]
    paramsFile.write(string + '
')
paramsFile.close()
myOdb.close()
