Home | Develop | Download | Contact
 Todo Estructuras de Datos Funciones Variables 'typedefs' Grupos Páginas
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 
52 int pds_matrix_copy_vector_col(PdsMatrix *Matrix,const PdsVector *VecSrc,PdsRaNatural col)
53 {
54  PdsRaNatural i,j;
55  PdsRaNatural N;
56 
57  if(Matrix==NULL) return FALSE;
58  if(VecSrc==NULL) return FALSE;
59  if(col>=Matrix->Ncol) return FALSE;
60 
61  if( Matrix->Nlin < VecSrc->Nel ) N=Matrix->Nlin;
62  else N=VecSrc->Nel;
63 
64  for(i=0;i<N;i++) Matrix->M[i][col]=VecSrc->V[i];
65 
66  return TRUE;
67 }
68 
80 int pds_octplot_surf_matrix_in_png(const PdsMatrix *M,const char *labelx,const char *labely,const char *labelz,const char *octfile,const char *pngfile)
81 {
82  int i,j;
83  FILE *fd=NULL;
84  char *orden=NULL;
85 
86  if(M==NULL) return FALSE;
87  if(labelx==NULL) return FALSE;
88  if(labely==NULL) return FALSE;
89  if(labelz==NULL) return FALSE;
90  if(octfile==NULL) return FALSE;
91  if(pngfile==NULL) return FALSE;
92 
93  fd=fopen(octfile,"w");
94  if(fd==NULL) return FALSE;
95  fprintf(fd,"M=[");
96  for(i=0 ; i<M->Nlin ; i++)
97  {
98  for(j=0 ; j<M->Ncol ; j++)
99  {
100  if(j!=M->Ncol-1) fprintf(fd,"%e\t",M->M[i][j]);
101  else fprintf(fd,"%e\n",M->M[i][j]);
102  }
103  }
104  fprintf(fd,"];\n");
105  fprintf(fd,"surf(M);\n");
106  fprintf(fd,"grid on;\n");
107  fprintf(fd,"xlabel(\'%s\');\n",labelx);
108  fprintf(fd,"ylabel(\'%s\');\n",labely);
109  fprintf(fd,"zlabel(\'%s\');\n",labelz);
110  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
111  fprintf(fd,"tmp=input('<< ..:: Press enter to finish ::.. >>');\n"); // <----OJO----
112  fprintf(fd,"\n");
113  fprintf(fd,"\n");
114  fclose(fd);
115 
116  orden=(char *)calloc(1,16+strlen(octfile));
117  if(orden==NULL) return FALSE;
118  sprintf(orden,"octave -q %s",octfile);
119  i=system(orden);
120 
121  return TRUE;
122 }
123 
124 
136 int pds_octplot_pcolor_matrix_in_png(const PdsMatrix *M,const char *labelx,const char *labely,const char *labelz,const char *octfile,const char *pngfile)
137 {
138  int i,j;
139  FILE *fd=NULL;
140  char *orden=NULL;
141 
142  if(M==NULL) return FALSE;
143  if(labelx==NULL) return FALSE;
144  if(labely==NULL) return FALSE;
145  if(labelz==NULL) return FALSE;
146  if(octfile==NULL) return FALSE;
147  if(pngfile==NULL) return FALSE;
148 
149  fd=fopen(octfile,"w");
150  if(fd==NULL) return FALSE;
151  fprintf(fd,"M=[");
152  for(i=0 ; i<M->Nlin ; i++)
153  {
154  for(j=0 ; j<M->Ncol ; j++)
155  {
156  if(j!=M->Ncol-1) fprintf(fd,"%e\t",M->M[i][j]);
157  else fprintf(fd,"%e\n",M->M[i][j]);
158  }
159  }
160  fprintf(fd,"];\n");
161  fprintf(fd,"pcolor(M);\n");
162  fprintf(fd,"grid on;\n");
163  fprintf(fd,"xlabel(\'%s\');\n",labelx);
164  fprintf(fd,"ylabel(\'%s\');\n",labely);
165  fprintf(fd,"zlabel(\'%s\');\n",labelz);
166  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
167  fprintf(fd,"\n");
168  fprintf(fd,"\n");
169  fclose(fd);
170 
171  orden=(char *)calloc(1,16+strlen(octfile));
172  if(orden==NULL) return FALSE;
173  sprintf(orden,"octave -q %s",octfile);
174  i=system(orden);
175 
176  return TRUE;
177 }
178 
179 
191 int pds_octplot_image_matrix_in_png(const PdsMatrix *M,const char *labelx,const char *labely,const char *labelz,const char *octfile,const char *pngfile)
192 {
193  int i,j;
194  FILE *fd=NULL;
195  char *orden=NULL;
196 
197  if(M==NULL) return FALSE;
198  if(labelx==NULL) return FALSE;
199  if(labely==NULL) return FALSE;
200  if(labelz==NULL) return FALSE;
201  if(octfile==NULL) return FALSE;
202  if(pngfile==NULL) return FALSE;
203 
204  fd=fopen(octfile,"w");
205  if(fd==NULL) return FALSE;
206  fprintf(fd,"M=[");
207  for(i=0 ; i<M->Nlin ; i++)
208  {
209  for(j=0 ; j<M->Ncol ; j++)
210  {
211  if(j!=M->Ncol-1) fprintf(fd,"%e\t",M->M[i][j]);
212  else fprintf(fd,"%e\n",M->M[i][j]);
213  }
214  }
215  fprintf(fd,"];\n");
216  fprintf(fd,"image(M);\n");
217  fprintf(fd,"grid on;\n");
218  fprintf(fd,"xlabel(\'%s\');\n",labelx);
219  fprintf(fd,"ylabel(\'%s\');\n",labely);
220  fprintf(fd,"zlabel(\'%s\');\n",labelz);
221  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
222  fprintf(fd,"\n");
223  fprintf(fd,"\n");
224  fclose(fd);
225 
226  orden=(char *)calloc(1,16+strlen(octfile));
227  if(orden==NULL) return FALSE;
228  sprintf(orden,"octave -q %s",octfile);
229  i=system(orden);
230 
231  return TRUE;
232 }
233 
244 int pds_octplot_vector_in_png(const PdsVector *V,const char *labelx,const char *labely,const char *octfile,const char *pngfile)
245 {
246  int i;
247  FILE *fd=NULL;
248  char *orden=NULL;
249 
250  if(V==NULL) return FALSE;
251  if(labelx==NULL) return FALSE;
252  if(labely==NULL) return FALSE;
253  if(octfile==NULL) return FALSE;
254  if(pngfile==NULL) return FALSE;
255 
256  fd=fopen(octfile,"w");
257  if(fd==NULL) return FALSE;
258  fprintf(fd,"V=[");
259  for(i=0 ; i<V->Nel ; i++) fprintf(fd,"%e\t",V->V[i]);
260  fprintf(fd,"];\n");
261  fprintf(fd,"plot(V,\'o-\');\n");
262  fprintf(fd,"grid on;\n");
263  fprintf(fd,"xlabel(\'%s\');\n",labelx);
264  fprintf(fd,"ylabel(\'%s\');\n",labely);
265  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
266  fprintf(fd,"\n");
267  fprintf(fd,"\n");
268  fclose(fd);
269 
270  orden=(char *)calloc(1,16+strlen(octfile));
271  if(orden==NULL) return FALSE;
272  sprintf(orden,"octave -q %s",octfile);
273  i=system(orden);
274 
275  return TRUE;
276 }
277 
288 int pds_octplot_cvector_in_png(const PdsCVector *V,const char *labelx,const char *labely,const char *octfile,const char *pngfile)
289 {
290  int i;
291  FILE *fd=NULL;
292  char *orden=NULL;
293 
294  if(V==NULL) return FALSE;
295  if(labelx==NULL) return FALSE;
296  if(labely==NULL) return FALSE;
297  if(octfile==NULL) return FALSE;
298  if(pngfile==NULL) return FALSE;
299 
300  fd=fopen(octfile,"w");
301  if(fd==NULL) return FALSE;
302  fprintf(fd,"Vreal=[");
303  for(i=0 ; i<V->Nel ; i++) fprintf(fd,"%e\t",V->V[i].Real);
304  fprintf(fd,"];\n");
305  fprintf(fd,"Vimag=[");
306  for(i=0 ; i<V->Nel ; i++) fprintf(fd,"%e\t",V->V[i].Imag);
307  fprintf(fd,"];\n");
308  fprintf(fd,"plot(Vreal,\'o-\',Vimag,\'o-\');\n");
309  fprintf(fd,"grid on;\n");
310  fprintf(fd,"xlabel(\'%s\');\n",labelx);
311  fprintf(fd,"ylabel(\'%s\');\n",labely);
312  fprintf(fd,"legend('Real','Imag');\n");
313  fprintf(fd,"print(\'%s\',\'-dpng\',\'-Farial:20\',\'-S800,600\');\n",pngfile);
314  fprintf(fd,"\n");
315  fprintf(fd,"\n");
316  fclose(fd);
317 
318  orden=(char *)calloc(1,16+strlen(octfile));
319  if(orden==NULL) return FALSE;
320  sprintf(orden,"octave -q %s",octfile);
321  i=system(orden);
322 
323  return TRUE;
324 }
325 
326 
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 
332 
333 #endif /* __EXTRAS_H__ */
334 

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed