added mechanism to count number of digits to use in filename