I am not sure if this condition is enough. What would happen if the user specifies a filename like `mygridfile.xmf` and you create two files named `mygridfile_grid.xmf` and `mygridfile_poly.xmf`. Condition 1 would be true for both so you would create 3 three files.