# This glish module lists the scan numbers and observed object names from # all of the files under /home/gbtdata for the specified project ID and # device. The default device is the spectral processor. The default # output is stdout, but the output may be directed to a file named in the # third argument. # To run from the glish prompt: # - include 'list_scans.g' # - list_scans('AGBT02A_069_01') include '/users/rfisher/Applications/FitsCode/fits_client.g'; function list_scans ( project, device='SpectralProcessor', out_file='' ) { # assemble the directory path name and get a list of file names path := spaste('/home/gbtdata/', project, '/', device) ls := shell(spaste('ls ', path)) if (len(ls) < 1) { return } file_num := 0 # if file output has been requested, open the file if (out_file != '') { fd := open(spaste('> ', out_file)) } # step through every file in the list for (fn in ls) { sfn := split(fn, '.') # if it's not a FITS file, skip it if (sfn[len(sfn)] == 'fits') { file_num +:= 1 fpn := spaste(path, '/', fn) # load the contents of the fits file into a record ft := get_fits(fpn) # heck for empty headers if (has_field(ft.main_header, 'SCAN')) { # retrieve the SCAN and OBJECT keyword values in the main header scan := ft.main_header.SCAN object := ft.main_header.OBJECT # if it's a spectral pocessor FITS file, use the DATA array # dimensions to get the number of receivers and number # of records (integrations) in the data table if (device == 'SpectralProcessor') { num_rcvrs := ft.DATA.Columns.DATA::shape[3] num_records := ft.DATA.Columns.DATA::shape[4] # assemble the output string line := spaste('Scan ', scan, ' ', object, ' - ', num_rcvrs, ' receivers ', num_records, ' records') } else { line := spaste('Scan ', scan, object) } # print or write the output line if (out_file == '') { print line } else { write(fd, spaste(line, '\n')) } } # and repeat until no more files } } # Tell how many FITS files and files of all sort were found in this # directory print file_num, 'FITS files in this directory' print 'Total number of files:', len(ls) } # To test uncover one of the list_scans calls below and, from the glish # prompt, execute # include 'list_scans.g' list_scans('AGBT02A_069_01') # list_scans('AGBT02A_069_01', 'Antenna') # list_scans('AGBT02A_069_01', out_file='testlist')