;+NAME/ONE LINE DESCRIPTION OF ROUTINE: ; STR_LEN returns the length of a structure variable in bytes. ; ;------------------------------------------------------------------------------- ; Function str_len ; ; Returns the length of a structure variable, in bytes. ; ; Written By: BA Franz, GSC, June 1996 ;------------------------------------------------------------------------------- function str_len,str ntag = n_tags(str) nbytes = 0 for i=0,ntag-1 do begin s = size(str(0).(i)) n = n_elements(s)-1 type = s(n-1) nelm = s(n) case type of 0 : nbytes = 0 1 : nbytes = nbytes + nelm*1 ; byte 2 : nbytes = nbytes + nelm*2 ; int 3 : nbytes = nbytes + nelm*4 ; long 4 : nbytes = nbytes + nelm*4 ; float 5 : nbytes = nbytes + nelm*8 ; double 6 : nbytes = nbytes + nelm*8 ; complex 7 : nbytes = nbytes + nelm*strlen(str(0).(i)) ; string 8 : nbytes = nbytes + nelm*str_len(str(0).(i)) ; structure 9 : nbytes = nbytes + nelm*16 ; complex double endcase endfor if (nbytes eq 0) then message,'Zero length, or otherwise ambiguous structure.',/info return,nbytes end