X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



152 Rate this article:
No rating

How to pass an IDL structure into (or out of) an IDL-IDL bridge child process

The IDL-IDL bridge can be useful for parallel processing, among many other things. Variable data from your parent IDL session can be copied into the child (bridge) process using the SetVar function of the IDL_IDLBridge object. However, this function only supports scalar and array variables of numeric and string type. Complex datatypes, such as structures, are not supported using this method.

However, to work around this limitation, you can convert the structure into a string with IDLDehydrate and JSON_SERIALIZE. The resulting string can be copied to the bridge. Then, inside the bridge, use JSON_PARSE and IDLHydrate to bring it back to its original, identical structure form. 

Below is an IDL code example of this process in action:
 

PRO test_bridgeStructurePass

;Create a structure, convert it to a hash, then to a string
struct = {name:'NameOne', data1:50, data2:['a','b','c'], data3:FLTARR(12)}
h = hash(struct,/extract)
str = json_serialize(h.dehydrate())

;Spawn an IDL-IDL bridge and copy the string variable into the bridge session
oBridge = IDL_IDLBridge()
oBridge.SetVar,'j',str

;Inside the bridge, convert the string to a hash, and then the hash back to a structure
oBridge.EXECUTE, 'd =JSON_PARSE(j)'
oBridge.EXECUTE, "h = IDLHydrate(d,TYPE='ORDEREDHASH')"
oBridge.EXECUTE, 's = h.ToStruct()'

;Modify the structure elements inside the bridge
oBridge.EXECUTE, 's.data1=s.data1*3'
oBridge.EXECUTE, 's.data2=["g","e","f"]'
oBridge.EXECUTE, 's.data3=s.data3+5'

;Convert the structure back to a string inside the bridge
oBridge.EXECUTE, 'h = hash(s,/extract)'
oBridge.EXECUTE, 'str = json_serialize(h.dehydrate())'

;Copy the new string back into the parent IDL session from the bridge and convert it back into a structure
j=oBridge.GetVar('str')
d =JSON_PARSE(j)
h2 = IDLHydrate(d,TYPE='ORDEREDHASH')
s = h2.ToStruct()

;Print the updated structure elements
print,s.data1
print,s.data2
print,s.data3

;Terminate the bridge
oBridge.Cleanup


END

 

Note: The Hydrate and Dehydrate functionality was added in IDL 8.5.2. You must use at least that version for this trick to be possible.

 

 

Created: BC-US 12/23/204
Reviewed: BC-EU 1/25/2025

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »