code: def _write(self, session, openFile, replaceParamFile):
          events = self.precipEvents
          for event in events:
              openFile.write('EVENT "%s"\nNRGAG %s\nNRPDS %s\n' % (event.description, event.nrGag, event.nrPds))
              if event.nrGag > 0:
                  values = event.values
                  valList = []
                  for value in values:
                      valList.append({'ValueType': value.valueType,
                                      'DateTime': value.dateTime,
                                      'Gage': value.gage.id,
                                      'Value': value.value})
                  pivotedValues = pivot.pivot(valList, ('DateTime', 'ValueType'), ('Gage',), 'Value')
                  gages = session.query(PrecipGage). \
                      filter(PrecipGage.event == event). \
                      order_by(PrecipGage.id). \
                      all()
                  for gage in gages:
                      openFile.write('COORD %s %s "%s"\n' % (gage.x, gage.y, gage.description))
                  for row in pivotedValues:
                      valString = ''
                      keys = sorted([key for key in row if key != 'DateTime' and key != 'ValueType'])
                      for key in keys:
                          if key != 'DateTime' and key != 'ValueType':
                              valString = '%s %.3f' % (valString, row[key])
                      openFile.write('%s %.4d %.2d %.2d %.2d %.2d%s\n' % (
                          row['ValueType'],
                          row['DateTime'].year,
                          row['DateTime'].month,
                          row['DateTime'].day,
                          row['DateTime'].hour,
                          row['DateTime'].minute,
                          valString))