Annotation of OpenXM_contrib2/asir2000/io/bload.c, Revision 1.18
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
1.18 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/bload.c,v 1.17 2015/08/04 06:20:45 noro Exp $
1.2 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
51: #include "com.h"
52:
53: extern VL file_vl;
54:
1.15 noro 55: void loadnbp(FILE *s,NBP *p);
56:
1.1 noro 57: void (*loadf[])() = { 0, loadnum, loadp, loadr, loadlist, loadvect, loadmat,
1.15 noro 58: loadstring, 0, loaddp, loadui, loaderror,0,0,0,loadgfmmat,
59: loadbytearray, 0, 0, 0, 0, 0, 0, 0, 0, loadnbp };
60:
1.6 saito 61: #if defined(INTERVAL)
1.7 saito 62: void loaditv();
63: void loaditvd();
1.14 noro 64: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loaditv, loaditvd, 0, loaditv, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn, loaddalg };
1.6 saito 65: #else
1.14 noro 66: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn, loaddalg };
1.6 saito 67: #endif
1.1 noro 68:
1.10 noro 69: void loadobj(FILE *s,Obj *p)
1.1 noro 70: {
71: short id;
72:
73: read_short(s,&id);
74: if ( !id )
75: *p = 0;
76: else if ( !loadf[id] )
77: error("loadobj : not implemented");
78: else
79: (*loadf[id])(s,p);
80: }
81:
1.10 noro 82: void loadnum(FILE *s,Num *p)
1.1 noro 83: {
84: char nid;
85:
86: read_char(s,&nid);
87: if ( !nloadf[nid] )
88: error("loadnum : not implemented");
89: else
90: (*nloadf[nid])(s,p);
91: }
92:
1.10 noro 93: void loadq(FILE *s,Q *p)
1.1 noro 94: {
95: int size[2];
96: char sgn;
97: int len = 2;
98: N nm,dn;
99:
100: read_char(s,&sgn); read_intarray(s,size,len);
101: nm = NALLOC(size[0]); PL(nm) = size[0];
102: read_intarray(s,BD(nm),size[0]);
103: if ( size[1] ) {
104: dn = NALLOC(size[1]); PL(dn) = size[1];
105: read_intarray(s,BD(dn),size[1]);
106: } else
107: dn = 0;
108: NDTOQ(nm,dn,sgn,*p);
109: }
110:
1.10 noro 111: void loadreal(FILE *s,Real *p)
1.1 noro 112: {
113: Real q;
114: char dmy;
115:
116: read_char(s,&dmy);
117: NEWReal(q); read_double(s,&BDY(q));
118: *p = q;
119: }
120:
1.10 noro 121: void loadbf(FILE *s,BF *p)
1.1 noro 122: {
1.17 noro 123: BF r;
124: char dmy;
125: int sgn,prec;
126: UL exp;
1.1 noro 127:
1.17 noro 128: int len;
1.1 noro 129: read_char(s,&dmy);
1.17 noro 130: NEWBF(r);
131: read_int(s,&sgn);
132: read_int(s,&prec);
133: read_int64(s,&exp);
134: read_int(s,&len);
135: mpfr_init2(r->body,prec);
136: MPFR_SIGN(r->body) = sgn;
137: MPFR_EXP(r->body) = (int)exp;
1.18 ! noro 138: #if defined(VISUAL)
! 139: #if !defined(_WIN64)
! 140: read_intarray(s,(int *)r->body->_mpfr_d,len);
! 141: #else
! 142: read_longarray(s,(long long*)r->body->_mpfr_d,len);
! 143: #endif
! 144: #else
1.16 ohara 145: #if SIZEOF_LONG == 4
1.17 noro 146: read_intarray(s,(int *)r->body->_mpfr_d,len);
147: #else /* SIZEOF_LONG == 8 */
148: read_longarray(s,(long *)r->body->_mpfr_d,len);
1.1 noro 149: #endif
1.18 ! noro 150: #endif
1.17 noro 151: *p = r;
1.1 noro 152: }
1.6 saito 153:
154: #if defined(INTERVAL)
1.10 noro 155: void loaditv(FILE *s,Itv *p)
1.6 saito 156: {
157: Itv q;
158: char dmy;
159:
160: read_char(s,&dmy);
161: NEWItvP(q); loadobj(s,(Obj *)&INF(q)); loadobj(s,(Obj *)&SUP(q));
162: *p = q;
163: }
164:
1.11 kondoh 165: void loaditvd(FILE *s,IntervalDouble *p)
1.6 saito 166: {
1.11 kondoh 167: IntervalDouble q;
1.6 saito 168: char dmy;
169:
170: read_char(s,&dmy);
1.11 kondoh 171: NEWIntervalDouble(q);
1.6 saito 172: read_double(s,&INF(q));
173: read_double(s,&SUP(q));
174: *p = q;
175: }
176: #endif
1.1 noro 177:
1.10 noro 178: void loadcplx(FILE *s,C *p)
1.1 noro 179: {
180: C q;
181: char dmy;
182:
183: read_char(s,&dmy);
184: NEWC(q); loadobj(s,(Obj *)&q->r); loadobj(s,(Obj *)&q->i);
185: *p = q;
186: }
187:
1.10 noro 188: void loadmi(FILE *s,MQ *p)
1.1 noro 189: {
190: MQ q;
191: char dmy;
192:
193: read_char(s,&dmy);
194: NEWMQ(q); read_int(s,(int *)&CONT(q));
195: *p = q;
196: }
197:
1.10 noro 198: void loadlm(FILE *s,LM *p)
1.1 noro 199: {
200: int size;
201: char dmy;
202: N body;
203:
204: read_char(s,&dmy); read_int(s,&size);
205: body = NALLOC(size); PL(body) = size;
206: read_intarray(s,BD(body),size);
207: MKLM(body,*p);
208: }
209:
1.10 noro 210: void loadgf2n(FILE *s,GF2N *p)
1.1 noro 211: {
212: char dmy;
213: int len;
214: UP2 body;
215:
216: read_char(s,&dmy); read_int(s,&len);
217: NEWUP2(body,len); body->w = len;
218: read_intarray(s,body->b,len);
219: MKGF2N(body,*p);
220: }
221:
1.10 noro 222: void loadgfpn(FILE *s,GFPN *p)
1.1 noro 223: {
224: char dmy;
225: int d,i;
226: UP body;
227:
228: read_char(s,&dmy); read_int(s,&d);
229: body = UPALLOC(d);
230: body->d = d;
231: for ( i = 0; i <= d; i++ )
232: loadobj(s,(Obj *)&body->c[i]);
233: MKGFPN(body,*p);
1.8 noro 234: }
235:
1.10 noro 236: void loadgfs(FILE *s,GFS *p)
1.8 noro 237: {
238: GFS q;
239: char dmy;
240:
241: read_char(s,&dmy);
242: NEWGFS(q); read_int(s,(int *)&CONT(q));
243: *p = q;
1.9 noro 244: }
245:
1.10 noro 246: void loadgfsn(FILE *s,GFSN *p)
1.9 noro 247: {
248: char dmy;
249: int d;
250: UM body;
251:
252: read_char(s,&dmy); read_int(s,&d);
253: body = UMALLOC(d); DEG(body) = d;
254: read_intarray(s,COEF(body),d+1);
255: MKGFSN(body,*p);
1.14 noro 256: }
257:
258: void loaddalg(FILE *s,DAlg *p)
259: {
260: char dmy;
261: Obj nm,dn;
262:
263: read_char(s,&dmy);
264: loadobj(s,&nm);
265: loadobj(s,&dn);
266: MKDAlg((DP)nm,(Q)dn,*p);
1.1 noro 267: }
268:
1.10 noro 269: void loadp(FILE *s,P *p)
1.1 noro 270: {
271: V v;
272: int n,vindex;
273: DCP dc,dc0;
274: P t;
275:
276: read_int(s,&vindex);
277: if ( vindex < 0 )
278: /* v is a pure function */
279: v = loadpfins(s);
280: else
281: v = (V)load_convv(vindex);
282: read_int(s,&n);
283: for ( dc0 = 0; n; n-- ) {
284: NEXTDC(dc0,dc); loadobj(s,(Obj *)&DEG(dc)); loadobj(s,(Obj *)&COEF(dc));
285: }
286: NEXT(dc) = 0;
287: MKP(v,dc0,t);
288: if ( vindex < 0 || file_vl )
289: reorderp(CO,file_vl,t,p);
290: else
291: *p = t;
292: }
293:
294: /* |name(str)|argc(int)|darray(intarray)|args| */
295:
1.10 noro 296: V loadpfins(FILE *s)
1.1 noro 297: {
298: char *name;
299: FUNC fp;
300: int argc,i;
301: V v;
302: int *darray;
303: Obj *args;
304: PF pf;
305: char *buf;
306: V *a;
307: P u;
308:
309: loadstr(s,&name);
310: read_int(s,&argc);
311: searchpf(name,&fp);
312: if ( fp ) {
313: pf = fp->f.puref;
314: if ( pf->argc != argc )
315: error("loadpfins : argument mismatch");
316: } else {
317: a = (V *)MALLOC(argc*sizeof(V));
318: buf = (char *)ALLOCA(BUFSIZ);
319: for ( i = 0; i < argc; i++ ) {
320: sprintf(buf,"_%c",'a'+i);
321: makevar(buf,&u); a[i] = VR(u);
322: }
323: mkpf(name,0,argc,a,0,0,0,&pf);
324: }
325: darray = (int *)ALLOCA(argc*sizeof(int));
326: args = (Obj *)ALLOCA(argc*sizeof(int));
327: read_intarray(s,darray,argc);
328: for ( i = 0; i < argc; i++ )
329: loadobj(s,&args[i]);
330: _mkpfins_with_darray(pf,args,darray,&v);
331: return v;
332: }
333:
1.10 noro 334: void loadr(FILE *s,R *p)
1.1 noro 335: {
336: R r;
337:
338: NEWR(r); read_short(s,&r->reduced);
339: loadobj(s,(Obj *)&NM(r)); loadobj(s,(Obj *)&DN(r)); *p = r;
340: }
341:
1.10 noro 342: void loadlist(FILE *s,LIST *p)
1.1 noro 343: {
344: int n;
345: NODE tn,tn0;
346:
347: read_int(s,&n);
348: for ( tn0 = 0; n; n-- ) {
349: NEXTNODE(tn0,tn); loadobj(s,(Obj *)&BDY(tn));
350: }
351: if ( tn0 )
352: NEXT(tn) = 0;
353: MKLIST(*p,tn0);
354: }
355:
1.10 noro 356: void loadvect(FILE *s,VECT *p)
1.1 noro 357: {
358: int i,len;
359: VECT vect;
360:
361: read_int(s,&len); MKVECT(vect,len);
362: for ( i = 0; i < len; i++ )
363: loadobj(s,(Obj *)&BDY(vect)[i]);
364: *p = vect;
365: }
366:
1.10 noro 367: void loadmat(FILE *s,MAT *p)
1.1 noro 368: {
369: int row,col,i,j;
370: MAT mat;
371:
372: read_int(s,&row); read_int(s,&col); MKMAT(mat,row,col);
373: for ( i = 0; i < row; i++ )
374: for ( j = 0; j < col; j++ )
375: loadobj(s,(Obj *)&BDY(mat)[i][j]);
376: *p = mat;
377: }
378:
1.10 noro 379: void loadstring(FILE *s,STRING *p)
1.1 noro 380: {
381: char *t;
382:
383: loadstr(s,&t); MKSTR(*p,t);
384: }
385:
1.10 noro 386: void loadstr(FILE *s,char **p)
1.1 noro 387: {
388: int len;
389: char *t;
390:
391: read_int(s,&len);
392: if ( len ) {
393: t = (char *)MALLOC(len+1); read_string(s,t,len); t[len] = 0;
394: } else
395: t = "";
396: *p = t;
1.4 noro 397: }
398:
1.10 noro 399: void loadbytearray(FILE *s,BYTEARRAY *p)
1.4 noro 400: {
401: int len;
402: BYTEARRAY array;
403:
404: read_int(s,&len);
405: MKBYTEARRAY(array,len);
406: if ( len ) {
407: read_string(s,array->body,len);
408: }
409: *p = array;
1.1 noro 410: }
411:
1.10 noro 412: void loaddp(FILE *s,DP *p)
1.1 noro 413: {
414: int nv,n,i,sugar;
415: DP dp;
416: MP m,m0;
417: DL dl;
418:
419: read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
420: for ( i = 0, m0 = 0; i < n; i++ ) {
421: NEXTMP(m0,m);
422: loadobj(s,(Obj *)&(m->c));
423: NEWDL(dl,nv); m->dl = dl;
424: read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
425: }
426: NEXT(m) = 0; MKDP(nv,m0,dp); dp->sugar = sugar; *p = dp;
427: }
428:
1.10 noro 429: void loadui(FILE *s,USINT *u)
1.1 noro 430: {
431: unsigned int b;
432:
433: read_int(s,&b); MKUSINT(*u,b);
434: }
435:
1.10 noro 436: void loaderror(FILE *s,ERR *e)
1.1 noro 437: {
438: Obj b;
439:
440: loadobj(s,&b); MKERR(*e,b);
441: }
442:
443:
1.10 noro 444: void loadgfmmat(FILE *s,GFMMAT *p)
1.1 noro 445: {
1.10 noro 446: int i,row,col;
1.1 noro 447: unsigned int **a;
448: GFMMAT mat;
449:
450: read_int(s,&row); read_int(s,&col);
451: a = (unsigned int **)almat(row,col);
452: TOGFMMAT(row,col,a,mat);
453: for ( i = 0; i < row; i++ )
454: read_intarray(s,a[i],col);
455: *p = mat;
1.15 noro 456: }
457:
458: void loadnbp(FILE *s,NBP *p)
459: {
460: int n,i;
461: NBM m;
462: NODE r0,r;
463:
464: read_int(s,&n);
465: for ( i = 0, r0 = 0; i < n; i++ ) {
466: NEWNBM(m);
467: loadobj(s,(Obj *)&m->c);
468: read_int(s,&m->d);
469: NEWNBMBDY(m,m->d); read_intarray(s,m->b,(m->d+31)/32);
470: NEXTNODE(r0,r); BDY(r) = (pointer)m;
471: }
472: if ( r0 ) NEXT(r) = 0;
473: MKNBP(*p,r0);
1.1 noro 474: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>