~ubuntu-branches/ubuntu/utopic/adios/utopic

« back to all changes in this revision

Viewing changes to utils/bpls/bpls.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-12-09 15:21:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131209152131-jtd4fpmdv3xnunnm
Tags: 1.5.0-1
* New upstream.
* Standards-Version: 3.9.5
* Include latest config.{sub,guess} 
* New watch file.
* Create libadios-bin for binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
bool noindex;              // do no print array indices with data
66
66
bool printByteAsChar;      // print 8 bit integer arrays as string
67
67
bool plot;                 // dump histogram related information
 
68
bool hidden_attrs;         // show hidden attrs in BP file
68
69
 
69
70
// other global variables
70
71
char *prgname; /* argv[0] */
89
90
    {"start",                required_argument,    NULL,    's'}, 
90
91
    {"count",                required_argument,    NULL,    'c'}, 
91
92
    {"noindex",              no_argument,          NULL,    'y'},
92
 
    {"sort",                 no_argument,          NULL,    'r'},
 
93
//    {"sort",                 no_argument,          NULL,    'r'},
93
94
    {"timestep",             no_argument,          NULL,    't'},
94
95
    {"attrs",                no_argument,          NULL,    'a'},
95
96
    {"attrsonly",            no_argument,          NULL,    'A'},
97
98
    {"string",               no_argument,          NULL,    'S'},
98
99
    {"columns",              required_argument,    NULL,    'n'}, 
99
100
    {"format",               required_argument,    NULL,    'f'}, 
 
101
    {"hidden_attrs",         no_argument,          &hidden_attrs,    true}, 
100
102
    //    {"time",                 required_argument,    NULL,    't'}, 
101
103
    {NULL,                   0,                    NULL,    0}
102
104
};
117
119
            "                               min/max values of arrays (no overhead to get them!)\n"
118
120
            "  --attrs     | -a           List/match attributes too\n"
119
121
            "  --attrsonly | -A           List attributes only\n"
 
122
            /*
120
123
            "  --sort      | -r           Sort names before listing\n"
 
124
            */
121
125
            "  --timestep  | -t           Print values of timestep elements\n"
122
126
            "  --group     | -g <mask>    List/dump groups matching the mask only\n"
123
127
            "  --dump      | -d           Dump matched variables/attributes\n"
139
143
            "  --columns   | -n \"cols\"    Number of data elements per row to print\n"
140
144
            "  --format    | -f \"str\"     Format string to use for one data item in print\n"
141
145
            "                               instead of the default. E.g. \"%%6.3f\"\n"
 
146
            "  --hidden_attrs             Show hidden ADIOS attributes in the file\n"
142
147
            /*
143
148
               "  --time    | -t N [M]      # print data for timesteps N..M only (or only N)\n"
144
149
               "                              default is to print all available timesteps\n"
200
205
                display_help();
201
206
                return 0;
202
207
            case 'r':
203
 
                sortnames = true;
 
208
                //sortnames = true;
204
209
                break;
205
210
            case 'l':
206
211
                longopt = true;
252
257
                   break;
253
258
                 */
254
259
 
 
260
            //case 200:
 
261
            //    hidden_attrs = true;
 
262
            //    break;
 
263
 
255
264
            case 1:
256
265
                /* This means a field is unknown, or could be multiple arg or bad arg*/
257
266
                /*
353
362
    //timeto               = -1;
354
363
    use_regexp           = false;
355
364
    plot                 = false;
 
365
    hidden_attrs         = false;
356
366
    formatgiven          = false;
357
367
    printByteAsChar      = false;
358
368
    for (i=0; i<MAX_DIMS; i++) {
402
412
        printf("      -f : dump using printf format \"%s\"\n", format);
403
413
    if (output_xml)
404
414
        printf("      -x : output data in XML format\n");
 
415
    if (hidden_attrs)
 
416
        printf("         : show hidden attributes in the file\n");
405
417
}
406
418
 
407
 
    void bpexit(int code, ADIOS_FILE *fp, ADIOS_GROUP *gp) {
408
 
        if (gp > 0)
409
 
            adios_gclose (gp);
 
419
    void bpexit(int code, ADIOS_FILE *fp) {
410
420
        if (fp > 0)
411
 
            adios_fclose (fp);
 
421
            adios_read_close (fp);
412
422
        exit(code);
413
423
    }
414
424
 
433
443
int print_data_hist(ADIOS_VARINFO * vi, char * varname);
434
444
int print_data_characteristics(void * min, void * max, double * avg, double * std_dev, enum ADIOS_DATATYPES adiosvartype, bool allowformat);
435
445
 
436
 
int doList(const char *path) {
437
 
    //int     ntsteps;
 
446
int     nVarsMatched=0;
438
447
 
439
 
    ADIOS_FILE  *fp;
440
 
    ADIOS_GROUP *gp; // reused for each group
 
448
int doList_group (ADIOS_FILE *fp)
 
449
{
441
450
    ADIOS_VARINFO *vi; 
 
451
    ADIOS_VARINFO **vis; 
442
452
    enum ADIOS_DATATYPES vartype;
443
 
    int     grpid, i, j, n;             // loop vars
 
453
    int     i, j, n;             // loop vars
444
454
    int     status;
445
455
    int     attrsize;                       // info about one attribute
446
456
    int     mpi_comm_dummy=0;
447
457
    bool    matches;
448
 
    int     len, maxlen;
449
 
    int     nVarsMatched=0;
450
 
    int     nGroupsMatched=0;
 
458
    int     len, maxlen, maxtypelen;
451
459
    int     retval;
452
460
    char  **names;  // vars and attrs together, sorted or unsorted
453
461
    bool   *isVar;  // true for each var, false for each attr
454
462
    int     nNames; // number of vars + attrs
455
463
    void   *value;  // scalar value is returned by get_attr
 
464
    bool    timed;  // variable has multiple timesteps
 
465
 
 
466
 
 
467
    if (attrsonly)
 
468
        nNames = fp->nattrs;
 
469
    else if (listattrs)
 
470
        nNames = fp->nvars + fp->nattrs;
 
471
    else 
 
472
        nNames = fp->nvars;
 
473
 
 
474
    /*
 
475
       if (sortnames) {
 
476
       if (!attrsonly)
 
477
       qsort(gp->var_namelist, gp->vars_count, sizeof(char *), cmpstringp);
 
478
       if (listattrs)
 
479
       qsort(gp->attr_namelist, gp->attrs_count, sizeof(char *), cmpstringp);
 
480
       }
 
481
     */
 
