File Coverage

lib/PDL/IO/Misc-pp-rasc.c
Criterion Covered Total %
statement 115 151 76.1
branch 91 204 44.6
condition n/a
subroutine n/a
pod n/a
total 206 355 58.0


line stmt bran cond sub pod time code
1              
2             #line 453 "lib/PDL/PP.pm"
3             /*
4             * THIS FILE WAS GENERATED BY PDL::PP from lib/PDL/IO/Misc.pd! Do not modify!
5             */
6              
7             #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \
8             if (destroy) { \
9             comp_free_code \
10             } \
11             if ((trans)->dims_redone) { \
12             ntpriv_free_code \
13             }
14              
15             #include "EXTERN.h"
16             #include "perl.h"
17             #include "XSUB.h"
18             #include "pdl.h"
19             #include "pdlcore.h"
20             #define PDL PDL_IO_Misc
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "lib/PDL/IO/Misc-pp-rasc.c"
23             #define SWALLOWLINE(fp) while ((s = PerlIO_getc(fp)) != '\n' && s != EOF)
24             #define TRAILING_WHITESPACE_CHECK(s, label) \
25             if (s!=' ' && s!='\t' && s!='\r' && s!='\n' && s!=',') { nread = -1; goto label; }
26              
27              
28              
29             #line 1846 "lib/PDL/PP.pm"
30             typedef struct pdl_params_rasc {
31             #line 32 "lib/PDL/IO/Misc-pp-rasc.c"
32             PerlIO *fp;
33             IV num;
34             } pdl_params_rasc;
35              
36              
37             #line 1857 "lib/PDL/PP.pm"
38             pdl_error pdl_rasc_redodims(pdl_trans *__privtrans) {
39             pdl_error PDL_err = {0, NULL, 0};
40             #line 41 "lib/PDL/IO/Misc-pp-rasc.c"
41 2           pdl_params_rasc *__params = __privtrans->params; (void)__params;
42 2           __privtrans->ind_sizes[0] = __params->num;
43 2 50         PDL_RETERROR(PDL_err, PDL->redodims_default(__privtrans));
44 2           return PDL_err;
45             }
46              
47              
48             #line 1857 "lib/PDL/PP.pm"
49             pdl_error pdl_rasc_readdata(pdl_trans *__privtrans) {
50             pdl_error PDL_err = {0, NULL, 0};
51             #line 52 "lib/PDL/IO/Misc-pp-rasc.c"
52 2           pdl_params_rasc *__params = __privtrans->params; (void)__params;
53 2 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in rasc:" "broadcast.incs NULL");
54             /* broadcastloop declarations */
55             int __brcloopval;
56             register PDL_Indx __tind0,__tind1; /* counters along dim */
57 2           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
58             /* dims here are how many steps along those dims */
59 2           register PDL_Indx __tinc0_nums = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
60 2           register PDL_Indx __tinc0_ierr = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
61 2           register PDL_Indx __tinc1_nums = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
62 2           register PDL_Indx __tinc1_ierr = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
63             #define PDL_BROADCASTLOOP_START_rasc_readdata PDL_BROADCASTLOOP_START( \
64             readdata, \
65             __privtrans->broadcast, \
66             __privtrans->vtable, \
67             nums_datap += __offsp[0]; \
68             ierr_datap += __offsp[1]; \
69             , \
70             ( ,nums_datap += __tinc1_nums - __tinc0_nums * __tdims0 \
71             ,ierr_datap += __tinc1_ierr - __tinc0_ierr * __tdims0 \
72             ), \
73             ( ,nums_datap += __tinc0_nums \
74             ,ierr_datap += __tinc0_ierr \
75             ) \
76             )
77             #define PDL_BROADCASTLOOP_END_rasc_readdata PDL_BROADCASTLOOP_END( \
78             __privtrans->broadcast, \
79             nums_datap -= __tinc1_nums * __tdims1 + __offsp[0]; \
80             ierr_datap -= __tinc1_ierr * __tdims1 + __offsp[1]; \
81             )
82 2           register PDL_Indx __inc_ierr_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,1,0)]; (void)__inc_ierr_n;
83 2           register PDL_Indx __inc_nums_n = __privtrans->inc_sizes[PDL_INC_ID(__privtrans->vtable,0,0)]; (void)__inc_nums_n;
84             #ifndef PDL_DECLARE_PARAMS_rasc_1
85             #define PDL_DECLARE_PARAMS_rasc_1(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_ierr,PDL_PPSYM_PARAM_ierr) \
86             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, nums, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
87             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_ierr, ierr, (__privtrans->pdls[1]), 1, PDL_PPSYM_PARAM_ierr)
88             #endif
89             #define PDL_IF_BAD(t,f) f
90 2           switch (__privtrans->__datatype) { /* Start generic switch */
91 1           case PDL_F: {
92 1 50         PDL_DECLARE_PARAMS_rasc_1(PDL_Float,F,PDL_Long,L)
    50          
    50          
    50          
    50          
    50          
93             {int ns, i, j;
94 1           ns = __privtrans->ind_sizes[0];
95 5 50         PDL_BROADCASTLOOP_START_rasc_readdata
    50          
    50          
    50          
    50          
    100          
    100          
96 22 100         for (i=0;i
97 21           PDL_Float f = 0;
98 21           int nread = 0;
99 21           int s = PerlIO_getc(__params->fp);
100 21           int afterp = 0, aftere=0;
101 21           int expo = 0;
102 21           PDL_Float sig = 1.0, esig = 1.0;
103 21           PDL_Float div = 1.0;
104 21 50         if (s == EOF) { nread = 0; goto endread_PDL_Float; }
105             while (1) {
106 22 100         if (s == EOF) { nread = 0; goto endread_PDL_Float; } /* signal end of line */
107 21 50         if (s == '#')
108 0 0         SWALLOWLINE(__params->fp);
    0          
109 21 100         if ((s >='0' && s <='9') || s =='.' || s == 'e' || s == 'E'
    50          
    50          
    50          
    50          
110 1 50         || s == '+' || s == '-') break;
    50          
111 1 50         if (s!=' ' && s!='\t' && s!='\r' && s!='\n' && s!=',')
    50          
    50          
    50          
    0          
112 0           { nread = -1; goto endread_PDL_Float; } /* garbage */
113 1           s = PerlIO_getc(__params->fp); /* else skip whitespace */
114             }
115             /* parse number */
116             while (1) {
117 238           switch (s) {
118 198           case '0': case '1': case '2': case '3': case '4':
119             case '5': case '6': case '7': case '8': case '9':
120 198 50         if (aftere)
121 0           expo = (expo*10) + (s - '0');
122 198 100         else if (afterp) {
123 178           div /= 10.0;
124 178           f += div*(s - '0');
125             } else
126 20           f = (f*10) + (s - '0');
127 198           break;
128 0           case '+':
129             /* ignore */
130 0           break;
131 0           case '-':
132 0 0         if (aftere)
133 0           esig = -1;
134             else
135 0           sig = -1;
136 0           break;
137 0           case 'e': case 'E':
138 0 0         if (aftere) { nread = -1; goto endread_PDL_Float; }
139 0           aftere = 1;
140 0           break;
141 20           case '.':
142 20 50         if (afterp || aftere) { nread = -1; goto endread_PDL_Float; }
    50          
143 20           afterp = 1;
144 20           break;
145 20           default:
146 20           goto endread_PDL_Float;
147             break;
148             }
149 218           nread++;
150 218           s = PerlIO_getc(__params->fp);
151             }
152 21           endread_PDL_Float:
153 21 100         if (((ierr_datap)[0+(__inc_ierr_n*(i))] = nread) <= 0)
154 1           break;
155 20           f *= sig;
156             int i2;
157 20 50         for (i2=0;i2
158 0 0         f *= (esig > 0 ? 10.0 : 0.1);
159 20           (nums_datap)[0+(__inc_nums_n*(i))] = f;
160 20 50         TRAILING_WHITESPACE_CHECK(s, endread_PDL_Float);
    50          
    50          
    50          
    0          
161             }
162 21 100         for (j=i+1; j
163 19           (ierr_datap)[0+(__inc_ierr_n*(j))] = (ierr_datap)[0+(__inc_ierr_n*(i))]; /* inherit error flags */
164 1 50         PDL_BROADCASTLOOP_END_rasc_readdata
    50          
165             }
166 1           } break;
167 1           case PDL_D: {
168 1 50         PDL_DECLARE_PARAMS_rasc_1(PDL_Double,D,PDL_Long,L)
    50          
    50          
    50          
    50          
    50          
169             {int ns, i, j;
170 1           ns = __privtrans->ind_sizes[0];
171 4 50         PDL_BROADCASTLOOP_START_rasc_readdata
    50          
    50          
    50          
    50          
    100          
    100          
172 21 100         for (i=0;i
173 20           PDL_Double f = 0;
174 20           int nread = 0;
175 20           int s = PerlIO_getc(__params->fp);
176 20           int afterp = 0, aftere=0;
177 20           int expo = 0;
178 20           PDL_Double sig = 1.0, esig = 1.0;
179 20           PDL_Double div = 1.0;
180 20 50         if (s == EOF) { nread = 0; goto endread_PDL_Double; }
181             while (1) {
182 20 50         if (s == EOF) { nread = 0; goto endread_PDL_Double; } /* signal end of line */
183 20 50         if (s == '#')
184 0 0         SWALLOWLINE(__params->fp);
    0          
185 20 50         if ((s >='0' && s <='9') || s =='.' || s == 'e' || s == 'E'
    50          
    0          
    0          
    0          
186 0 0         || s == '+' || s == '-') break;
    0          
187 0 0         if (s!=' ' && s!='\t' && s!='\r' && s!='\n' && s!=',')
    0          
    0          
    0          
    0          
188 0           { nread = -1; goto endread_PDL_Double; } /* garbage */
189 0           s = PerlIO_getc(__params->fp); /* else skip whitespace */
190             }
191             /* parse number */
192             while (1) {
193 238           switch (s) {
194 198           case '0': case '1': case '2': case '3': case '4':
195             case '5': case '6': case '7': case '8': case '9':
196 198 50         if (aftere)
197 0           expo = (expo*10) + (s - '0');
198 198 100         else if (afterp) {
199 178           div /= 10.0;
200 178           f += div*(s - '0');
201             } else
202 20           f = (f*10) + (s - '0');
203 198           break;
204 0           case '+':
205             /* ignore */
206 0           break;
207 0           case '-':
208 0 0         if (aftere)
209 0           esig = -1;
210             else
211 0           sig = -1;
212 0           break;
213 0           case 'e': case 'E':
214 0 0         if (aftere) { nread = -1; goto endread_PDL_Double; }
215 0           aftere = 1;
216 0           break;
217 20           case '.':
218 20 50         if (afterp || aftere) { nread = -1; goto endread_PDL_Double; }
    50          
219 20           afterp = 1;
220 20           break;
221 20           default:
222 20           goto endread_PDL_Double;
223             break;
224             }
225 218           nread++;
226 218           s = PerlIO_getc(__params->fp);
227             }
228 20           endread_PDL_Double:
229 20 50         if (((ierr_datap)[0+(__inc_ierr_n*(i))] = nread) <= 0)
230 0           break;
231 20           f *= sig;
232             int i2;
233 20 50         for (i2=0;i2
234 0 0         f *= (esig > 0 ? 10.0 : 0.1);
235 20           (nums_datap)[0+(__inc_nums_n*(i))] = f;
236 20 50         TRAILING_WHITESPACE_CHECK(s, endread_PDL_Double);
    50          
    50          
    50          
    0          
237             }
238 1 50         for (j=i+1; j
239 0           (ierr_datap)[0+(__inc_ierr_n*(j))] = (ierr_datap)[0+(__inc_ierr_n*(i))]; /* inherit error flags */
240 1 50         PDL_BROADCASTLOOP_END_rasc_readdata
    50          
241             }
242 1           } break;
243 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in rasc: unhandled datatype(%d), only handles (FD)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
244             }
245             #undef PDL_IF_BAD
246 2           return PDL_err;
247             }
248              
249             static pdl_datatypes pdl_rasc_vtable_gentypes[] = { PDL_F, PDL_D, -1 };
250             static PDL_Indx pdl_rasc_vtable_realdims[] = { 1, 1 };
251             static char *pdl_rasc_vtable_parnames[] = { "nums","ierr" };
252             static short pdl_rasc_vtable_parflags[] = {
253             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE,
254             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISTYPED|PDL_PARAM_ISWRITE
255             };
256             static pdl_datatypes pdl_rasc_vtable_partypes[] = { -1, PDL_L };
257             static PDL_Indx pdl_rasc_vtable_realdims_starts[] = { 0, 1 };
258             static PDL_Indx pdl_rasc_vtable_realdims_ind_ids[] = { 0, 0 };
259             static char *pdl_rasc_vtable_indnames[] = { "n" };
260             pdl_transvtable pdl_rasc_vtable = {
261             PDL_TRANS_DO_BROADCAST, 0, pdl_rasc_vtable_gentypes, 0, 2, NULL /*CORE21*/,
262             pdl_rasc_vtable_realdims, pdl_rasc_vtable_parnames,
263             pdl_rasc_vtable_parflags, pdl_rasc_vtable_partypes,
264             pdl_rasc_vtable_realdims_starts, pdl_rasc_vtable_realdims_ind_ids, 2,
265             1, pdl_rasc_vtable_indnames,
266             pdl_rasc_redodims, pdl_rasc_readdata, NULL,
267             NULL,
268             sizeof(pdl_params_rasc),"PDL::IO::Misc::rasc"
269             };
270              
271              
272 2           pdl_error pdl_run_rasc(pdl *nums,pdl *ierr,PerlIO *fp,IV num) {
273 2           pdl_error PDL_err = {0, NULL, 0};
274 2 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
275 2           pdl_trans *__privtrans = PDL->create_trans(&pdl_rasc_vtable);
276 2 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
277 2           pdl_params_rasc *__params = __privtrans->params;
278 2           __privtrans->pdls[0] = nums;
279 2           __privtrans->pdls[1] = ierr;
280 2 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
281 2           (__params->fp) = (fp); /* CType.get_copy */
282 2           (__params->num) = (num); /* CType.get_copy */
283 2 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
284 2           return PDL_err;
285             }