version 1.7, 2000/12/24 06:32:31 |
version 1.17, 2015/08/04 06:20:45 |
|
|
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. |
* $OpenXM: OpenXM_contrib2/asir2000/io/bsave.c,v 1.6 2000/12/22 10:03:30 saito Exp $ |
* $OpenXM: OpenXM_contrib2/asir2000/io/bsave.c,v 1.16 2009/03/16 16:43:03 ohara Exp $ |
*/ |
*/ |
/* saveXXX must not use GC_malloc(), GC_malloc_atomic(). */ |
/* saveXXX must not use GC_malloc(), GC_malloc_atomic(). */ |
|
|
|
|
#include "parse.h" |
#include "parse.h" |
#include "com.h" |
#include "com.h" |
|
|
#if PARI |
void savenbp(FILE *s,NBP p); |
#include "genpari.h" |
|
int get_lg(GEN); |
|
#endif |
|
|
|
void saveerror(FILE *,ERR); |
|
void saveui(FILE *,USINT); |
|
void savedp(FILE *,DP); |
|
void savestr(FILE *,char *); |
|
void savestring(FILE *,STRING); |
|
void savemat(FILE *,MAT); |
|
void savevect(FILE *,VECT); |
|
void savelist(FILE *,LIST); |
|
void saver(FILE *,R); |
|
void savep(FILE *,P); |
|
void savegf2n(FILE *,GF2N); |
|
void savegfpn(FILE *,GFPN); |
|
void savelm(FILE *,LM); |
|
void savemi(FILE *,MQ); |
|
void savecplx(FILE *,C); |
|
void savebf(FILE *,BF); |
|
void savereal(FILE *,Real); |
|
void saveq(FILE *,Q); |
|
void savenum(FILE *,Num); |
|
void savepfins(FILE *,V); |
|
void savegfmmat(FILE *,GFMMAT); |
|
void savebytearray(FILE *,BYTEARRAY); |
|
|
|
void (*savef[])() = { 0, savenum, savep, saver, savelist, savevect, |
void (*savef[])() = { 0, savenum, savep, saver, savelist, savevect, |
savemat, savestring, 0, savedp, saveui, saveerror,0,0,0,savegfmmat, savebytearray }; |
savemat, savestring, 0, savedp, saveui, saveerror,0,0,0,savegfmmat, |
|
savebytearray, 0, 0, 0, 0, 0, 0, 0, 0, savenbp }; |
#if defined(INTERVAL) |
#if defined(INTERVAL) |
void saveitv(); |
void saveitv(); |
void saveitvd(); |
void saveitvd(); |
void (*nsavef[])() = { saveq, savereal, 0, savebf, saveitv, saveitvd, 0, saveitv, savecplx ,savemi, savelm, savegf2n, savegfpn}; |
void (*nsavef[])() = { saveq, savereal, 0, savebf, saveitv, saveitvd, 0, saveitv, savecplx ,savemi, savelm, savegf2n, savegfpn, savegfs, savegfsn,savedalg}; |
#else |
#else |
void (*nsavef[])() = { saveq, savereal, 0, savebf, savecplx ,savemi, savelm, savegf2n, savegfpn}; |
void (*nsavef[])() = { saveq, savereal, 0, savebf, savecplx ,savemi, savelm, savegf2n, savegfpn, savegfs, savegfsn,savedalg}; |
#endif |
#endif |
|
|
static short zeroval = 0; |
static short zeroval = 0; |
|
|
void saveobj(s,p) |
void saveobj(FILE *s,Obj p) |
FILE *s; |
|
Obj p; |
|
{ |
{ |
if ( !p ) |
if ( !p ) |
write_short(s,&zeroval); |
write_short(s,&zeroval); |
|
|
(*savef[OID(p)])(s,p); |
(*savef[OID(p)])(s,p); |
} |
} |
|
|
void savenum(s,p) |
void savenum(FILE *s,Num p) |
FILE *s; |
|
Num p; |
|
{ |
{ |
if ( !nsavef[NID(p)] ) |
if ( !nsavef[NID(p)] ) |
error("savenum : not implemented"); |
error("savenum : not implemented"); |
|
|
} |
} |
} |
} |
|
|
void saveq(s,p) |
void saveq(FILE *s,Q p) |
FILE *s; |
|
Q p; |
|
{ |
{ |
int size[2]; |
int size[2]; |
int len = 2; |
int len = 2; |
|
|
write_intarray(s,BD(DN(p)),size[1]); |
write_intarray(s,BD(DN(p)),size[1]); |
} |
} |
|
|
void savereal(s,p) |
void savereal(FILE *s,Real p) |
FILE *s; |
|
Real p; |
|
{ write_double(s,&BDY(p)); } |
{ write_double(s,&BDY(p)); } |
|
|
/* |
/* |
|
|
* -> | id(2) | nid(1) | sgn(1) | expo>>32 | expo&0xffffffff | len | ... | |
* -> | id(2) | nid(1) | sgn(1) | expo>>32 | expo&0xffffffff | len | ... | |
*/ |
*/ |
|
|
void savebf(s,p) |
void savebf(FILE *s,BF p) |
FILE *s; |
|
BF p; |
|
{ |
{ |
#if PARI |
unsigned int zero = 0; |
GEN z; |
unsigned int prec; |
int sign; |
L exp; |
unsigned long expo; |
int sgn,len,t; |
unsigned int len,t; |
|
|
|
z = (GEN)BDY(p); |
prec = MPFR_PREC(p->body); |
sign = signe(z); |
exp = MPFR_EXP(p->body); |
len = lg(z)-2; |
sgn = MPFR_SIGN(p->body); |
expo = expo(z); |
len = MPFR_LIMB_SIZE(p->body); |
|
|
write_int(s,&sign); |
write_int(s,&sgn); |
|
write_int(s,(int *)&prec); |
#if defined(LONG_IS_32BIT) |
write_int64(s,(UL *)&exp); |
write_int(s,(int *)&zeroval); /* expo>>32 is always 0 */ |
#if SIZEOF_LONG == 4 |
write_int(s,(int *)&expo); |
|
write_int(s,&len); |
write_int(s,&len); |
write_intarray(s,(int *)&z[2],len); |
write_intarray(s,p->body->_mpfr_d,len); |
#elif defined(LONG_IS_64BIT) |
#else /* SIZEOF_LONG == 8 */ |
t = expo>>32; write_int(s,(int *)&t); |
t = 2*len; |
t = expo&0xffffffff; write_int(s,&t); |
write_int(s,&t); |
t = 2*len; write_int(s,&t); |
write_longarray(s,p->body->_mpfr_d,len); |
write_longarray(s,&z[2],len); |
|
#endif |
#endif |
#else |
|
error("savebf : PARI is not combined"); |
|
#endif |
|
} |
} |
|
|
#if defined(INTERVAL) |
#if defined(INTERVAL) |
void saveitv(s,p) |
void saveitv(FILE *s,Itv p) |
FILE *s; |
|
Itv p; |
|
{ |
{ |
saveobj(s,(Obj)INF(p)); |
saveobj(s,(Obj)INF(p)); |
saveobj(s,(Obj)SUP(p)); |
saveobj(s,(Obj)SUP(p)); |
} |
} |
|
|
void saveitvd(s,p) |
void saveitvd(FILE *s,IntervalDouble p) |
FILE *s; |
|
ItvD p; |
|
{ |
{ |
write_double(s,&INF(p)); |
write_double(s,&INF(p)); |
write_double(s,&SUP(p)); |
write_double(s,&SUP(p)); |
} |
} |
#endif |
#endif |
|
|
void savecplx(s,p) |
void savecplx(FILE *s,C p) |
FILE *s; |
|
C p; |
|
{ saveobj(s,(Obj)p->r); saveobj(s,(Obj)p->i); } |
{ saveobj(s,(Obj)p->r); saveobj(s,(Obj)p->i); } |
|
|
void savemi(s,p) |
void savemi(FILE *s,MQ p) |
FILE *s; |
|
MQ p; |
|
{ write_int(s,&CONT(p)); } |
{ write_int(s,&CONT(p)); } |
|
|
void savelm(s,p) |
void savelm(FILE *s,LM p) |
FILE *s; |
|
LM p; |
|
{ |
{ |
int size; |
int size; |
|
|
|
|
write_intarray(s,BD(BDY(p)),size); |
write_intarray(s,BD(BDY(p)),size); |
} |
} |
|
|
void savegf2n(s,p) |
void savegf2n(FILE *s,GF2N p) |
FILE *s; |
|
GF2N p; |
|
{ |
{ |
int len; |
int len; |
|
|
|
|
write_intarray(s,p->body->b,len); |
write_intarray(s,p->body->b,len); |
} |
} |
|
|
void savegfpn(s,p) |
void savegfpn(FILE *s,GFPN p) |
FILE *s; |
|
GFPN p; |
|
{ |
{ |
int d,i; |
int d,i; |
|
|
|
|
saveobj(s,(Obj)p->body->c[i]); |
saveobj(s,(Obj)p->body->c[i]); |
} |
} |
|
|
void savep(s,p) |
void savegfs(FILE *s,GFS p) |
FILE *s; |
{ write_int(s,&CONT(p)); } |
P p; |
|
|
void savegfsn(FILE *s,GFSN p) |
{ |
{ |
|
int d; |
|
|
|
d = DEG(BDY(p)); |
|
write_int(s,&d); |
|
write_intarray(s,COEF(BDY(p)),d+1); |
|
} |
|
|
|
void savedalg(FILE *s,DAlg p) |
|
{ |
|
saveobj(s,(Obj)p->nm); |
|
saveobj(s,(Obj)p->dn); |
|
} |
|
|
|
void savep(FILE *s,P p) |
|
{ |
DCP dc; |
DCP dc; |
int n; |
int n; |
int vindex; |
int vindex; |
|
|
/* save a pure function (v->attr = V_PF) */ |
/* save a pure function (v->attr = V_PF) */ |
/* |name(str)|argc(int)|darray(intarray)|args| */ |
/* |name(str)|argc(int)|darray(intarray)|args| */ |
|
|
void savepfins(s,v) |
void savepfins(FILE *s,V v) |
FILE *s; |
|
V v; |
|
{ |
{ |
PFINS ins; |
PFINS ins; |
PF pf; |
PF pf; |
|
|
saveobj(s,ins->ad[i].arg); |
saveobj(s,ins->ad[i].arg); |
} |
} |
|
|
void saver(s,p) |
void saver(FILE *s,R p) |
FILE *s; |
|
R p; |
|
{ |
{ |
if ( !RAT(p) ) |
if ( !RAT(p) ) |
savep(s,(P)p); |
savep(s,(P)p); |
|
|
} |
} |
} |
} |
|
|
void savelist(s,p) |
void savelist(FILE *s,LIST p) |
FILE *s; |
|
LIST p; |
|
{ |
{ |
int n; |
int n; |
NODE tn; |
NODE tn; |
|
|
saveobj(s,(Obj)BDY(tn)); |
saveobj(s,(Obj)BDY(tn)); |
} |
} |
|
|
void savevect(s,p) |
void savevect(FILE *s,VECT p) |
FILE *s; |
|
VECT p; |
|
{ |
{ |
int i,len = 2; |
int i,len = 2; |
|
|
|
|
saveobj(s,(Obj)BDY(p)[i]); |
saveobj(s,(Obj)BDY(p)[i]); |
} |
} |
|
|
void savemat(s,p) |
void savemat(FILE *s,MAT p) |
FILE *s; |
|
MAT p; |
|
{ |
{ |
int i,j,row,col; |
int i,j,row,col; |
int len = 3; |
int len = 3; |
|
|
saveobj(s,(Obj)BDY(p)[i][j]); |
saveobj(s,(Obj)BDY(p)[i][j]); |
} |
} |
|
|
void savestring(s,p) |
void savestring(FILE *s,STRING p) |
FILE *s; |
|
STRING p; |
|
{ |
{ |
write_short(s,&OID(p)); savestr(s,BDY(p)); |
write_short(s,&OID(p)); savestr(s,BDY(p)); |
} |
} |
|
|
void savestr(s,p) |
void savestr(FILE *s,char *p) |
FILE *s; |
|
char *p; |
|
{ |
{ |
int size; |
int size; |
|
|
|
|
write_string(s,p,size); |
write_string(s,p,size); |
} |
} |
|
|
void savedp(s,p) |
void savedp(FILE *s,DP p) |
FILE *s; |
|
DP p; |
|
{ |
{ |
int nv,n,i,sugar; |
int nv,n,i,sugar; |
MP m,t; |
MP m,t; |
|
|
} |
} |
} |
} |
|
|
void saveui(s,u) |
void saveui(FILE *s,USINT u) |
FILE *s; |
|
USINT u; |
|
{ |
{ |
write_short(s,&OID(u)); write_int(s,&BDY(u)); |
write_short(s,&OID(u)); write_int(s,&BDY(u)); |
} |
} |
|
|
void saveerror(s,e) |
void saveerror(FILE *s,ERR e) |
FILE *s; |
|
ERR e; |
|
{ |
{ |
write_short(s,&OID(e)); saveobj(s,(Obj)BDY(e)); |
write_short(s,&OID(e)); saveobj(s,(Obj)BDY(e)); |
} |
} |
|
|
void savegfmmat(s,p) |
void savegfmmat(FILE *s,GFMMAT p) |
FILE *s; |
|
GFMMAT p; |
|
{ |
{ |
int i,j,row,col; |
int i,row,col; |
|
|
write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col); |
write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col); |
for ( i = 0, row = p->row, col = p->col; i < row; i++ ) |
for ( i = 0, row = p->row, col = p->col; i < row; i++ ) |
write_intarray(s,p->body[i],col); |
write_intarray(s,p->body[i],col); |
} |
} |
|
|
void savebytearray(s,p) |
void savebytearray(FILE *s,BYTEARRAY p) |
FILE *s; |
|
BYTEARRAY p; |
|
{ |
{ |
write_short(s,&OID(p)); write_int(s,&p->len); |
write_short(s,&OID(p)); write_int(s,&p->len); |
write_string(s,p->body,p->len); |
write_string(s,p->body,p->len); |
|
} |
|
|
|
void savenbp(FILE *s,NBP p) |
|
{ |
|
int i,n; |
|
NODE t; |
|
NBM m; |
|
|
|
write_short(s,&OID(p)); |
|
for ( n = 0, t = BDY(p); t; t = NEXT(t), n++ ); |
|
write_int(s,&n); |
|
for ( i = 0, t = BDY(p); i < n; t = NEXT(t), i++ ) { |
|
m = (NBM)BDY(t); |
|
saveobj(s,(Obj)m->c); |
|
write_int(s,&m->d); |
|
write_intarray(s,m->b,(m->d+31)/32); |
|
} |
} |
} |