FUNCTION modify_mystruct,a,var,tag,value
atags = tag_names(a)
s = size(var) & ns = n_elements(s)
if s(ns-2) eq 7 then begin
w = where(atags eq strupcase(var),wc)
if wc gt 0 then vnum = w[0] $
else begin
print,'ERROR>modify_mystruct:named variable not in structure!' & return,-1
endelse
endif else begin
if ((var ge 0)AND(var lt n_elements(atags))) then vnum = var $
else begin
print,'ERROR>modify_mystruct:variable# not in structure!' & return,-1
endelse
endelse
vtags = tag_names(a.(vnum))
s = size(tag)
if s[n_elements(s)-2] eq 7 then begin
w = where(vtags eq strupcase(tag))
if w[0] ne -1 then tnum = w[0] $
else begin
print,'ERROR>modify_mystruct:named tag not in structure!' & return,-1
endelse
endif else begin
if ((tag ge 0)AND(tag lt n_elements(vtags))) then tnum = tag $
else begin
print,'ERROR>modify_mystruct:tag# not in structure!' & return,-1
endelse
endelse
for i=0,n_elements(atags)-1 do begin
if (i ne vnum) then b = a.(i) $
else begin
tnames = tag_names(a.(i))
for j=0,n_elements(tnames)-1 do begin
if (j ne tnum) then c = create_struct(tnames(j),a.(i).(j)) $
else c = create_struct(tnames[j],value)
if (j eq 0) then b = c $
else b = create_struct(b,c)
endfor
endelse
if (i eq 0) then aa = create_struct(atags[i],b) $ create initial structure
else begin
c = create_struct(atags[i],b) & aa = create_struct(aa,c)
endelse
endfor
return,aa
end