#include #define FALSE 0 #define TRUE 1 FILE *MF1_FILE; /*-------------------------------------------------------------------*/ /* */ /* open_maf1 opens a DE RIMS MAF1 file */ /* */ /*-------------------------------------------------------------------*/ open_maf1 (ieof) int *ieof; { char maf1_file[80]; int str_length; printf (" Enter MAF1 file name: "); scanf ("%s", maf1_file); str_length = strlen (maf1_file); *ieof = 0; if (str_length > 0) { if ((MF1_FILE = fopen(maf1_file, "r")) == NULL) { printf ("ERROR: cannot open %s\n", maf1_file); exit(0); } } else { *ieof = 1; } } /*-------------------------------------------------------------------*/ /* */ /* read_maf1 reads a DE RIMS MAF1 file */ /* */ /*-------------------------------------------------------------------*/ read_maf1 (buf, lbuf, read_err) short int buf[]; int *lbuf, *read_err; { register int i, itime, lbuf1, lbuf2, nbytes; register char tmp; union { char c[2]; short int i; } num; /*-------------------------------------------------------------------*/ /* initialize some variables */ /*-------------------------------------------------------------------*/ lbuf1 = *lbuf; lbuf1 = lbuf1 - 1; lbuf2 = 0; *read_err = -1; /*-------------------------------------------------------------------*/ /* read in first two bytes of this record */ /*-------------------------------------------------------------------*/ for (i = 0; i < 2; ++i) { num.c[i] = getc(MF1_FILE); } /*-------------------------------------------------------------------*/ /* read the rest of the record */ /*-------------------------------------------------------------------*/ nbytes = 0; if (feof(MF1_FILE) == FALSE) /* if wasn't file end */ { *read_err = 0; for (itime = 0; itime < lbuf1; ++itime) { tmp = num.c[0]; /* swap the two bytes */ num.c[0] = num.c[1]; num.c[1] = tmp; buf[lbuf2++] = num.i; for (i = 0; i < 2; ++i) /* read in next 2 bytes*/ { num.c[i] = getc(MF1_FILE); } } tmp = num.c[0]; /* swap the last two bytes */ num.c[0] = num.c[1]; num.c[1] = tmp; buf[lbuf2] = num.i; } else { *read_err = -10; } /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ } /* end read_maf1 */ /*-------------------------------------------------------------------*/ /* */ /* open_maf1 opens a DE RIMS MAF1 file */ /* */ /*-------------------------------------------------------------------*/ close_maf1() { fclose (MF1_FILE); }