tomwalters@0
|
1 /*
|
tomwalters@0
|
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
|
tomwalters@0
|
3 ===========================================================================
|
tomwalters@0
|
4
|
tomwalters@0
|
5 Permission to use, copy, modify, and distribute this software without fee
|
tomwalters@0
|
6 is hereby granted for research purposes, provided that this copyright
|
tomwalters@0
|
7 notice appears in all copies and in all supporting documentation, and that
|
tomwalters@0
|
8 the software is not redistributed for any fee (except for a nominal
|
tomwalters@0
|
9 shipping charge). Anyone wanting to incorporate all or part of this
|
tomwalters@0
|
10 software in a commercial product must obtain a license from the Medical
|
tomwalters@0
|
11 Research Council.
|
tomwalters@0
|
12
|
tomwalters@0
|
13 The MRC makes no representations about the suitability of this
|
tomwalters@0
|
14 software for any purpose. It is provided "as is" without express or
|
tomwalters@0
|
15 implied warranty.
|
tomwalters@0
|
16
|
tomwalters@0
|
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
tomwalters@0
|
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
tomwalters@0
|
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
|
tomwalters@0
|
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
tomwalters@0
|
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
tomwalters@0
|
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
tomwalters@0
|
23 SOFTWARE.
|
tomwalters@0
|
24 */
|
tomwalters@0
|
25
|
tomwalters@0
|
26 /*--------------------------------------------------------------------------*/
|
tomwalters@0
|
27
|
tomwalters@0
|
28 /* inout.c
|
tomwalters@0
|
29 * ----------
|
tomwalters@0
|
30 *
|
tomwalters@0
|
31 * Some of the data in/out functions.
|
tomwalters@0
|
32 *
|
tomwalters@0
|
33 *
|
tomwalters@0
|
34 * M. Akeroyd. 26th May 1993. Revised Winter 1994.
|
tomwalters@0
|
35 */
|
tomwalters@0
|
36
|
tomwalters@0
|
37
|
tomwalters@0
|
38 #include <stdio.h>
|
tomwalters@0
|
39 #include <string.h>
|
tomwalters@0
|
40 #include <stdlib.h>
|
tomwalters@0
|
41 #include "tip.h"
|
tomwalters@0
|
42
|
tomwalters@0
|
43
|
tomwalters@0
|
44 extern short outputfiguredata[MAX_DATA];
|
tomwalters@0
|
45 extern short outputgrounddata[MAX_DATA];
|
tomwalters@0
|
46
|
tomwalters@0
|
47 extern int verboseflag;
|
tomwalters@0
|
48 extern char progname[MAX_STRING_LENGTH];
|
tomwalters@0
|
49
|
tomwalters@0
|
50
|
tomwalters@0
|
51 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
52
|
tomwalters@0
|
53
|
tomwalters@0
|
54 FILE *open_file(char filefn[], FILE *dir_default, int streamtype)
|
tomwalters@0
|
55 {
|
tomwalters@0
|
56 /* Opens a file stream associated with filefn[].
|
tomwalters@0
|
57 * If that's null, then the stream is a copy of the dir_default:
|
tomwalters@0
|
58 * stdin / stdout / stderr.
|
tomwalters@0
|
59 * 'streamtype' is either READ (for "rb") or WRITE ("wb")
|
tomwalters@0
|
60 */
|
tomwalters@0
|
61
|
tomwalters@0
|
62 char tempfilefn[MAX_STRING_LENGTH];
|
tomwalters@0
|
63 FILE *filefp = NULL;
|
tomwalters@0
|
64
|
tomwalters@0
|
65 if (strcmp(filefn, "") == 0)
|
tomwalters@0
|
66 filefp = dir_default;
|
tomwalters@0
|
67 else
|
tomwalters@0
|
68 if (streamtype == READ)
|
tomwalters@0
|
69 filefp = fopen(filefn, "rb");
|
tomwalters@0
|
70 else /* WRITE */
|
tomwalters@0
|
71 filefp = fopen(filefn, "wb");
|
tomwalters@0
|
72
|
tomwalters@0
|
73 if (filefp == NULL) {
|
tomwalters@0
|
74 fprintf(stderr, " %s : unable to open file %s\n", progname, filefn);
|
tomwalters@0
|
75 exit(-1);}
|
tomwalters@0
|
76
|
tomwalters@0
|
77
|
tomwalters@0
|
78 return filefp;
|
tomwalters@0
|
79
|
tomwalters@0
|
80 }
|
tomwalters@0
|
81
|
tomwalters@0
|
82
|
tomwalters@0
|
83
|
tomwalters@0
|
84 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
85
|
tomwalters@0
|
86
|
tomwalters@0
|
87
|
tomwalters@0
|
88
|
tomwalters@0
|
89 void writedata_output(FILE *outputfp, int samples_to_write)
|
tomwalters@0
|
90 {
|
tomwalters@0
|
91 /* writes an array shorts to outputfp
|
tomwalters@0
|
92 */
|
tomwalters@0
|
93
|
tomwalters@0
|
94 fwrite(outputfiguredata, 2, samples_to_write, outputfp);
|
tomwalters@0
|
95
|
tomwalters@0
|
96 if (ferror(outputfp)) {
|
tomwalters@0
|
97 fprintf(stderr, " %s : something's gone wrong: error writing output \n", progname);
|
tomwalters@0
|
98 exit(-1);}
|
tomwalters@0
|
99 }
|
tomwalters@0
|
100
|
tomwalters@0
|
101
|
tomwalters@0
|
102
|
tomwalters@0
|
103 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
104
|
tomwalters@0
|
105
|
tomwalters@0
|
106
|
tomwalters@0
|
107 void writedata_output_fg(FILE *figurefp, FILE *groundfp, int samples_to_write)
|
tomwalters@0
|
108 {
|
tomwalters@0
|
109 /* similar to writedata_output, but uses both figure and ground
|
tomwalters@0
|
110 * arrays
|
tomwalters@0
|
111 */
|
tomwalters@0
|
112
|
tomwalters@0
|
113 fwrite(outputfiguredata, 2, samples_to_write, figurefp);
|
tomwalters@0
|
114 fwrite(outputgrounddata, 2, samples_to_write, groundfp);
|
tomwalters@0
|
115
|
tomwalters@0
|
116 if (ferror(figurefp)!=0) {
|
tomwalters@0
|
117 fprintf(stderr, " %s : something's gone wrong: error writing figure \n", progname);
|
tomwalters@0
|
118 exit(-1);}
|
tomwalters@0
|
119
|
tomwalters@0
|
120 if (ferror(groundfp)!=0) {
|
tomwalters@0
|
121 fprintf(stderr, " %s : something's gone wrong: error writing ground \n", progname);
|
tomwalters@0
|
122 exit(-1);}
|
tomwalters@0
|
123 }
|
tomwalters@0
|
124
|
tomwalters@0
|
125
|
tomwalters@0
|
126
|
tomwalters@0
|
127 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
128
|
tomwalters@0
|
129
|
tomwalters@0
|
130
|
tomwalters@0
|
131 void close_files(FILE *fp)
|
tomwalters@0
|
132 {
|
tomwalters@0
|
133
|
tomwalters@0
|
134 if (verboseflag == ON)
|
tomwalters@0
|
135 fprintf(stderr, "\n");
|
tomwalters@0
|
136
|
tomwalters@0
|
137 fclose(fp);
|
tomwalters@0
|
138
|
tomwalters@0
|
139 if ( ferror(fp) != 0) {
|
tomwalters@0
|
140 fprintf(stderr, " %s : error closing file.\n", progname);
|
tomwalters@0
|
141 exit(-1);}
|
tomwalters@0
|
142 }
|
tomwalters@0
|
143
|
tomwalters@0
|
144
|
tomwalters@0
|
145 /* The End */
|
tomwalters@0
|
146 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
147
|
tomwalters@0
|
148
|
tomwalters@0
|
149
|
tomwalters@0
|
150
|