;+
; NAME:
;   MAP_GETDATA
;
; PURPOSE:
;   This function reads coordinate data from an IDL map database file.
;
; CATEGORY:
;   Widgets.
;
; CALLING SEQUENCE:
;   Result = MAP_GETDATA(MapFile[, Segments])
;
; INPUTS:
;   MapFile:    The map data file, eg "...resources\maps\high\bhigh.dat".
;
; OPTIONAL INPUTS:
;   Segments:   A list of the segments to read from the data file. If this is undefined
;               all segments are returned. WARNING: some of these files are BIG.
;
; OUTPUTS:
;   The function returns the lon/lat data in a single structure with tags LON and LAT,
;   each a 1-D vector with segments separated by NaNs.
;
; DEPENDENCIES:
;   Calls FDECOMP from the IDL Astronomy Users' Library.
;
; MODIFICATION HISTORY:
;   Mark Hadfield, March 1996:
;       Written.
;-
function MAP_GETDATA, MapFile, Segments

    fdecomp, mapfile, disk, dir, name, ext

    datafile = disk+dir+name+'.dat '
    indxfile = disk+dir+name+'.ndx '

    index = map_getindex(indxfile)

    if n_elements(segments) eq 0 then segments = lindgen(n_elements(index))

    nn = round(total(index(segments).npts,/double)) + n_elements(segments) - 1L
    out = {lon:replicate(!values.f_nan,nn), lat:replicate(!values.f_nan,nn)}

    openr, lun, /get, datafile, /xdr, /stream

    p = 0L
    for i=0L,n_elements(segments)-1 do begin
        point_lun, lun, index(segments(i)).fptr
        npts = index(segments(i)).npts
        xy=fltarr(2,npts)  &  readu, lun, xy
        out.lon[p+lindgen(npts)] = xy[1,*]
        out.lat[p+lindgen(npts)] = xy[0,*]
        p = p + npts + 1L
    endfor

    free_lun,lun

    return, out

end



