Annotation of OpenXM_contrib2/asir2000/io/bload.c, Revision 1.14
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.14 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/bload.c,v 1.13 2003/12/22 09:33:47 noro 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.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.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.14 ! noro 267: }
! 268:
! 269: void loaddalg(FILE *s,DAlg *p)
! 270: {
! 271: char dmy;
! 272: Obj nm,dn;
! 273:
! 274: read_char(s,&dmy);
! 275: loadobj(s,&nm);
! 276: loadobj(s,&dn);
! 277: MKDAlg((DP)nm,(Q)dn,*p);
1.1 noro 278: }
279:
1.10 noro 280: void loadp(FILE *s,P *p)
1.1 noro 281: {
282: V v;
283: int n,vindex;
284: DCP dc,dc0;
285: P t;
286:
287: read_int(s,&vindex);
288: if ( vindex < 0 )
289: /* v is a pure function */
290: v = loadpfins(s);
291: else
292: v = (V)load_convv(vindex);
293: read_int(s,&n);
294: for ( dc0 = 0; n; n-- ) {
295: NEXTDC(dc0,dc); loadobj(s,(Obj *)&DEG(dc)); loadobj(s,(Obj *)&COEF(dc));
296: }
297: NEXT(dc) = 0;
298: MKP(v,dc0,t);
299: if ( vindex < 0 || file_vl )
300: reorderp(CO,file_vl,t,p);
301: else
302: *p = t;
303: }
304:
305: /* |name(str)|argc(int)|darray(intarray)|args| */
306:
1.10 noro 307: V loadpfins(FILE *s)
1.1 noro 308: {
309: char *name;
310: FUNC fp;
311: int argc,i;
312: V v;
313: int *darray;
314: Obj *args;
315: PF pf;
316: char *buf;
317: V *a;
318: P u;
319:
320: loadstr(s,&name);
321: read_int(s,&argc);
322: searchpf(name,&fp);
323: if ( fp ) {
324: pf = fp->f.puref;
325: if ( pf->argc != argc )
326: error("loadpfins : argument mismatch");
327: } else {
328: a = (V *)MALLOC(argc*sizeof(V));
329: buf = (char *)ALLOCA(BUFSIZ);
330: for ( i = 0; i < argc; i++ ) {
331: sprintf(buf,"_%c",'a'+i);
332: makevar(buf,&u); a[i] = VR(u);
333: }
334: mkpf(name,0,argc,a,0,0,0,&pf);
335: }
336: darray = (int *)ALLOCA(argc*sizeof(int));
337: args = (Obj *)ALLOCA(argc*sizeof(int));
338: read_intarray(s,darray,argc);
339: for ( i = 0; i < argc; i++ )
340: loadobj(s,&args[i]);
341: _mkpfins_with_darray(pf,args,darray,&v);
342: return v;
343: }
344:
1.10 noro 345: void loadr(FILE *s,R *p)
1.1 noro 346: {
347: R r;
348:
349: NEWR(r); read_short(s,&r->reduced);
350: loadobj(s,(Obj *)&NM(r)); loadobj(s,(Obj *)&DN(r)); *p = r;
351: }
352:
1.10 noro 353: void loadlist(FILE *s,LIST *p)
1.1 noro 354: {
355: int n;
356: NODE tn,tn0;
357:
358: read_int(s,&n);
359: for ( tn0 = 0; n; n-- ) {
360: NEXTNODE(tn0,tn); loadobj(s,(Obj *)&BDY(tn));
361: }
362: if ( tn0 )
363: NEXT(tn) = 0;
364: MKLIST(*p,tn0);
365: }
366:
1.10 noro 367: void loadvect(FILE *s,VECT *p)
1.1 noro 368: {
369: int i,len;
370: VECT vect;
371:
372: read_int(s,&len); MKVECT(vect,len);
373: for ( i = 0; i < len; i++ )
374: loadobj(s,(Obj *)&BDY(vect)[i]);
375: *p = vect;
376: }
377:
1.10 noro 378: void loadmat(FILE *s,MAT *p)
1.1 noro 379: {
380: int row,col,i,j;
381: MAT mat;
382:
383: read_int(s,&row); read_int(s,&col); MKMAT(mat,row,col);
384: for ( i = 0; i < row; i++ )
385: for ( j = 0; j < col; j++ )
386: loadobj(s,(Obj *)&BDY(mat)[i][j]);
387: *p = mat;
388: }
389:
1.10 noro 390: void loadstring(FILE *s,STRING *p)
1.1 noro 391: {
392: char *t;
393:
394: loadstr(s,&t); MKSTR(*p,t);
395: }
396:
1.10 noro 397: void loadstr(FILE *s,char **p)
1.1 noro 398: {
399: int len;
400: char *t;
401:
402: read_int(s,&len);
403: if ( len ) {
404: t = (char *)MALLOC(len+1); read_string(s,t,len); t[len] = 0;
405: } else
406: t = "";
407: *p = t;
1.4 noro 408: }
409:
1.10 noro 410: void loadbytearray(FILE *s,BYTEARRAY *p)
1.4 noro 411: {
412: int len;
413: BYTEARRAY array;
414:
415: read_int(s,&len);
416: MKBYTEARRAY(array,len);
417: if ( len ) {
418: read_string(s,array->body,len);
419: }
420: *p = array;
1.1 noro 421: }
422:
1.10 noro 423: void loaddp(FILE *s,DP *p)
1.1 noro 424: {
425: int nv,n,i,sugar;
426: DP dp;
427: MP m,m0;
428: DL dl;
429:
430: read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
431: for ( i = 0, m0 = 0; i < n; i++ ) {
432: NEXTMP(m0,m);
433: loadobj(s,(Obj *)&(m->c));
434: NEWDL(dl,nv); m->dl = dl;
435: read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
436: }
437: NEXT(m) = 0; MKDP(nv,m0,dp); dp->sugar = sugar; *p = dp;
438: }
439:
1.10 noro 440: void loadui(FILE *s,USINT *u)
1.1 noro 441: {
442: unsigned int b;
443:
444: read_int(s,&b); MKUSINT(*u,b);
445: }
446:
1.10 noro 447: void loaderror(FILE *s,ERR *e)
1.1 noro 448: {
449: Obj b;
450:
451: loadobj(s,&b); MKERR(*e,b);
452: }
453:
454:
1.10 noro 455: void loadgfmmat(FILE *s,GFMMAT *p)
1.1 noro 456: {
1.10 noro 457: int i,row,col;
1.1 noro 458: unsigned int **a;
459: GFMMAT mat;
460:
461: read_int(s,&row); read_int(s,&col);
462: a = (unsigned int **)almat(row,col);
463: TOGFMMAT(row,col,a,mat);
464: for ( i = 0; i < row; i++ )
465: read_intarray(s,a[i],col);
466: *p = mat;
467: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>