@Tom : I couldn't figure out how to do arrays or strings of a specific number of bytes.
On Thursday, October 1, 2015 at 6:41:30 PM UTC-4, Tom Breloff wrote: > > This is exactly what my packedStruct macro is for... define the type > (composed of bitstypes) and the macro will set up helper methods to read > raw bytes into the fields. I'm curious if it suits your needs, and what is > missing. > > On Thu, Oct 1, 2015 at 3:39 PM, David McInnis <[email protected] > <javascript:>> wrote: > >> Related follow-on question.. >> >> Is there a nice way to get the data into a type format rather than a >> dict ? >> >> Here's the form I'm using now.. >> function DNP(myfile::String) >> >> dnp = { "File" => myfile } >> fh = open(myfile, "r") >> >> dnp["Label"] = bytestring(readbytes(fh, 4)) >> dnp["Version"] = read(fh, Uint32) >> dnp["Revision"] = read(fh, Uint32) >> dnp["Date"] = bytestring(readbytes(fh, 28)) >> dnp["FileFormat"] = read(fh, Uint32) >> dnp["FileType"] = bytestring(readbytes(fh,4)) >> dnp["OriginalFileName"] = bytestring(readbytes(fh,68)) >> dnp["ReferenceFileName"] = bytestring(readbytes(fh,68)) >> dnp["RelatedFileNameA"] = bytestring(readbytes(fh,68)) >> dnp["RelatedFileNameB"] = bytestring(readbytes(fh,68)) >> dnp["RelatedFileNameC"] = bytestring(readbytes(fh,68)) >> dnp["Annotate"] = bytestring(readbytes(fh,84)) >> dnp["InstrumentModel"] = bytestring(readbytes(fh,36)) >> dnp["InstrumentSerialNumber"] = bytestring(readbytes(fh,36)) >> dnp["SoftwareVersionNumber"] = bytestring(readbytes(fh,36)) >> dnp["CrystalMaterial"] = bytestring(readbytes(fh,36)) >> dnp["LaserWavelengthMicrons"] = read(fh, Float64) >> dnp["LaserNullDoubling"] = read(fh, Uint32) >> dnp["Padding"] = read(fh, Uint32) >> dnp["DispersionConstantXc"] = read(fh, Float64) >> dnp["DispersionConstantXm"] = read(fh, Float64) >> dnp["DispersionConstantXb"] = read(fh, Float64) >> dnp["NumChan"] = read(fh, Uint32) >> dnp["InterferogramSize"] = read(fh, Uint32) >> dnp["ScanDirection"] = read(fh, Uint32) >> dnp["ACQUIREMODE"] = read(fh, Uint32) >> dnp["EMISSIWITY"] = read(fh, Uint32) >> dnp["APODIZATION"] = read(fh, Uint32) >> dnp["ZEROFILL"] = read(fh, Uint32) >> dnp["RUNTIMEMATH"] = read(fh, Uint32) >> dnp["FFTSize"] = read(fh, Uint32) >> dnp["NumberOfCoAdds"] = read(fh, Uint32) >> dnp["SingleSided"] = read(fh, Uint32) >> dnp["ChanDisplay"] = read(fh, Uint32) >> dnp["AmbTemperature"] = read(fh, Float64) >> dnp["InstTemperature"] = read(fh, Float64) >> dnp["WBBTemperature"] = read(fh, Float64) >> dnp["CBBTemperature"] = read(fh, Float64) >> dnp["TEMPERATURE_DWR"] = read(fh, Float64) >> dnp["EMISSIVITY_DWR"] = read(fh, Float64) >> dnp["LaserTemperature"] = read(fh, Float64) >> dnp["SpareI"] = read(fh, Uint32,10) >> dnp["SpareF"] = read(fh, Float64,10) >> dnp["SpareNA"] = bytestring(readbytes(fh,68)) >> dnp["SpareNB"] = bytestring(readbytes(fh,68)) >> dnp["SpareNC"] = bytestring(readbytes(fh,68)) >> dnp["SpareND"] = bytestring(readbytes(fh,68)) >> dnp["SpareNE"] = bytestring(readbytes(fh,68)) >> dnp["End"] = bytestring(readbytes(fh,4)) >> >> >> dnp["Interferograms"] = read(fh, Int16, dnp["InterferogramSize"], >> dnp["NumberOfCoAdds"]) >> fft_size = dnp["FFTSize"] * dnp["ZEROFILL"] * 512 >> dnp["Spectrum"] = read(fh, Float32, fft_size) >> >> close(fh) >> >> wavelength_range = 10000.0 / dnp["LaserWavelengthMicrons"] >> spectral_range = wavelength_range / 2 >> spectral_binsize = spectral_range / fft_size >> x_fft = [0:fft_size-1] * spectral_binsize >> m = dnp["DispersionConstantXm"] >> b = dnp["DispersionConstantXb"] >> c = dnp["DispersionConstantXc"] >> x_corrected = x_fft + c + exp10(m * x_fft + b) >> dnp["WL_cm"] = x_corrected >> dnp["WL_microns"] = 10000.0 ./ x_corrected >> >> >> return dnp >> end >> >> Which works fine, but it leaves me with the data in a form that's ugly >> (to me) in calculations: dnp["InterferogramSize"] * dnp["NumberOfCoAdds"] >> Instead of: dnp.InterferogramSize * dnp.NumberOfCoAdds >> >> I can create an appropriate type like: >> type DNP >> Label >> Version >> Revision >> Date >> #### etc etc >> end >> >> ..but I can't figure out a good way to get the data there. Well, other >> than keeping my current function, defining the type, and then having >> another function to copy the data into the type... ugggggly. >> >> I read all the docs I could find on types but never saw anything that >> hinted at a solution.. maybe a function/type hybrid?? >> I tried creating the type within the function but didn't get anywhere. >> Ideas? >> > >
