Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

dumplib.c File Reference

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "netcdf.h"
#include "dumplib.h"

Go to the source code of this file.


Defines

#define LINEPIND   " "
#define C_FMT_NAME   "C_format"
#define MAX_CFMT_LEN   100

Functions

char * has_c_format_att (int ncid, int varid)
vnodenewvnode (void)
void error (const char *fmt,...)
void set_indent (int in)
void set_max_len (int len)
void lput (const char *cp)
void set_formats (int float_digits, int double_digits)
char * get_fmt (int ncid, int varid, nc_type type)
vnodenewvlist (void)
void varadd (vnode *vlist, int varid)
int varmember (const vnode *vlist, int varid)

Variables

int float_precision_specified = 0
int double_precision_specified = 0
char float_var_fmt [] = "%.NNg"
char double_var_fmt [] = "%.NNg"
char float_att_fmt [] = "%#.NNgf"
char double_att_fmt [] = "%#.NNg"
int linep
int max_line_len

Define Documentation

#define C_FMT_NAME   "C_format"
 

#define LINEPIND   " "
 

Definition at line 47 of file dumplib.c.

Referenced by lput().

#define MAX_CFMT_LEN   100
 


Function Documentation

void error const char *    fmt,
...   
 

Definition at line 33 of file dumplib.c.

References args.

Referenced by crop_image(), do_ncdump(), find_background(), find_color_or_error(), frame_argument(), get_fmt(), get_input_stream(), gifread_error(), input_stream(), main(), make_lvars(), merge_frame_interval(), name_path(), new_viewer(), newvnode(), output_information(), pipe_color_transformer(), pr_att(), pr_att_vals(), read_colormap_file(), read_text_colormap(), set_precision(), set_sigdigs(), type_name(), vardata(), and write_stream().

00034 {
00035     va_list args ;
00036 
00037     (void) fprintf(stderr,"%s: ", progname);
00038     va_start(args, fmt) ;
00039     (void) vfprintf(stderr,fmt,args) ;
00040     va_end(args) ;
00041 
00042     (void) fprintf(stderr, "\n") ;
00043     (void) fflush(stderr);      /* to ensure log files are current */
00044     exit(EXIT_FAILURE);
00045 }

char* get_fmt int    ncid,
int    varid,
nc_type    type
 

Definition at line 130 of file dumplib.c.

References double_precision_specified, double_var_fmt, error(), float_precision_specified, float_var_fmt, and has_c_format_att().

Referenced by vardata().

00135 {
00136     char *c_format_att;
00137 
00138     /* float or double precision specified with -p option overrides any
00139        C_format attribute value, so check for that first. */
00140 
00141     if (float_precision_specified && type == NC_FLOAT)
00142         return float_var_fmt;
00143 
00144     if (double_precision_specified && type == NC_DOUBLE)
00145         return double_var_fmt;
00146 
00147     /* If C_format attribute exists, return it */
00148     c_format_att = has_c_format_att(ncid, varid);
00149     if (c_format_att)
00150       return c_format_att;    
00151 
00152     /* Otherwise return sensible default. */
00153     switch (type) {
00154       case NC_BYTE:
00155         return "%d";
00156       case NC_CHAR:
00157         return "%s";
00158       case NC_SHORT:
00159         return "%d";
00160       case NC_INT:
00161         return "%d";
00162       case NC_FLOAT:
00163         return float_var_fmt;
00164       case NC_DOUBLE:
00165         return double_var_fmt;
00166       default:
00167         error("pr_vals: bad type");
00168     }
00169 
00170     return 0;
00171 }

char * has_c_format_att int    ncid,
int    varid
[static]
 

Definition at line 92 of file dumplib.c.

References nc_advise(), nc_get_att_text(), and nc_inq_att().

Referenced by get_fmt().

00096 {
00097     nc_type cfmt_type;
00098     size_t cfmt_len;
00099 #define C_FMT_NAME      "C_format" /* name of C format attribute */
00100 #define MAX_CFMT_LEN    100     /* max length of C format attribute */
00101     static char cfmt[MAX_CFMT_LEN];
00102     
00103     /* we expect nc_inq_att to fail if there is no "C_format" attribute */
00104     int nc_stat = nc_inq_att(ncid, varid, "C_format", &cfmt_type, &cfmt_len);
00105 
00106     switch(nc_stat) {
00107     case NC_NOERR:
00108         if (cfmt_type == NC_CHAR && cfmt_len != 0 && cfmt_len < MAX_CFMT_LEN) {
00109             int nc_stat = nc_get_att_text(ncid, varid, "C_format", cfmt);
00110             if(nc_stat != NC_NOERR)
00111                 nc_advise("Getting 'C_format' attribute", nc_stat, "");
00112             return &cfmt[0];
00113         }
00114         break;
00115     case NC_ENOTATT:
00116         break;
00117     default:
00118         nc_advise("Inquiring about 'C_format' attribute", nc_stat, "");
00119         break;
00120     }
00121     return 0;
00122 }

