Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


APDL Helpful Tip: MD5 Checksum for Input File Validation

APDL Helpful Tip: MD5 Checksum for Input File Validation

APDL Helpful Tip: MD5 Checksum for Input File Validation

Recently, I've been using Python to generate APDL run scripts for (somewhat complicated) mission analyses in ANSYS. File management can be difficult for such analyses, and it is helpful to be able to easily verify that a particular set of input files was run for a given set of outputs.

To do this validation, I have found that it is useful to generate a checksum file using an MD5 hashing algorithm when I generate my inputs with Python. Alternatively, you can generate such a file with CYGWIN BASH or in a Linux environment using the md5sum command:


md5sum inputfile.inp database.db *.load *.pres *.temp *.etc>checksum.md5 

What the heck is a hash function?
An MD5 hash can be thought of simply as a 32-digit hexadecimal fingerprint for a blob of data. Identical files will always produce the same hash, however a small change in the data will result in a very different hash.

For example:


> echo "Hello world"|md5sum
f0ef7081e1539ac00ef5b761b4fb01b3 *-
> echo "Hello world."|md5sum
fa093de5fc603823f08524f9801f0546 *- 

Hashing functions are often used to check the validity of files downloaded from the internet. A user can be certain that a file or program wasn't tampered with by a third party if its hash checks out. There are many hashing algorithms; the MD5 is adequate for checking file validity.

Back to ANSYS...
Generating a checksum of a bunch of files is trivial (see above); I've found that it is useful to store that checksum in my ANSYS database files at runtime. I include a few lines of code in my main run script:

CODE --> inputfile.inp

resume, database, db
/filname, loadstep1
*sread, chksum, checksum, md5,,80,,chklines
/sys, md5sum -c checksum.md5>validate_inputs.out
... ! Apply some loads

The data is stored as a string array; you can pull it back out again later with a simple macro. Alas, the system call may not work on all operating systems; Windows users can download a utility to perform MD5 or SHA1 checksums instead.

Microsoft File Checksum Integrity Verifier

Retrieving your checksum later...
Of course, the reason for storing the checksum in the ANSYS database is to verify that your output matches a certain set of inputs. To do so, you'll need to be able to pull the checksum back out of the database. I'd recommend something like this:

CODE --> getchecksum.mac

! Retrieve checksum from database

/sys,sed --in-place -e 's/ *//g' checksum.md5 

ANSYS kicks out your checksum file with leading whitespace to make each line 80 characters. I use SED to strip off leading the whitespace. Windows users have several different options to accomplish this.

SED in Windows

You can then use a utility to run your checksum against a set of input files to easily verify that they were used to generate the output.


md5sum -c checksum.md5 

Quick shout-out
I found the following PADT post very helpful to figure out the best way to store and retrieve the checksum in ANSYS:

Happy holidays,

Christopher K. Hubley
Mechanical Engineer
Cincinnati, Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close