Home | Develop | Download | Contact
octplot.h
1 /*
2  * octplot.h
3  *
4  * Copyright 2011 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  */
22 
23 
31 #ifndef __OCTPLOT_H__
32 #define __OCTPLOT_H__
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <pds/pdsvector.h>
42 
53 int function_octplot_vector_in_png(const PdsVector *V,const char *labelx,const char *labely,const char *octfile,const char *pngfile)
54 {
55  int i;
56  FILE *fd=NULL;
57  char *orden=NULL;
58 
59  if(V==NULL) return FALSE;
60  if(labelx==NULL) return FALSE;
61  if(labely==NULL) return FALSE;
62  if(octfile==NULL) return FALSE;
63  if(pngfile==NULL) return FALSE;
64 
65  fd=fopen(octfile,"w");
66  if(fd==NULL) return FALSE;
67  fprintf(fd,"V=[");
68  for(i=0 ; i<V->Nel ; i++) fprintf(fd,"%e\t",V->V[i]);
69  fprintf(fd,"];\n");
70  fprintf(fd,"plot(V,\'o-\');\n");
71  fprintf(fd,"grid on;\n");
72  fprintf(fd,"xlabel(\'%s\');\n",labelx);
73  fprintf(fd,"ylabel(\'%s\');\n",labely);
74  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
75  fprintf(fd,"\n");
76  fprintf(fd,"\n");
77  fclose(fd);
78 
79  orden=(char *)calloc(1,32+strlen(octfile));
80  if(orden==NULL) return FALSE;
81  sprintf(orden,"octave --silent %s",octfile);
82  i=system(orden);
83 
84  return TRUE;
85 }
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 
92 #endif /* __OCTPLOT_H__ */
93 

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed