[2] | 1 | ;------------------------------------------------------------- |
---|
| 2 | ;+ |
---|
| 3 | ; NAME: |
---|
| 4 | ; PUTFILE |
---|
| 5 | ; PURPOSE: |
---|
| 6 | ; Write a text file from a string array. |
---|
| 7 | ; CATEGORY: |
---|
| 8 | ; CALLING SEQUENCE: |
---|
| 9 | ; putfile, f, s |
---|
| 10 | ; INPUTS: |
---|
| 11 | ; f = text file name. in |
---|
| 12 | ; s = string array. in |
---|
| 13 | ; KEYWORD PARAMETERS: |
---|
| 14 | ; Keywords: |
---|
| 15 | ; ERROR=err error flag: 0=ok, 1=invalid string array. |
---|
| 16 | ; OUTPUTS: |
---|
| 17 | ; COMMON BLOCKS: |
---|
| 18 | ; NOTES: |
---|
| 19 | ; MODIFICATION HISTORY: |
---|
| 20 | ; R. Sterner, 20 Mar, 1990 |
---|
| 21 | ; R. Sterner, 4 Nov, 1992 --- allowed scalar strings. |
---|
| 22 | ; |
---|
| 23 | ; Copyright (C) 1990, Johns Hopkins University/Applied Physics Laboratory |
---|
| 24 | ; This software may be used, copied, or redistributed as long as it is not |
---|
| 25 | ; sold and this copyright notice is reproduced on each copy made. This |
---|
| 26 | ; routine is provided as is without any express or implied warranties |
---|
| 27 | ; whatsoever. Other limitations apply as described in the file disclaimer.txt. |
---|
| 28 | ;- |
---|
| 29 | ;------------------------------------------------------------- |
---|
| 30 | |
---|
| 31 | pro putfile, file, s, error=err, help=hlp |
---|
| 32 | |
---|
| 33 | if (n_params(0) lt 1) or keyword_set(hlp) then begin |
---|
| 34 | print,' Write a text file from a string array.' |
---|
| 35 | print,' putfile, f, s' |
---|
| 36 | print,' f = text file name. in' |
---|
| 37 | print,' s = string array. in' |
---|
| 38 | print,' Keywords:' |
---|
| 39 | print,' ERROR=err error flag: 0=ok, 1=invalid string array.' |
---|
| 40 | return |
---|
| 41 | endif |
---|
| 42 | ; |
---|
| 43 | if lmgr(/demo) then begin |
---|
| 44 | print, 'you are in Demo mode. It is impossible to write a file' |
---|
| 45 | return |
---|
| 46 | endif |
---|
| 47 | ; |
---|
| 48 | if size(s, /type) ne 7 then begin |
---|
| 49 | print,' Error in putfile: argument must be a string array.' |
---|
| 50 | err = 1 |
---|
| 51 | return |
---|
| 52 | endif |
---|
| 53 | |
---|
| 54 | get_lun, lun |
---|
| 55 | openw, lun, file |
---|
| 56 | |
---|
| 57 | for i = 0, n_elements(s)-1 do begin |
---|
| 58 | t = s(i) |
---|
| 59 | if t eq '' then t = ' ' |
---|
| 60 | printf, lun, t |
---|
| 61 | endfor |
---|
| 62 | |
---|
| 63 | close, lun |
---|
| 64 | free_lun, lun |
---|
| 65 | err = 0 |
---|
| 66 | return |
---|
| 67 | |
---|
| 68 | end |
---|