File IO using polymorphic datatypes in Fortran
===

I am writing a library for importing geometries of many types (spheres,planes,NURBS surfaces, stl files...) into a scientific Fortran code. This kind of problem seems taylor-made for OOP because it is simple to define a `type :: geom` and then `type,extends(geom) :: analytic` and so on. The part I am having trouble with is the file IO. 

My solution at this point is to write the parameters defining the shapes, including some flags which tell me which shape it is. When reading, I instantiate a `class(geom) :: object`, (since I don't know ahead of time which subtype it will be) but how can I read it? 

I can't access any of the specific components of the subtype. I read that downcasting is *verboten*, and besides, the new `allocate(subtype :: class)` doesn't seem to work. The new `READ(FORMATTED)` doesn't seem to be implemented by ifort or gfortran. i.e.

    module geom_mod
      type :: geom
      end type
      type,extends(geom) :: sphere
        integer :: type
        real(8) :: center(3),radius
       contains
        generic :: READ(FORMATTED)=> read_sphere ! not implemented anywhere
      end type
    contains
      subroutine read_geom(object)
        class(geom),intent(out),pointer :: object     
        integer :: type

        read(10,*) object%type   ! can't access the subtype data yet

        read(10,*) type
        backspace(10)
        if(type==1) then
          allocate(sphere :: object)! downcast?
          read(10,*) object         ! doesn't work
        end if 
        
      end read_geom
    end module

Am I going about this all wrong? I could hack this using something other than polymorphism, but this seems cleaner everywhere else. Assistance would be greatly appreciated. 