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