fxgwrite.pro
2.86 KB
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
;+
; NAME:
; FXGWRITE
;
; AUTHOR:
; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
; craigm@lheamail.gsfc.nasa.gov
; UPDATED VERSIONs can be found on my WEB PAGE:
; http://cow.physics.wisc.edu/~craigm/idl/idl.html
;
; PURPOSE:
; Perform an unformatted write to a generic resource.
;
; MAJOR TOPICS:
; File I/O, Pipes, URLs, FITS
;
; CALLING SEQUENCE:
; FXWRITE, UNIT, BUFFER, TRANSFER_COUNT=TC
;
; DESCRIPTION:
;
; FXGWRITE performs an unformatted write to the unit UNIT. The UNIT
; must have previously been opened by FXGOPEN with write access.
;
; Currently only unformatted reads are permitted because the precise
; number of bytes to written must be known ahead of time.
;
; In other respects, this procedure is similar to the WRITEU
; built-in IDL procedure.
;
; You must use the specialized 'FXG' style functions to read, write
; and seek on file units opened with FXGOPEN:
;
; FXGOPEN - open resource
; FXGCLOSE - close resource
; FXGREAD - read from resource
; FXGWRITE - write to resource
; FXGSEEK - seek on resource (i.e., perform POINT_LUN)
;
; FXGFILTERED - determine if resource is a normal file.
;
; INPUTS:
;
; UNIT - the unit number to operate on. The unit must have been
; previously opened by FXGOPEN.
;
; BUFFER - the array to be written. Only basic types are permitted.
; The actual number of bytes transferred can be determined
; by examining the TRANSFER_COUNT.
;
;
; KEYWORD PARAMETERS:
;
; TRANSFER_COUNT - upon output, contains the number of elements
; transferred from BUFFER.
;
; MODIFICATION HISTORY:
; Written, 1999, CM
; Documented, 02 Oct 1999, CM
; Changed copyright notice, 21 Sep 2000, CM
;
; $Id: fxgwrite.pro,v 1.3 2007/09/01 23:03:23 craigm Exp $
;
;-
; Copyright (C) 1999-2000, Craig Markwardt
; This software is provided as is without any warranty whatsoever.
; Permission to use, copy, modify, and distribute modified or
; unmodified copies is granted, provided this copyright and disclaimer
; are included unchanged.
;-
PRO FXGWRITE, UNIT, BUFFER, TRANSFER_COUNT=TC
on_error, 2
if n_params() NE 2 then begin
message, 'USAGE: FXGWRITE, UNIT, BUFFER [, TRANSFER_COUNT=TC ]', /info
return
endif
if n_elements(unit) EQ 0 then $
message, 'ERROR: UNIT is not defined'
if n_elements(buffer) EQ 0 then $
message, 'ERROR: BUFFER is not defined'
@fxfilter
if unit LT 0 OR unit GE FXFILTER_MAX_LUN then $
message, 'ERROR: UNIT is not a valid file unit'
writeu = 'WRITEU'
if filterflag(unit) AND 1 then $
if write_cmd(unit) NE '' then writeu = write_cmd(unit)
if writeu EQ '-' then begin
errmsg = string(unit, $
format='("ERROR: Resource unit ",I0," does not support writing.")')
message, errmsg
endif
call_procedure, writeu, unit, buffer, transfer_count=tc
return
end