code to merge memd files