Comprehensive Guide to Programming in IDL with Pointers and Extensions
Explore the world of programming in IDL with a focus on dynamic variables, heap and pointers, scientific data formats, GUI development, and IDL extensions. Learn about working with pointers, handling dynamic memory, dealing with external software, and examples of code implementation. Discover how to manipulate pointers, manage memory allocation, and integrate IDL with external languages like Java and Python.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
Programming in IDL Ukazatele, dynamick prom nn , roz en IDL, v deck datov form ty, GUI Pointers, dynamic variables, IDL extension, scientific data formats, GUI L. P ech 8/12/2021, 15/12/2021, 5/1/2022
Outline Dynamic variables in IDL, heap and pointers, functions and procedures working with pointers Scientific formats, data and metadata, examples of cdf and netcdf usage IDL library IDL extension working with dynamic-link libraries (DLL) dynamic-link modules examples of HK-geopack library usage Objects in IDL data and methods, classes and instances, encapsulation, inheritance, polymorphism usage: object (class) definition and instantiation, object lifecycle examples Graphical user interface (GUI) widgets concept example of simple GUI code Code examples at ftp://aurora.troja.mff.cuni.cz/idl_kurs
Pointers help, /mem help, /heap ptr_new(), ptr_new(/no_copy), temporary(), ptr_arr() Null pointer Pointer dereferencing Allocation of space on heap, ptr_new(/alloc) Validation of pointers, ptr_valid() Reference count, heap_refcount, ptr_valid(count= ) Destroying pointers, ptr_free, dangling references Recurrent memory deallocation heap_free, /ptr Restoration of lost pointers, ptr_valid(/cast) Heap memory leakage, garbage collection heap_gc, /ptr Saving heap variables, heap_save, heap_nosave
IDL extensions Cooperation with external software See External Development Guide (IDL Help) spawn running a process (external executable code) outside of IDL communication via pipes possible call_external() calling a subroutine inside external DLL data exchange using subroutine parameters Dynamical Loadable Modules (DLM) calling subroutines of external DLL as if native IDL functions/procedures Remote Procedure Calls (RPC) IDL can work as RPC server - callable from outside COM (e.g. Visual Basic .NET) Export/Import connectors JAVA IDL Export Bridge connector Java Import Bridge Python to IDL Bridge IDL to Python Bridge
SPAWN example External conversion of PS file to PNG From make_png.pro Fin input file (PostScript) Outf output file (PNG) oldpath = getenv('path') setenv, 'path='+oldpath+';C:\Progra~1\gs\gs9.22\bin;C:\Progra~1\gs\gs9.22\lib;C:\Progra~1\gs\fonts;C:\Progra~1\gs\gs9.22\Resource;' gspath = 'gswin64c.exe spawn, gspath + ' -sDEVICE=png256 -r120 -sOutputFile=' + Outf + ' ' + Fin, /log_output
CALL_EXTERNAL example BMSW solar wind flux vector estimation Installation mypath = /mnt/raid3_4/jdata/dll/GNZ_Fcang-sw-kj/libfang.so.1 print, CALL_EXTERNAL(mypath, 'compute_BMSW_init_idl', k) ; path to a loadable library (linux) Usage Itot = 0D & Delta = 0D & Phi = 0D & Mode = 0B ; prepare output variables hvfc = [datHV(*,iii), datFC(*,iii)] ; input one time point f_res=CALL_EXTERNAL(mypath, 'compute_BMSW_angle_idl', hvfc, Itot, Delta, Phi, mode)
DLM example Interface to COM port (serial communication) serial.dlm + serial.dll (compiled from serial.c) both files should be in a folder pointed by the !DLM_PATH system variable MODULE serial FUNCTION COMM_OPEN 1 1 KEYWORDS FUNCTION COMM_CLOSE 0 1 KEYWORDS FUNCTION COMM_READ 1 1 KEYWORDS FUNCTION COMM_WRITE 2 2 IDL code : serial_example.pro port = 'COM4' handle = COMM_OPEN(port, MODE=2) result = COMM_WRITE(handle, 'a') result = COMM_CLOSE(handle) GEOPACK library access idl_geopack.dlm + idl_geopack.dll or use PREF_SET, 'IDL_DLM_PATH', '<IDL_DEFAULT>;M:\software\tdas\idl_geopack\win64', /commit to integrate them into IDL. Restart IDL. both files should be in a folder pointed by the !DLM_PATH system variable print, igp_test() ; test if geopackroutine correctly installed/accessible geopack_recalc_08, long(yy), long(ddd), long(hh), long(mm), long(ss), vgse = [-300,0,0] ; calculate transfer matrix for YYDDD HH:MM:SS geopack_conv_coord_08, xi, yi, zi, xo, yo, zo, /from_gse, /to_gsm ; transfer vector [xi,yi,zi] to [xo,yo,zo]
Scientific data formats One (binary) file contains Scientific data measurements, simulation output Metadata description and properties of sc. data Library SW and tools for access from different languages (IDL, C, C#, Fortran, Java, MATLAB ) Currently v3.7.1 in IDL v8.7
Scientific data formats - CDF CDF variable concept rVaribles all same format (dimensions * number_of_records) zVariables individual formatting (dimensionality) different binary encoding possible (host, network = XDR big endian) Data types (CDF_CHAR, CDF_UCHAR | CDF_BYTE, CDF_INT1, CDF_UINT1 | CDF_INT2, CDF_UINT2, CDF_INT4, CDF_UINT4, CDF_INT8, CDF_UINT8, CDF_EPOCH, CDF_EPOCH16, CDF_TIME_TT2000 | CDF_REAL4, CDF_FLOAT, CDF_REAL8, CDF_DOUBLE ) 0-dimensional rVariable zVariables 2-dimensional rVariable
Scientific data formats - CDF CDF 2-D rVariables In Bold physically stored values
Scientific data formats - CDF CDF Epoch data types CDF_EPOCH 8 bytes, double precision UTC epoch ms from 01-Jan-0000 00:00:00.000 (01-Jan 1 BC) CDF_EPOCH16 2x 8 bytes, double precision UTC epoch ps from 01-Jan-0000 00:00:00.000.000.000.000 (01-Jan 1 BC) CDF TT2000 data types CDF_TIME_TT2000 8 bytes, signed integer, referenced to J2000 ns from 2000-01-01T12:00:00.000000000, leap seconds included TT = UTC + deltaAT + 32.184s, where deltaAT is the sum of the leap seconds since 1960; for example, for 2009, deltaAT is 34s The date range covered for TT2000 is between 1707-09-22 and 2292-04-11 See also M:\cdaweb\misc\CDFLeapSeconds.txt Several compression algorithms supported by CDF library Run-Length encoding of zeros Huffman, adaptive Huffman frequency of certain bytes (optimal encoding tree) GZIP (Lempel-Ziv 77) common substrings
Scientific data formats - CDF CDF metadata global attributes
Scientific data formats - CDF Z-variables time array Local attributes
Scientific data formats - CDF Z-variables scalar array
Scientific data formats - CDF Z-variables vector array related metadata
Scientific data formats - CDF CDF routines in IDL Attributes CDF_ATTCREATE, CDF_ATTDELETE, CDF_ATTEXISTS, CDF_ATTGET, CDF_ATTGET_ENTRY, CDF_ATTINQ, CDF_ATTNUM, CDF_ATTPUT, CDF_ATTRENAME Files CDF_OPEN, CDF_CLOSE, CDF_CREATE, CDF_DELETE, CDF_EXISTS, CDF_COMPRESSION, CDF_SET_MD5CHECKSUM Working w. time CDF_TT2000, CDF_ENCODE_EPOCH, CDF_ENCODE_EPOCH16, CDF_ENCODE_TT2000, CDF_EPOCH, CDF_EPOCH16, CDF_EPOCH_COMPARE, CDF_EPOCH_DIFF, CDF_EPOCH_TOJULDAYS, CDF_LEAPSECONDS_INFO, CDF_PARSE_EPOCH, CDF_PARSE_EPOCH16, CDF_PARSE_TT2000, CDF_TIME conversion to mjd Misc. CDF_DOC, CDF_ERROR, CDF_INQUIRE, CDF_LIB_INFO, CDF_SET_CDF27_BACKWARD_COMPATIBLE, CDF_SET_VALIDATE Variables CDF_VARCREATE, CDF_VARDELETE, CDF_VARGET, CDF_VARGET1, CDF_VARINQ, CDF_VARNUM, CDF_VARPUT, CDF_VARRENAME, CDF_CONTROL
Scientific data formats CDF examples CLUSTER constellation position cdf_close, thfile THEMIS-B position MMS-1 position
Scientific data formats CDF examples WIND interplanetary magnetic field WI_K0_MFI / WI_H0_MFI (dual resolution) Not needed if variable selected by name and not by ID
Scientific data formats CDF examples SolO SWA/PAS L2 alpha ground moments - CDF file creation
Scientific data formats netCDF example DSCOVR position data (NOAA is not NASA so it uses netCDF) ;find GSE position data in NetCDF file
IDL application with graphical user interface
IDL 6.4 can use GUI builder IDL 8.x use code skeletons
Widgets Standard widgets widget_base(), widget_button(), widget_draw(), widget_slider(), widget_droplist(), widget_label(), widget_list(), widget_text(), widget_tab(), widget_table() widget_info(), widget_control Compound widgets CW_bgroup(), CW_pdmenu(), CW_rgbslider(), CW_colorsel(), CW_arcball(), CW_fslider(), CW_field Own widgets, own GUI dialogs
Events Events make GUI application alive GUI apps are Event-driven OS events mouse events, keyboard events timer events tracking event context menu events GUI life 1. Construct widget tree {tree of data structures} 2. Provide Event-handling routine(s) 3. Instantiate widgets on screen {realize widgets} Mapping, sensitivity, visibility, resizing, moving, modal dialogs, blocking/nonblocking 4. Register GUI app. with Xmanager 5. GUI app. Running interaction w. user Events => event handler => event callback routines 6. Destroy widgets MyApp1.pro MyApp1_eventcb.pro MyApp1_eventcb.pro
IDL Virtual Machine How to run your IDL code on a computer without IDL license Write and debug your code on a computer with IDL license Save all compiled procedures/functions to .sav file ;For IDL VM ;save, /routines, filename='X:\ftp_Luna-GL\ait\bmswlgdop_read_tm_kia.sav' Install IDL virtual Machine on a target computer Run IDL VM executable with .sav file as parameter (or select it in the initial dialog) Start > Programs > IDL x.x > IDL Virtual Machine idlrt -vm=<path><filename> Limitations No access to the IDL command line or IDL compiler is provided. Startup files are only executed when a command line is present. No EXECUTE, use CALL_FUNCTION, CALL_METHOD, CALL_PROCEDURE instead w. references to precompiled routines stored in .sav file The COM and Java IDL Export Bridge connector objects are disabled. Callable IDL applications will not run in the IDL Virtual Machine.
Objects in IDL data and methods, classes and instances, encapsulation, inheritance, polymorphism usage: object (class) definition and instantiation, object lifecycle examples