How to use the cdflib.cdfwrite.CDF._convert_type function in cdflib

To help you get started, we’ve selected a few cdflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MAVENSDC / cdflib / cdflib / cdfwrite.py View on Github external
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)):
github MAVENSDC / cdflib / cdflib / cdfwrite.py View on Github external
if indata.size == num_values:  # Check if only one record is being read in
                recs = 1
            else:
                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 Exception:
                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)
github MAVENSDC / cdflib / cdflib / cdfwrite.py View on Github external
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)
            if indata.size == num_values:  # Check if only one record is being read in
                recs = 1
            else:
                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 Exception:
github MAVENSDC / cdflib / cdflib / cdfwrite.py View on Github external
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)
            if indata.size == num_values:  # Check if only one record is being read in
                recs = 1
            else:
                recs = len(indata)
            dt_string = CDF._convert_type(data_type)
            if (data_type == CDF.CDF_EPOCH16):