Annotation of OpenXM_contrib2/asir2000/io/bload.c, Revision 1.13
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.13 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/bload.c,v 1.12 2003/02/14 22:29:15 ohara Exp $
1.2 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
51: #include "com.h"
1.12 ohara 52: #if defined(PARI)
1.1 noro 53: #include "genpari.h"
54: int get_lg(GEN);
55: #endif
56:
57: extern VL file_vl;
58:
59: void (*loadf[])() = { 0, loadnum, loadp, loadr, loadlist, loadvect, loadmat,
1.4 noro 60: loadstring, 0, loaddp, loadui, loaderror,0,0,0,loadgfmmat, loadbytearray };
1.6 saito 61: #if defined(INTERVAL)
1.7 saito 62: void loaditv();
63: void loaditvd();
1.9 noro 64: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loaditv, loaditvd, 0, loaditv, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn };
1.6 saito 65: #else
1.9 noro 66: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn };
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.12 ohara 123: #if defined(PARI)
1.1 noro 124: GEN z;
125: unsigned int uexpo,lexpo;
126: char dmy;
127: int sign;
128: unsigned int len;
1.13 ! noro 129: unsigned long expo;
1.1 noro 130: BF q;
131:
132: read_char(s,&dmy);
133: read_int(s,&sign);
134: read_int(s,&uexpo);
135: read_int(s,&lexpo);
136:
137: #if defined(LONG_IS_32BIT)
138: if ( uexpo )
139: error("loadbf : exponent too large");
140: read_int(s,&len);
141: NEWBF(q,len+2);
142: z = (GEN)BDY(q);
143: settyp(z,t_REAL);
144: setlg(z,len+2);
145: setsigne(z,(long)sign);
146: setexpo(z,(long)lexpo);
147: read_intarray(s,(int *)(z+2),len);
148: #elif defined(LONG_IS_64BIT)
149: expo = (((UL)uexpo)<<32)|((UL)lexpo);
150: read_int(s,&len);
151: NEWBF(q,(len+5)/2); /* 2+(len+1)/2 */
152: z = (GEN)BDY(q);
153: settyp(z,t_REAL);
154: setlg(z,(len+5)/2);
155: setsigne(z,(long)sign);
156: setexpo(z,(long)expo);
157: read_longarray(s,z+2,len);
158: #endif
159: *p = q;
160: #else
161: error("loadbf : PARI is not combined");
162: #endif
163: }
1.6 saito 164:
165: #if defined(INTERVAL)
1.10 noro 166: void loaditv(FILE *s,Itv *p)
1.6 saito 167: {
168: Itv q;
169: char dmy;
170:
171: read_char(s,&dmy);
172: NEWItvP(q); loadobj(s,(Obj *)&INF(q)); loadobj(s,(Obj *)&SUP(q));
173: *p = q;
174: }
175:
1.11 kondoh 176: void loaditvd(FILE *s,IntervalDouble *p)
1.6 saito 177: {
1.11 kondoh 178: IntervalDouble q;
1.6 saito 179: char dmy;
180:
181: read_char(s,&dmy);
1.11 kondoh 182: NEWIntervalDouble(q);
1.6 saito 183: read_double(s,&INF(q));
184: read_double(s,&SUP(q));
185: *p = q;
186: }
187: #endif
1.1 noro 188:
1.10 noro 189: void loadcplx(FILE *s,C *p)
1.1 noro 190: {
191: C q;
192: char dmy;
193:
194: read_char(s,&dmy);
195: NEWC(q); loadobj(s,(Obj *)&q->r); loadobj(s,(Obj *)&q->i);
196: *p = q;
197: }
198:
1.10 noro 199: void loadmi(FILE *s,MQ *p)
1.1 noro 200: {
201: MQ q;
202: char dmy;
203:
204: read_char(s,&dmy);
205: NEWMQ(q); read_int(s,(int *)&CONT(q));
206: *p = q;
207: }
208:
1.10 noro 209: void loadlm(FILE *s,LM *p)
1.1 noro 210: {
211: int size;
212: char dmy;
213: N body;
214:
215: read_char(s,&dmy); read_int(s,&size);
216: body = NALLOC(size); PL(body) = size;
217: read_intarray(s,BD(body),size);
218: MKLM(body,*p);
219: }
220:
1.10 noro 221: void loadgf2n(FILE *s,GF2N *p)
1.1 noro 222: {
223: char dmy;
224: int len;
225: UP2 body;
226:
227: read_char(s,&dmy); read_int(s,&len);
228: NEWUP2(body,len); body->w = len;
229: read_intarray(s,body->b,len);
230: MKGF2N(body,*p);
231: }
232:
1.10 noro 233: void loadgfpn(FILE *s,GFPN *p)
1.1 noro 234: {
235: char dmy;
236: int d,i;
237: UP body;
238:
239: read_char(s,&dmy); read_int(s,&d);
240: body = UPALLOC(d);
241: body->d = d;
242: for ( i = 0; i <= d; i++ )
243: loadobj(s,(Obj *)&body->c[i]);
244: MKGFPN(body,*p);
1.8 noro 245: }
246:
1.10 noro 247: void loadgfs(FILE *s,GFS *p)
1.8 noro 248: {
249: GFS q;
250: char dmy;
251:
252: read_char(s,&dmy);
253: NEWGFS(q); read_int(s,(int *)&CONT(q));
254: *p = q;
1.9 noro 255: }
256:
1.10 noro 257: void loadgfsn(FILE *s,GFSN *p)
1.9 noro 258: {
259: char dmy;
260: int d;
261: UM body;
262:
263: read_char(s,&dmy); read_int(s,&d);
264: body = UMALLOC(d); DEG(body) = d;
265: read_intarray(s,COEF(body),d+1);
266: MKGFSN(body,*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;
456: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>