/* Display non-null header field values */ void printheader(segy *tp) { int i; /* index over header fields */ int j; /* index over non-null header fields */ Value val; /* value in header field */ String type; /* ... its data type */ String key; /* ... the name of the header field */ Value zeroval; /* zero value to compare with */ zeroval.l = 0; j = 0; for (i = 0; i < SU_NKEYS; i++) { gethval(tp, i, &val); key = getkey(i); type = hdtype(key); if (valcmp(type, val, zeroval)) { /* not equal to zero */ (void) printf(" %s=", key); printfval(type, val); if ((++j % 6) == 0) putchar('\n'); } } putchar('\n'); return; }
/* * Print a number of float variable values, where the optional comments * for each value identify the variable, and each dimension index. */ static void pr_fvals( 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 float *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++) { printfval(sout, fmt, vp, *vals++); if (fsp->full_data_cmnts) { Printf("%s", sout); Printf(","); annotate (vp, fsp, cor, iel); } else { (void) strcat(sout, ", "); lput(sout); } } printfval(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); } }
main(int argc, char **argv) { String output; bool asciiout = true; /* Initialize */ initargs(argc, argv); askdoc(1); file2g(stdin); /* Argument count check */ if (argc == 1) err("must specify key(s) as command line arguments"); /* Set and check output disposition (ascii or binary) */ if (!getparstring("output", &output)) output = "ascii"; if ((!STREQ(output, "ascii")) && (!STREQ(output, "binary"))) err("output parameter=%s, must be ascii or binary", output); if (STREQ(output, "binary")) asciiout = false; /* Loop over traces writing selected header field values */ while (gettr(&tr)) { register int i; for (i = 1; i < argc; ++i) { String key = argv[i]; Value val; /* discard command line parameter strings */ if (STREQ(key, "output=ascii") || STREQ(key, "output=binary")) continue; gethdval(&tr, key, &val); if (asciiout) { /* ascii output */ printf("%6s=", key); printfval(hdtype(key), val); putchar('\t'); } else { /* binary output */ float fval = vtof(hdtype(key), val); efwrite((char *) &fval, FSIZE, 1, stdout); } } if (asciiout) printf("\n\n"); } return EXIT_SUCCESS; }
/* ============== */ 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; }