1 /*****************************************************************************
2 * RRDtool 1.2.12 Copyright by Tobi Oetiker, 1997-2005
3 *****************************************************************************
5 *****************************************************************************
6 * Initial version by Burton Strauss, ntopSupport.com - 3/2005
7 *****************************************************************************/
13 rrd_first(int argc, char **argv)
15 int target_rraindex=0;
17 optind = 0; opterr = 0; /* initialize getopt */
20 static struct option long_options[] =
22 {"rraindex", required_argument, 0, 129},
27 opt = getopt_long(argc, argv, "", long_options, &option_index);
34 target_rraindex=strtol(optarg,&endptr,0);
35 if(target_rraindex < 0) {
36 rrd_set_error("invalid rraindex number");
41 rrd_set_error("usage rrdtool %s [--rraindex number] file.rrd", argv[0]);
47 rrd_set_error("not enough arguments");
51 return(rrd_first_r(argv[optind], target_rraindex));
56 rrd_first_r(const char *filename, const int rraindex)
64 if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1){
65 rrd_set_error("could not open RRD");
69 if((rraindex < 0) || (rraindex >= (int)rrd.stat_head->rra_cnt)) {
70 rrd_set_error("invalid rraindex number");
74 rra_start = ftell(in_file);
77 (rrd.rra_ptr[rraindex].cur_row+1) *
78 rrd.stat_head->ds_cnt *
81 timer = - (rrd.rra_def[rraindex].row_cnt-1);
82 if (rrd.rra_ptr[rraindex].cur_row + 1 > rrd.rra_def[rraindex].row_cnt) {
83 fseek(in_file,rra_start,SEEK_SET);
85 then = (rrd.live_head->last_up -
86 rrd.live_head->last_up %
87 (rrd.rra_def[rraindex].pdp_cnt*rrd.stat_head->pdp_step)) +
89 rrd.rra_def[rraindex].pdp_cnt*rrd.stat_head->pdp_step);