コード例 #1
0
ファイル: vardata.c プロジェクト: Angel-Fernandez/minc-tools
/*
 * Print a number of double variable values, where the optional comments
 * for each value identify the variable, and each dimension index.
 */
static void
pr_dvals(
     const struct ncvar *vp,		/* variable */
     long len,			/* number of values to print */
     const char *fmt,		/* printf format used for each value.  If
				 * nc_type is NC_CHAR and this is NULL,
				 * character arrays will be printed as
				 * strings enclosed in quotes.  */
     boolean more,		/* true if more data for this row will
				 * follow, so add trailing comma */
     boolean lastrow,		/* true if this is the last row for this
				 * variable, so terminate with ";" instead
				 * of "," */
     const double *vals,	/* pointer to block of values */
     const struct fspec* fsp,	/* formatting specs */
     const long *cor		/* corner coordinates */
     )
{
    long iel;
    char sout[100];		/* temporary string for each encoded output */

    for (iel = 0; iel < len-1; iel++) {
	printdval(sout, fmt, vp, *vals++);
	if (fsp->full_data_cmnts) {
	    Printf("%s", sout);
	    Printf(",");
	    annotate (vp, fsp, cor, iel);
	} else {
	    (void) strcat(sout, ", ");
	    lput(sout);
	}
    }
    printdval(sout, fmt, vp, *vals++);
    if (fsp->full_data_cmnts) {
	Printf("%s", sout);
	lastdelim (more, lastrow);
	annotate (vp, fsp, cor, iel);
    } else {
	lput(sout);
	lastdelim2 (more, lastrow);
    }
}
コード例 #2
0
ファイル: astbad.c プロジェクト: Starlink/ast
/* ============== */
int main( int argc, char *argv[] ) {
/*
*+
*  Name:
*     astbad

*  Purpose:
*     Generate a string representing an AST floating point constant.

*  Invocation:
*     astbad <value>

*  Type:
*     C program.

*  Description:
*     This program writes a string to standard output containing
*     a formatted decimal representation of a specified C floating point
*     constant defined by AST. This is intended for use in defining these
*     constants for use from languages other than C.
*
*     The value written should contain sufficient decimal digits so
*     that a routine that uses it to generate a value in another
*     language will produce exactly the same value as a C program
*     using the same macro.

*  Arguments:
*     value = LITERAL
*        The name of the constant to be printed: AST__BAD, AST__NAN or
*        AST__NANF. If not supplied, AST__BAD is printed.

*  Copyright:
*     Copyright (C) 2009-2011 Science & Technology Facilities Council.
*     Copyright (C) 1997-2006 Council for the Central Laboratory of the
*     Research Councils

*  Licence:
*     This program is free software: you can redistribute it and/or
*     modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*     
*     You should have received a copy of the GNU Lesser General
*     License along with this program.  If not, see
*     <http://www.gnu.org/licenses/>.

*  Authors:
*     RFWS: R.F. Warren-Smith (Starlink)
*     DSB: David S. Berry (Starlink)
*     TIMJ: Tim Jenness (JAC, Hawaii)

*  History:
*     18-NOV-1997 (RFWS);
*        Original version.
*     24-OCT-2000 (DSB):
*        Ensure that the number of digits used is at least the minimum
*        required by IEEE for a conversion from binary to string and back
*        to binary to be an identity.
*     31-MAR-2009 (TIMJ):
*        Does not take any arguments so don't try to read arguments.
*     18-JAN-2011 (DSB):
*        Extend to print other floating point constants as well as
*        AST__BAD.
*-
*/

/* Local Variables; */
   const char *name;        /* Pointer to name of constant to be printed */

/* Get the name of the constant to be printed. */
   if( argc > 1 ) {
      name = argv[1];
   } else {
      name = "AST__BAD";
   }

/* Print it. */
   if( !strcmp( name, "AST__BAD" ) ) {
      printdval( AST__BAD );

   } else if( !strcmp( name, "AST__NAN" ) ) {
      printdval( AST__NAN );

   } else if( !strcmp( name, "AST__NANF" ) ) {
      printfval( AST__NANF );

/* Issue an error message if the argument is unknown. */
   } else {
      (void) fprintf( stderr, "astbad: Unknown constant requested: %s\n",
                      name );
   }

/* Exit. */
   return 0;
}