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 y crea un archivo de matlab con el 'nombre'.
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','-S800,600');\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,strlen(nombre)+16);
77  sprintf(ORDEN,"octave -q %s\n",nombre);
78  n=system(ORDEN);
79  free(ORDEN);
80  return 1;
81 }
82 
83 // Grafica las lineas del archivo datalinfile y crea un archivo de matlab con el 'nombre'.
84 int pds_octave_plot_lin(char nombre[],char datalinfile[])
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",datalinfile);
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','-S800,600');\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,strlen(nombre)+16);
117  sprintf(ORDEN,"octave -q %s\n",nombre);
118  n=system(ORDEN);
119  free(ORDEN);
120 
121  return 1;
122 }
123 
124 // Grafica las lineas del archivo datalinfile y crea un archivo de matlab con el 'nombre'.
125 int pds_octave_plot_lin_fft(char nombre[],char datalinfile[])
126 {
127  FILE *fd=NULL;
128  char *ORDEN=NULL;
129  int n;
130 
131  fd=fopen(nombre,"w");
132  if(fd==NULL) return 0;
133 
134  fprintf(fd,"Y=load(\'%s\')';\n",datalinfile);
135  fprintf(fd,"\n");
136  fprintf(fd,"t=size(Y);\n");
137  fprintf(fd,"Nx=t(1);\n");
138  fprintf(fd,"Ny=t(2);\n");
139  fprintf(fd,"\n");
140  fprintf(fd,"x1=[0:(Nx-1)]'*2.0*pi/Nx;\n");
141  fprintf(fd,"x6=[0:6*Nx-1]'*2.0*pi/(6*Nx);\n");
142  fprintf(fd,"ceros=0*x1;\n");
143  fprintf(fd,"\n");
144  fprintf(fd,"for II=1:Ny\n");
145  fprintf(fd,"\tfigure(II);\n");
146  fprintf(fd,"\tY1=abs(fft(Y(:,II)));\n");
147  fprintf(fd,"\ty6=[Y(:,II);ceros;ceros;ceros;ceros;ceros];\n");
148  fprintf(fd,"\tY6=abs(fft(y6));\n");
149  fprintf(fd,"\tplot(x1,Y1,'*',x6,Y6,'--');\n");
150  fprintf(fd,"\tgrid on;\n");
151  fprintf(fd,"\n");
152  fprintf(fd,"\txlabel('angle');\n");
153  fprintf(fd,"\tylabel('FFT');\n");
154  fprintf(fd,"\n");
155  fprintf(fd,"\tnombre=sprintf('graficofft%cd.png',II);\n",'%');
156  fprintf(fd,"\tprint(nombre,'-dpng','-Farial:20','-S800,600');\n");
157  fprintf(fd,"\n");
158  fprintf(fd,"end\n");
159  fprintf(fd,"\n");
160  fprintf(fd,"\n");
161 
162  fclose(fd);
163 
164  ORDEN=(char*)calloc(1,strlen(nombre)+16);
165  sprintf(ORDEN,"octave -q %s\n",nombre);
166  n=system(ORDEN);
167  free(ORDEN);
168 
169  return 1;
170 }
171 
172 
183 int pds_octplot_vector_in_png(const PdsVector *V,const char *labelx,const char *labely,const char *octfile,const char *pngfile)
184 {
185  int i;
186  FILE *fd=NULL;
187  char *orden=NULL;
188 
189  if(V==NULL) return FALSE;
190  if(labelx==NULL) return FALSE;
191  if(labely==NULL) return FALSE;
192  if(octfile==NULL) return FALSE;
193  if(pngfile==NULL) return FALSE;
194 
195  fd=fopen(octfile,"w");
196  if(fd==NULL) return FALSE;
197  fprintf(fd,"V=[");
198  for(i=0 ; i<V->Nel ; i++) fprintf(fd,"%e\t",V->V[i]);
199  fprintf(fd,"];\n");
200  fprintf(fd,"plot(V,\'o-\');\n");
201  fprintf(fd,"grid on;\n");
202  fprintf(fd,"xlabel(\'%s\');\n",labelx);
203  fprintf(fd,"ylabel(\'%s\');\n",labely);
204  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
205  fprintf(fd,"\n");
206  fprintf(fd,"\n");
207  fclose(fd);
208 
209  orden=(char *)calloc(1,32+strlen(octfile));
210  if(orden==NULL) return FALSE;
211  sprintf(orden,"octave --silent %s",octfile);
212  i=system(orden);
213 
214  return TRUE;
215 }
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 
222 #endif /* __EXTRAS_H__ */
223 

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed