;***************************************************************************** ; t_tables is a test program to test the OAL/IDL interface. It is functionally ; equivalent to the C and Fortran versions. ; The two files SGC_0031.LBL and SGC_0031.DAT must be present in the directory ; the program is run under. ; ; Platforms and compilers this has been tested on are: ; 1) SGI/Irix ; 2) Sun SPARCstation/Solaris ; 3) DecAlpha/OSF ; 4) PowerMac, Metrowerks CodeWarrier ; ;***************************************************************************** pro t_tables, TABLE case 1 of (!VERSION.arch eq 'mipseb'): begin ;SGI LABEL_DIR = '/miranda2/monk/oal/lbls/' end (!VERSION.arch eq 'sparc'): begin ;Sun SPARCstation LABEL_DIR = '/hale2/monk/oal/lbls/' end (!VERSION.arch eq 'alpha' and !VERSION.os eq 'OSF'): begin ;Dec Alpha/OSF LABEL_DIR = '/usr/users/monks/oal/lbls/' end else: begin ;Macintosh LABEL_DIR = 'MacT06-2:OAL:' end endcase Z = OaRouteErrorMessages( LABEL_DIR + 'OAL_ERRORS.TXT', 0) print,'' print,'Reading ' + LABEL_DIR + 'SGC_0031.LBL' + '...' print,'' ROOT_NODE = OaParseLabelFile( LABEL_DIR + 'SGC_0031.LBL', $ LABEL_DIR + 'ODL_ERRORS.TXT', 1, 0) if ROOT_NODE eq 0 then begin print,'OaParseLabelFile returned NULL!' return endif TABLE_NODE = OdlFindObjDesc( ROOT_NODE, 'SGC_TABLE', '', '', 0, 0) if TABLE_NODE eq 0 then begin print,'OdlFindObjDesc could not find SGC_TABLE node!' return endif ; Get the VENUS_SC_VECTOR column of the TABLE into memory two different ways. ; #1: Read in the entire table, then extract the VENUS_SC_VECTOR column. TABLE_A = OaReadObject( TABLE_NODE) if TABLE_A eq 0 then begin print,'OaReadObject returned NULL!' return endif ; Find the VENUS_SC_VECTOR column node (in the ODL tree of the in-memory ; table). OA_OBJECT_STRUCT = OaIDLGetOaObjectStruct( TABLE_A) COLUMN_NODE = OdlFindObjDesc( OA_OBJECT_STRUCT.odltree, 'COLUMN', 'NAME', $ 'VENUS_SC_VECTOR', 0, 0) if COLUMN_NODE eq 0 then begin print,'OdlFindObjDesc could not find VENUS_SC_VECTOR node!' return endif TABLE_B = OaGetSubTable( TABLE_A, 1, 256, [COLUMN_NODE], 1) if TABLE_B eq 0 then begin print,'OaGetSubTable failed!' return endif ; Free TABLE_A Z = OaDeleteObject( TABLE_A) ; Method #2: read in only the VENUS_SC_VECTOR with OaReadSubTable. COLUMN_NODE = OdlFindObjDesc( ROOT_NODE, 'COLUMN', 'NAME', 'VENUS_SC_VECTOR', $ 0, 0) if COLUMN_NODE eq 0 then begin print,'OdlFindObjDesc could not find VENUS_SC_VECTOR node!' return endif print,'OaReadSubTable reading in VENUS_SC_VECTOR...' print,'' TABLE_A = OaReadSubTable( TABLE_NODE, 1, 256, [COLUMN_NODE], 1) if TABLE_A eq 0 then begin print,'OaReadSubTable failed!' return endif TABLE_A_VAR = OaIDLGetObjectData( TABLE_A) TABLE_B_VAR = OaIDLGetObjectData( TABLE_B) ; Print out a few values to see if it worked. print, 'First 3 values should be: 5940.21 -729.04 10895.34' print, 'First 3 values are: ', TABLE_A_VAR(0).(0)([0,1,2]) print,'' ; Compare every element in the two tables. W = where( TABLE_A_VAR(*).(0) ne TABLE_B_VAR(*).(0), COUNT) if COUNT eq 0 then begin print,'All the data in the two tables matches.' print,'' endif else begin print,'Data in the two tables does not match!' return endelse Z = OaDeleteObject( TABLE_B) ; Set profile so all SDT's will convert data to ASCII. Whenever you change ; the profile, be sure to remember to set it back afterwords! OaIDLGetProfile, PROFILE PROFILE.dst_format_for_binary_src = !OA.ascii_interchange_format OaIDLSetProfile, PROFILE print,'Converting column data to ASCII...' TABLE_B = OaConvertObject( TABLE_A) if TABLE_B eq 0 then begin print,'OaConvertObject failed!' return endif PROFILE.dst_format_for_binary_src = !OA.binary_interchange_format OaIDLSetProfile, PROFILE ; Print out first row of ASCII data TABLE_B_VAR = OaIDLGetObjectData( TABLE_B) print,'First row of ASCII table is: ' + TABLE_B_VAR(0).(0)(0) + $ TABLE_B_VAR(0).(0)(1) + TABLE_B_VAR(0).(0)(2) print,'' ; Append CR/LF to each row of the ASCII table. TABLE_B = OaAddLineTerminatorstoTable( TABLE_B) if TABLE_B eq 0 then begin print, 'OaAddLineTerminatorstoTable failed!' return endif ; Open output file. FILE_OBJECT = OaOpenOutputFile( 'TMP_TABLE.DAT', !OA.stream, 0) if FILE_OBJECT eq 0 then begin print,'OaOpenOutputFile failed!' return endif ; Write the ASCII table to the output file. Z = OaWriteObject( FILE_OBJECT, TABLE_B) if Z ne 0 then begin print,'OaWriteObject failed!' return endif ; Close the output file and write the label. Z = OaCloseOutputFile( FILE_OBJECT, 'TMP_TABLE.LBL') if Z ne 0 then begin print,'OaCloseOutputFile failed!' return endif print,'Type out TMP_TABLE.DAT and TMP_TABLE.LBL and verify contents.' print,'' ; Import a couple columns, then slice and dice them. TABLE_A_VAR = create_struct( 'FIRST_COLUMN', [11,21,31]) TABLE_B_VAR = create_struct( 'SECOND_COLUMN', [12,22,32]) TABLE_A = OaIDLVariabletoOaObject( TABLE_A_VAR, 'TABLE') TABLE_B = OaIDLVariabletoOaObject( TABLE_B_VAR, 'TABLE') TABLE_A = OaJoinTables( TABLE_A, TABLE_B, !OA.add_columns) Z = OaDeleteObject( TABLE_B) TABLE_A_VAR = OaIDLGetObjectData( TABLE_A) print,'TABLE should have three rows and two columns:' for I=0,2 do begin print,TABLE_A_VAR(I).(0), TABLE_A_VAR(I).(1) endfor print,'' ; Delete the middle row and print out the data. print,'Calling OaDeleteRow to delete second row...' if OaDeleteRow( TABLE_A, 2) eq 0 then begin print,'OaDeleteRow failed!' return endif print,'TABLE should have first and third rows and two columns:' TABLE_A_VAR = OaIDLGetObjectData( TABLE_A) for I=0,1 do begin print,TABLE_A_VAR(I).(0), TABLE_A_VAR(I).(1) endfor print,'' ; Delete the first column. OA_OBJECT_STRUCT = OaIDLGetOaObjectStruct( TABLE_A) COLUMN_NODE = OdlFindObjDesc( OA_OBJECT_STRUCT.odltree, 'COLUMN', 'NAME', $ 'FIRST_COLUMN', 0, 0) if COLUMN_NODE eq 0 then begin print,'Could not find COLUMN node with NAME=FIRST_COLUMN' endif print,'Calling OaDeleteColumn to delete first column...' if OaDeleteColumn( TABLE_A, COLUMN_NODE) eq 0 then begin print,'OaDeleteColumn failed!' return endif print,'TABLE should have first and third rows and second column:' TABLE_A_VAR = OaIDLGetObjectData( TABLE_A) for I=0,1 do begin print,TABLE_A_VAR(I).(0) endfor print,'' print,'All tests worked!' end