OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_c/] [plot/] [plot.c] - Blame information for rev 43

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 alirezamon
#include <stdlib.h>
2
#include <stdio.h>
3
#include <string.h>
4
 
5
#include "plot_command.h"
6
 
7
#define NUM_POINTS 5
8
 
9
#define MAX_INDEX       12
10
 
11
 
12
int count_index_num (char *);
13
int get_index_names (char [][30] ,char * );
14
 
15
void usage (){
16
        printf("\nUsage: ./plot in.sv out.eps x_axis_label  y_axis_label key_pos   \n");
17
        printf("  in.sv : input file contains the plotting data:\n");
18
        printf(" \t #name:first_graph_name\n");
19
        printf(" \t first_graph_x1 first_graph_y1 \n \t first_graph_x2 first_graph_y2\n\t . \n\t .\n");
20
        printf(" \t first_graph_xn first_graph_yn \n \n\n");
21
        printf(" \t #name:second_graph_name\n");
22
        printf(" \t second_graph_x1 second_graph_y1 \n \t . \n \t . \n\n");
23
        printf("  y_axis_label: this label will be shown for y axis data in graph\n");
24
        printf("  x_axis_label: this label will be shown for x axis data in graph\n");
25
        printf("  out.eps : output file name\n");
26
        printf("  key_pos : Gnuplot key position. e.g. \"left bottom\"\n");
27
 
28
 
29
}
30
 
31
 
32
 
33
//int plot(char in_file_name[], char out_file_name[])
34
int main (int argc, char *argv[])
35
{
36
 printf("argc=%d\n",argc);
37 43 alirezamon
if(argc!= 6) {usage();  return 1;}
38 16 alirezamon
 char * in_file_name =argv[1];
39
 char * out_file_name=argv[2];
40
 char * x_lable      =argv[3];
41
 char * y_lable      =argv[4];
42
 char * key_pos         = argv[5];
43
 
44
 int i, index_num;
45
 
46
char  label [MAX_INDEX][30];
47
 
48
for (i=0; i<MAX_INDEX; i++) sprintf(label [i],"Index%u",i);
49
 
50
 
51
 
52
 
53
char plot_cmd[3000]={};
54
 
55
 
56
   // double xvals[NUM_POINTS] = {1.0, 2.0, 3.0, 4.0, 5.0};
57
  //  double yvals[NUM_POINTS] = {5.0 ,3.0, 1.0, 3.0, 5.0};
58
    //FILE * temp = fopen("data.temp", "w");
59
    /*Opens an interface that one can use to send commands as if they were typing into the
60
     *     gnuplot command line.  "The -persistent" keeps the plot open even after your
61
     *     C program terminates.
62
     */
63
FILE * pipe = popen ("gnuplot -persistent", "w");
64
 
65
 
66
 
67
 index_num=count_index_num (in_file_name);
68 43 alirezamon
 //if(index==0)return 1;
69 16 alirezamon
 if(get_index_names(label,in_file_name)) return 1;
70
 
71
 
72
  //  sprintf(plot_cmd,"plot '%s' index 0 with linespoints ls 1 title '%s', \"\" index 1 with linespoints ls 2 title '%s', \"\" index 2  with linespoints ls 3 title '%s', \"\" index 3 with linespoints ls 4 title '%s'",in_file_name,label1,label2,label3,label4);
73
    sprintf(plot_cmd,"plot '%s' index 0 with linespoints ls 1 title '%s'", in_file_name,label[1]);
74
    for (i=1; i < index_num; i++){
75
        sprintf(plot_cmd,"%s , \"\" index %d with linespoints ls %d title '%s'  ",plot_cmd,i,i+1,label[i+1]);
76
    }
77
        i=0;
78
    while (commandsForGnuplot[i]!=NULL)
79
    {
80
        fprintf(pipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
81
        i++;
82
    }
83
 
84
    //set ylable title
85
    fprintf(pipe, "set ylabel \"%s\"\n   ",y_lable);
86
    fprintf(pipe, "set xlabel \"%s\"\n   ",x_lable);
87
    fprintf(pipe, "set key %s \n",key_pos);
88
    fprintf(pipe, "%s \n",plot_cmd);
89
 
90
        fflush(pipe);
91
        fclose(pipe);
92
        rename("temp.eps",out_file_name);
93
    return 0;
94
}
95
 
96
 
97
typedef enum { false = 0, true } bool;
98
 
99
bool isEmptyLine(const char *s) {
100
  static const char *emptyline_detector = " \t\n";
101
 
102
  return strspn(s, emptyline_detector) == strlen(s);
103
}
104
 
105
 
106
int count_index_num (char * file_name){
107
        FILE * in;
108
        char line [1000];
109
        int index =1;
110
        bool last_result = false;
111
        in= fopen (file_name,"r");
112
        if(in==NULL){printf ("Error: failed to open %s file in read mode\n",file_name); return 0;}
113
        while (fgets ( line, sizeof line, in )!=NULL){
114
 
115
                if ( isEmptyLine(line) == false && last_result == true ) index++;
116
                last_result = isEmptyLine(line);
117
                //printf("%d\t\t %s\n",index,line);
118
 
119
        }
120
        fclose(in);
121
        return index;
122
}
123
 
124
char out[100];
125
char * check_format(char * ch){
126
 
127
        int i =0;
128
        while((*ch)!= 0){
129
                if((*ch)=='_') {out[i]= '\\'; i++;}
130
                out[i] = *ch;
131
                ch++;
132
                i++;
133
        }
134
        out[i] = 0;
135
        return out;
136
}
137
 
138
 
139
 int get_index_names (char label[MAX_INDEX][30] ,char * file_name){
140
        FILE * in;
141
        char line [1000];
142
        char * ch;
143
        in= fopen (file_name,"r");
144
        if(in==NULL){printf ("Error: failed to open %s file in read mode\n",file_name); return 1;}
145
        int index =1;
146
        while (fgets ( line, sizeof line, in )!=NULL){
147
                        if(strncmp(line,"#name:",6)==0) {
148
                                ch=strtok(line,":");
149
                                ch=strtok(NULL,"\n");
150
                                ch = check_format(ch);
151
                                //strcpy(label[index],ch);
152
                                sprintf(label[index],"%s",ch);
153
                                index++;
154
 
155
 
156
                        }
157
        }
158
 
159
         fclose(in);
160
         return 0;
161
 
162
 
163
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.