482
 
 
483
    names = (char **) malloc (nNames * sizeof (char*)); // store only pointers
 
484
    isVar = (bool *) malloc (nNames * sizeof (bool));
 
485
    vis   = (ADIOS_VARINFO **) malloc (nNames * sizeof (ADIOS_VARINFO*));
 
486
    if (names == NULL || isVar == NULL || vis == NULL) {
 
487
        fprintf(stderr, "Error: could not allocate char* and bool arrays of %d elements\n", nNames);
 
488
        return 5;
 
489
    }
 
490
    mergeLists(fp->nvars, fp->var_namelist, fp->nattrs, fp->attr_namelist, names, isVar);
 
491
 
 
492
    // calculate max length of variable names in the first round
 
493
    maxlen = 4;
 
494
    for (n=0; n<nNames; n++) {
 
495
        len = strlen(names[n]);
 
496
        if (len > maxlen) maxlen = len;
 
497
    }
 
498
 
 
499
    // Get VARINFO's and attr types and calculate max length of type names 
 
500
    maxtypelen = 7;
 
501
    for (n=0; n<nNames; n++) {
 
502
        if (isVar[n])  {
 
503
            vis[n] = adios_inq_var (fp, names[n]);
 
504
            if (!vis[n]) {
 
505
                fprintf(stderr, "Error: %s\n", adios_errmsg());
 
506
            }
 
507
            vartype = vis[n]->type;
 
508
        } else {
 
509
            retval = adios_get_attr (fp, names[n], &vartype, &attrsize, &value);
 
510
            if (retval) {
 
511
                fprintf(stderr, "Error: %s\n", adios_errmsg());
 
512
            }
 
513
        }
 
514
        len = strlen(adios_type_to_string(vartype));
 
515
        if (len > maxtypelen) maxtypelen = len;
 
516
    }
 
517
 
 
518
    /* VARIABLES */
 
