;+ ; NAME: ; usno_init ; PURPOSE: ; Initialize and close USNO AE98 asteroid file ; CATEGORY: ; smei/gen/idl/ephem; USNO Asteroid Ephemeris ; CALLING SEQUENCE: FUNCTION usno_init, asteroid, silent=silent ; INPUTS: ; asteroid scalar; type: string or integer ; asteroid name or asteroid number (see: usno_body) ; OUTPUTS: ; ast_index scalar; type: integer ; index of asteroid in pointer array USNO_PNTR ; ast=-1 if the initialized failed (probably because the ; asteroid files couldn't be located (see usno_body). ; SEE ALSO: ; usno_close, usno_body ; CALLS: ; IsType, usno_body, usno_read ; INCLUDE: @compile_opt.pro ; On error, return to caller ; COMMON BLOCKS: common USNO_INFO, USNO_PNTR ; SIDE EFFECTS: ; Opens an ephemeris file and defines a heap variable. ; RESTRICTIONS: ; usno_close must be called separately to close all open asteroid ; files and free the memory used by the heap variables. ; PROCEDURE: ; > Common block USNO_INFO contains the pointer array USNO_PNTR. ; ; > An asteroid is initialized by opening the asteroid file, reading the ; header and first record of Chebyshev coefficients, and setting up ; a structure in heap memory pointed to by one of the pointers ; in USNO_PNTR. ; > Fhe structure is set up as follows: ; USNO_PNTR[ast] = ptr_new( {USNO_STRUCT, $ ; iU : iU, $ logical unit of asteroid file ; name : ast_name, $ name of asteroid (see usno_body) ; number : ast_number, $ number of asteroid (see usno_body) ; jdi : jdi, $ start JD of ephemeris file ; jdf : jdf, $ end JD of ephemeris file ; jd : ptr_new(jd) , $ start JDs for each record in file ; span : ptr_new(span) , $ periods covered by each record (days) ; order : ptr_new(order), $ order of Chebyshev polynomial for each record ; currec : long(0), $ current record ; curjd : double(-1), $ start JD of current record ; curspan : double(-1), $ period covered by current record ; curorder: long(-1), $ order of Chebeshyv polynomial for current record ; coef : dblarr(14,3)}) Chebyshev coefficients (only coef[0:order;*] is used) ; > The pointer USNO_PNTR[ast] is first checked for validity. If it is a valid heap ; pointer then the asteroid has been initialized already, and usno_init quietly returns. ; USNO_PNTR is an array of heap pointers (one for each asteroid). ; ; MODIFICATION HISTORY: ; SEP-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Modified from USNO AE98 C-software ;- ; Check presence of asteroid ephemeris files ast_name = usno_body(asteroid, file=ast_file, number=ast_number, index=ast_index, total_count=ast_count) IF ast_name EQ '' THEN BEGIN message, /info, 'ephemeris file for asteroid "'+asteroid+'"not available' RETURN, -1 ENDIF InitVar, silent, 0 ; Set up array of pointers; one for each ephemeris file. ; If USNO_PNTR doesn't exist yet it is initialized to an array of NULL pointers. ; (these test as invalid pointers in ptr_valid). IF IsType(USNO_PNTR,/undefined) THEN USNO_PNTR = ptrarr(ast_count) ; Ephemeris for 'ast' already initialized IF ptr_valid(USNO_PNTR[ast_index]) THEN RETURN, ast_index IF silent LE 0 THEN message, /info, 'asteroid '+ast_name+' ('+strcompress(ast_number,/rem)+')' openr, iU, /get_lun, ast_file hdr6 = bytarr(6) hdrint = 0L readu, iU, hdr6, hdrint ; 6+4=10 bytes; hdrinfo=STRING byteorder, hdrint , /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdr6),hdrint hdrinfo = bytarr(hdrint) readu, iU, hdrinfo, hdrint ; 6+4=10 bytes; hdrinfo=Header byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdrinfo),hdrint head = bytarr(hdrint) ; User added string readu, iU, head, hdr6, hdrint ; (user len)+6+4 bytes; hdrinf=_INT__ byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(head),' ', string(hdr6), hdrint hdrinfo = bytarr(hdrint) readu, iU, hdrinfo, hdrint ; hdrinfo=MP_Num byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN mp = hdrint ;print, string(hdrinfo), hdrint readu, iU, hdr6, hdrint ; 6+4=10 bytes; hdrinfo=STRING byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdr6), hdrint hdrinfo = bytarr(hdrint) readu, iU, hdrinfo, hdrint ; hdrinfo=MP_Name byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdrinfo), hdrint hdrinfo = bytarr(hdrint) readu, iU, hdrinfo ; hdrinfo=ceres ;print, string(hdrinfo) readu, iU, hdr6, hdrint ; 6+4=10 bytes; hdrinfo=DOUBLE byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdr6), hdrint hdrinfo = bytarr(hdrint) jdi = double(0) readu, iU, hdrinfo, jdi ; hdrinfo=InitJD byteorder, jdi, /XDRTOD, /SWAP_IF_BIG_ENDIAN ;print, string(hdrinfo),jdi readu, iU, hdr6, hdrint ; 6+4=10 bytes; hdrinfo=DOUBLE byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdr6), hdrint hdrinfo = bytarr(hdrint) jdf = double(0) readu, iU, hdrinfo, jdf ; hdrinfo=FinlJD byteorder, jdf, /XDRTOD, /SWAP_IF_BIG_ENDIAN ;print, string(hdrinfo),jdf readu, iU, hdr6, hdrint ; 6+4=10 bytes; hdrinfo=_INT__ byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdr6), hdrint hdrinfo = bytarr(hdrint) readu, iU, hdrinfo, hdrint ; hdrinfo=NumRec byteorder, hdrint, /LSWAP, /SWAP_IF_BIG_ENDIAN ;print, string(hdrinfo),hdrint numrec = hdrint readu, iU, hdr6 ; 6+4=10 bytes; hdrinfo=_END__ ;print, string(hdr6) hdrinfo = bytarr(12,numrec) readu, iU, hdrinfo ; 6+4=10 bytes; hdrinfo=_END__ jd = double( hdrinfo[ 0: 7,*], 0, numrec) byteorder, jd, /XDRTOD, /SWAP_IF_BIG_ENDIAN span = fix ( hdrinfo[ 8: 9,*], 0, numrec) byteorder, jd, /SSWAP, /SWAP_IF_BIG_ENDIAN span = double( span ) order = fix ( hdrinfo[10:11,*], 0, numrec) byteorder, order, /SSWAP, /SWAP_IF_BIG_ENDIAN order = long ( order ) point_lun, -iU, pos USNO_PNTR[ast_index] = ptr_new( {USNO_STRUCT, $ iU : iU, $ ; used by usno_read ;mp : mp, $ name : ast_name, $ number : ast_number, $ jdi : jdi, $ ; get by usno_eph jdf : jdf, $ ; get by usno_eph ;numrec : numrec, $ jd : ptr_new(jd) , $ ; get by usno_eph span : ptr_new(span) , $ ; get by usno_eph order : ptr_new(order), $ ; get by usno_eph currec : long(0), $ ; set by usno_eph curjd : double(-1), $ ; set by usno_read, get by usno_eph curspan : double(-1), $ ; set by usno_read, get by usno_eph curorder: long(-1), $ ; set by usno_read, get by usno_eph coef : dblarr(14,3)}) ; set by usno_read, get by usno_eph usno_read, ast_index RETURN, ast_index & END