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  

vp_util.c

Go to the documentation of this file.
00001 /*
00002  * vp_util.c
00003  *
00004  * Miscellaneous utility routines.
00005  *
00006  * Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00007  * Junior University.  All rights reserved.
00008  *
00009  * Permission to use, copy, modify and distribute this software and its
00010  * documentation for any purpose is hereby granted without fee, provided
00011  * that the above copyright notice and this permission notice appear in
00012  * all copies of this software and that you do not sell the software.
00013  * Commercial licensing is available by contacting the author.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
00016  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
00017  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00018  *
00019  * Author:
00020  *    Phil Lacroute
00021  *    Computer Systems Laboratory
00022  *    Electrical Engineering Dept.
00023  *    Stanford University
00024  */
00025 
00026 /*
00027  * $Date: 2001/12/17 16:16:23 $
00028  * $Revision: 1.1 $
00029  */
00030 
00031 #include "vp_global.h"
00032 
00033 /*
00034  * vpRamp
00035  *
00036  * Fill a float array with a ramp (a piecewise linear function).
00037  */
00038 
00039 vpResult
00040 vpRamp(dst, stride, num_points, ramp_x, ramp_y)
00041 float *dst;     /* array to store ramp into */
00042 int stride;     /* stride (in bytes) for dst */
00043 int num_points; /* number of linear segment endpoints */
00044 int *ramp_x;    /* x coordinates of the endpoints (and indexes into dst) */
00045 float *ramp_y;  /* y coordinates of the endpoints */
00046 {
00047     int i, x;
00048     int lastx, nextx;
00049     double lasty, nexty, dydx, y;
00050 
00051     if (num_points < 1)
00052         return(VPERROR_BAD_VALUE);
00053     for (i = 1; i < num_points; i++)
00054         if (ramp_x[i] <= ramp_x[i-1])
00055             return(VPERROR_BAD_VALUE);
00056     dst[*ramp_x * stride/sizeof(float)] = *ramp_y;
00057     if (num_points == 1)
00058         return(VP_OK);
00059     for (i = 1; i < num_points; i++) {
00060         lastx = ramp_x[i-1];
00061         lasty = ramp_y[i-1];
00062         nextx = ramp_x[i];
00063         nexty = ramp_y[i];
00064         dydx = (double)(nexty - lasty) / (double)(nextx - lastx);
00065         for (x = lastx+1, y = lasty+dydx; x < nextx; x++, y += dydx)
00066             dst[x * stride/sizeof(float)] = y;
00067         dst[x * stride/sizeof(float)] = nexty;
00068     }
00069     return(VP_OK);
00070 }
00071 
00072 /*
00073  * VPBug
00074  *
00075  * Print an error message and exit.  The argument is a printf-style format
00076  * string followed by parameters. 
00077  */
00078 
00079 #ifdef ANSI_C
00080 void
00081 VPBug(char *fmt, ...)
00082 #else
00083 void
00084 VPBug(fmt, va_alist)
00085 char *fmt;
00086 va_dcl
00087 #endif
00088 {
00089     va_list args;
00090     extern void exit ANSI_ARGS((int status));
00091 
00092     fprintf(stderr, "BUG: ");
00093 #ifdef ANSI_C
00094     va_start(args, fmt);
00095 #else
00096     va_start(args);
00097 #endif
00098 #ifdef HAVE_VPRINTF
00099     vfprintf(stderr, fmt, args);
00100 #else
00101 #ifdef HAVE_DOPRNT
00102     _doprnt(fmt, args, stderr);
00103 #else
00104     fprintf(stderr, "unrecoverable error");
00105 #endif
00106 #endif
00107     va_end(args);
00108     fprintf(stderr, "\n");
00109     exit(1);
00110 }
00111 
00112 #ifdef DEBUG
00113 /*
00114  * VPDebug
00115  *
00116  * Print a debugging message.
00117  *    VPDebug(debug_code, format, parameters, ...)
00118  */
00119 
00120 #ifdef ANSI_C
00121 void
00122 VPDebug(vpContext *vpc, int debug_code, char *fmt, ...)
00123 #else
00124 void
00125 VPDebug(vpc, debug_code, fmt, va_alist)
00126 vpContext *vpc;
00127 int debug_code;
00128 char *fmt;
00129 va_dcl
00130 #endif
00131 {
00132     va_list args;
00133 
00134     if (vpc->debug_enable[debug_code]) {
00135 #ifdef ANSI_C
00136         va_start(args, fmt);
00137 #else
00138         va_start(args);
00139 #endif
00140 #ifdef HAVE_VPRINTF
00141         vfprintf(stdout, fmt, args);
00142 #else
00143 #ifdef HAVE_DOPRNT
00144         _doprnt(fmt, args, stdout);
00145 #else
00146         printf("unrecoverable error");
00147 #endif
00148 #endif
00149         va_end(args);
00150     }
00151 }
00152 #endif /* DEBUG */
 

Powered by Plone

This site conforms to the following standards: