generic code with arguments
calc error and output to file