1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
121 |
|
setambient(afile) /* initialize calculation */ |
122 |
|
char *afile; |
123 |
|
{ |
124 |
< |
long headlen; |
124 |
> |
long pos, flen; |
125 |
|
AMBVAL amb; |
126 |
|
/* init ambient limits */ |
127 |
|
setambres(ambres); |
137 |
|
/* open ambient file */ |
138 |
|
if ((ambfp = fopen(afile, "r+")) != NULL) { |
139 |
|
initambfile(0); |
140 |
< |
headlen = ftell(ambfp); |
140 |
> |
pos = ftell(ambfp); |
141 |
|
while (readambval(&amb, ambfp)) |
142 |
|
avinsert(avstore(&amb)); |
143 |
|
/* align */ |
144 |
< |
fseek(ambfp, -((ftell(ambfp)-headlen)%AMBVALSIZ), 1); |
144 |
> |
pos += (long)nambvals*AMBVALSIZ; |
145 |
> |
flen = lseek(fileno(ambfp), 0L, 2); |
146 |
> |
if (flen != pos) { |
147 |
> |
error(WARNING, |
148 |
> |
"ignoring last %ld values in ambient file (corrupted)", |
149 |
> |
(flen - pos)/AMBVALSIZ); |
150 |
> |
fseek(ambfp, pos, 0); |
151 |
> |
ftruncate(fileno(ambfp), pos); |
152 |
> |
} |
153 |
|
nambshare = nambvals; |
154 |
|
} else if ((ambfp = fopen(afile, "w+")) != NULL) |
155 |
|
initambfile(1); |
572 |
|
alatcmp(avp1, avp2) /* compare ambient values for MRA */ |
573 |
|
AMBVAL **avp1, **avp2; |
574 |
|
{ |
575 |
< |
return((**avp2).latick - (**avp1).latick); |
575 |
> |
register long lc = (**avp2).latick - (**avp1).latick; |
576 |
> |
return(lc<0 ? -1 : lc>0 ? 1 : 0); |
577 |
|
} |
578 |
|
|
579 |
|
|
585 |
|
} |
586 |
|
|
587 |
|
|
588 |
< |
#ifdef DEBUG |
588 |
> |
#if 1 |
589 |
|
static int |
590 |
|
avlmemi(avaddr) /* find list position from address */ |
591 |
|
AMBVAL *avaddr; |
740 |
|
if (fseek(ambinp, lastpos, 0) < 0) |
741 |
|
goto seekerr; |
742 |
|
while (n >= AMBVALSIZ) { /* load contributed values */ |
743 |
< |
readambval(&avs, ambinp); |
743 |
> |
if (!readambval(&avs, ambinp)) { |
744 |
> |
sprintf(errmsg, |
745 |
> |
"ambient file corrupted near character %ld", |
746 |
> |
flen - n); |
747 |
> |
error(WARNING, errmsg); |
748 |
> |
break; |
749 |
> |
} |
750 |
|
avinsert(avstore(&avs)); |
751 |
|
n -= AMBVALSIZ; |
752 |
|
} |