code: def to_canstrat(self, key, log, lith_field, filename=None, as_text=False):
          
          if (filename is None):
              if (not as_text):
                  m = "You must provide a filename or set as_text to True."
                  raise WellError(m)
  
          strip = self.data[key]
          strip = strip.fill()  # Default is to fill with 'null' intervals.
  
          record = {1: [well_to_card_1(self)],
                    2: [well_to_card_2(self, key)],
                    8: [],
                    7: [interval_to_card_7(iv, lith_field) for iv in strip]
                    }
  
          result = ''
          for c in [1, 2, 8, 7]:
              for d in record[c]:
                  result += write_row(d, card=c, log=log)
  
          if as_text:
              return result
          else:
              with open(filename, 'w') as f:
                  f.write(result)
              return None
docs: Make a Canstrat DAT (aka ASCII) file.
  
          TODO:
              The data part should probably belong to striplog, and only the
              header should be written by the well.
  
          Args:
             filename (str)
             key (str)
             log (str): the log name, should be 6 characters.
             lith_field (str) the name of the lithology field in the striplog's
                 Primary component. Must match the Canstrat definitions.
             filename (str)
             as_text (bool): if you don't want to write a file.