;------------------------------------------------------------------------------ ; NAME: POINTPDS ; ; PURPOSE: To process the pointer to an object in a PDS file ; ; CALLING SEQUENCE: Result = POINTPDS (label, filename, objectname) ; ; INPUTS: ; Label: String array containing the PDS header ; Filename: Scalar string containing the name of the PDS file to read ; objectname: The name of the object to process pointer information for ; OUTPUTS: ; Result: a structure containing the name of the datafile and the skip ; offset in bytes ; ; OPTIONAL INPUT: none ; ; EXAMPLES: ; To obtain information from TABLE.LBL on a TABLE object: ; IDL> label = HEADPDS ("TABLE.LBL",/SILENT) ; IDL> pointer = POINTPDS (label, "TABLE.LBL","TABLE") ; IDL> help, /STRUCTURE, pointer ; FLAG 1 ; DATAFILE "TABLE.TAB" ; SKIP 2056 ; ; PROCEDURES USED: ; Functions: PDSPAR, CLEAN, STR2NUM ; ; MODIFICATION HISTORY: ; Code to look for both uppercase and lowercase ; datafile name. Parin Choganwala, April 2008 ; ; Code to look into "label" directory for ; formate file(.FMT). Parin Choganwala, April 2008 ; ; Written by: Puneet Khetarpal [August, 2002] ; For a complete list of modifications, see changelog.txt file. ; Modified: P.Choganwala 2008Apr: Enhanced the pointpds to look into ; label directory for .fmt files ; Modified: A.Cardesin 2006Jan: Check RECORD_BYTES only if needed ; A.Cardesin 2005May: Corrected path separator for windows ;------------------------------------------------------------------------------ function pointpds, label, fname, objname ; error protection: on_error, 2 ; initialize structure: pointer = create_struct("flag", 1) ;Modified A.Cardesin 2006Jan: check RECORD_BYTES only if needed (further down) ; ; obtain record bytes keyword value: ; record_bytes = pdspar (label, "RECORD_BYTES", COUNT=recbytescount) ; if (recbytescount eq 0) then begin ; print, "Error: missing required RECORD_BYTES keyword." ; goto, endfun ; endif ; obtain pointer to objname: param = "^" + objname point = PDSPAR (label, param, COUNT=pointercount) if (pointercount eq 0) then begin print, "Error: pointer to " + objname + " object missing." goto, endfun endif ; clean and save pointer as backup: point = clean(point[0], /space) savepoint = point ; remove parentheses from string: rightp = strpos(point, "(" ) leftp = strpos(point, ")" ) if (rightp gt -1 && leftp gt -1) then begin rightp += 1 length = leftp - rightp point = strmid(point, rightp, length) endif ; check for flag and remove it if found: rightp = strpos (point, "") if (rightp gt -1) then begin byte_offset_flag = 1 point = strmid(point, 0, rightp) endif else begin byte_offset_flag = 0 endelse ; check for double quotes and extract: rightp = strpos (point, '"') if (rightp gt -1) then begin leftp = strpos (point,'"', rightp + 1) endif else begin leftp = -1 endelse ; if there was a filename, save it: datafile = "" if (rightp gt -1 && leftp gt -1) then begin rightp += 1 length = leftp - rightp datafile = strmid (point, rightp, length) ; remove the file name from the pointer string: length = strlen(point) - leftp point = strmid (point, leftp + 1, length) endif else if (rightp eq -1 xor leftp eq -1) then begin print, "Error: badly formatted file pointer " + savepoint goto, endfun endif ; obtain bytes_offset or skip bytes: rightp = strpos (point, ",") if (rightp gt -1) then begin rightp += 1 length = strlen(point) point = strmid (point, rightp, length - rightp) endif skip = (strlen(point) eq 0) ? 0 : long(str2num(point)) ; assign the skip bytes for byte offset flag: if (~byte_offset_flag && skip ne 0) then begin ;Modified A.Cardesin 2006Jan: check RECORD_BYTES only if needed; ; ; ; ; ; ; ; obtain record bytes keyword value: ; record_bytes = pdspar (label, "RECORD_BYTES", COUNT=recbytescount) ; if (recbytescount eq 0) then begin ; print, "Error: missing required RECORD_BYTES keyword." ; goto, endfun ; endif ; skip = (skip - 1) * record_bytes[0] endif else if (byte_offset_flag && skip ne 0) then begin skip -= 1 endif ; if there is a datafile, then check: if (strlen(datafile) gt 0) then begin ;Modified A.Cardesin 23 May 2005 ;corrected for Windows, using File_Dirname dir = FILE_DIRNAME(fname,/MARK_DIRECTORY) ;Modification - Apr 2008 - Parin - starts ;Enhanced the pointpds to look into label directory for .fmt files len=strlen(dir) pos=stregex(dir,PATH_SEP()+'data'+PATH_SEP(),/FOLD_CASE) dir1=strmid(dir,0,pos+1) dir2=strlowcase(strmid(dir,pos+1,len)+datafile) dir_lc=dir1+dir2 chk_lc = FILE_TEST(dir_lc) dir2=strupcase(strmid(dir,pos+1,len)+datafile) dir_uc=dir1+dir2 chk_uc = FILE_TEST(dir_uc) if (chk_lc EQ 1) then begin openr, unit, dir_lc, error = err, /get_lun fname = dir_lc endif if (chk_uc EQ 1) then begin openr, unit, dir_uc, error = err, /get_lun fname = dir_uc endif if (chk_lc EQ 0 and chk_uc EQ 0) then begin if (strpos(datafile,'FMT') gt 0) then begin pos=stregex(dir,PATH_SEP()+'data'+PATH_SEP(),/FOLD_CASE) dir1=strmid(dir,0,pos+1) dir2=strlowcase('label/'+ datafile) dir_lc = dir1+dir2 chk_lc = FILE_TEST(dir_lc) dir2=strupcase('label/' + datafile) dir_uc=dir1+dir2 chk_uc = FILE_TEST(dir_uc) if (chk_lc EQ 1) then begin openr, unit, dir_lc, error = err, /get_lun fname = dir_lc endif if (chk_uc EQ 1) then begin openr, unit, dir_uc, error = err, /get_lun fname = dir_uc endif endif endif if (chk_lc EQ 0 and chk_uc EQ 0) then begin message, "Error: could not open data file: " + dir + datafile endif ;Modification - Apr 2008 - Parin - ends endif else begin openr, unit, fname, error = err, /get_lun if (err ne 0) then begin print, "Error: could not re-open " + fname goto, endfun endif endelse close, unit free_lun, unit ; store pointer information in a structure: pointer = create_struct (pointer, "datafile", fname, "skip", skip) return, pointer endfun: pointer.flag = -1 return, pointer end