[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.4

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.4     ! kondoh     47:  * $OpenXM: OpenXM_contrib2/asir2018/io/bload.c,v 1.3 2019/08/28 23:27:34 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,
1.3       noro       60:   loadbytearray, 0, 0, 0, 0, 0, 0, 0, 0,  loadnbp, loaddpm };
1.1       noro       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:     }
1.4     ! kondoh    336: #if defined(INTERVAL)
        !           337:     mkpf(name,0,argc,a,0,0,0,0,&pf);
        !           338: #else
1.1       noro      339:     mkpf(name,0,argc,a,0,0,0,&pf);
1.4     ! kondoh    340: #endif
1.1       noro      341:   }
                    342:   darray = (int *)ALLOCA(argc*sizeof(int));
                    343:   args = (Obj *)ALLOCA(argc*sizeof(int));
                    344:   read_intarray(s,darray,argc);
                    345:   for ( i = 0; i < argc; i++ )
                    346:     loadobj(s,&args[i]);
                    347:   _mkpfins_with_darray(pf,args,darray,&v);
                    348:   return v;
                    349: }
                    350:
                    351: void loadr(FILE *s,R *p)
                    352: {
                    353:   R r;
                    354:
                    355:   NEWR(r); read_short(s,&r->reduced);
                    356:   loadobj(s,(Obj *)&NM(r)); loadobj(s,(Obj *)&DN(r)); *p = r;
                    357: }
                    358:
                    359: void loadlist(FILE *s,LIST *p)
                    360: {
                    361:   int n;
                    362:   NODE tn,tn0;
                    363:
                    364:   read_int(s,&n);
                    365:   for ( tn0 = 0; n; n-- ) {
                    366:     NEXTNODE(tn0,tn); loadobj(s,(Obj *)&BDY(tn));
                    367:   }
                    368:   if ( tn0 )
                    369:     NEXT(tn) = 0;
                    370:   MKLIST(*p,tn0);
                    371: }
                    372:
                    373: void loadvect(FILE *s,VECT *p)
                    374: {
                    375:   int i,len;
                    376:   VECT vect;
                    377:
                    378:   read_int(s,&len); MKVECT(vect,len);
                    379:   for ( i = 0; i < len; i++ )
                    380:     loadobj(s,(Obj *)&BDY(vect)[i]);
                    381:   *p = vect;
                    382: }
                    383:
                    384: void loadmat(FILE *s,MAT *p)
                    385: {
                    386:   int row,col,i,j;
                    387:   MAT mat;
                    388:
                    389:   read_int(s,&row); read_int(s,&col); MKMAT(mat,row,col);
                    390:   for ( i = 0; i < row; i++ )
                    391:     for ( j = 0; j < col; j++ )
                    392:       loadobj(s,(Obj *)&BDY(mat)[i][j]);
                    393:   *p = mat;
                    394: }
                    395:
                    396: void loadstring(FILE *s,STRING *p)
                    397: {
                    398:   char *t;
                    399:
                    400:   loadstr(s,&t); MKSTR(*p,t);
                    401: }
                    402:
                    403: void loadstr(FILE *s,char **p)
                    404: {
                    405:   int len;
                    406:   char *t;
                    407:
                    408:   read_int(s,&len);
                    409:   if ( len ) {
                    410:     t = (char *)MALLOC(len+1); read_string(s,t,len); t[len] = 0;
                    411:   } else
                    412:     t = "";
                    413:   *p = t;
                    414: }
                    415:
                    416: void loadbytearray(FILE *s,BYTEARRAY *p)
                    417: {
                    418:   int len;
                    419:   BYTEARRAY array;
                    420:
                    421:   read_int(s,&len);
                    422:   MKBYTEARRAY(array,len);
                    423:   if ( len ) {
                    424:     read_string(s,array->body,len);
                    425:   }
                    426:   *p = array;
                    427: }
                    428:
                    429: void loaddp(FILE *s,DP *p)
                    430: {
                    431:   int nv,n,i,sugar;
                    432:   DP dp;
                    433:   MP m,m0;
                    434:   DL dl;
                    435:
                    436:   read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
                    437:   for ( i = 0, m0 = 0; i < n; i++ ) {
                    438:     NEXTMP(m0,m);
                    439:     loadobj(s,(Obj *)&(m->c));
                    440:     NEWDL(dl,nv); m->dl = dl;
                    441:     read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
                    442:   }
                    443:   NEXT(m) = 0; MKDP(nv,m0,dp); dp->sugar = sugar; *p = dp;
                    444: }
                    445:
1.3       noro      446: void loaddpm(FILE *s,DPM *p)
                    447: {
                    448:   int nv,n,i,sugar;
                    449:   DPM dp;
                    450:   DMM m,m0;
                    451:   DL dl;
                    452:
                    453:   read_int(s,&nv); read_int(s,&sugar); read_int(s,&n);
                    454:   for ( i = 0, m0 = 0; i < n; i++ ) {
                    455:     NEXTDMM(m0,m);
                    456:     loadobj(s,(Obj *)&(m->c));
                    457:     read_int(s,&m->pos);
                    458:     NEWDL(dl,nv); m->dl = dl;
                    459:     read_int(s,&dl->td); read_intarray(s,&(dl->d[0]),nv);
                    460:   }
                    461:   NEXT(m) = 0; MKDPM(nv,m0,dp); dp->sugar = sugar; *p = dp;
                    462: }
                    463:
1.1       noro      464: void loadui(FILE *s,USINT *u)
                    465: {
                    466:   unsigned int b;
                    467:
                    468:   read_int(s,&b); MKUSINT(*u,b);
                    469: }
                    470:
                    471: void loaderror(FILE *s,ERR *e)
                    472: {
                    473:   Obj b;
                    474:
                    475:   loadobj(s,&b); MKERR(*e,b);
                    476: }
                    477:
                    478:
                    479: void loadgfmmat(FILE *s,GFMMAT *p)
                    480: {
                    481:   int i,row,col;
                    482:   unsigned int **a;
                    483:   GFMMAT mat;
                    484:
                    485:   read_int(s,&row); read_int(s,&col);
                    486:   a = (unsigned int **)almat(row,col);
                    487:   TOGFMMAT(row,col,a,mat);
                    488:   for ( i = 0; i < row; i++ )
                    489:     read_intarray(s,a[i],col);
                    490:   *p = mat;
                    491: }
                    492:
                    493: void loadnbp(FILE *s,NBP *p)
                    494: {
                    495:   int n,i;
                    496:   NBM m;
                    497:   NODE r0,r;
                    498:
                    499:   read_int(s,&n);
                    500:   for ( i = 0, r0 = 0; i < n; i++ ) {
                    501:     NEWNBM(m);
                    502:     loadobj(s,(Obj *)&m->c);
                    503:     read_int(s,&m->d);
                    504:     NEWNBMBDY(m,m->d); read_intarray(s,m->b,(m->d+31)/32);
                    505:     NEXTNODE(r0,r); BDY(r) = (pointer)m;
                    506:   }
                    507:   if ( r0 ) NEXT(r) = 0;
                    508:   MKNBP(*p,r0);
                    509: }

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