~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/draw/drawPlot_gnu.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawPlot_gnu.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: drawPlot_gnu.c,v 1.5 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Notes :
 42  *
 43  *
 44  *********
 45 */
 46 
 47 #include "drawPlot_gnu.h"
 48 
 49 #if HAVE_CONFIG_H
 50   #include <config.h>
 51 #endif
 52 
 53 #include <stdio.h>
 54 #include <stdlib.h>
 55 #include <math.h>
 56 #include <string.h>
 57 #include <unistd.h>
 58 #include <sys/types.h>
 59 #include <sys/stat.h>
 60 #include <tina/sys/sysDef.h>
 61 #include <tina/sys/sysPro.h>
 62 #include <tina/math/mathDef.h>
 63 #include <tina/math/mathPro.h>
 64 #include <tina/file/filePro.h>
 65 
 66 #ifdef MINGW
 67 static int mkfifo(char *p, int u) {}
 68 #endif
 69 
 70 
 71 static   FILE   *gnu_comm = NULL;
 72 static   FILE   *gnu_data = NULL;
 73 static   char    tname[64] = {"./t_gpipe"};
 74 
 75 
 76 /**
 77  * @brief Create connection to gnuplot application.
 78  * @param gpname String containing complete path to application gnuplot.
 79  * @return bool Success of application start.
 80  */
 81 Bool     open_gnuplot_program_link(char *gpname)
 82 {
 83   /* fixme: popen isn't getting declared by stdio.h on Solaris 10,
 84      even with __EXTENSIONS__ */
 85   if ((gnu_comm = (FILE *)popen(gpname, "w")) == NULL)
 86     return (false);
 87 
 88   return(true);
 89 }
 90 
 91 /**
 92  * @brief Convey command to connected gnuplot application.
 93  * @param comm String containing command.
 94  * @return bool Success of command transmission.
 95  */
 96 Bool    send_gnuplot_comm(char *comm)
 97 {
 98   if ((gnu_comm == NULL) || (comm == NULL))
 99     return(false);
100 
101   if (fputs(comm, gnu_comm) == EOF)
102     return (false);
103 
104   fflush(gnu_comm);
105   return (true);   
106 }
107 
108 
109 /**
110  * @brief Close command connection to gnuplot application.
111  */
112 void    close_gnuplot_program_link()
113 {
114   if (gnu_comm == NULL)
115     return;
116 
117   fflush(gnu_comm); 
118   pclose(gnu_comm);
119 
120   gnu_comm = NULL;
121 }
122 
123 
124 /**
125  * @brief Create data connection to previously opened gnuplot application.
126  * @param pl_comm String containing plot command to use on data.
127  * @return gnu_data Pointer to stream to which data is sent.
128  *
129  * Requires open command channel - see open_gnuplot_program_link
130  */
131 FILE  *open_gnuplot_data_link(char *pl_comm)
132 {
133   if (pl_comm == NULL)
134     return (NULL);
135 
136   if (mkfifo(tname, S_IRUSR | S_IWUSR) != 0)
137     {
138       unlink(tname);
139       return(NULL);
140     }
141 
142   send_gnuplot_comm(pl_comm);
143   fflush(gnu_comm); 
144 
145   if ((gnu_data = fopen(tname, "w")) == NULL)
146     {
147       unlink(tname);
148       return(NULL);
149     }
150 
151   return(gnu_data); 
152 }
153 
154 /**
155  * @brief Return the name of the FIFO pipe.
156  * @return tname Pointer to char[64] containing name of pipe.
157  */
158 char  *get_gnuplot_tname()
159 {
160   return(tname);
161 }
162 
163 
164 /**
165  * @brief Close data connection to gnuplot application.
166  */
167 void    close_gnuplot_data_link()
168 {
169   if (gnu_data == NULL)
170     return;
171 
172   fflush(gnu_data);
173   fclose(gnu_data);
174   unlink(tname);
175 
176   gnu_data = NULL;
177 }
178 
179 
180 /**
181  * @brief Close both data and command link to gnuplot application.
182  * @param func Pointer to function to execute prior to link closure.
183  */
184 void    close_gnuplot_link(void *func)
185 {
186   if (func != NULL)
187     ((void (*) ()) func)();
188   
189   close_gnuplot_data_link();
190   close_gnuplot_program_link();
191 }
192 
193 
194 
195 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.