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