def _convert_data(self, data_type, num_elems, num_values, indata):
        '''
        Converts "indata" into a byte stream

        Parameters:
            data_type : int
                The CDF file data type

            num_elems : int
                The number of elements in the data

            num_values : int
                The number of values in each record

            indata : (varies)
                The data to be converted

        Returns:
            recs : int
                The number of records generated by converting indata
            odata : byte stream
                The stream of bytes to write to the CDF file
        '''

        recSize = CDF._datatype_size(data_type, num_elems) * num_values
        if (isinstance(indata, list) or isinstance(indata, tuple)):
            size = len(indata)
            if (data_type == CDF.CDF_CHAR or data_type == CDF.CDF_UCHAR):
                odata = ''
                for x in range(0, size):
                    adata = indata[x]
                    if (isinstance(adata, list) or isinstance(adata, tuple)):
                        size2 = len(adata)
                        for y in range(0, size2):
                            odata += adata[y].ljust(num_elems, '\x00')
                    else:
                        size2 = 1
                        odata += adata.ljust(num_elems, '\x00')
                recs = int((size*size2)/num_values)
                return recs, odata.encode()
            else:
                tofrom = self._convert_option()
                dt_string = CDF._convert_type(data_type)
                recs = int(size/num_values)
                if (data_type == CDF.CDF_EPOCH16 and
                        isinstance(indata[0], complex)):
                    complex_data = []
                    for x in range(0, recs):
                        acomplex = indata[x]
                        complex_data.append(acomplex.real)
                        complex_data.append(acomplex.imag)
                    size = 2 * size
                    indata = complex_data
                if (data_type == CDF.CDF_EPOCH16 and
                        not isinstance(indata[0], complex)):
                    recs = int(recs/2)
                form = tofrom + str(size) + dt_string
                return recs, struct.pack(form, *indata)
        elif (isinstance(indata, bytes)):
            tofrom = self._convert_option()
            recs = int(len(indata) / recSize)
            dt_string = CDF._convert_type(data_type)
            size = recs * num_values * num_elems
            if (data_type == CDF.CDF_EPOCH16):
                size = size * 2
            form = str(size) + dt_string
            form2 = tofrom + form
            datau = struct.unpack(form, indata)
            return recs, struct.pack(form2, *datau)
        elif (isinstance(indata, np.ndarray)):
            tofrom = self._convert_option()
            npdata = CDF._convert_nptype(data_type, indata)
            recs = len(indata)
            dt_string = CDF._convert_type(data_type)
            if (data_type == CDF.CDF_EPOCH16):
                num_elems = 2 * num_elems
            form = str(recs*num_values*num_elems) + dt_string
            form2 = tofrom + str(recs*num_values*num_elems) + dt_string
            datau = struct.unpack(form, npdata)
            return recs, struct.pack(form2, *datau)
        elif (isinstance(indata, str)):
            return 1, indata.ljust(num_elems, '\x00').encode()
        else:
            tofrom = self._convert_option()
            dt_string = CDF._convert_type(data_type)
            if (data_type == CDF.CDF_EPOCH16):
                num_elems = 2 * num_elems
            try:
                recs = int(len(indata) / recSize)
            except:
                recs = 1
            if (data_type == CDF.CDF_EPOCH16):
                complex_data = []
                if (recs > 1):
                    for x in range(0, recs):
                        acomplex = indata[x]
                        complex_data.append(acomplex.real)
                        complex_data.append(acomplex.imag)
                else:
                    complex_data.append(indata.real)
                    complex_data.append(indata.imag)
                indata = complex_data
            form = tofrom + str(recs*num_values*num_elems) + dt_string
            if (recs*num_values*num_elems > 1):
                return recs, struct.pack(form, *indata)
            else:
                return recs, struct.pack(form, indata)
def _convert_data ( self , data_type , num_elems , num_values , indata ) : recSize = CDF . _datatype_size ( data_type , num_elems ) * num_values if ( isinstance ( indata , list ) or isinstance ( indata , tuple ) ) : size = len ( indata ) if ( data_type == CDF . CDF_CHAR or data_type == CDF . CDF_UCHAR ) : odata = '' for x in range ( 0 , size ) : adata = indata [ x ] if ( isinstance ( adata , list ) or isinstance ( adata , tuple ) ) : size2 = len ( adata ) for y in range ( 0 , size2 ) : odata += adata [ y ] . ljust ( num_elems , '\x00' ) else : size2 = 1 odata += adata . ljust ( num_elems , '\x00' ) recs = int ( ( size * size2 ) / num_values ) return recs , odata . encode ( ) else : tofrom = self . _convert_option ( ) dt_string = CDF . _convert_type ( data_type ) recs = int ( size / num_values ) if ( data_type == CDF . CDF_EPOCH16 and isinstance ( indata [ 0 ] , complex ) ) : complex_data = [ ] for x in range ( 0 , recs ) : acomplex = indata [ x ] complex_data . append ( acomplex . real ) complex_data . append ( acomplex . imag ) size = 2 * size indata = complex_data if ( data_type == CDF . CDF_EPOCH16 and not isinstance ( indata [ 0 ] , complex ) ) : recs = int ( recs / 2 ) form = tofrom + str ( size ) + dt_string return recs , struct . pack ( form , * indata ) elif ( isinstance ( indata , bytes ) ) : tofrom = self . _convert_option ( ) recs = int ( len ( indata ) / recSize ) dt_string = CDF . _convert_type ( data_type ) size = recs * num_values * num_elems if ( data_type == CDF . CDF_EPOCH16 ) : size = size * 2 form = str ( size ) + dt_string form2 = tofrom + form datau = struct . unpack ( form , indata ) return recs , struct . pack ( form2 , * datau ) elif ( isinstance ( indata , np . ndarray ) ) : tofrom = self . _convert_option ( ) npdata = CDF . _convert_nptype ( data_type , indata ) recs = len ( indata ) dt_string = CDF . _convert_type ( data_type ) if ( data_type == CDF . CDF_EPOCH16 ) : num_elems = 2 * num_elems form = str ( recs * num_values * num_elems ) + dt_string form2 = tofrom + str ( recs * num_values * num_elems ) + dt_string datau = struct . unpack ( form , npdata ) return recs , struct . pack ( form2 , * datau ) elif ( isinstance ( indata , str ) ) : return 1 , indata . ljust ( num_elems , '\x00' ) . encode ( ) else : tofrom = self . _convert_option ( ) dt_string = CDF . _convert_type ( data_type ) if ( data_type == CDF . CDF_EPOCH16 ) : num_elems = 2 * num_elems try : recs = int ( len ( indata ) / recSize ) except : recs = 1 if ( data_type == CDF . CDF_EPOCH16 ) : complex_data = [ ] if ( recs > 1 ) : for x in range ( 0 , recs ) : acomplex = indata [ x ] complex_data . append ( acomplex . real ) complex_data . append ( acomplex . imag ) else : complex_data . append ( indata . real ) complex_data . append ( indata . imag ) indata = complex_data form = tofrom + str ( recs * num_values * num_elems ) + dt_string if ( recs * num_values * num_elems > 1 ) : return recs , struct . pack ( form , * indata ) else : return recs , struct . pack ( form , indata )
Converts "indata" into a byte stream

        Parameters:
            data_type : int
                The CDF file data type

            num_elems : int
                The number of elements in the data

            num_values : int
                The number of values in each record

            indata : (varies)
                The data to be converted

        Returns:
            recs : int
                The number of records generated by converting indata
            odata : byte stream
                The stream of bytes to write to the CDF file