-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleio.c
54 lines (43 loc) · 1.27 KB
/
simpleio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* $Id: simpleio.c,v 1.4 2001/12/19 22:41:47 acs Exp $
Written by Adam Siepel, Spring 2001
Copyright 2001, Adam Siepel */
/* Simple utilities to read and write permutations */
#include "simpleio.h"
void
print_genome ( FILE * outf, char *name, int *genome, int ngenes )
{
int i;
fprintf ( outf, "> %s\n", name );
for ( i = 0; i < ngenes; i++ )
fprintf ( outf, "%d ", genome[i] );
fprintf ( outf, "\n" );
}
int
read3 ( FILE * in, struct genome_struct *gen1, struct genome_struct *gen2,
struct genome_struct *gen3, int ngenes )
{
if ( read_genome ( in, gen1, ngenes ) == EOF )
return EOF;
if ( read_genome ( in, gen2, ngenes ) == EOF )
return EOF;
if ( read_genome ( in, gen3, ngenes ) == EOF )
return EOF;
return 0;
}
int
read_genome ( FILE * in, struct genome_struct *genome, int ngenes )
{
char tmp[100];
int i;
if ( fgets ( tmp, 100, in ) == NULL )
return EOF;
genome->genes = ( int * ) malloc ( ngenes * sizeof ( int ) );
for ( i = 0; i < ngenes; i++ )
if ( fscanf ( in, "%d ", &( genome->genes[i] ) ) <= 0 )
{
fprintf ( stderr, "ERROR reading gene %d for genome %s.\n", i,
tmp );
exit ( 1 );
}
return 0;
}