Astro-PAL
view release on metacpan or search on metacpan
palsrc/palDfltin.c view on Meta::CPAN
* Purpose:
* Convert free-format input into double precision floating point
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* void palDfltin( const char * string, int *nstrt,
* double *dreslt, int *jflag );
* Arguments:
* string = const char * (Given)
* String containing number to be decoded.
* nstrt = int * (Given and Returned)
* Character number indicating where decoding should start.
* On output its value is updated to be the location of the
* possible next value. For compatibility with SLA the first
* character is index 1.
* dreslt = double * (Returned)
* Result. Not updated when jflag=1.
* jflag = int * (Returned)
* status: -1 = -OK, 0 = +OK, 1 = null, 2 = error
* Description:
* Extracts a number from an input string starting at the specified
* index.
* Authors:
* TIMJ: Tim Jenness (JAC, Hawaii)
* {enter_new_authors_here}
* Notes:
* - Uses the strtod() system call to do the parsing. This may lead to
* subtle differences when compared to the SLA/F parsing.
* - All "D" characters are converted to "E" to handle fortran exponents.
* - Commas are recognized as a special case and are skipped if one happens
* to be the next character when updating nstrt. Additionally the output
* nstrt position will skip past any trailing space.
* - If no number can be found flag will be set to 1.
* - If the number overflows or underflows jflag will be set to 2. For overflow
* the returned result will have the value HUGE_VAL, for underflow it
* will have the value 0.0.
* - For compatiblity with SLA/F -0 will be returned as "0" with jflag == -1.
* - Unlike slaDfltin a standalone "E" will return status 1 (could not find
* a number) rather than 2 (bad number).
* Implementation Status:
* - The code is more robust if the C99 copysign() function is available.
* This can recognize the -0.0 values returned by strtod. If copysign() is
* missing we try to scan the string looking for minus signs.
* History:
* 2012-03-08 (TIMJ):
* Initial version based on strtod
* Adapted with permission from the Fortran SLALIB library
* although this is a completely distinct implementation of the SLA API.
* 2012-06-21 (TIMJ):
* Provide a backup for missing copysign.
* 2012-06-22 (TIMJ):
* Check __STDC_VERSION__
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2012 Science and Technology Facilities Council.
* All Rights Reserved.
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* Bugs:
* {note_any_bugs_here}
*-
*/
/* Use the config file if we have one, else look at
compiler defines to see if we have C99 */
#if HAVE_CONFIG_H
#include <config.h>
#else
#ifdef __STDC_VERSION__
# if (__STDC_VERSION__ >= 199901L)
# define HAVE_COPYSIGN 1
# endif
#endif
#endif
/* isblank() is a C99 feature so we just reimplement it if it is missing */
#if HAVE_ISBLANK
#define _POSIX_C_SOURCE 200112L
#define _ISOC99_SOURCE
#include <ctype.h>
# define ISBLANK isblank
#else
static int ISBLANK( int c ) {
return ( c == ' ' || c == '\t' );
}
#endif
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
/* System include files */
( run in 2.217 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )