~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to system/vms/tapeio/wtape.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)wtape.c  19.1 (ES0-DMD) 02/25/03 14:32:28 */
 
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: midas@eso.org
 
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        wtape.c
 
33
.AUTHOR       P.Grosbol   ESO/IPG
 
34
.KEYWORDS     copy file to tape, write tape
 
35
.ENVIRON      VAX/VMS
 
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
--------------------------------------------------------------------*/
 
40
 
 
41
#define   MBUF              31680   /* max. no. of bytes in record */
 
42
#define   FLR                2880   /* FITS logical record length  */
 
43
 
 
44
static    char         buf[MBUF];       /* I/O buffer              */
 
45
 
 
46
main()
 
47
{
 
48
  int     no,nof,n,rec,nr,den;
 
49
  int     fdi,mb,idx,nb,i,bf;
 
50
  int     fdo;
 
51
  char    *input,*newfn();
 
52
  char    list[80],app[80];
 
53
  char    output[80],prefix[80];
 
54
 
 
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");
 
60
     ospexit(1);
 
61
  }
 
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);
 
65
 
 
66
  if (bf<1) bf = 1; else if (10<bf) bf = 10;   /* check blocking factor */
 
67
  bf *= FLR;
 
68
 
 
69
  fdo = ioopen(output,1,den);                    /* Open Mag. tape unit */
 
70
  if (fdi<=0) ospexit(1);
 
71
 
 
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");
 
77
        iobsf(fdo,1);
 
78
     }
 
79
     else {                                  /* not empty - skip to end */
 
80
        do { iofsf(fdo,1);
 
81
        } while (0<ioread(fdo,buf,bf));
 
82
        iobsf(fdo,1);                         /* position between EOF's */
 
83
     }
 
84
  }
 
85
 
 
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);
 
91
         continue;
 
92
      }
 
93
      rec = 0; idx = 0; nr = 0;
 
94
      mb = MBUF - FLR;
 
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);
 
101
               break;
 
102
            }
 
103
         }
 
104
         if (0<no) idx += no;
 
105
         if (bf<=idx || no<=0) {              /* write block tp tape    */
 
106
            nb = 0;
 
107
            n = (idx/FLR) * FLR;
 
108
            n = (bf<n) ? bf : n;
 
109
            while (n && n<=idx-nb) {
 
110
               i = iowrite(fdo,&buf[nb],n);
 
111
               if (i<0) {                     /* End of tape reached    */
 
112
                  iobsf(fdo,1);
 
113
                  ioweof(fdo);
 
114
                  close(fdi);
 
115
                  printf("Warning: End of Tape Mark detected !!\n");
 
116
                  ioclose(fdo); ospexit(1);
 
117
               }
 
118
               nb += i; rec++;
 
119
            }
 
120
            n = idx; idx = 0;
 
121
            for (i=nb; i<n; i++) buf[idx++] = buf[i];
 
122
         }
 
123
      } while (0<no);
 
124
      close(fdi);
 
125
      if (rec) {
 
126
         i = ioweof(fdo);
 
127
         printf(" File >%s< written to tape with %5d records\n",input,rec);
 
128
      }
 
129
  }
 
130
  ioweof(fdo); iobsf(fdo,1);
 
131
  ospexit(0);
 
132
}