comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Putting bytes into structures

Re: Putting bytes into structures
type: item
description: This is a multi-part message in MIME format. --------------2BE345064975 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Marty Ryba wrote: > Brian Jackel wrote: >> What's the best way to load a given number of bytes into a structure? > Here's a routine called READB.PRO that does exactly what you want. > It recursively descends structures and places the bytes into them. Oops, I noticed it uses a routine called NBYTES.PRO; here it is. Also, both routines need updating to handle type DCOMPLEX for IDL 5.0 -- Dr. Marty Ryba | Of course nothing I say here is official MIT Lincoln Laboratory | policy, and Laboratory affililaton is ryba@ll.mit.edu | for identification purposes only, | blah, blah, blah, ... --------------2BE345064975 Content-Type: text/plain; charset=us-ascii; name="nbytes.pro" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="nbytes.pro" ;+ ; Name: ; nbytes ; Purpose: ; Return the number of bytes in the variable ; Usage: ; nb = nbytes(variable) ; Inputs: ; variable = any IDL variable ; Optional Inputs or Keywords: ; help = flag to print header ; Outputs: ; nb = number of bytes in variable ; Common blocks: ; none ; Procedure: ; Idea from David Stern. ; Modification history: ; write, 22 Feb 92, F.K.Knight ; increase speed by writing to disk only for structures, 10 Sep 92, FKK ; eliminate Unix-specific file (from ali@rsinc.com), 11 Sep 92, FKK ;- function nbytes,variable,help=help ; ; =====>> HELP ; on_error,2 if keyword_set(help) then begin & doc_library,'nbytes' & return,-1 & endif ; ; =====>> CHOOSE OPTION BASED ON TYPE OF VARIABLE ; sz = size(variable) type = sz(sz(0)+1) nelements = sz(sz(0)+2) case type of 0:return,0 ; UNDEFINED 1:return,nelements ; BYTE 2:return,nelements*2 ; INT 3:return,nelements*4 ; LONG 4:return,nelements*4 ; FLOAT 5:return,nelements*8 ; DOUBLE 6:return,nelements*8 ; COMPLEX 7:return,long(total(strlen(variable))) ; STRING: DOESN'T COUNT NULLS 8:begin ; STRUCTURE: COMPILER-SPECIFIC LENGTH …
creator: Marty Ryba
date: 1997-10-23T07:00:00-00:00

Re: Putting bytes into structures
type: item
description: This is a multi-part message in MIME format. --------------4C447A4A12D4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Brian Jackel wrote: > What's the best way to load a given number of bytes into a structure? Here's a routine called READB.PRO that does exactly what you want. It recursively descends structures and places the bytes into them. -- Dr. Marty Ryba | Of course nothing I say here is official MIT Lincoln Laboratory | policy, and Laboratory affililaton is ryba@ll.mit.edu | for identification purposes only, | blah, blah, blah, ... --------------4C447A4A12D4 Content-Type: text/plain; charset=us-ascii; name="readb.pro" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="readb.pro" ;+ ; Name: ; readb ; Purpose: ; Procedure to copy the bits of an array to another IDL variable. ; Good for internal conversion, but limited in scope. ; A more general approach would allow other than array input. ; Examples: ; #1 ; a = replicate(byte('ff'x),4) ; MAKE A SOURCE ARRAY ; t = intarr(2) ; MAKE A DESTINATION ARRAY ; readb,a,t ; NEW ROUTINE ; print,t ; EQUIVALENT TO: t = fix(a,0,2) ; -1 -1 ; #2 ; print, 'test of nested structures' ; print, '=========================' ; st1 = {st1, aa:0L, bb:55.} ; a=bindgen(216) ; JUST ENOUGH BYTES! ; b={t1:0L, t2:0.0, t3:lonarr(5,5), t4:fltarr(5,5), t5:st1} ; readb, a, b ; Usage: ; readb,source,destination[,offset][,/help] ; Inputs: ; source = IDL source array, not a structure ; Optional Inputs: ; offset = offset of starting point measured in elements of source ; Offset is set if this is a recursive call. It might also be ; set if you want to start reading from the middle of the source array. ; Note that offset is just like offset in a = fix(source,offset). ; Keywords: ; help = flag to print header ; Outputs: ; destination = IDL destination variable, any type ; Common blocks: ; none ; Procedure: ; If keyword help is set, call doc_library to print header. ; The recursive portion is from Alan Youn…
creator: Marty Ryba
date: 1997-10-23T07:00:00-00:00