/* * MADER Project N.O.A.A. - FSL/NCDC * * This software and its documentation are in the public domain * and are furnished "as is." The United States government, * its instrumentalities, officers, employees, and agents make * no warranty, express or implied, as to the usefulness of the * software and documentation for any purpose. They assume no * responsibility (1) for the use of the software and * documentation; or (2) to provide technical support to users. * */ #include #include #include #include #include #include #define BUFF 20000 #define PERMS 0666 /* RW for owner, group, others */ #define ERR -1 #define FLEN 10 #define OUT 50 #define OFF 270 long int lseek(); /*----------------------------------------------------------------------------- * Name: wrebufr.c * * Author: Dan Manns * * Purpose: write the EBUFR data files to disk as they exist on tape * (these files are not readable by EBUFR software because of * the leading 4 character record length field) * * Parameters: nskip - This parameter indicates how many days of data the * user wants to skip before writing to disk. If the tape was created at * NCDC then it is probably unlabeled. If the tape is labeled obviously * either the script or the this program must be altered to skip the * appropriate number of files. * * Return values: * 0 -- successful * not 0 -- some error causing archive termination * * Dependencies: The user needs to change this software to access the proper * tape drive id. * * Modifications: none *----------------------------------------------------------------------------- */ main( argc, argv ) int argc; char **argv; { int fdisk, ftape, n, totrd, rd, nfile, eofct; int sector, nskip, flog; char fname[FLEN]; char buf[BUFF]; char orec[OUT]; struct mtop mt_command; /* the user must change the tape drive id */ rd = 0; if ((ftape = open("/dev/rst1",0)) == ERR) { printf("Can't open /dev/rst1 %d\n",ERR); exit(ERR); } /* the user must change the tape drive id */ printf("\n opened /dev/rst1 \n"); mt_command.mt_op = MTREW; mt_command.mt_count = 1; ioctl(ftape,MTIOCTOP,&mt_command); if ((flog = open("arc.log",O_RDONLY,0)) == ERR) { printf("Can't open arc.log\n"); exit(ERR); } /* * read the number of files to skip */ nskip=atoi(argv[1]); if( nskip != 0 ) { mt_command.mt_op = MTFSF; mt_command.mt_count = nskip; ioctl(ftape,MTIOCTOP,&mt_command); } /* * Continue processing as long as filenames are read from arc.log */ nfile = 0; while ((n = read(flog, fname, FLEN)) > 0) { fname[9]='\0'; /* Read the data files and write them to disk . */ nfile = 0; eofct = 0; if ((fdisk = creat(fname,PERMS )) == ERR) printf("Can't open %s\n",fname); else { printf(" created %s \n",fname); while (eofct < 1) { mt_command.mt_op = MTFSF; mt_command.mt_count = 1; ioctl(ftape,MTIOCTOP,&mt_command); while ((n = read(ftape, buf, BUFF)) > 0) { ++rd; if (nfile < 1) { if (write(fdisk, buf, n) != n) { printf("Write error on %s\n",fname); exit(ERR); } } } totrd = totrd + rd; printf(" found EOF mark \n"); rd = 0; ++eofct; } printf(" finished writing to %s\n",fname); mt_command.mt_op = MTFSF; mt_command.mt_count = 1; ioctl(ftape,MTIOCTOP,&mt_command); } close(fdisk); } return; }