Extract common code from PETSc read and write routines into subroutines.