I've committed to CVS a modified version of chr_ctoi.f that returns
non-zero status if the supplied number will not fit into a INTEGER*4. It
now looks like this (sorry TimJ, still in fortran):
* Local Variables:
INTEGER IOSTAT ! I/O status from READ/WRITE
INTEGER*8 LVALUE ! Long value
...
* Read the value into a long int first to reduce chances of overflow.
FORMAT = '(BN, I'//COUNT//')'
READ( STRING( 1 : NCHAR ), FORMAT , IOSTAT=IOSTAT ) LVALUE
* Check the read operation was succesfull.
IF ( IOSTAT .NE. 0 ) THEN
STATUS = SAI__ERROR
* If it was, convert the long int to a short int and check for overflow
* by comparing their values.
ELSE
IVALUE = LVALUE
IF( IVALUE .NE. LVALUE ) STATUS = SAI__ERROR
END IF
Speed-wise, converting 5,000,000 random integers seems to take no longer
with the new version than with the old.
This seems to fix the problem in KAPPA:FITSMOD reported by TimL.
David
|