519
    for (n=0; n<nNames; n++) {
 
520
        matches = false;
 
521
        if (isVar[n])  {
 
522
            vi = vis[n];
 
523
            vartype = vi->type;
 
524
            //timed = adios_read_bp_is_var_timed(fp, vi->varid);
 
525
            timed = (vi->nsteps > 1);
 
526
        } else {
 
527
            retval = adios_get_attr (fp, names[n], &vartype, &attrsize, &value);
 
528
            if (retval) {
 
529
                fprintf(stderr, "Error: %s\n", adios_errmsg());
 
530
            }
 
531
        }
 
532
 
 
533
        matches = matchesAMask(names[n]);
 
534
 
 
535
        if (matches) {
 
536
            nVarsMatched++;
 
537
 
 
538
            // print definition of variable
 
539
            fprintf(outf,"%c %-*s  %-*s", commentchar, maxtypelen, 
 
540
                    adios_type_to_string(vartype), maxlen, names[n]); 
 
541
            if (!isVar[n]) {
 
542
                // list (and print) attribute
 
543
                if (readattrs || dump) {
 
544
                    fprintf(outf,"  attr   = ");
 
545
                    print_data(value, 0, vartype, false); 
 
546
                    fprintf(outf,"\n");
 
547
                    matches = false; // already printed
 
548
                } else {
 
549
                    fprintf(outf,"  attr\n");
 
550
                }
 
551
            } else if (!vi) { 
 
552
                // after error
 
553
                fprintf(outf, "\n");
 
554
            } else if (vi->ndim > 0 || timed) {
 
555
                // array
 
556
                //fprintf(outf,"  {%s%d", (vi->timedim==0 ? "T-": ""),vi->dims[0]);
 
557
 
 
558
                fprintf(outf,"  ");
 
559
                if (timed) 
 
560
                    fprintf(outf, "%d*", vi->nsteps);
 
561
                if (vi->ndim > 0) {
 
562
                    fprintf(outf,"{%lld", vi->dims[0]);
 
563
                    for (j=1; j < vi->ndim; j++) {
 
564
                        fprintf(outf,", %lld", vi->dims[j]);
 
565
                    }
 
566
                    fprintf(outf,"}");
 
567
                } else {
 
568
                    fprintf(outf,"scalar");
 
569
                }
 
570
 
 
571
                if (longopt || plot) {
 
572
                    status = adios_inq_var_stat (fp, vi, timestep && timed, 0);
 
573
                }
 
574
 
 
575
                if (plot && vi->statistics && vi->statistics->histogram) {
 
576
                    print_data_hist(vi, &names[n][1]);
 
577
                }
 
578
 
 
579
 
 
580
                if (longopt && vi->statistics) {
 
581
 
 
582
                    if(timestep == false || timed == false ) {
 
583
 
 
584
                        fprintf(outf," = ");
 
585
                        print_data(vi->statistics->min, 0, vartype, false); 
 
586
 
 
587
                        fprintf(outf,"/ ");
 
588
                        print_data(vi->statistics->max, 0, vartype, false); 
 
589
 
 
590
                        if(vartype == adios_complex || vartype == adios_double_complex) {
 
591
 
 
592
                            fprintf(outf,"/ ");
 
593
                            print_data(vi->statistics->avg, 0, adios_double_complex, false);
 
594
                        } else {
 
595
 
 
596
                            fprintf(outf,"/ ");
 
597
                            print_data(vi->statistics->avg, 0, adios_double, false);
 
598
                        }
 
599
 
 
600
                        if(vartype == adios_complex || vartype == adios_double_complex) {
 
601
 
 
602
                            fprintf(outf,"/ ");
 
603
                            print_data(vi->statistics->std_dev, 0, adios_double_complex, false);
 
604
                        } else {
 
605
 
 
606
                            fprintf(outf,"/ ");
 
607
                            print_data(vi->statistics->std_dev, 0, adios_double, false);
 
608
                        }
 
609
 
 
610
                        //fprintf(outf," {MIN / MAX / AVG / STD_DEV} ");
 
611
                    } else {
 
612
                        int time_start = 0, time_end = vi->nsteps;
 
613
 
 
614
                        if (start != NULL) {
 
615
                            if (istart[0] >= 0)
 
616
                                time_start = istart[0];
 
617
                            else
 
618
                                time_start = vi->nsteps - 1 + istart[0];
 
619
                        }
 
620
 
 
621
                        if (count != NULL) {
 
622
                            if(icount[0] > 0)
 
623
                                time_end = time_start + icount[0];
 
624
                            else
 
625
                                time_end = vi->nsteps + icount[0] + 1;
 
626
                        }
 
627
 
 
628
                        if (time_start < 0 || time_start >= vi->nsteps) {
 
629
                            fprintf (stderr, "Error when reading variable %s. errno=%d : Variable (id=%d) has no data at %d time step\n", names[n], 15, vi->varid, time_start);
 
630
                            bpexit(15,fp);
 
631
                        }
 
632
 
 
633
                        if (time_end < 0 || time_end > vi->nsteps) {
 
634
                            fprintf (stderr, "Error when reading variable %s. errno=%d : Variable (id=%d) has no data at %d time step\n", names[n], 15, vi->varid, time_end);
 
635
                            bpexit(16,fp);
 
636
                        }
 
637
 
 
638
                        static char *indent_char = " ";
 
639
                        int indent_len=11;
 
640
 
 
641
                        /* Start - Print the headers of statistics first */
 
642
                        fprintf(outf, "\n%-*s", indent_len+7, indent_char);
 
643
                        fprintf(outf, "%10s  ", "MIN");
 
644
                        fprintf(outf, "%10s  ", "MAX");
 
645
                        fprintf(outf, "%10s  ", "AVG");
 
646
                        fprintf(outf, "%10s  ", "STD DEV");
 
647
 
 
648
                        /* End - Print the headers of statistics first */
 
649
 
 
650
                        void *min, *max, *avg, *std_dev;
 
651
                        enum ADIOS_DATATYPES vt = vartype;
 
652
                        struct ADIOS_STAT_STEP *s = vi->statistics->steps;
 
653
                        if (vi->type == adios_complex || vi->type == adios_double_complex)
 
654
                            vt = adios_double;
 
655
                        fprintf(outf, "\n%-*sglobal:", indent_len, indent_char);
 
656
                        print_data_characteristics (vi->statistics->min, 
 
657
                                vi->statistics->max, 
 
658
                                vi->statistics->avg, 
 
659
                                vi->statistics->std_dev, 
 
660
                                vt, false);
 
661
 
 
662
                        for(i = time_start; i < time_end; i++) {
 
663
                            min = max = avg = std_dev = 0;
 
664
                            if (s->maxs && s->maxs[i]) max = s->maxs[i];
 
665
                            if (s->mins && s->mins[i]) min = s->mins[i];
 
666
                            if (s->avgs && s->avgs[i]) avg = s->avgs[i];
 
667
                            if (s->std_devs && s->std_devs[i]) std_dev = s->std_devs[i];
 
668
 
 
669
                            // Align the output, previous lines has atleast (maxlen + strlen(names[n])) characters
 
670
                            // Better way to printf N spaces?
 
671
                            fprintf(outf, "\n%-*st%-5d:", indent_len, indent_char, i);
 
672
                            print_data_characteristics(min, max, avg, std_dev, vt, false);
 
673
                        }
 
674
                        fprintf(outf, "\n");
 
675
                    }
 
676
                } // longopt && vi->statistics 
 
677
                fprintf(outf,"\n");
 
678
            } else {
 
679
                // scalar
 
680
                fprintf(outf,"  scalar");
 
681
                if (longopt && vi->value) {
 
682
                    fprintf(outf," = ");
 
683
                    print_data(vi->value, 0, vartype, false); 
 
684
                    matches = false; // already printed
 
685
                }
 
686
                fprintf(outf,"\n");
 
687
            }
 
688
        }
 
689
 
 
690
        if (matches && dump) {
 
691
            // print variable content 
 
692
            if (isVar[n])
 
693
                retval = readVar(fp, vi, names[n], timed);
 
694
            if (retval && retval != 10) // do not return after unsupported type
 
695
                return retval;
 
696
            fprintf(outf,"\n");
 
697
        }
 
698
 
 
699
        //if (isVar[n])
 
700
        //    adios_free_varinfo(vi);
 
701
        //else
 
702
        if (!isVar[n])
 
703
            free(value);
 
704
    }
 
705
    /* Free ADIOS_VARINFOs */
 
706
    for (n=0; n<nNames; n++) {
 
707
        if (isVar[n])  {
 
708
            adios_free_varinfo(vis[n]);
 
709
        }
 
710
    }
 
711
    free(names);
 
712
    free(isVar);
 
713
    return 0;
 
714
}                
 
715
 
 
716
 
 
717
int doList(const char *path) {
 
718
    ADIOS_FILE  *fp;
 
719
    int     grpid;     // loop vars
 
720
    int     status;
 
721
    int     mpi_comm_dummy=0;
 
722
    int     nGroupsMatched=0;
 
723
    int     nGroups; // number of groups
 
724
    char  **group_namelist;
 
725
    char    init_params[128];
456
726
 
457
727
    if (verbose>1) printf("\nADIOS BP open: read header info from %s\n", path);
458
728
 
 
729
    // initialize BP reader
 
730
    strcpy (init_params, "verbose=2");
 
731
    if (hidden_attrs)
 
732
        strcat (init_params, ";show_hidden_attrs");
 
733
    status = adios_read_init_method (ADIOS_READ_METHOD_BP, mpi_comm_dummy, init_params);
 
734
    if (status) {
 
735
        fprintf(stderr, "Error: %s\n", adios_errmsg());
 
736
        bpexit(6, 0);
 
737
    }
 
738
 
459
739
    // open the BP file
460
 
    fp = adios_fopen (path, mpi_comm_dummy); 
 
740
    fp = adios_read_open_file (path, ADIOS_READ_METHOD_BP, mpi_comm_dummy); 
461
741
    if (fp == NULL) {
462
742
        fprintf(stderr, "Error: %s\n", adios_errmsg());
463
 
        bpexit(7, 0, 0);
 
743
        bpexit(7, 0);
464
744
    }
465
745
 
466
 
    // get number of groups, variables, timesteps, and attributes 
 
746
    // get number of groups
 
747
    nGroups = adios_get_grouplist (fp, &group_namelist);
 
748
 
 
749
    //, variables, timesteps, and attributes 
467
750
    // all parameters are integers, 
468
751
    // besides the last parameter, which is an array of strings for holding the list of group names
469
752
    //ntsteps = fp->tidx_stop - fp->tidx_start + 1;
470
753
    if (verbose) {
471
754
        printf ("File info:\n");
472
 
        printf ("  of groups:     %d\n", fp->groups_count);
473
 
        printf ("  of variables:  %d\n", fp->vars_count);
474
 
        printf ("  of attributes: %d\n", fp->attrs_count);
475
 
        printf ("  time steps:    %d starting from %d\n", fp->ntimesteps, fp->tidx_start);
 
755
        printf ("  of groups:     %d\n", nGroups);
 
756
        printf ("  of variables:  %d\n", fp->nvars);
 
757
        printf ("  of attributes: %d\n", fp->nattrs);
 
758
        printf ("  time steps:    %d - %d\n", fp->current_step, fp->last_step);
476
759
        print_file_size(fp->file_size);
477
760
        printf ("  bp version:    %d\n", fp->version);
478
761
        printf ("  endianness:    %s\n", (fp->endianness ? "Big Endian" : "Little Endian"));
482
765
    }
483
766
 
484
767
 
485
 
    // each group has to be handled separately
486
 
    for (grpid=0; grpid < fp->groups_count; grpid++) {
487
 
        if (!grpMatchesMask(fp->group_namelist[grpid]))
488
 
            continue;
489
 
        nGroupsMatched++;
490
 
        if (!dump) fprintf(outf, "Group %s:\n", fp->group_namelist[grpid]);
491
 
        gp = adios_gopen_byid (fp, grpid);
492
 
        if (gp == NULL) {
493
 
            fprintf(stderr, "Error: %s\n", adios_errmsg());
494
 
            bpexit(8, fp, 0);
495
 
        }
496
 
 
497
 
        if (sortnames) {
498
 
            if (!attrsonly)
499
 
                qsort(gp->var_namelist, gp->vars_count, sizeof(char *), cmpstringp);
500
 
            if (listattrs)
501
 
                qsort(gp->attr_namelist, gp->attrs_count, sizeof(char *), cmpstringp);
502
 
        }
503
 
 
504
 
        if (attrsonly)
505
 
            nNames = gp->attrs_count;
506
 
        else if (listattrs)
507
 
            nNames = gp->vars_count + gp->attrs_count;
508
 
        else 
509
 
            nNames = gp->vars_count;
510
 
        names = (char **) malloc (nNames * sizeof (char*)); // store only pointers
511
 
        isVar = (bool *) malloc (nNames * sizeof (bool));
512
 
        if (names == NULL || isVar == NULL) {
513
 
            fprintf(stderr, "Error: could not allocate char* and bool arrays of %d elements\n", nNames);
514
 
            return 5;
515
 
        }
516
 
        mergeLists(gp->vars_count, gp->var_namelist, gp->attrs_count, gp->attr_namelist,
517
 
                names, isVar);
518
 
 
519
 
        // calculate max length of variable names in the first round
520
 
        maxlen = 4;
521
 
        for (n=0; n<nNames; n++) {
522
 
            len = strlen(names[n]);
523
 
            if (len > maxlen) maxlen = len;
524
 
        }
525
 
 
526
 
        /* VARIABLES */
527
 
        for (n=0; n<nNames; n++) {
528
 
            matches = false;
529
 
            if (isVar[n])  {
530
 
                vi = adios_inq_var (gp, names[n]);
531
 
                if (!vi) {
532
 
                    fprintf(stderr, "Error: %s\n", adios_errmsg());
533
 
                }
534
 
                vartype = vi->type;
535
 
            } else {
536
 
                retval = adios_get_attr (gp, names[n], &vartype, &attrsize, &value);
537
 
                if (retval) {
538
 
                    fprintf(stderr, "Error: %s\n", adios_errmsg());
539
 
                }
540
 
            }
541
 
 
542
 
            matches = matchesAMask(names[n]);
543
 
 
544
 
            if (matches) {
545
 
                nVarsMatched++;
546
 
                // print definition of variable
547
 
                fprintf(outf,"%c %-*s  %-*s", commentchar, 9, adios_type_to_string(vartype), maxlen, names[n]); 
548
 
                if (!isVar[n]) {
549
 
                    // list (and print) attribute
550
 
                    if (readattrs || dump) {
551
 
                        fprintf(outf,"  attr   = ");
552
 
                        print_data(value, 0, vartype, false); 
553
 
                        fprintf(outf,"\n");
554
 
                        matches = false; // already printed
555
 
                    } else {
556
 
                        fprintf(outf,"  attr\n");
557
 
                    }
558
 
                } else if (!vi) { 
559
 
                    // after error
560
 
                    fprintf(outf, "\n");
561
 
                } else if (vi->ndim > 0) {
562
 
                    // array
563
 
                    //fprintf(outf,"  {%s%d", (vi->timedim==0 ? "T-": ""),vi->dims[0]);
564
 
                    fprintf(outf,"  {%lld", vi->dims[0]);
565
 
                    for (j=1; j < vi->ndim; j++) {
566
 
                        fprintf(outf,", %lld", vi->dims[j]);
567
 
                    }
568
 
                    fprintf(outf,"}");
569
 
 
570
 
                    if (vi->hist && plot) {
571
 
                        print_data_hist(vi, &names[n][1]);
572
 
                    }
573
 
 
574
 
                    if (longopt && vi->gmin && vi->gmax) {
575
 
 
576
 
                        if(timestep == false || (vi->timedim < 0)) {    
577
 
 
578
 
                            fprintf(outf," = ");
579
 
                            print_data(vi->gmin, 0, vartype, false); 
580
 
 
581
 
                            fprintf(outf,"/ ");
582
 
                            print_data(vi->gmax, 0, vartype, false); 
583
 
 
584
 
                            if(vartype == adios_complex || vartype == adios_double_complex) {
585
 
 
586
 
                                fprintf(outf,"/ ");
587
 
                                print_data(vi->gavg, 0, adios_double_complex, false);
588
 
                            } else {
589
 
 
590
 
                                fprintf(outf,"/ ");
591
 
                                print_data(vi->gavg, 0, adios_double, false);
592
 
                            }
593
 
 
594
 
                            if(vartype == adios_complex || vartype == adios_double_complex) {
595
 
 
596
 
                                fprintf(outf,"/ ");
597
 
                                print_data(vi->gstd_dev, 0, adios_double_complex, false);
598
 
                            } else {
599
 
 
600
 
                                fprintf(outf,"/ ");
601
 
                                print_data(vi->gstd_dev, 0, adios_double, false);
602
 
                            }
603
 
 
604
 
                            //fprintf(outf," {MIN / MAX / AVG / STD_DEV} ");
605
 
                        } else {
606
 
                            int time_start = 0, time_end = vi->dims[0];
607
 
 
608
 
                            if (start != NULL) {
609
 
                                if (istart[0] >= 0)
610
 
                                    time_start = istart[0];
611
 
                                else
612
 
                                    time_start = vi->dims[0] - 1 + istart[0];
613
 
                            }
614
 
 
615
 
                            if (count != NULL) {
616
 
                                if(icount[0] > 0)
617
 
                                    time_end = time_start + icount[0];
618
 
                                else
619
 
                                    time_end = vi->dims[0] + icount[0] + 1;
620
 
                            }
621
 
 
622
 
                            if (time_start < 0 || time_start >= vi->dims[0]) {
623
 
                                fprintf (stderr, "Error when reading variable %s. errno=%d : Variable (id=%d) has no data at %d time step\n", names[n], 15, vi->varid, time_start);
624
 
                                return 15;
625
 
                            }
626
 
 
627
 
                            if (time_end < 0 || time_end > vi->dims[0]) {
628
 
                                fprintf (stderr, "Error when reading variable %s. errno=%d : Variable (id=%d) has no data at %d time step\n", names[n], 15, vi->varid, time_end);
629
 
                                return 15;
630
 
                            }
631
 
 
632
 
                            static char *indent_char = " ";
633
 
                            int indent_len=11;
634
 
 
635
 
                            /* Start - Print the headers of statistics first */
636
 
                            fprintf(outf, "\n%-*s", indent_len+7, indent_char);
637
 
                            fprintf(outf, "%10s  ", "MIN");
638
 
                            fprintf(outf, "%10s  ", "MAX");
639
 
                            fprintf(outf, "%10s  ", "AVG");
640
 
                            fprintf(outf, "%10s  ", "STD DEV");
641
 
 
642
 
                            /* End - Print the headers of statistics first */
643
 
 
644
 
                            void *min, *max, *avg, *std_dev;
645
 
                            enum ADIOS_DATATYPES vt = vartype;
646
 
                            if (vi->type == adios_complex || vi->type == adios_double_complex)
647
 
                                vt = adios_double;
648
 
                            fprintf(outf, "\n%-*sglobal:", indent_len, indent_char);
649
 
                            print_data_characteristics(vi->gmin, vi->gmax, vi->gavg, vi->gstd_dev, vt, false);
650
 
 
651
 
                            for(i = time_start; i < time_end; i++) {
652
 
                                min = max = avg = std_dev = 0;
653
 
                                if (vi->maxs && vi->maxs[i]) max = vi->maxs[i];
654
 
                                if (vi->mins && vi->mins[i]) min = vi->mins[i];
655
 
                                if (vi->avgs && vi->avgs[i]) avg = vi->avgs[i];
656
 
                                if (vi->std_devs && vi->std_devs[i]) std_dev = vi->std_devs[i];
657
 
 
658
 
                                // Align the output, previous lines has atleast (maxlen + strlen(names[n])) characters
659
 
                                // Better way to printf N spaces?
660
 
                                fprintf(outf, "\n%-*st%-5d:", indent_len, indent_char, i);
661
 
                                print_data_characteristics(min, max, avg, std_dev, vt, false);
662
 
                            }
663
 
                            fprintf(outf, "\n");
664
 
                        }
665
 
                    }
666
 
                    fprintf(outf,"\n");
667
 
                } else {
668
 
                    // scalar
669
 
                    fprintf(outf,"  scalar");
670
 
                    if (longopt && vi->value) {
671
 
                        fprintf(outf," = ");
672
 
                        print_data(vi->value, 0, vartype, false); 
673
 
                        matches = false; // already printed
674
 
                    }
675
 
                    fprintf(outf,"\n");
676
 
                }
677
 
            }
678
 
 
679
 
            if (matches && dump) {
680
 
                // print variable content 
681
 
                if (isVar[n])
682
 
                    retval = readVar(gp, vi, names[n]);
683
 
                if (retval && retval != 10) // do not return after unsupported type
684
 
                    return retval;
685
 
                fprintf(outf,"\n");
686
 
            }
687
 
 
688
 
            if (isVar[n])
689
 
                adios_free_varinfo(vi);
690
 
            else
691
 
                free(value);
692
 
        }
693
 
        adios_gclose (gp);
694
 
        free(names);
695
 
        free(isVar);
 
768
    if (grpmask) {
 
769
        // each group has to be handled separately
 
770
        for (grpid=0; grpid < nGroups; grpid++) {
 
771
            if (!grpMatchesMask(group_namelist[grpid]))
 
772
                continue;
 
773
            nGroupsMatched++;
 
774
            if (!dump) fprintf(outf, "Group %s:\n", group_namelist[grpid]);
 
775
            status = adios_group_view (fp, grpid);
 
776
            if (status) {
 
777
                fprintf(stderr, "Error: %s\n", adios_errmsg());
 
778
                bpexit(8, fp);
 
779
            }
 
780
 
 
781
            doList_group (fp);
 
782
 
 
783
            adios_group_view (fp, -1); // reset full view (for next group view)
 
784
        }
 
785
    } else {
 
786
        doList_group (fp);
696
787
    }
697
788
 
698
789
    if (grpmask != NULL && nGroupsMatched == 0) {
703
794
        fprintf(stderr, "\nError: None of the variables matched any name/regexp you provided\n");
704
795
        return 4;
705
796
    }
706
 
    adios_fclose (fp);
 
797
    adios_read_close (fp);
707
798
    return 0;
708
 
}                
 
799
}
 
800
 
 
801
 
709
802
 
710
803
int print_data_hist(ADIOS_VARINFO * vi, char * varname)
711
804
{
713
806
    int i;
714
807
    char xtics[512], str[512];
715
808
    FILE * out_hist, * out_plot;
 
809
    struct ADIOS_HIST *h = vi->statistics->histogram;
716
810
 
717
811
    memcpy(hist_file,  varname, strlen(varname) + 1);    
718
812
    strcat(hist_file, ".hist");
734
828
 
735
829
    xtics[0] = '\0';
736
830
    strcat(xtics, "set xtics offset start axis (");
737
 
    for (i = 0; i <= vi->hist->num_breaks; i++)
 
831
    for (i = 0; i <= h->num_breaks; i++)
738
832
    {
739
833
        if (i == 0)
740
834
        {
741
 
            fprintf(out_hist, "-Inf %.2lf %u\n", vi->hist->breaks[i], vi->hist->gfrequencies[i]);
 
835
            fprintf(out_hist, "-Inf %.2lf %u\n", h->breaks[i], h->gfrequencies[i]);
742
836
            sprintf(str, "\"-Inf\" pos(%d)", i); 
743
837
        }
744
 
        else if (i < vi->hist->num_breaks)
 
838
        else if (i < h->num_breaks)
745
839
        {
746
 
            fprintf(out_hist, "%.2lf %.2lf %u\n", vi->hist->breaks[i - 1], vi->hist->breaks[i], vi->hist->gfrequencies[i]);
747
 
            sprintf(str, ", \"%.2lf\" pos(%d)", vi->hist->breaks[i - 1], i); 
 
840
            fprintf(out_hist, "%.2lf %.2lf %u\n", h->breaks[i - 1], h->breaks[i], h->gfrequencies[i]);
 
841
            sprintf(str, ", \"%.2lf\" pos(%d)", h->breaks[i - 1], i); 
748
842
        }
749
843
        else     
750
844
        {
751
 
            fprintf(out_hist, "%.2lf Inf %u\n", vi->hist->breaks[i], vi->hist->gfrequencies[i]);
 
845
            fprintf(out_hist, "%.2lf Inf %u\n", h->breaks[i], h->gfrequencies[i]);
752
846
            sprintf(str, ", \"Inf\" pos(%d)", i); 
753
847
        }
754
848
        strcat(xtics, str);
872
966
/** Read data of a variable and print 
873
967
 * Return: 0: ok, != 0 on error
874
968
 */
875
 
int readVar(ADIOS_GROUP *gp, ADIOS_VARINFO *vi, const char * name)
 
969
int readVar(ADIOS_FILE *fp, ADIOS_VARINFO *vi, const char * name, bool timed)
876
970
{
877
971
    int i,j;
878
972
    uint64_t start_t[MAX_DIMS], count_t[MAX_DIMS]; // processed <0 values in start/count
879
973
    uint64_t s[MAX_DIMS], c[MAX_DIMS]; // for block reading of smaller chunks
 
974
    int tdims;               // number of dimensions including time
 
975
    int tidx;                // 0 or 1 to account for time dimension
880
976
    uint64_t nelems;         // number of elements to read
881
977
    int elemsize;            // size in bytes of one element
882
978
    uint64_t st, ct;
885
981
    int  maxreadn;          // max number of elements to read once up to a limit (10MB of data)
886
982
    int  actualreadn;       // our decision how much to read at once
887
983
    int  readn[MAX_DIMS];   // how big chunk to read in in each dimension?
888
 
    int64_t bytes_read;     // retval from adios_get_var()
 
984
    int  status;            
889
985
    bool incdim;            // used in incremental reading in
 
986
    ADIOS_SELECTION * sel;  // boundnig box to read
890
987
 
891
988
    if (getTypeInfo(vi->type, &elemsize)) {
892
989
        fprintf(stderr, "Adios type %d (%s) not supported in bpls. var=%s\n", 
898
995
    // transfer start and count arrays to format dependent arrays
899
996
 
900
997
    nelems = 1;
 
998
    tidx = 0;
 
999
 
 
1000
    if (timed) {
 
1001
        if (istart[0] < 0)  // negative index means last-|index|
 
1002
            st = vi->nsteps+istart[0];
 
1003
        else
 
1004
            st = istart[0];
 
1005
        if (icount[0] < 0)  // negative index means last-|index|+1-start
 
1006
            ct = vi->nsteps+icount[0]+1-st;
 
1007
        else
 
1008
            ct = icount[0];
 
1009
 
 
1010
        if (verbose>2) 
 
1011
            printf("    j=0, st=%llu ct=%llu\n", st, ct);
 
1012
 
 
1013
        start_t[0] = st;
 
1014
        count_t[0] = ct;
 
1015
        nelems *= ct;
 
1016
        if (verbose>1) 
 
1017
            printf("    s[0]=%llu, c[0]=%llu, n=%llu\n", 
 
1018
                    start_t[0], count_t[0], nelems);
 
1019
        
 
1020
        tidx = 1;
 
1021
    }
 
1022
    tdims = vi->ndim + tidx;
 
1023
 
901
1024
    for (j=0; j<vi->ndim; j++) {
902
 
        if (istart[j] < 0)  // negative index means last-|index|
903
 
            st = vi->dims[j]+istart[j];
904
 
        else
905
 
            st = istart[j];
906
 
        if (icount[j] < 0)  // negative index means last-|index|+1-start
907
 
            ct = vi->dims[j]+icount[j]+1-st;
908
 
        else
909
 
            ct = icount[j];
 
1025
        if (istart[j+tidx] < 0)  // negative index means last-|index|
 
1026
            st = vi->dims[j]+istart[j+tidx];
 
1027
        else
 
1028
            st = istart[j+tidx];
 
1029
        if (icount[j+tidx] < 0)  // negative index means last-|index|+1-start
 
1030
            ct = vi->dims[j]+icount[j+tidx]+1-st;
 
1031
        else
 
1032
            ct = icount[j+tidx];
910
1033
 
911
1034
        if (verbose>2) 
912
 
            printf("    j=%d, st=%llu ct=%llu\n", j, st, ct);
 
1035
            printf("    j=%d, st=%llu ct=%llu\n", j+tidx, st, ct);
913
1036
 
914
 
        start_t[j] = st;
915
 
        count_t[j] = ct;
 
1037
        start_t[j+tidx] = st;
 
1038
        count_t[j+tidx] = ct;
916
1039
        nelems *= ct;
917
1040
        if (verbose>1) 
918
 
            printf("    s[%d]=%llu, c[%d]=%llu, n=%llu\n", j, start_t[j], j, count_t[j], nelems);
 
1041
            printf("    s[%d]=%llu, c[%d]=%llu, n=%llu\n", 
 
1042
                    j+tidx, start_t[j+tidx], j+tidx, count_t[j+tidx], nelems);
919
1043
    }
920
1044
 
921
1045
    if (verbose>1) {
922
1046
        printf(" total size of data to read = %llu\n", nelems*elemsize);
923
1047
    }
924
1048
 
925
 
    print_slice_info(vi->ndim, vi->dims, start_t, count_t);
 
1049
    print_slice_info(vi->ndim, vi->dims, timed, vi->nsteps, start_t, count_t);
926
1050
 
927
1051
    maxreadn = MAX_BUFFERSIZE/elemsize;
928
1052
    if (nelems < maxreadn)
946
1070
    if (verbose>1) printf("Read size strategy:\n");
947
1071
    sum = (uint64_t) 1;
948
1072
    actualreadn = (uint64_t) 1;
949
 
    for (i=vi->ndim-1; i>=0; i--) {
 
1073
    for (i=tdims-1; i>=0; i--) {
950
1074
        if (sum >= (uint64_t) maxreadn) {
951
1075
            readn[i] = 1;
952
1076
        } else {
963
1087
 
964
1088
 
965
1089
    // init s and c
966
 
    for (j=0; j<vi->ndim; j++) {
 
1090
    for (j=0; j<tdims; j++) {
967
1091
        s[j]=start_t[j];
968
1092
        c[j]=readn[j];
969
1093
    }
974
1098
 
975
1099
        // how many elements do we read in next?
976
1100
        actualreadn = 1;
977
 
        for (j=0; j<vi->ndim; j++) 
 
1101
        for (j=0; j<tdims; j++) 
978
1102
            actualreadn *= c[j];
979
1103
 
980
1104
        if (verbose>2) {
981
1105
            printf("adios_read_var name=%s ", name);
982
 
            PRINT_DIMS("  start", s, vi->ndim, j); 
983
 
            PRINT_DIMS("  count", c, vi->ndim, j); 
 
1106
            PRINT_DIMS("  start", s, tdims, j); 
 
1107
            PRINT_DIMS("  count", c, tdims, j); 
984
1108
            printf("  read %d elems\n", actualreadn);
985
1109
        }
986
1110
 
987
1111
        // read a slice finally
988
 
        bytes_read = adios_read_var_byid (gp, vi->varid, s, c, data); 
989
 
 
990
 
        if (bytes_read < 0) {
 
1112
        sel = adios_selection_boundingbox (vi->ndim, s+tidx, c+tidx);
 
1113
        if (timed) {
 
1114
            status = adios_schedule_read_byid (fp, sel, vi->varid, s[0], c[0], data); 
 
1115
        } else {
 
1116
            status = adios_schedule_read_byid (fp, sel, vi->varid, 0, 1, data); 
 
1117
        }
 
1118
 
 
1119
        if (status < 0) {
 
1120
            fprintf(stderr, "Error when scheduling variable %s for reading. errno=%d : %s \n", name, adios_errno, adios_errmsg());
 
1121
            free(data);
 
1122
            return 11;
 
1123
        }
 
1124
 
 
1125
        status = adios_perform_reads (fp, 1); // blocking read performed here
 
1126
        if (status < 0) {
991
1127
            fprintf(stderr, "Error when reading variable %s. errno=%d : %s \n", name, adios_errno, adios_errmsg());
992
1128
            free(data);
993
1129
            return 11;
994
1130
        }
995
1131
 
996
 
        if (verbose>2) printf("  read %lld bytes\n", bytes_read);
 
1132
        //if (verbose>2) printf("  read %lld bytes\n", bytes_read);
997
1133
 
998
1134
        // print slice
999
 
        print_dataset(data, vi->type, s, c, vi->ndim, vi->dims); 
 
1135
        print_dataset(data, vi->type, s, c, tdims); 
1000
1136
 
1001
1137
        // prepare for next read
1002
1138
        sum += actualreadn;
1003
1139
        incdim=true; // largest dim should be increased 
1004
 
        for (j=vi->ndim-1; j>=0; j--) {
 
1140
        for (j=tdims-1; j>=0; j--) {
1005
1141
            if (incdim) {
1006
1142
                if (s[j]+c[j] == start_t[j]+count_t[j]) {
1007
1143
                    // reached the end of this dimension
1120
1256
 
1121
1257
static int nextcol=0;  // column index to start with (can have lines split in two calls)
1122
1258
 
1123
 
void print_slice_info(int ndim, uint64_t *dims, uint64_t *s, uint64_t *c)
 
1259
void print_slice_info(int ndim, uint64_t *dims, int timed, int nsteps, uint64_t *s, uint64_t *c)
1124
1260
{
1125
1261
    // print the slice info in indexing is on and 
1126
1262
    // not the complete variable is read
1127
1263
    int i;
1128
1264
    bool isaslice = false;
 
1265
    int tidx = (timed == true);
 
1266
    int tdim = ndim + tidx;
 
1267
    if (timed) {
 
1268
        if (c[0] < nsteps) 
 
1269
            isaslice = true;
 
1270
    }
1129
1271
    for (i=0; i<ndim; i++) {
1130
 
        if (c[i] < dims[i])
 
1272
        if (c[i+tidx] < dims[i])
1131
1273
            isaslice = true;
1132
1274
    }
1133
1275
    if (isaslice) {
1134
1276
        fprintf(outf,"%c   slice (%lld:%lld", commentchar, s[0], s[0]+c[0]-1);
1135
 
        for (i=1; i<ndim; i++) {
 
1277
        for (i=1; i<tdim; i++) {
1136
1278
            fprintf(outf,", %lld:%lld", s[i], s[i]+c[i]-1);
1137
1279
        }
1138
1280
        fprintf(outf,")\n");
1367
1509
}
1368
1510
 
1369
1511
int print_dataset(void *data, enum ADIOS_DATATYPES adiosvartype, 
1370
 
        uint64_t *s, uint64_t *c, int ndim, uint64_t *dims)
 
1512
        uint64_t *s, uint64_t *c, int tdims)
1371
1513
{
1372
1514
    int i,item, steps;
1373
1515
    char idxstr[128], vstr[128], buf[16];
1376
1518
 
1377
1519
    // init current indices
1378
1520
    steps = 1;
1379
 
    for (i=0; i<ndim; i++) {
 
1521
    for (i=0; i<tdims; i++) {
1380
1522
        ids[i] = s[i];
1381
1523
        steps *= c[i];
1382
1524
    }
1388
1530
        // print indices if needed into idxstr;
1389
1531
        idxstr[0] = '\0'; // empty idx string
1390
1532
        if (nextcol == 0) {
1391
 
            if (!noindex && ndim > 0) {
 
1533
            if (!noindex && tdims > 0) {
1392
1534
                sprintf(idxstr,"    (%lld",ids[0]);
1393
 
                for (i=1; i<ndim; i++) {
 
1535
                for (i=1; i<tdims; i++) {
1394
1536
                    sprintf(buf,",%lld",ids[i]);
1395
1537
                    strcat(idxstr, buf);
1396
1538
                }
1402
1544
        fprintf(outf, "%s", idxstr);
1403
1545
        if (printByteAsChar && (adiosvartype == adios_byte || adiosvartype == adios_unsigned_byte)) {
1404
1546
            /* special case: k-D byte array printed as (k-1)D array of strings */
1405
 
            if (ndim == 0) {
 
1547
            if (tdims == 0) {
1406
1548
                print_data_as_string(data, steps, adiosvartype);
1407
1549
            } else {
1408
 
                print_data_as_string(data+item, c[ndim-1], adiosvartype); // print data of last dim as string
1409
 
                item += c[ndim-1]-1; // will be ++-ed once below
1410
 
                ids[ndim-1] = s[ndim-1]+c[ndim-1]-1; // will be rolled below
 
1550
                print_data_as_string(data+item, c[tdims-1], adiosvartype); // print data of last dim as string
 
1551
                item += c[tdims-1]-1; // will be ++-ed once below
 
1552
                ids[tdims-1] = s[tdims-1]+c[tdims-1]-1; // will be rolled below
1411
1553
            }
1412
1554
            nextcol = ncols-1; // force new line, will be ++-ed once below
1413
1555
        } else {
1424
1566
        // increment indices
1425
1567
        item++;
1426
1568
        roll = true;
1427
 
        for (i=ndim-1; i>=0; i--) {
 
1569
        for (i=tdims-1; i>=0; i--) {
1428
1570
            if (roll) {
1429
1571
                if (ids[i] == s[i]+c[i]-1 ) {
1430
1572
                    // last index in this dimension, roll upward