/usr/share/gnudatalanguage/astrolib/ftprint.pro is in gdl-astrolib 2018.02.16+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | pro ftprint,h,tab,columns,rows,textout=textout
;+
; NAME:
; FTPRINT
; PURPOSE:
; Procedure to print specified columns and rows of a FITS table
;
; CALLING SEQUENCE:
; FTPRINT, h, tab, columns, [ rows, TEXTOUT = ]
;
; INPUTS:
; h - Fits header for table, string array
; tab - table array
; columns - string giving column names, or vector giving
; column numbers (beginning with 1). If string
; supplied then column names should be separated by comma's.
; rows - (optional) vector of row numbers to print. If
; not supplied or set to scalar, -1, then all rows
; are printed.
;
; OUTPUTS:
; None
;
; OPTIONAL INPUT KEYWORDS:
; TEXTOUT controls the output device; see the procedure TEXTOPEN
;
; SYSTEM VARIABLES:
; Uses nonstandard system variables !TEXTOUT and !TEXTOPEN
; These will be defined (using ASTROLIB) if not already present.
; Set !TEXTOUT = 3 to direct output to a disk file. The system
; variable is overriden by the value of the keyword TEXTOUT
;
; EXAMPLES:
;
; ftprint,h,tab,'STAR ID,RA,DEC' ;print id,ra,dec for all stars
; ftprint,h,tab,[2,3,4],indgen(100) ;print columns 2-4 for
; ;first 100 stars
; ftprint,h,tab,text="stars.dat" ;Convert entire FITS table to
; ;an ASCII file named STARS.DAT
;
; PROCEDURES USED:
; FTSIZE, FTINFO, TEXTOPEN, TEXTCLOSE
;
; RESTRICTIONS:
; (1) Program does not check whether output length exceeds output
; device capacity (e.g. 80 or 132).
; (2) Column heading may be truncated to fit in space defined by
; the FORMAT specified for the column
; (3) Program does not check for null values
;
; HISTORY:
; version 1 D. Lindler Feb. 1987
; Accept undefined values of rows, columns W. Landsman August 1997
; New FTINFO calling sequence W. Landsman May 2000
; Parse scalar string with STRSPLIT W. Landsman July 2002
; Fix format display of row number W. Landsman March 2003
; Fix format display of row number again W. Landsman May 2003
;-
; On_error,2
compile_opt idl2
;
; set defaulted parameters
;
if N_params() LT 2 then begin
print,'Syntax - FTPRINT, h, tab, [ columns, rows, TEXTOUT= ]'
return
endif
if N_elements(columns) EQ 0 then columns = -1
if N_elements(rows) EQ 0 then rows= -1
; make sure rows is a vector
n = N_elements(rows)
if n EQ 1 then r = [rows] else r = long(rows)
ftsize,h,tab,ncols,nrows,tfields,allcols,allrows, ERRMSG = errmsg ;table size
if ERRMSG NE '' then message,errmsg
if r[0] EQ -1 then r = lindgen(nrows) ;default
Nr = N_elements(r)
good = where( (r GE 0) and (r LT nrows), Ngood)
if Ngood NE Nr then begin
if Ngood EQ 0 then message,'ERROR - No valid row numbers supplied'
r = r[good]
endif
;
; extract column info
;
title1 = ''
title2 = ''
FTINFO,h,ft_str
;
; if columns is a string, change it to string array
;
if size(columns,/TNAME) EQ 'STRING' then begin
colnames = strsplit(columns,',',/EXTRACT)
numcol = N_elements(colnames)
colnames = strupcase(strtrim(colnames,2))
ttype = strtrim(ft_str.ttype,2)
colnum = intarr(numcol)
for i = 0,numcol-1 do begin
icol = where(ttype EQ colnames[i], Nfound)
if Nfound EQ 0 then message, $
'ERROR - Field ' + colnames[i] + ' not found in FITS ASCII table'
colnum[i] = icol[0]
endfor
end else begin ;user supplied vector
colnum = fix(columns) -1 ;make sure it is integer
numcol = N_elements(colnum) ;number of elements
if numcol EQ 1 then begin
if colnum[0] LT 0 then begin
colnum = indgen(tfields) & numcol = tfields
endif & endif
end
flen = ft_str.width[colnum]
colpos = ft_str.tbcol[colnum]
ttype = strtrim( ft_str.ttype[colnum],2)
tunit = strtrim( ft_str.tunit[colnum],2)
;
; create header lines
;
for i=0,numcol-1 do begin
name = strn(ttype[i],padtype=2,len=flen[i] )
unit = strn(tunit[i],padtype=2,len=flen[i] )
title1 = title1 + ' ' + name
title2 = title2 + ' ' + unit
endfor
;
; open output file
;
textopen,'FTPRINT',TEXTOUT=textout, MORE_SET = more_set
ifmt = fix(alog10(max(r)+1)) > 3
title1 = strn('ROW',padtype=2,len = ifmt) + title1
title2 = string(replicate(32b,ifmt+1)) + title2
ifmt = strtrim(ifmt,2)
;
; loop on rows
;
printf,!TEXTUNIT,title1
printf,!TEXTUNIT,title2
printf,!TEXTUNIT,' '
for i = 0, Nr-1 do begin
;
; loop on columns
;
line = string(r[i],format='(i' + ifmt + ')') ;print line
for j = 0,numcol-1 do begin
cpos=colpos[j]-1 ;column number
val = string(tab[cpos:cpos+flen[j]-1,r[i]])
line = line+' '+ val
endfor
printf,!TEXTUNIT,line
if more_set then if (!ERR EQ 1) then goto, DONE
endfor
;
; done
;
DONE:
textclose,textout=textout
return
end
|