void lput const char *    cp
 

Definition at line 67 of file dumplib.c.

References linep, LINEPIND, and max_line_len.

Referenced by lastdelim2(), pr_bvals(), pr_dvals(), pr_fvals(), pr_ivals(), pr_svals(), and pr_tvals().

00068 {
00069     size_t nn = strlen(cp);
00070 
00071     if (nn+linep > max_line_len && nn > 2) {
00072         (void) fputs("\n", stdout);
00073         (void) fputs(LINEPIND, stdout);
00074         linep = (int)strlen(LINEPIND);
00075     }
00076     (void) fputs(cp,stdout);
00077     linep += nn;
00078 }

vnode* newvlist void   
 

Definition at line 190 of file dumplib.c.

References newvnode().

Referenced by do_ncdump().

00191 {
00192     vnode *vp = newvnode();
00193 
00194     vp -> next = 0;
00195     vp -> id = -1;              /* bad id */
00196 
00197     return vp;
00198 }

vnode * newvnode void    [static]
 

Definition at line 175 of file dumplib.c.

References error(), and malloc.

Referenced by newvlist(), and varadd().

00176 {
00177     vnode *newvp = (vnode*) malloc(sizeof(vnode));
00178     
00179     if (!newvp) {
00180         error("out of memory!");
00181     }
00182     return newvp;
00183 }

void set_formats int    float_digits,
int    double_digits
 

Definition at line 82 of file dumplib.c.

References double_att_fmt, double_var_fmt, float_att_fmt, and float_var_fmt.

Referenced by main(), set_precision(), and set_sigdigs().

00083 {
00084     (void) sprintf(float_var_fmt, "%%.%dg", float_digits);
00085     (void) sprintf(double_var_fmt, "%%.%dg", double_digits);
00086     (void) sprintf(float_att_fmt, "%%#.%dgf", float_digits);
00087     (void) sprintf(double_att_fmt, "%%#.%dg", double_digits);
00088 }

void set_indent int    in
 

Definition at line 53 of file dumplib.c.

References linep.

Referenced by vardata().

00054 {
00055     linep = in;
00056 }

void set_max_len int    len
 

Definition at line 60 of file dumplib.c.

References max_line_len.

Referenced by main().

00061 {
00062     max_line_len = len-2;
00063 }

void varadd vnode   vlist,
int    varid
 

Definition at line 202 of file dumplib.c.

References newvnode().

Referenced by do_ncdump().

00203 {
00204     vnode *newvp = newvnode();
00205     
00206     newvp -> next = vlist -> next;
00207     newvp -> id = varid;
00208     vlist -> next = newvp;
00209 }

int varmember const vnode   vlist,
int    varid
 

Definition at line 213 of file dumplib.c.

References vnode::id, and vnode::next.

Referenced by do_ncdump().

00214 {
00215     vnode *vp = vlist -> next;
00216 
00217     for (; vp ; vp = vp->next)
00218       if (vp->id == varid)
00219         return 1;
00220     return 0;    
00221 }

Variable Documentation

char double_att_fmt[] = "%#.NNg"
 

Definition at line 27 of file dumplib.c.

Referenced by set_formats().

int double_precision_specified = 0
 

Definition at line 23 of file dumplib.c.

Referenced by get_fmt().

char double_var_fmt[] = "%.NNg"
 

Definition at line 25 of file dumplib.c.

Referenced by get_fmt(), and set_formats().

char float_att_fmt[] = "%#.NNgf"
 

Definition at line 26 of file dumplib.c.

Referenced by set_formats().

int float_precision_specified = 0
 

Definition at line 22 of file dumplib.c.

Referenced by get_fmt().

char float_var_fmt[] = "%.NNg"
 

Definition at line 24 of file dumplib.c.

Referenced by get_fmt(), and set_formats().

int linep [static]
 

Definition at line 49 of file dumplib.c.

Referenced by lput(), and set_indent().

int max_line_len [static]
 

Definition at line 50 of file dumplib.c.

Referenced by lput(), and set_max_len().

 

Powered by Plone

This site conforms to the following standards: