subroutine omgrism read parameters get handle on source rates file check if this file contains data get handle on the input image file check if the image file corersponds to the Grism-1 or Grism-2 filters set the grism-state for the CAL routines get CAL plate scale get the number of sources detected by omdetect allocate indicators for source shapes and source relations loop source=0, nSources determine the source shape and classify each source according to the filter-dependents specific criteria end loop loop source=0, nSources if source is extended (first-order) loop iSource=0, nSources check if the extended source corresponds to a point-like source (zero-order) by the criteria corresponding to the given Grism filter and mark the zero- and first-order sources as related to each other end loop end if end loop loop source=0, nSource if source is marked as having a corresponding zero-order within the image then extract the spectrum and add the corresponding data table to the output FITS-file end loop write spectra keywords to header write output spectrum file release handles end subroutine omgrism