Debian Codegraph @

system/vms/tapeio/rtape.c

raw
1 /* @(#)rtape.c 19.1 (ES0-DMD) 02/25/03 14:32:27 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
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.
9
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.
14
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,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 .COPYRIGHT (c) 1988 European Southern Observatory
31 .LANGUAGE C
32 .IDENT rtape.c
33 .AUTHOR P.Grosbol ESO/IPG
34 .KEYWORDS read tape, copy tape to disk
35 .ENVIRON VAX/VMS
36 .PURPOSE copy tape to disk files in fix block format
37 .COMMENT Fix block file format is used only because it is more
38 efficient on a VAX/VMS system!!
39 Size could be increased from 512 to 1024 or larger.
40 .VERSION 1.0 1988-Dec-16 : Creation, PJG
41 .VERSION 1.1 1989-Mar-11 : Increase to 1024 byte blocks, PJG
42 --------------------------------------------------------------------*/
43
44 #define MBUF 32000 /* max. no. of bytes in record */
45 #define BZ 1024 /* block size on disk */
46
47 static char buf[MBUF]; /* I/O buffer */
48
49 main()
50 {
51 int no,nof,n,rec,nol;
52 int mb,idx,nb,i,nbyte;
53 int fdo,fdi;
54 float byte;
55 char *output,*newfn();
56 char input[80],prefix[80],list[80];
57
58 printf("Name of input tape unit : "); scanf("%s",input);
59 printf("Prefix on output filename : "); scanf("%s",prefix);
60 printf("List of file no. to copy : "); scanf("%s",list);
61 if (deflist(list)) { /* check if list valid */
62 printf("Error: Invalid list of file no's\n");
63 ospexit(1);
64 }
65 fdi = ioopen(input,0,1600); /* Open Mag. tape unit */
66 if (fdi<=0) ospexit(1);
67 iorew(fdi); /* rewind to file no.1 */
68 nol = 1;
69 while (getlist(&nof)) { /* read file one by one */
70 if (nol<nof) { /* position tape */
71 for (i=nol; i<nof; i++) {
72 n = ioread(fdi,buf,BZ);
73 if (n<=0) { /* error of EOT detected */
74 printf("Warning: End of Information detected on tape!\n");
75 iorew(fdi,0); ospexit(1);
76 }
77 iofsf(fdi,1);
78 }
79 }
80 else if (nof<nol) { /* wrong order in list */
81 printf("Error: List NOT ascending\n");
82 break;
83 }
84
85 outname(prefix,nof); /* get new file name */
86 output = newfn('I',".mt");
87
88 rec = 0; idx = 0;
89 mb = MBUF - BZ;
90 for (;;) { /* copy block by block */
91 if ((no=ioread(fdi,&buf[idx],mb))<=0) break;
92 if (!rec) {
93 if ((fdo=creat(output,0
94 #ifdef vms
95 ,"rfm=fix","mrs=1024"
96 #endif
97 ))<0) ospexit(1);
98 nbyte = 0;
99 }
100 if (no<=0) break;
101 rec++; nbyte += no; idx += no;
102 nb = (idx/BZ) * BZ;
103 nb = write(fdo,buf,nb);
104 no = idx; idx = 0;
105 for (i=nb; i<no; i++) buf[idx++] = buf[i];
106 }
107 if (no<=0 && rec==0) { /* End of Tape mark */
108 printf("Warning: End of Information detected on tape!\n");
109 break;
110 }
111 if (idx) { /* write remaining data to disk */
112 nb = ((idx-1)/BZ + 1) * BZ;
113 i = write(fdo,buf,nb);
114 }
115 nol = nof + 1;
116 close(fdo);
117 byte = nbyte/(1024.0*1024.0);
118 printf(" %7.2f Mbyte in %5d records copied to file: %s\n",
119 byte,rec,output);
120 }
121 ioclose(fdi);
122 ospexit(0);
123 }