jplephem/daf.py
def add_array(self, name, values, array):
        """Add a new array to the DAF file.

        The summary will be initialized with the `name` and `values`,
        and will have its start word and end word fields set to point to
        where the `array` of floats has been appended to the file.

        """
        f = self.file
        scs = self.summary_control_struct

        record_number = self.bward
        data = bytearray(self.read_record(record_number))
        next_record, previous_record, n_summaries = scs.unpack(data[:24])

        if n_summaries < self.summaries_per_record:
            summary_record = record_number
            name_record = summary_record + 1
            data[:24] = scs.pack(next_record, previous_record, n_summaries + 1)
            self.write_record(summary_record, data)
        else:
            summary_record = ((self.free - 1) * 8 + 1023) // 1024 + 1
            name_record = summary_record + 1
            free_record = summary_record + 2

            n_summaries = 0
            data[:24] = scs.pack(summary_record, previous_record, n_summaries)
            self.write_record(record_number, data)

            summaries = scs.pack(0, record_number, 1).ljust(1024, b'\0')
            names = b'\0' * 1024
            self.write_record(summary_record, summaries)
            self.write_record(name_record, names)

            self.bward = summary_record
            self.free = (free_record - 1) * 1024 // 8 + 1

        start_word = self.free
        f.seek((start_word - 1) * 8)
        array = numpy_array(array)  # TODO: force correct endian
        f.write(array.view())
        end_word = f.tell() // 8

        self.free = end_word + 1
        self.write_file_record()

        values = values[:self.nd + self.ni - 2] + (start_word, end_word)

        base = 1024 * (summary_record - 1)
        offset = int(n_summaries) * self.summary_step
        f.seek(base + scs.size + offset)
        f.write(self.summary_struct.pack(*values))
        f.seek(base + 1024 + offset)
        f.write(name[:self.summary_length].ljust(self.summary_step, b' '))
def add_array(self, name, values, array):
        """Add a new array to the DAF file.

        The summary will be initialized with the `name` and `values`,
        and will have its start word and end word fields set to point to
        where the `array` of floats has been appended to the file.

        """
        f = self.file
        scs = self.summary_control_struct

        record_number = self.bward
        data = bytearray(self.read_record(record_number))
        next_record, previous_record, n_summaries = scs.unpack(data[:24])

        if n_summaries < self.summaries_per_record:
            summary_record = record_number
            name_record = summary_record + 1
            data[:24] = scs.pack(next_record, previous_record, n_summaries + 1)
            self.write_record(summary_record, data)
        else:
            summary_record = ((self.free - 1) * 8 + 1023) // 1024 + 1
            name_record = summary_record + 1
            free_record = summary_record + 2

            n_summaries = 0
            data[:24] = scs.pack(summary_record, previous_record, n_summaries)
            self.write_record(record_number, data)

            summaries = scs.pack(0, record_number, 1).ljust(1024, b'\0')
            names = b'\0' * 1024
            self.write_record(summary_record, summaries)
            self.write_record(name_record, names)

            self.bward = summary_record
            self.free = (free_record - 1) * 1024 // 8 + 1

        start_word = self.free
        f.seek((start_word - 1) * 8)
        array = numpy_array(array)  # TODO: force correct endian
        f.write(array.view())
        end_word = f.tell() // 8

        self.free = end_word + 1
        self.write_file_record()

        values = values[:self.nd + self.ni - 2] + (start_word, end_word)

        base = 1024 * (summary_record - 1)
        offset = int(n_summaries) * self.summary_step
        f.seek(base + scs.size + offset)
        f.write(self.summary_struct.pack(*values))
        f.seek(base + 1024 + offset)
        f.write(name[:self.summary_length].ljust(self.summary_step, b' '))
def add_array ( self , name , values , array ) : f = self . file scs = self . summary_control_struct record_number = self . bward data = bytearray ( self . read_record ( record_number ) ) next_record , previous_record , n_summaries = scs . unpack ( data [ : 24 ] ) if n_summaries < self . summaries_per_record : summary_record = record_number name_record = summary_record + 1 data [ : 24 ] = scs . pack ( next_record , previous_record , n_summaries + 1 ) self . write_record ( summary_record , data ) else : summary_record = ( ( self . free - 1 ) * 8 + 1023 ) // 1024 + 1 name_record = summary_record + 1 free_record = summary_record + 2 n_summaries = 0 data [ : 24 ] = scs . pack ( summary_record , previous_record , n_summaries ) self . write_record ( record_number , data ) summaries = scs . pack ( 0 , record_number , 1 ) . ljust ( 1024 , b'\0' ) names = b'\0' * 1024 self . write_record ( summary_record , summaries ) self . write_record ( name_record , names ) self . bward = summary_record self . free = ( free_record - 1 ) * 1024 // 8 + 1 start_word = self . free f . seek ( ( start_word - 1 ) * 8 ) array = numpy_array ( array ) # TODO: force correct endian f . write ( array . view ( ) ) end_word = f . tell ( ) // 8 self . free = end_word + 1 self . write_file_record ( ) values = values [ : self . nd + self . ni - 2 ] + ( start_word , end_word ) base = 1024 * ( summary_record - 1 ) offset = int ( n_summaries ) * self . summary_step f . seek ( base + scs . size + offset ) f . write ( self . summary_struct . pack ( * values ) ) f . seek ( base + 1024 + offset ) f . write ( name [ : self . summary_length ] . ljust ( self . summary_step , b' ' ) )
Add a new array to the DAF file.

        The summary will be initialized with the `name` and `values`,
        and will have its start word and end word fields set to point to
        where the `array` of floats has been appended to the file.
Add a new array to the DAF file .