/* This file contains a few input/output routines for use with the faster /* versions of LODSCORE, ILINK, LINKMAP, and MLINK described in: /* R. W. Cottingham, Jr., R. M. Idury, and A. A. Schaffer /* Faster Sequential Genetic Linkage Computations /* American Journal of Human Genetics, 53(1993), pp. 252--263 /* and A. A. Schaffer, S. K. Gupta, K. Shriram, and R. W. Cottingham, Jr., /* Avoiding Recomputation in Linkage Analysis*/ /* Human Heredity 44(1994), pp. 225-237. */ /* Two routines taken from */ /* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. * This file may be copied, modified, etc. in any way. It is not restricted * by the licence agreement accompanying p2c itself. */ /* Check if at end of file, using Pascal "eof" semantics. End-of-file for stdin is broken; remove the special case for it to be broken in a different way. */ #include #include "commondefs.h" int P_eof(f) FILE *f; { register int ch; if (feof(f)) return 1; if (f == stdin) return 0; /* not safe to look-ahead on the keyboard! */ ch = getc(f); if (ch == EOF) return 1; ungetc(ch, f); return 0; } /* Check if at end of line (or end of entire file). */ int P_eoln(f) FILE *f; { register int ch; ch = getc(f); if (ch == EOF) return 1; ungetc(ch, f); return (ch == '\n'); } /*This routine is a simple exit routine, when the sytem is out of memory*/ void malloc_err(message) char * message; { FILE *errorfile; time_t secondsNow; fprintf(stderr, "\nProblem with malloc, probably not enough space\n"); fprintf(stderr, "Problem occurred when allocating %s\n", message); errorfile = fopen("FASTLINK.err","a"); if (errorfile) { time (&secondsNow); fprintf(errorfile,"\n%s",ctime(&secondsNow)); fprintf(errorfile, "\nProblem with malloc, probably not enough space\n"); fprintf(errorfile, "Problem occurred when allocating %s\n", message); fclose(errorfile); } exit(EXIT_FAILURE); } /*The routine check_consatnts checks to see if the constant maxhap has been set appropriately*/ void check_constants() { int prod, l; boolean shouldexit, firstprint; FILE *errorfile; time_t secondsNow; shouldexit = false; firstprint = false; time(&secondsNow); prod = 1; for(l=0; l < mlocus; l++){ printf("\nNumber of alleles at locus %d is %d",l+1, thislocus[l]->nallele); prod *= thislocus[l]->nallele; } if (prod < maxhap){ printf("\nYour allele product is %d ; you may benefit from reducing the", prod); printf("\nconstant maxhap, defined in commondefs.h to %d\n",prod); } if (prod > maxhap){ printf("\nYour allele product is %d ; your value of maxhap, defined in", prod); printf("\ncommondefs.h, is too low; you must increase it to at least %d .",prod); printf("\nFASTLINK will exit politely to allow you to fix this problem.\n"); errorfile = fopen("FASTLINK.err", "a"); if (errorfile) { fprintf(errorfile,"\n%s", ctime(&secondsNow)); fprintf(errorfile,"\nYour allele product is %d ; your value of maxhap, defined in", prod); fprintf(errorfile,"\ncommondefs.h, is too low; you must increase it to at least %d .",prod); firstprint = true; } shouldexit = true; } if (maxseg > BIGMAXSEG){ printf("\nYour value of maxseg is dangerously high."); printf("\nIt is safest to keep maxseg below %d and maxlocus below %d",BIGMAXSEG,BIGMAXLOCUS); printf("\nRemember that maxlocus is only a limit on how many loci are in one analysis."); printf("\nYou can have many more loci in your pedin.dat file."); if (!firstprint) errorfile = fopen("FASTLINK.err", "a"); if (errorfile) { fprintf(errorfile,"\n%s", ctime(&secondsNow)); fprintf(errorfile,"\nYour value of maxseg is dangerously high."); fprintf(errorfile,"\nIt is safest to keep maxseg below %d and maxlocus below %d",BIGMAXSEG,BIGMAXLOCUS); firstprint = true; } shouldexit = true; } printf("\n"); if (firstprint && errorfile) fclose(errorfile); if (shouldexit) exit(EXIT_FAILURE); }