2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 /*--------------------------------------------------------------------------*/
19 #include "filesmanagement.h"
21 #include "islittleendian.h"
22 #include "convert_tools.h"
23 #include "localization.h"
24 /*--------------------------------------------------------------------------*/
27 /*--------------------------------------------------------------------------*/
28 /* =================================================
29 * reads data and store them without type conversion
30 * =================================================*/
31 /*--------------------------------------------------------------------------*/
32 #define MGET_CHAR_NC(Type) \
34 Type *val = (Type *) res ; \
35 items=(int)fread(val,sizeof(Type),n,fa); \
38 /*--------------------------------------------------------------------------*/
39 #define MGET_NC(Type) { \
40 Type *val = (Type *) res ; \
43 for ( i=0; i< n; i++) { \
44 unsigned long long tmp; \
45 items+=(int)fread(&tmp,sizeof(Type),1,fa); \
46 swap_generic((char *)&tmp,(char *)val, sizeof(Type)); \
50 else items=(int)fread(val,sizeof(Type),n,fa); \
52 /*--------------------------------------------------------------------------*/
53 #define MGET_GEN_NC(NumType,cf) \
57 MGET_NC(NumType);break; \
59 swap = (islittleendian()==1)? 1:0; \
60 MGET_NC(NumType); break; \
62 swap = (islittleendian()==1) ? 0:1; \
63 MGET_NC(NumType); break; \
65 sciprint(_("%s: Wrong value for input argument #%d: '%s' or '%s' or '%s' expected.\n"),"mget",4," ","b","l"); \
69 /*--------------------------------------------------------------------------*/
70 void C2F(mgetnc) (int *fd, void *res, int *n1, char *type, int *ierr)
73 int i, items, n = *n1;
77 if ((fa = GetFileOpenedInScilab(*fd)) == NULL)
79 sciprint(_("%s: No input file associated to logical unit %d.\n"), "mget", *fd);
83 swap = GetSwapStatus(*fd);
84 c1 = (strlen(type) > 1) ? type[1] : ' ';
85 c2 = (strlen(type) > 2) ? type[2] : ' ';
93 MGET_GEN_NC(long long, c1);
97 MGET_GEN_NC(short, c1);
105 MGET_GEN_NC(double, c1);
109 MGET_GEN_NC(float, c1);
116 MGET_GEN_NC(unsigned int, c2);
120 MGET_GEN_NC(unsigned long long, c2);
124 MGET_GEN_NC(unsigned short, c2);
128 MGET_GEN_NC(unsigned int, ' ');
132 MGET_CHAR_NC(unsigned char);
146 *ierr = -(items) - 1;
147 /** sciprint("Read %d out of\n",items,n); **/
152 /*--------------------------------------------------------------------------*/
153 /* =================================================
154 * reads data and store them in double
155 * =================================================*/
157 /* conversion macro */
158 #define CONVGD(Type) \
160 Type *val = (Type *) res ; \
161 for ( i = items-1 ; i >=0 ; i--) \
164 /*--------------------------------------------------------------------------*/
165 #define MGET_GEN(NumType,cf) MGET_GEN_NC(NumType,cf); CONVGD(NumType);
166 #define MGET_CHAR(NumType) MGET_CHAR_NC(NumType); CONVGD(NumType);
167 /*--------------------------------------------------------------------------*/
168 /* reads data and store them in double */
169 void mget2(FILE * fa, int swap2, double *res, int n, char *type, int *ierr)
175 c1 = (strlen(type) > 1) ? type[1] : ' ';
176 c2 = (strlen(type) > 2) ? type[2] : ' ';
184 MGET_GEN(long long, c1);
196 MGET_GEN(double, c1);
207 MGET_GEN(unsigned int, c2);
211 MGET_GEN(unsigned long long, c2);
215 MGET_GEN(unsigned short, c2);
219 MGET_GEN(unsigned int, ' ');
223 MGET_CHAR(unsigned char);
237 *ierr = -(items) - 1;
238 /** sciprint("Read %d out of\n",items,n); **/
243 /*--------------------------------------------------------------------------*/
244 void C2F(mget) (int *fd, double *res, int *n, char *type, int *ierr)
249 nc = (int)strlen(type);
253 sciprint(_("%s: Wrong size for input argument #%d: Non-empty string expected.\n"), "mput", 4, type);
257 fa = GetFileOpenedInScilab(*fd);
260 swap2 = GetSwapStatus(*fd);
261 mget2(fa, swap2, res, *n, type, ierr);
264 sciprint(_("%s: Wrong value for input argument #%d: Format not recognized.\n"), "mget", 4);
269 sciprint(_("%s: No input file associated to logical unit %d.\n"), "mget", *fd);
274 /*--------------------------------------------------------------------------*/