;+
; NAME:
;     PUTDATA
; PURPOSE:
;     Writes a data record into an APC data file.  The file must already
;     be open for writing, and attached to a variable with ASSOC().
; CATEGORY:
;     OVRO APC UTIL
; CALLING SEQUENCE:
;     result = putdata(rec_n,a,data)
; INPUTS:
;     rec_n     the record number in which to place the desired data record
;     a         the associated variable for the file, attached
;                   with ASSOC(lun,intarr(1024))
;     data      the properly formatted DATA record
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
; OUTPUTS:
;     result    An indication of the success [1] or failure [0] of the write
;                 operation
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 04-Feb-2000 by Dale Gary
;-
function putdata,rec_n,a,data

   ON_IOERROR,altret

   ; Check that DATA is at least reasonable
   if (size(data,/type) ne 2 or n_elements(data) ne 1024) then return,0

   ; Copy the data in case byte swapping is necessary.

   b = data
   if(strlowcase(!VERSION.ARCH) eq 'sparc') then byteorder,b   ; Byte-swap if SPARC

   ; Write the data record to the file
   a(rec_n) = b

   return,1

altret:
   return,0

end
