-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllloadonly_main.c
More file actions
163 lines (136 loc) · 3.57 KB
/
llloadonly_main.c
File metadata and controls
163 lines (136 loc) · 3.57 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include "fasta.h"
int
processFasta(char *filename, double *timeTaken)
{
FILE *fp;
FASTArecord fRecord;
int lineNumber = 0, recordNumber = 0, status;
int eofSeen = 0;
clock_t startTime, endTime;
fp = fopen(filename, "r");
if (fp == NULL) {
fprintf(stderr, "Failure opening %s : %s\n",
filename, strerror(errno));
return -1;
}
/** record the time now, before we do the work */
startTime = clock();
do {
/** print a '.' every 10,000 records so
* we know something is happening */
if ((recordNumber % 10000) == 0) {
printf(".");
fflush(stdout);
}
fastaInitializeRecord(&fRecord);
status = fastaReadRecord(fp, &fRecord);
if (status == 0) {
eofSeen = 1;
} else if (status > 0) {
lineNumber += status;
recordNumber++;
//fastaPrintRecord(stdout, &fRecord);
fastaClearRecord(&fRecord);
} else {
fprintf(stderr, "status = %d\n", status);
fprintf(stderr, "Error: failure at line %d of '%s'\n",
lineNumber, filename);
return -1;
}
} while ( ! eofSeen);
printf(" %d FASTA records\n", recordNumber);
/** record the time now, when the work is done,
* and calculate the difference*/
endTime = clock();
(*timeTaken) = ((double) (endTime - startTime)) / CLOCKS_PER_SEC;
fclose(fp);
return recordNumber;
}
int
processFastaRepeatedly(
char *filename,
long repeatsRequested
)
{
double timeThisIterationInSeconds;
double totalTimeInSeconds = 0;
int minutesPortion;
int status;
long i;
for (i = 0; i < repeatsRequested; i++) {
status = processFasta(filename, &timeThisIterationInSeconds);
if (status < 0) return -1;
totalTimeInSeconds += timeThisIterationInSeconds;
}
printf("%lf seconds taken for processing total\n", totalTimeInSeconds);
totalTimeInSeconds /= (double) repeatsRequested;
minutesPortion = (int) (totalTimeInSeconds / 60);
totalTimeInSeconds = totalTimeInSeconds - (60 * minutesPortion);
printf("On average: %d minutes, %lf second per run\n",
minutesPortion, totalTimeInSeconds);
return status;
}
void usage(char *progname)
{
fprintf(stderr, "%s [<OPTIONS>] <file> [ <file> ...]\n", progname);
fprintf(stderr, "\n");
fprintf(stderr, "Prints timing of loading and storing FASTA records.\n");
fprintf(stderr, "\n");
fprintf(stderr, "Options: \n");
fprintf(stderr, "-R <REPEATS> : Number of times to repeat load.\n");
fprintf(stderr, " : Time reported will be average time.\n");
fprintf(stderr, "\n");
}
/**
* Program mainline
*/
int
main(int argc, char **argv)
{
int i, recordsProcessed = 0;
long repeatsRequested = 1;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (argv[i][1] == 'R') {
if (i >= argc) {
fprintf(stderr,
"Error: need argument for repeats requested\n");
return 1;
}
if (sscanf(argv[++i], "%ld", &repeatsRequested) != 1) {
fprintf(stderr,
"Error: cannot parse repeats requested from '%s'\n",
argv[i]);
return 1;
}
} else {
fprintf(stderr,
"Error: unknown option '%s'\n", argv[i]);
usage(argv[0]);
}
} else {
recordsProcessed = processFastaRepeatedly(argv[i],
repeatsRequested);
if (recordsProcessed < 0) {
fprintf(stderr, "Error: Processing '%s' failed -- exitting\n",
argv[i]);
return 1;
}
printf("%d records processed from '%s'\n",
recordsProcessed, argv[i]);
}
}
if ( recordsProcessed == 0 ) {
fprintf(stderr,
"No data processed -- provide the name of"
" a file on the command line\n");
usage(argv[0]);
return 1;
}
return 0;
}