fixed bug in writedatafile - emp. weight a age
merge with Steve's changes