1
/* @(#)wtape.c 19.1 (ES0-DMD) 02/25/03 14:32:28 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.COPYRIGHT (c) 1988 European Southern Observatory
33
.AUTHOR P.Grosbol ESO/IPG
34
.KEYWORDS copy file to tape, write tape
36
.PURPOSE copy FITS file in byte stream format to mag. tape
37
.VERSION 1.0 1988-Nov-28 : Creation, PJG
38
.VERSION 1.1 1989-Mar-12 : Correct error in block count, PJG
39
--------------------------------------------------------------------*/
41
#define MBUF 31680 /* max. no. of bytes in record */
42
#define FLR 2880 /* FITS logical record length */
44
static char buf[MBUF]; /* I/O buffer */
48
int no,nof,n,rec,nr,den;
49
int fdi,mb,idx,nb,i,bf;
52
char list[80],app[80];
53
char output[80],prefix[80];
55
printf("Name of output tape unit : "); scanf("%s",output);
56
printf("Prefix on FITS filename : "); scanf("%s",prefix);
57
printf("List of file no. to copy : "); scanf("%s",list);
58
if (deflist(list)) { /* check if valid list */
59
printf("Error: Invalid list specification\n");
62
printf("Append file to tape (Y/N) : "); scanf("%s",app);
63
printf("Tape density in bpi : "); scanf("%d",&den);
64
printf("FITS blocking factor (1-10): "); scanf("%d",&bf);
66
if (bf<1) bf = 1; else if (10<bf) bf = 10; /* check blocking factor */
69
fdo = ioopen(output,1,den); /* Open Mag. tape unit */
70
if (fdi<=0) ospexit(1);
72
if (app[0]!='N' && app[0]!='n') { /* move to end of tape */
73
printf("Files will be appended to tape!\n");
74
n = ioread(fdo,buf,bf);
75
if (n<=0) { /* empty tape */
76
printf("Warning: Tape was empty!\n");
79
else { /* not empty - skip to end */
81
} while (0<ioread(fdo,buf,bf));
82
iobsf(fdo,1); /* position between EOF's */
86
while (getlist(&nof)) { /* read file one by one */
87
outname(prefix,nof); /* get new file name */
88
input = newfn('I',".mt");
89
if ((fdi=open(input,0))<0) { /* open FITS input file */
90
printf("Cannot open file >%s<\n",input);
93
rec = 0; idx = 0; nr = 0;
95
do { /* copy block by block */
96
no = read(fdi,&buf[idx],mb);
97
if (!nr++ && no) { /* check if FITS file */
98
for (i=0; i<9 && buf[i]=="SIMPLE ="[i]; i++);
99
if (i!=9) { /* no FITS file - skip */
100
printf("Error: file >%s< not FITS format - skipped!\n",input);
105
if (bf<=idx || no<=0) { /* write block tp tape */
109
while (n && n<=idx-nb) {
110
i = iowrite(fdo,&buf[nb],n);
111
if (i<0) { /* End of tape reached */
115
printf("Warning: End of Tape Mark detected !!\n");
116
ioclose(fdo); ospexit(1);
121
for (i=nb; i<n; i++) buf[idx++] = buf[i];
127
printf(" File >%s< written to tape with %5d records\n",input,rec);
130
ioweof(fdo); iobsf(fdo,1);