[BACK]Return to bload.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / io

Annotation of OpenXM_contrib2/asir2018/io/bload.c, Revision 1.2

1.1       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
                     26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
                     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.2     ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2018/io/bload.c,v 1.1 2018/09/19 05:45:08 noro Exp $
1.1       noro       48: */
                     49: #include "ca.h"
                     50: #include "parse.h"
                     51: #include "com.h"
                     52: #include "ox.h"
                     53:
                     54: extern VL file_vl;
                     55:
                     56: void loadnbp(FILE *s,NBP *p);
                     57:
                     58: void (*loadf[])() = { 0, loadnum, loadp, loadr, loadlist, loadvect, loadmat,
                     59:   loadstring, 0, loaddp, loadui, loaderror,0,0,0,loadgfmmat,
                     60:   loadbytearray, 0, 0, 0, 0, 0, 0, 0, 0,  loadnbp };
                     61:
                     62: #if defined(INTERVAL)
                     63: void loaditv();
                     64: void loaditvd();
                     65: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loaditv, loaditvd, 0, loaditv, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn, loaddalg };
                     66: #else
                     67: void (*nloadf[])() = { loadq, loadreal, 0, loadbf, loadcplx, loadmi, loadlm, loadgf2n, loadgfpn, loadgfs, loadgfsn, loaddalg };
                     68: #endif
                     69:
                     70: void loadobj(FILE *s,Obj *p)
                     71: {
                     72:   short id;
                     73:
                     74:   read_short(s,&id);
                     75:   if ( !id )
                     76:     *p = 0;
                     77:   else if ( !loadf[id] )
                     78:     error("loadobj : not implemented");
                     79:   else
                     80:     (*loadf[id])(s,p);
                     81: }
                     82:
                     83: void loadnum(FILE *s,Num *p)
                     84: {
                     85:   char nid;
                     86:
                     87:   read_char(s,&nid);
                     88:   if ( !nloadf[nid] )
                     89:     error("loadnum : not implemented");
                     90:   else
                     91:     (*nloadf[nid])(s,p);
                     92: }
                     93:
                     94: void loadq(FILE *s,Q *p)
                     95: {
                     96:   int size[2];
                     97:   char sgn;
                     98:   int *bnm,*bdn;
                     99:   int len=2;
                    100:   mpz_t z;
                    101:   Z nm,dn;
                    102:
                    103:   read_char(s,&sgn); read_intarray(s,size,len);
                    104:   bnm = (int *)MALLOC(size[0]*sizeof(int));
                    105:   read_intarray(s,bnm,size[0]);
                    106:   mpz_init(z);
                    107:   mpz_import(z,size[0],-1,sizeof(int),0,0,bnm);
                    108:   if ( sgn < 0 ) mpz_neg(z,z);
                    109:   MPZTOZ(z,nm);
                    110:   if ( size[1] ) {
                    111:     bdn = (int *)MALLOC(size[1]*sizeof(int));
                    112:     read_intarray(s,bdn,size[1]);
                    113:     mpz_init(z);
                    114:     mpz_import(z,size[1],-1,sizeof(int),0,0,bdn);
                    115:     MPZTOZ(z,dn);
                    116:     divq((Q)nm,(Q)dn,p);
                    117:   } else
                    118:     *p = (Q)nm;
                    119: }
                    120:
                    121: void loadreal(FILE *s,Real *p)
                    122: {
                    123:   Real q;
                    124:   char dmy;
                    125:
                    126:   read_char(s,&dmy);
                    127:   NEWReal(q); read_double(s,&BDY(q));
                    128:   *p = q;
                    129: }
                    130:
                    131: void loadbf(FILE *s,BF *p)
                    132: {
                    133:   BF r;
                    134:   char dmy;
                    135:   int sgn,prec;
                    136:   UL exp;
                    137:
                    138:   int len;
                    139:   read_char(s,&dmy);
                    140:   NEWBF(r);
                    141:   read_int(s,&sgn);
                    142:   read_int(s,&prec);
                    143:   read_int64(s,&exp);
                    144:   read_int(s,&len);
                    145:   mpfr_init2(r->body,prec);
                    146:   MPFR_SIGN(r->body) = sgn;
                    147:   MPFR_EXP(r->body) = (int)exp;
                    148: #if defined(VISUAL)
                    149: #if !defined(_WIN64)
                    150:   read_intarray(s,(int *)r->body->_mpfr_d,len);
                    151: #else
                    152:   read_longarray(s,(long long*)r->body->_mpfr_d,len);
                    153: #endif
                    154: #else
                    155: #if SIZEOF_LONG == 4
                    156:   read_intarray(s,(int *)r->body->_mpfr_d,len);
                    157: #else /* SIZEOF_LONG == 8 */
                    158:   read_longarray(s,(long *)r->body->_mpfr_d,len);
                    159: #endif
                    160: #endif
                    161:   *p = r;
                    162: }
                    163:
                    164: #if defined(INTERVAL)
                    165: void loaditv(FILE *s,Itv *p)
                    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:
                    175: void loaditvd(FILE *s,IntervalDouble *p)
                    176: {
                    177:   IntervalDouble q;
                    178:   char dmy;
                    179:
                    180:   read_char(s,&dmy);
                    181:   NEWIntervalDouble(q);
                    182:   read_double(s,&INF(q));
                    183:   read_double(s,&SUP(q));
                    184:   *p = q;
                    185: }
                    186: #endif
                    187:
                    188: void loadcplx(FILE *s,C *p)
                    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:
                    198: void loadmi(FILE *s,MQ *p)
                    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:
                    208: void loadlm(FILE *s,LM *p)
                    209: {
                    210:   int size,len;
                    211:   char dmy;
                    212:   int *b;
                    213:   mpz_t z;
                    214:
                    215:   read_char(s,&dmy); read_int(s,&size);
                    216:   b = (int *)MALLOC(size*sizeof(int));
                    217:   read_intarray(s,b,size);
                    218:   mpz_init(z);
1.2     ! noro      219:   mpz_import(z,size,-1,sizeof(int),0,0,b);
1.1       noro      220:   MKLM(z,*p);
                    221: }
                    222:
                    223: void loadgf2n(FILE *s,GF2N *p)
                    224: {
                    225:   char dmy;
                    226:   int len;
                    227:   UP2 body;
                    228:
                    229:   read_char(s,&dmy); read_int(s,&len);
                    230:   NEWUP2(body,len); body->w = len;
                    231:   read_intarray(s,body->b,len);
                    232:   MKGF2N(body,*p);
                    233: }
                    234:
                    235: void loadgfpn(FILE *s,GFPN *p)
                    236: {
                    237:   char dmy;
                    238:   int d,i;
                    239:   UP body;
                    240:
                    241:   read_char(s,&dmy); read_int(s,&d);
                    242:   body = UPALLOC(d);
                    243:   body->d = d;
                    244:   for ( i = 0; i <= d; i++ )
                    245:     loadobj(s,(Obj *)&body->c[i]);
                    246:   MKGFPN(body,*p);
                    247: }
                    248:
                    249: void loadgfs(FILE *s,GFS *p)
                    250: {
                    251:   GFS q;
                    252:   char dmy;
                    253:
                    254:   read_char(s,&dmy);
                    255:   NEWGFS(q); read_int(s,(int *)&CONT(q));
                    256:   *p = q;
                    257: }
                    258:
                    259: void loadgfsn(FILE *s,GFSN *p)
                    260: {
                    261:   char dmy;
                    262:   int d;
                    263:   UM body;
                    264:
                    265:   read_char(s,&dmy); read_int(s,&d);
                    266:   body = UMALLOC(d); DEG(body) = d;
                    267:   read_intarray(s,COEF(body),d+1);
                    268:   MKGFSN(body,*p);
                    269: }
                    270:
                    271: void loaddalg(FILE *s,DAlg *p)
                    272: {
                    273:   char dmy;
                    274:   Obj nm,dn;
                    275:
                    276:   read_char(s,&dmy);
                    277:   loadobj(s,&nm);
                    278:   loadobj(s,&dn);
                    279:   MKDAlg((DP)nm,(Z)dn,*p);
                    280: }
                    281:
                    282: void loadp(FILE *s,P *p)
                    283: {
                    284:   V v;
                    285:   int n,vindex;
                    286:   DCP dc,dc0;
                    287:   P t;
                    288:
                    289:   read_int(s,&vindex);
                    290:   if ( vindex < 0 )
                    291:   /* v is a pure function */
                    292:     v = loadpfins(s);
                    293:   else
                    294:     v = (V)load_convv(vindex);
                    295:   read_int(s,&n);
                    296:   for ( dc0 = 0; n; n-- ) {
                    297:     NEXTDC(dc0,dc); loadobj(s,(Obj *)&DEG(dc)); loadobj(s,(Obj *)&COEF(dc));
                    298:   }
                    299:   NEXT(dc) = 0;
                    300:   MKP(v,dc0,t);
                    301:   if ( vindex < 0 || file_vl )
                    302:     reorderp(CO,file_vl,t,p);
                    303:   else
                    304:     *p = t;
                    305: }
                    306:
                    307: /* |name(str)|argc(int)|darray(intarray)|args| */
                    308:
                    309: V loadpfins(FILE *s)
                    310: {
                    311:   char *name;
                    312:   FUNC fp;
                    313:   int argc,i;
                    314:   V v;
                    315:   int *darray;
                    316:   Obj *args;
                    317:   PF pf;
                    318:   char *buf;
                    319:   V *a;
                    320:   P u;
                    321:
                    322:   loadstr(s,&name);
                    323:   read_int(s,&argc);
                    324:   searchpf(name,&fp);
                    325:   if ( fp ) {
                    326:     pf = fp->f.puref;
                    327:     if ( pf->argc != argc )
                    328:       error("loadpfins : argument mismatch");
                    329:   } else {
                    330:     a = (V *)MALLOC(argc*sizeof(V));
                    331:     buf = (char *)ALLOCA(BUFSIZ);
                    332:     for ( i = 0; i < argc; i++ ) {
                    333:       sprintf(buf,"_%c",'a'+i);
                    334:       makevar(buf,&u); a[i] = VR(u);
                    335:     }
                    336:     mkpf(name,0,argc,a,0,0,0,&pf);
                    337:   }
                    338:   darray = (int *)ALLOCA(argc*sizeof(int));
                    339:   args = (Obj *)ALLOCA(argc*sizeof(int));
                    340:   read_intarray(s,darray,argc);
                    341:   for ( i = 0; i < argc; i++ )
                    342:     loadobj(s,&args[i]);
                    343:   _mkpfins_with_darray(pf,args,darray,&v);
                    344:   return v;
                    345: }
                    346:
                    347: void loadr(FILE *s,R *p)
                    348: {
                    349:   R r;
                    350:
                    351:   NEWR(r); read_short(s,&r->reduced);
                    352:   loadobj(s,(Obj *)&NM(r)); loadobj(s,(Obj *)&DN(r)); *p = r;
                    353: }
                    354:
                    355: void loadlist(FILE *s,LIST *p)
                    356: {
                    357:   int n;
                    358:   NODE tn,tn0;
                    359:
                    360:   read_int(s,&n);
                    361:   for ( tn0 = 0; n; n-- ) {
                    362:     NEXTNODE(tn0,tn); loadobj(s,(Obj *)&BDY(tn));
                    363:   }
                    364:   if ( tn0 )
                    365:     NEXT(tn) = 0;
                    366:   MKLIST(*p,tn0);
                    367: }
                    368:
                    369: void loadvect(FILE *s,VECT *p)
                    370: {
                    371:   int i,len;
                    372:   VECT vect;
                    373:
                    374:   read_int(s,&len); MKVECT(vect,len);
                    375:   for ( i = 0; i < len; i++ )
                    376:     loadobj(s,(Obj *)&BDY(vect)[i]);
                    377:   *p = vect;
                    378: }
                    379:
                    380: void loadmat(FILE *s,MAT *p)
                    381: {
                    382:   int row,col,i,j;
                    383:   MAT mat;
                    384:
                    385:   read_int(s,&row); read_int(s,&col); MKMAT(mat,row,col);
                    386:   for ( i = 0; i < row; i++ )
                    387:     for ( j = 0; j < col; j++ )
                    388:       loadobj(s,(Obj *)&BDY(mat)[i][j]);
                    389:   *p = mat;
                    390: }
                    391:
                    392: void loadstring(FILE *s,STRING *p)
                    393: {
                    394:   char *t;
                    395:
                    396:   loadstr(s,&t); MKSTR(*p,t);
                    397: }
                    398:
                    399: void loadstr(FILE *s,char **p)
                    400: {
                    401:   int len;
                    402:   char *t;
                    403:
                    404:   read_int(s,&len);
                    405:   if ( len ) {
                    406:     t = (char *)MALLOC(len+1); read_string(s,t,len); t[len] = 0;
                    407:   } else
                    408:     t = "";
                    409:   *p = t;
                    410: }
                    411:
                    412: void loadbytearray(FILE *s,BYTEARRAY *p)
                    413: {
                    414:   int len;
                    415:   BYTEARRAY array;
                    416:
                    417:   read_int(s,&len);
                    418:   MKBYTEARRAY(array,len);
                    419:   if ( len ) {
                    420:     read_string(s,array->body,len);
                    421:   }
                    422:   *p = array;
                    423: }
                    424:
                    425: void loaddp(FILE *s,DP *p)
                    426: {
                    427:   int nv,n,i,sugar;
                    428:   DP dp;
                    429:   MP m,m0;
                    430:   DL dl;
                    431:
                    432:   read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
                    433:   for ( i = 0, m0 = 0; i < n; i++ ) {
                    434:     NEXTMP(m0,m);
                    435:     loadobj(s,(Obj *)&(m->c));
                    436:     NEWDL(dl,nv); m->dl = dl;
                    437:     read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
                    438:   }
                    439:   NEXT(m) = 0; MKDP(nv,m0,dp); dp->sugar = sugar; *p = dp;
                    440: }
                    441:
                    442: void loadui(FILE *s,USINT *u)
                    443: {
                    444:   unsigned int b;
                    445:
                    446:   read_int(s,&b); MKUSINT(*u,b);
                    447: }
                    448:
                    449: void loaderror(FILE *s,ERR *e)
                    450: {
                    451:   Obj b;
                    452:
                    453:   loadobj(s,&b); MKERR(*e,b);
                    454: }
                    455:
                    456:
                    457: void loadgfmmat(FILE *s,GFMMAT *p)
                    458: {
                    459:   int i,row,col;
                    460:   unsigned int **a;
                    461:   GFMMAT mat;
                    462:
                    463:   read_int(s,&row); read_int(s,&col);
                    464:   a = (unsigned int **)almat(row,col);
                    465:   TOGFMMAT(row,col,a,mat);
                    466:   for ( i = 0; i < row; i++ )
                    467:     read_intarray(s,a[i],col);
                    468:   *p = mat;
                    469: }
                    470:
                    471: void loadnbp(FILE *s,NBP *p)
                    472: {
                    473:   int n,i;
                    474:   NBM m;
                    475:   NODE r0,r;
                    476:
                    477:   read_int(s,&n);
                    478:   for ( i = 0, r0 = 0; i < n; i++ ) {
                    479:     NEWNBM(m);
                    480:     loadobj(s,(Obj *)&m->c);
                    481:     read_int(s,&m->d);
                    482:     NEWNBMBDY(m,m->d); read_intarray(s,m->b,(m->d+31)/32);
                    483:     NEXTNODE(r0,r); BDY(r) = (pointer)m;
                    484:   }
                    485:   if ( r0 ) NEXT(r) = 0;
                    486:   MKNBP(*p,r0);
                    487: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>