def read_metadata(sdmfile, scan=<NUM_LIT:0>, bdfdir=None):
sdmfile = sdmfile.rstrip('<STR_LIT:/>')<EOL>assert os.path.exists(sdmfile), '<STR_LIT>' % sdmfile<EOL>if bdfdir:<EOL><INDENT>if not os.path.exists(bdfdir):<EOL><INDENT>logger.info('<STR_LIT>' % bdfdir)<EOL>bdfdir = os.path.join(sdmfile, '<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>bdfdir = os.path.join(sdmfile, '<STR_LIT>')<EOL><DEDENT>logger.info('<STR_LIT>' % bdfdir)<EOL>sdmfile = sdmfile.rstrip('<STR_LIT:/>')<EOL>scandict = {}; sourcedict = {}<EOL>sdm = sdmpy.SDM(sdmfile)<EOL>if len(sdm['<STR_LIT>']) > <NUM_LIT:1>:    <EOL><INDENT>for i in range(len(sdm['<STR_LIT>'])):<EOL><INDENT>row  = sdm['<STR_LIT>'][i]<EOL>scannum = int(row['<STR_LIT>'])<EOL>if scan in [<NUM_LIT:0>, scannum]:<EOL><INDENT>rowkey = [k for k in row.keys if k.lower() == '<STR_LIT>'][<NUM_LIT:0>]   <EOL>nsubs = int(row[rowkey])<EOL>scanintents = row['<STR_LIT>']<EOL>intentstr = string.join(scanintents.strip().split('<STR_LIT:U+0020>')[<NUM_LIT:2>:], '<STR_LIT:U+0020>')<EOL>startmjd = float(row['<STR_LIT>'])*<NUM_LIT>/<NUM_LIT>           <EOL>endmjd = float(row['<STR_LIT>'])*<NUM_LIT>/<NUM_LIT><EOL>try:<EOL><INDENT>src = str(row["<STR_LIT>"])        <EOL><DEDENT>except:<EOL><INDENT>logger.warn('<STR_LIT>' % (len(scandict)+<NUM_LIT:1>))<EOL><DEDENT>finally:<EOL><INDENT>scandict[scannum] = {}<EOL>scandict[scannum]['<STR_LIT:source>'] = src<EOL>scandict[scannum]['<STR_LIT>'] = startmjd<EOL>scandict[scannum]['<STR_LIT>'] = endmjd<EOL>scandict[scannum]['<STR_LIT>'] = intentstr<EOL>scandict[scannum]['<STR_LIT>'] = nsubs<EOL>scandict[scannum]['<STR_LIT>'] = endmjd-startmjd<EOL>scandict[scannum]['<STR_LIT>'] = int(sdm['<STR_LIT>'][i]['<STR_LIT>'])<EOL><DEDENT>try:<EOL><INDENT>bdfstr = sdm['<STR_LIT>'][i]['<STR_LIT>'].replace('<STR_LIT::>', '<STR_LIT:_>').replace('<STR_LIT:/>', '<STR_LIT:_>')<EOL><DEDENT>except KeyError:<EOL><INDENT>bdfstr = sdm['<STR_LIT>'][i]['<STR_LIT>'].replace('<STR_LIT::>', '<STR_LIT:_>').replace('<STR_LIT:/>', '<STR_LIT:_>')<EOL><DEDENT>scandict[scannum]['<STR_LIT>'] = os.path.join(bdfdir, bdfstr)<EOL>if (not os.path.exists(scandict[scannum]['<STR_LIT>'])) or ('<STR_LIT>' in bdfstr):<EOL><INDENT>scandict[scannum]['<STR_LIT>'] = None<EOL>logger.debug('<STR_LIT>' % (scannum, sdmfile) )<EOL><DEDENT>if scandict[scannum]['<STR_LIT:source>'] not in [sourcedict[source]['<STR_LIT:source>'] for source in sourcedict.iterkeys()]:<EOL><INDENT>for row in sdm['<STR_LIT>']:<EOL><INDENT>src = row['<STR_LIT>'].strip()<EOL>if src == scandict[scannum]['<STR_LIT:source>']:<EOL><INDENT>sourcenum = int(row["<STR_LIT>"])<EOL>direction = row["<STR_LIT>"].strip()<EOL>(ra,dec) = [float(val) for val in direction.strip().split('<STR_LIT:U+0020>')[<NUM_LIT:3>:]]  <EOL>sourcedict[sourcenum] = {}<EOL>sourcedict[sourcenum]['<STR_LIT:source>'] = src<EOL>sourcedict[sourcenum]['<STR_LIT>'] = ra<EOL>sourcedict[sourcenum]['<STR_LIT>'] = dec<EOL>break  <EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>elif ( (len(sdm['<STR_LIT>']) == <NUM_LIT:1>) and (len(sdm['<STR_LIT>']) > <NUM_LIT:1>) ):<EOL><INDENT>logger.warn('<STR_LIT>')<EOL>for row in sdm['<STR_LIT>']:<EOL><INDENT>scannum = int(row['<STR_LIT>'])<EOL>if scan in [<NUM_LIT:0>, scannum]:<EOL><INDENT>startmjd = float(row['<STR_LIT>'])*<NUM_LIT>/<NUM_LIT>           <EOL>endmjd = float(row['<STR_LIT>'])*<NUM_LIT>/<NUM_LIT><EOL>scanintents = row['<STR_LIT>']<EOL>if len(scanintents.strip().split('<STR_LIT:U+0020>')) > <NUM_LIT:1>:<EOL><INDENT>intentstr = string.join(scanintents.strip().split('<STR_LIT:U+0020>')[<NUM_LIT:2>:], '<STR_LIT:U+0020>')<EOL><DEDENT>else:<EOL><INDENT>intentstr = scanintents<EOL><DEDENT>try:<EOL><INDENT>src = row["<STR_LIT>"].strip()        <EOL><DEDENT>except:<EOL><INDENT>logger.warn('<STR_LIT>' % (len(scandict)+<NUM_LIT:1>))<EOL><DEDENT>finally:<EOL><INDENT>scandict[scannum] = {}<EOL>scandict[scannum]['<STR_LIT:source>'] = src<EOL>scandict[scannum]['<STR_LIT>'] = intentstr<EOL>scandict[scannum]['<STR_LIT>'] = startmjd<EOL>scandict[scannum]['<STR_LIT>'] = endmjd<EOL>scandict[scannum]['<STR_LIT>'] = endmjd-startmjd<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return [scandict, sourcedict]<EOL>
Parses XML files to get scan and source information.
    Returns tuple of dicts (scan, source).
    bdfdir is optional location to look for bdfs, will try that first, then ASDMBinary subdirectory.
    bdfstr in scan dict helps find BDFs with read_bdf (with special behavior for prearchive data.
    Optional arg scan can be used to speed up parsing for single scan.