Home | Develop | Download | Contact
extras.h
1 /*
2  * extras.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 __EXTRAS_H__
32 #define __EXTRAS_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 
43 // Grafica las columnas del archivo datacolfile.
44 int pds_octave_plot_col(char nombre[],char datacolfile[])
45 {
46  FILE *fd=NULL;
47  char *orden=NULL;
48  int n;
49 
50  fd=fopen(nombre,"w");
51  if(fd==NULL) return 0;
52 
53  fprintf(fd,"Y=load(\'%s\');\n",datacolfile);
54  fprintf(fd,"\n");
55  fprintf(fd,"t=size(Y);\n");
56  fprintf(fd,"Nx=t(1);\n");
57  fprintf(fd,"Ny=t(2);\n");
58  fprintf(fd,"\n");
59  fprintf(fd,"for II=1:Ny\n");
60  fprintf(fd,"\tfigure(II);\n");
61  fprintf(fd,"\tplot(Y(:,II),\'o-\');\n");
62  fprintf(fd,"\tgrid on;\n");
63  fprintf(fd,"\n");
64  fprintf(fd,"\txlabel('n');\n");
65  fprintf(fd,"\tylabel('f(n)');\n");
66  fprintf(fd,"\n");
67  fprintf(fd,"\tnombre=sprintf('grafico%cd.png',II);\n",'%');
68  fprintf(fd,"\tprint(nombre,'-dpng','-Farial:20','-S400,300');\n");
69  fprintf(fd,"\n");
70  fprintf(fd,"end\n");
71  fprintf(fd,"\n");
72  fprintf(fd,"\n");
73 
74  fclose(fd);
75 
76  orden=(char *)calloc(1,16+strlen(nombre));
77  sprintf(orden,"octave %s",nombre);
78  n=system(orden);
79 
80  return 1;
81 }
82 
83 // Grafica las lineas del archivo datacolfile.
84 int pds_octave_plot_lin(char nombre[],char datacolfile[])
85 {
86  FILE *fd=NULL;
87  char *orden=NULL;
88  int n;
89 
90  fd=fopen(nombre,"w");
91  if(fd==NULL) return 0;
92 
93  fprintf(fd,"Y=load(\'%s\')';\n",datacolfile);
94  fprintf(fd,"\n");
95  fprintf(fd,"t=size(Y);\n");
96  fprintf(fd,"Nx=t(1);\n");
97  fprintf(fd,"Ny=t(2);\n");
98  fprintf(fd,"\n");
99  fprintf(fd,"for II=1:Ny\n");
100  fprintf(fd,"\tfigure(II);\n");
101  fprintf(fd,"\tplot(Y(:,II),\'o-\');\n");
102  fprintf(fd,"\tgrid on;\n");
103  fprintf(fd,"\n");
104  fprintf(fd,"\txlabel('n');\n");
105  fprintf(fd,"\tylabel('f(n)');\n");
106  fprintf(fd,"\n");
107  fprintf(fd,"\tnombre=sprintf('grafico%cd.png',II);\n",'%');
108  fprintf(fd,"\tprint(nombre,'-dpng','-Farial:20','-S400,300');\n");
109  fprintf(fd,"\n");
110  fprintf(fd,"end\n");
111  fprintf(fd,"\n");
112  fprintf(fd,"\n");
113 
114  fclose(fd);
115 
116  orden=(char *)calloc(1,16+strlen(nombre));
117  sprintf(orden,"octave %s",nombre);
118  n=system(orden);
119 
120  return 1;
121 }
122 
123 // Grafica las 2lineas del archivo datacolfile.
124 int pds_octave_plot_2lin(char nombre[],char datacolfile[])
125 {
126  FILE *fd=NULL;
127  char *orden=NULL;
128  int n;
129 
130  fd=fopen(nombre,"w");
131  if(fd==NULL) return 0;
132 
133  fprintf(fd,"Y=load(\'%s\')';\n",datacolfile);
134  fprintf(fd,"\n");
135  fprintf(fd,"t=size(Y);\n");
136  fprintf(fd,"Nx=t(1);\n");
137  fprintf(fd,"Ny=t(2);\n");
138  fprintf(fd,"\n");
139  fprintf(fd,"plot([0:Nx-1],Y(:,1),\'o-\',[0:Nx-1],Y(:,2),\'o-\');\n");
140  fprintf(fd,"grid on;\n");
141  fprintf(fd,"\n");
142  fprintf(fd,"xlabel('n');\n");
143  fprintf(fd,"ylabel('Y(n)');\n");
144  fprintf(fd,"\n");
145  fprintf(fd,"print('grafico.png','-dpng','-Farial:20','-S400,300');\n");
146  fprintf(fd,"\n");
147  fprintf(fd,"\n");
148  fprintf(fd,"\n");
149 
150  fclose(fd);
151 
152  orden=(char *)calloc(1,16+strlen(nombre));
153  sprintf(orden,"octave %s",nombre);
154  n=system(orden);
155 
156  return 1;
157 }
158 
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 
165 #endif /* __EXTRAS_H__ */
166 

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed