Annotation of OpenXM_contrib2/asir2000/io/bload.c, Revision 1.17
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.17 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/bload.c,v 1.16 2009/03/16 16:43:03 ohara 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.16 ohara 138: #if SIZEOF_LONG == 4
1.17 ! noro 139: read_intarray(s,(int *)r->body->_mpfr_d,len);
! 140: #else /* SIZEOF_LONG == 8 */
! 141: read_longarray(s,(long *)r->body->_mpfr_d,len);
1.1 noro 142: #endif
1.17 ! noro 143: *p = r;
1.1 noro 144: }
1.6 saito 145:
146: #if defined(INTERVAL)
1.10 noro 147: void loaditv(FILE *s,Itv *p)
1.6 saito 148: {
149: Itv q;
150: char dmy;
151:
152: read_char(s,&dmy);
153: NEWItvP(q); loadobj(s,(Obj *)&INF(q)); loadobj(s,(Obj *)&SUP(q));
154: *p = q;
155: }
156:
1.11 kondoh 157: void loaditvd(FILE *s,IntervalDouble *p)
1.6 saito 158: {
1.11 kondoh 159: IntervalDouble q;
1.6 saito 160: char dmy;
161:
162: read_char(s,&dmy);
1.11 kondoh 163: NEWIntervalDouble(q);
1.6 saito 164: read_double(s,&INF(q));
165: read_double(s,&SUP(q));
166: *p = q;
167: }
168: #endif
1.1 noro 169:
1.10 noro 170: void loadcplx(FILE *s,C *p)
1.1 noro 171: {
172: C q;
173: char dmy;
174:
175: read_char(s,&dmy);
176: NEWC(q); loadobj(s,(Obj *)&q->r); loadobj(s,(Obj *)&q->i);
177: *p = q;
178: }
179:
1.10 noro 180: void loadmi(FILE *s,MQ *p)
1.1 noro 181: {
182: MQ q;
183: char dmy;
184:
185: read_char(s,&dmy);
186: NEWMQ(q); read_int(s,(int *)&CONT(q));
187: *p = q;
188: }
189:
1.10 noro 190: void loadlm(FILE *s,LM *p)
1.1 noro 191: {
192: int size;
193: char dmy;
194: N body;
195:
196: read_char(s,&dmy); read_int(s,&size);
197: body = NALLOC(size); PL(body) = size;
198: read_intarray(s,BD(body),size);
199: MKLM(body,*p);
200: }
201:
1.10 noro 202: void loadgf2n(FILE *s,GF2N *p)
1.1 noro 203: {
204: char dmy;
205: int len;
206: UP2 body;
207:
208: read_char(s,&dmy); read_int(s,&len);
209: NEWUP2(body,len); body->w = len;
210: read_intarray(s,body->b,len);
211: MKGF2N(body,*p);
212: }
213:
1.10 noro 214: void loadgfpn(FILE *s,GFPN *p)
1.1 noro 215: {
216: char dmy;
217: int d,i;
218: UP body;
219:
220: read_char(s,&dmy); read_int(s,&d);
221: body = UPALLOC(d);
222: body->d = d;
223: for ( i = 0; i <= d; i++ )
224: loadobj(s,(Obj *)&body->c[i]);
225: MKGFPN(body,*p);
1.8 noro 226: }
227:
1.10 noro 228: void loadgfs(FILE *s,GFS *p)
1.8 noro 229: {
230: GFS q;
231: char dmy;
232:
233: read_char(s,&dmy);
234: NEWGFS(q); read_int(s,(int *)&CONT(q));
235: *p = q;
1.9 noro 236: }
237:
1.10 noro 238: void loadgfsn(FILE *s,GFSN *p)
1.9 noro 239: {
240: char dmy;
241: int d;
242: UM body;
243:
244: read_char(s,&dmy); read_int(s,&d);
245: body = UMALLOC(d); DEG(body) = d;
246: read_intarray(s,COEF(body),d+1);
247: MKGFSN(body,*p);
1.14 noro 248: }
249:
250: void loaddalg(FILE *s,DAlg *p)
251: {
252: char dmy;
253: Obj nm,dn;
254:
255: read_char(s,&dmy);
256: loadobj(s,&nm);
257: loadobj(s,&dn);
258: MKDAlg((DP)nm,(Q)dn,*p);
1.1 noro 259: }
260:
1.10 noro 261: void loadp(FILE *s,P *p)
1.1 noro 262: {
263: V v;
264: int n,vindex;
265: DCP dc,dc0;
266: P t;
267:
268: read_int(s,&vindex);
269: if ( vindex < 0 )
270: /* v is a pure function */
271: v = loadpfins(s);
272: else
273: v = (V)load_convv(vindex);
274: read_int(s,&n);
275: for ( dc0 = 0; n; n-- ) {
276: NEXTDC(dc0,dc); loadobj(s,(Obj *)&DEG(dc)); loadobj(s,(Obj *)&COEF(dc));
277: }
278: NEXT(dc) = 0;
279: MKP(v,dc0,t);
280: if ( vindex < 0 || file_vl )
281: reorderp(CO,file_vl,t,p);
282: else
283: *p = t;
284: }
285:
286: /* |name(str)|argc(int)|darray(intarray)|args| */
287:
1.10 noro 288: V loadpfins(FILE *s)
1.1 noro 289: {
290: char *name;
291: FUNC fp;
292: int argc,i;
293: V v;
294: int *darray;
295: Obj *args;
296: PF pf;
297: char *buf;
298: V *a;
299: P u;
300:
301: loadstr(s,&name);
302: read_int(s,&argc);
303: searchpf(name,&fp);
304: if ( fp ) {
305: pf = fp->f.puref;
306: if ( pf->argc != argc )
307: error("loadpfins : argument mismatch");
308: } else {
309: a = (V *)MALLOC(argc*sizeof(V));
310: buf = (char *)ALLOCA(BUFSIZ);
311: for ( i = 0; i < argc; i++ ) {
312: sprintf(buf,"_%c",'a'+i);
313: makevar(buf,&u); a[i] = VR(u);
314: }
315: mkpf(name,0,argc,a,0,0,0,&pf);
316: }
317: darray = (int *)ALLOCA(argc*sizeof(int));
318: args = (Obj *)ALLOCA(argc*sizeof(int));
319: read_intarray(s,darray,argc);
320: for ( i = 0; i < argc; i++ )
321: loadobj(s,&args[i]);
322: _mkpfins_with_darray(pf,args,darray,&v);
323: return v;
324: }
325:
1.10 noro 326: void loadr(FILE *s,R *p)
1.1 noro 327: {
328: R r;
329:
330: NEWR(r); read_short(s,&r->reduced);
331: loadobj(s,(Obj *)&NM(r)); loadobj(s,(Obj *)&DN(r)); *p = r;
332: }
333:
1.10 noro 334: void loadlist(FILE *s,LIST *p)
1.1 noro 335: {
336: int n;
337: NODE tn,tn0;
338:
339: read_int(s,&n);
340: for ( tn0 = 0; n; n-- ) {
341: NEXTNODE(tn0,tn); loadobj(s,(Obj *)&BDY(tn));
342: }
343: if ( tn0 )
344: NEXT(tn) = 0;
345: MKLIST(*p,tn0);
346: }
347:
1.10 noro 348: void loadvect(FILE *s,VECT *p)
1.1 noro 349: {
350: int i,len;
351: VECT vect;
352:
353: read_int(s,&len); MKVECT(vect,len);
354: for ( i = 0; i < len; i++ )
355: loadobj(s,(Obj *)&BDY(vect)[i]);
356: *p = vect;
357: }
358:
1.10 noro 359: void loadmat(FILE *s,MAT *p)
1.1 noro 360: {
361: int row,col,i,j;
362: MAT mat;
363:
364: read_int(s,&row); read_int(s,&col); MKMAT(mat,row,col);
365: for ( i = 0; i < row; i++ )
366: for ( j = 0; j < col; j++ )
367: loadobj(s,(Obj *)&BDY(mat)[i][j]);
368: *p = mat;
369: }
370:
1.10 noro 371: void loadstring(FILE *s,STRING *p)
1.1 noro 372: {
373: char *t;
374:
375: loadstr(s,&t); MKSTR(*p,t);
376: }
377:
1.10 noro 378: void loadstr(FILE *s,char **p)
1.1 noro 379: {
380: int len;
381: char *t;
382:
383: read_int(s,&len);
384: if ( len ) {
385: t = (char *)MALLOC(len+1); read_string(s,t,len); t[len] = 0;
386: } else
387: t = "";
388: *p = t;
1.4 noro 389: }
390:
1.10 noro 391: void loadbytearray(FILE *s,BYTEARRAY *p)
1.4 noro 392: {
393: int len;
394: BYTEARRAY array;
395:
396: read_int(s,&len);
397: MKBYTEARRAY(array,len);
398: if ( len ) {
399: read_string(s,array->body,len);
400: }
401: *p = array;
1.1 noro 402: }
403:
1.10 noro 404: void loaddp(FILE *s,DP *p)
1.1 noro 405: {
406: int nv,n,i,sugar;
407: DP dp;
408: MP m,m0;
409: DL dl;
410:
411: read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
412: for ( i = 0, m0 = 0; i < n; i++ ) {
413: NEXTMP(m0,m);
414: loadobj(s,(Obj *)&(m->c));
415: NEWDL(dl,nv); m->dl = dl;
416: read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
417: }
418: NEXT(m) = 0; MKDP(nv,m0,dp); dp->sugar = sugar; *p = dp;
419: }
420:
1.10 noro 421: void loadui(FILE *s,USINT *u)
1.1 noro 422: {
423: unsigned int b;
424:
425: read_int(s,&b); MKUSINT(*u,b);
426: }
427:
1.10 noro 428: void loaderror(FILE *s,ERR *e)
1.1 noro 429: {
430: Obj b;
431:
432: loadobj(s,&b); MKERR(*e,b);
433: }
434:
435:
1.10 noro 436: void loadgfmmat(FILE *s,GFMMAT *p)
1.1 noro 437: {
1.10 noro 438: int i,row,col;
1.1 noro 439: unsigned int **a;
440: GFMMAT mat;
441:
442: read_int(s,&row); read_int(s,&col);
443: a = (unsigned int **)almat(row,col);
444: TOGFMMAT(row,col,a,mat);
445: for ( i = 0; i < row; i++ )
446: read_intarray(s,a[i],col);
447: *p = mat;
1.15 noro 448: }
449:
450: void loadnbp(FILE *s,NBP *p)
451: {
452: int n,i;
453: NBM m;
454: NODE r0,r;
455:
456: read_int(s,&n);
457: for ( i = 0, r0 = 0; i < n; i++ ) {
458: NEWNBM(m);
459: loadobj(s,(Obj *)&m->c);
460: read_int(s,&m->d);
461: NEWNBMBDY(m,m->d); read_intarray(s,m->b,(m->d+31)/32);
462: NEXTNODE(r0,r); BDY(r) = (pointer)m;
463: }
464: if ( r0 ) NEXT(r) = 0;
465: MKNBP(*p,r0);
1.1 noro 466: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>