/* ************************************************************************
 * *                                                                      *
 * *    Pipe function to convert a 7.22 IRIS tape inventory file to       *
 * *                            7.23 format                               *
 * *                                                                      *
 * ************************************************************************
 * File: utils/examples/TapeInv723.C
 *
 *                        COPYRIGHT (c) 2002  BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int iArgc, char *sArgv[])
{
  char  SiteList[32];
  int iCount, iLoop;

  /* Old format tape inventory file started with 20 32-byte site_list
   * structures.  New format starts with 31 28-byte site_list structures.
   * The structures are the same, and the last 4 bytes are unused.
   */

  for (iLoop=0; iLoop<20; iLoop++)
    {
      /* Read in */
      iCount =  fread( &SiteList, 32, 1, stdin );
      if (iCount != 1) fprintf( stderr, "Bad read, got%d, wanted%d\n", iCount, 32 );
      /* Write out */
      iCount = fwrite( &SiteList, 28, 1, stdout );
      if (iCount != 1) fprintf( stderr, "Bad write\n" );
    }

  memset( SiteList, 0, 32 );
  for (iLoop=0; iLoop<11; iLoop++)
    {
      /* Write out zeros. */
      iCount = fwrite( &SiteList, 28, 1, stdout );
      if (iCount != 1) fprintf( stderr, "Bad write\n" );
    }

  /* Copy the rest of the file, no changes are made */
  iCount = fread(  &SiteList, 1, 1, stdin );
  while (iCount==1)
    {
      iCount = fwrite( &SiteList, 1, 1, stdout );
      if (iCount != 1) fprintf( stderr, "Bad write\n" );
      iCount = fread(  &SiteList, 1, 1, stdin );
    }
  exit( EXIT_SUCCESS );
}


