/* $Id: testCedarIOBoundaries.c 3304 2011-01-17 15:25:59Z brideout $ */ /* modification history -------------------- 00a,21Feb00 original */ /* USAGE: testCedarIOBoundries madrigalFileName numberOfMadrigalCopies numberOfCbfCopies e.g.: testCedarIOBoundries /opt/madrigal/experiments/1998/mlh/23mar98/mil980323g.003 3 3 The Madrigal and CBF formats are blocked and each block contains control words in addition to CEDAR records. In practice, the block lengths are fixed, but the read and write routines in cedarIO.c allow an arbitrary block size (beyond the minimum possible size). This program test the blocking by repeatedly doing two transformations: Madrigal (standard block size) -> Madrigal(random block size) -> Madrigal(standard block size) Madrigal (standard block size) -> CBF (random block size) -> Madrigal (standard block size) The first and third files, file1 and file2, are then compared. Relatively small random block sizes are used to enhance the liklihood of encountering edge effects. */ #include #include #include #include int main (argc, argv) int argc; char *argv[]; { int i=0, nwords=0, ind1=0, ind2=0, nrec=0, nmad=0, ncbf=0; char infile[100]; Int16 w1=0, w2=0; FILE *finp, *foutp; Int16 *cedarRecordp=(Int16 *)NULL; /* madrigal state variables */ int madrigalBlockSize=6720, madrigalBlockSizex=0; int sigWords=0, blockIndex=0, prevRec=0, thisRec=0; Int16 *blockp=(Int16 *)NULL; /* Cbf state parameters */ int cbfBlockSize=4096, cbfBlockSizex=0; int forceCosRead=0, initPos8=0, initFwi=0, initPos=0, initLCosBlock=0, lCosBlock=0, gpos=0, fwi=0; Int16 *cosRecordp=(Int16 *) NULL; int lbuf=2; /* Are two extra words in Cos block */ int ppos=1; /* First word of Cos block is it's length */ int blockNumber=0; long lastControlWord=-1; int previousFileIndex=-1, previousRecordIndex=-1; if (argc == 4) { strcpy(infile, argv[1]); nmad = atoi(argv[2]); ncbf = atoi(argv[3]); } else { (void) printf("Usage: testCedarIOBoundries madrigalFileName numberOfMadrigalCopies numberOfCbfCopies\n"); return(1); } /* Madrigal to Madrigal */ finp = fopen(infile, "r"); foutp = fopen("file1", "w"); blockIndex = 0; blockp=(Int16 *)NULL; prevRec = 0; thisRec = 0; nrec = 0; while((ind1 = getNextMadrigalRecord(finp, &cedarRecordp, madrigalBlockSize, &sigWords)) == 0) { ind2 = putNextMadrigalRecord(foutp, &cedarRecordp, madrigalBlockSize, &blockIndex, &blockp, &prevRec, &thisRec); if (ind1 != 0 || ind2 != 0) (void) printf("Error: ind1,ind2 = %d %d\n", ind1,ind2); nrec++; } /* (void) printf("Initialization - %d records copied\n", nrec); */ if (cedarRecordp != (Int16 *)NULL) { free(cedarRecordp); cedarRecordp = (Int16 *)NULL; } if (blockp != (Int16 *)NULL) { free(blockp); blockp = (Int16 *)NULL; } (void) fclose(finp); (void) fclose(foutp); for (i=0; i The files are different - %6d %6d %6d\n <***", i,w1,w2); return(0); } } printf(" OK - madrigal - blockSize = %4d, %d words compared\n", madrigalBlockSizex, nwords); (void) fclose(finp); (void) fclose(foutp); } for (i=0; i The files are different - %6d %6d %6d <***\n", i,w1,w2); return(0); } } if (nwords > 0) { printf(" OK - cbf - blockSize = %4d, %d words compared\n", cbfBlockSizex, nwords); } else { printf(" ***> ERROR - %d words compared <***\n", nwords); return(0); } (void) fclose(finp); (void) fclose(foutp); } return(0); }