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);
436
int doList(const char *path) {
440
ADIOS_GROUP *gp; // reused for each group
448
int doList_group (ADIOS_FILE *fp)
441
450
ADIOS_VARINFO *vi;
442
452
enum ADIOS_DATATYPES vartype;
443
int grpid, i, j, n; // loop vars
453
int i, j, n; // loop vars
445
455
int attrsize; // info about one attribute
446
456
int mpi_comm_dummy=0;
450
int nGroupsMatched=0;
458
int len, maxlen, maxtypelen;
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
470
nNames = fp->nvars + fp->nattrs;
477
qsort(gp->var_namelist, gp->vars_count, sizeof(char *), cmpstringp);
479
qsort(gp->attr_namelist, gp->attrs_count, sizeof(char *), cmpstringp);
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);
490
mergeLists(fp->nvars, fp->var_namelist, fp->nattrs, fp->attr_namelist, names, isVar);
492
// calculate max length of variable names in the first round
494
for (n=0; n<nNames; n++) {
495
len = strlen(names[n]);
496
if (len > maxlen) maxlen = len;
499
// Get VARINFO's and attr types and calculate max length of type names
501
for (n=0; n<nNames; n++) {
503
vis[n] = adios_inq_var (fp, names[n]);
505
fprintf(stderr, "Error: %s\n", adios_errmsg());
507
vartype = vis[n]->type;
509
retval = adios_get_attr (fp, names[n], &vartype, &attrsize, &value);
511
fprintf(stderr, "Error: %s\n", adios_errmsg());
514
len = strlen(adios_type_to_string(vartype));
515
if (len > maxtypelen) maxtypelen = len;
519
for (n=0; n<nNames; n++) {
524
//timed = adios_read_bp_is_var_timed(fp, vi->varid);
525
timed = (vi->nsteps > 1);
527
retval = adios_get_attr (fp, names[n], &vartype, &attrsize, &value);
529
fprintf(stderr, "Error: %s\n", adios_errmsg());
533
matches = matchesAMask(names[n]);
538
// print definition of variable
539
fprintf(outf,"%c %-*s %-*s", commentchar, maxtypelen,
540
adios_type_to_string(vartype), maxlen, names[n]);
542
// list (and print) attribute
543
if (readattrs || dump) {
544
fprintf(outf," attr = ");
545
print_data(value, 0, vartype, false);
547
matches = false; // already printed
549
fprintf(outf," attr\n");
554
} else if (vi->ndim > 0 || timed) {
556
//fprintf(outf," {%s%d", (vi->timedim==0 ? "T-": ""),vi->dims[0]);
560
fprintf(outf, "%d*", vi->nsteps);
562
fprintf(outf,"{%lld", vi->dims[0]);
563
for (j=1; j < vi->ndim; j++) {
564
fprintf(outf,", %lld", vi->dims[j]);
568
fprintf(outf,"scalar");
571
if (longopt || plot) {
572
status = adios_inq_var_stat (fp, vi, timestep && timed, 0);
575
if (plot && vi->statistics && vi->statistics->histogram) {
576
print_data_hist(vi, &names[n][1]);
580
if (longopt && vi->statistics) {
582
if(timestep == false || timed == false ) {
585
print_data(vi->statistics->min, 0, vartype, false);
588
print_data(vi->statistics->max, 0, vartype, false);
590
if(vartype == adios_complex || vartype == adios_double_complex) {
593
print_data(vi->statistics->avg, 0, adios_double_complex, false);
597
print_data(vi->statistics->avg, 0, adios_double, false);
600
if(vartype == adios_complex || vartype == adios_double_complex) {
603
print_data(vi->statistics->std_dev, 0, adios_double_complex, false);
607
print_data(vi->statistics->std_dev, 0, adios_double, false);
610
//fprintf(outf," {MIN / MAX / AVG / STD_DEV} ");
612
int time_start = 0, time_end = vi->nsteps;
616
time_start = istart[0];
618
time_start = vi->nsteps - 1 + istart[0];
623
time_end = time_start + icount[0];
625
time_end = vi->nsteps + icount[0] + 1;
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);
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);
638
static char *indent_char = " ";
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");
648
/* End - Print the headers of statistics first */
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)
655
fprintf(outf, "\n%-*sglobal:", indent_len, indent_char);
656
print_data_characteristics (vi->statistics->min,
659
vi->statistics->std_dev,
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];
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);
676
} // longopt && vi->statistics
680
fprintf(outf," scalar");
681
if (longopt && vi->value) {
683
print_data(vi->value, 0, vartype, false);
684
matches = false; // already printed
690
if (matches && dump) {
691
// print variable content
693
retval = readVar(fp, vi, names[n], timed);
694
if (retval && retval != 10) // do not return after unsupported type
700
// adios_free_varinfo(vi);
705
/* Free ADIOS_VARINFOs */
706
for (n=0; n<nNames; n++) {
708
adios_free_varinfo(vis[n]);
717
int doList(const char *path) {
719
int grpid; // loop vars
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];
457
727
if (verbose>1) printf("\nADIOS BP open: read header info from %s\n", path);
729
// initialize BP reader
730
strcpy (init_params, "verbose=2");
732
strcat (init_params, ";show_hidden_attrs");
733
status = adios_read_init_method (ADIOS_READ_METHOD_BP, mpi_comm_dummy, init_params);
735
fprintf(stderr, "Error: %s\n", adios_errmsg());
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());
466
// get number of groups, variables, timesteps, and attributes
746
// get number of groups
747
nGroups = adios_get_grouplist (fp, &group_namelist);
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;
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"));
485
// each group has to be handled separately
486
for (grpid=0; grpid < fp->groups_count; grpid++) {
487
if (!grpMatchesMask(fp->group_namelist[grpid]))
490
if (!dump) fprintf(outf, "Group %s:\n", fp->group_namelist[grpid]);
491
gp = adios_gopen_byid (fp, grpid);
493
fprintf(stderr, "Error: %s\n", adios_errmsg());
499
qsort(gp->var_namelist, gp->vars_count, sizeof(char *), cmpstringp);
501
qsort(gp->attr_namelist, gp->attrs_count, sizeof(char *), cmpstringp);
505
nNames = gp->attrs_count;
507
nNames = gp->vars_count + gp->attrs_count;
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);
516
mergeLists(gp->vars_count, gp->var_namelist, gp->attrs_count, gp->attr_namelist,
519
// calculate max length of variable names in the first round
521
for (n=0; n<nNames; n++) {
522
len = strlen(names[n]);
523
if (len > maxlen) maxlen = len;
527
for (n=0; n<nNames; n++) {
530
vi = adios_inq_var (gp, names[n]);
532
fprintf(stderr, "Error: %s\n", adios_errmsg());
536
retval = adios_get_attr (gp, names[n], &vartype, &attrsize, &value);
538
fprintf(stderr, "Error: %s\n", adios_errmsg());
542
matches = matchesAMask(names[n]);
546
// print definition of variable
547
fprintf(outf,"%c %-*s %-*s", commentchar, 9, adios_type_to_string(vartype), maxlen, names[n]);
549
// list (and print) attribute
550
if (readattrs || dump) {
551
fprintf(outf," attr = ");
552
print_data(value, 0, vartype, false);
554
matches = false; // already printed
556
fprintf(outf," attr\n");
561
} else if (vi->ndim > 0) {
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]);
570
if (vi->hist && plot) {
571
print_data_hist(vi, &names[n][1]);
574
if (longopt && vi->gmin && vi->gmax) {
576
if(timestep == false || (vi->timedim < 0)) {
579
print_data(vi->gmin, 0, vartype, false);
582
print_data(vi->gmax, 0, vartype, false);
584
if(vartype == adios_complex || vartype == adios_double_complex) {
587
print_data(vi->gavg, 0, adios_double_complex, false);
591
print_data(vi->gavg, 0, adios_double, false);
594
if(vartype == adios_complex || vartype == adios_double_complex) {
597
print_data(vi->gstd_dev, 0, adios_double_complex, false);
601
print_data(vi->gstd_dev, 0, adios_double, false);
604
//fprintf(outf," {MIN / MAX / AVG / STD_DEV} ");
606
int time_start = 0, time_end = vi->dims[0];
610
time_start = istart[0];
612
time_start = vi->dims[0] - 1 + istart[0];
617
time_end = time_start + icount[0];
619
time_end = vi->dims[0] + icount[0] + 1;
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);
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);
632
static char *indent_char = " ";
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");
642
/* End - Print the headers of statistics first */
644
void *min, *max, *avg, *std_dev;
645
enum ADIOS_DATATYPES vt = vartype;
646
if (vi->type == adios_complex || vi->type == adios_double_complex)
648
fprintf(outf, "\n%-*sglobal:", indent_len, indent_char);
649
print_data_characteristics(vi->gmin, vi->gmax, vi->gavg, vi->gstd_dev, vt, false);
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];
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);
669
fprintf(outf," scalar");
670
if (longopt && vi->value) {
672
print_data(vi->value, 0, vartype, false);
673
matches = false; // already printed
679
if (matches && dump) {
680
// print variable content
682
retval = readVar(gp, vi, names[n]);
683
if (retval && retval != 10) // do not return after unsupported type
689
adios_free_varinfo(vi);
769
// each group has to be handled separately
770
for (grpid=0; grpid < nGroups; grpid++) {
771
if (!grpMatchesMask(group_namelist[grpid]))
774
if (!dump) fprintf(outf, "Group %s:\n", group_namelist[grpid]);
775
status = adios_group_view (fp, grpid);
777
fprintf(stderr, "Error: %s\n", adios_errmsg());
783
adios_group_view (fp, -1); // reset full view (for next group view)
698
789
if (grpmask != NULL && nGroupsMatched == 0) {
898
995
// transfer start and count arrays to format dependent arrays
1001
if (istart[0] < 0) // negative index means last-|index|
1002
st = vi->nsteps+istart[0];
1005
if (icount[0] < 0) // negative index means last-|index|+1-start
1006
ct = vi->nsteps+icount[0]+1-st;
1011
printf(" j=0, st=%llu ct=%llu\n", st, ct);
1017
printf(" s[0]=%llu, c[0]=%llu, n=%llu\n",
1018
start_t[0], count_t[0], nelems);
1022
tdims = vi->ndim + tidx;
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];
906
if (icount[j] < 0) // negative index means last-|index|+1-start
907
ct = vi->dims[j]+icount[j]+1-st;
1025
if (istart[j+tidx] < 0) // negative index means last-|index|
1026
st = vi->dims[j]+istart[j+tidx];
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;
1032
ct = icount[j+tidx];
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);
1037
start_t[j+tidx] = st;
1038
count_t[j+tidx] = ct;
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);
921
1045
if (verbose>1) {
922
1046
printf(" total size of data to read = %llu\n", nelems*elemsize);
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);
927
1051
maxreadn = MAX_BUFFERSIZE/elemsize;
928
1052
if (nelems < maxreadn)
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];
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);
987
1111
// read a slice finally
988
bytes_read = adios_read_var_byid (gp, vi->varid, s, c, data);
990
if (bytes_read < 0) {
1112
sel = adios_selection_boundingbox (vi->ndim, s+tidx, c+tidx);
1114
status = adios_schedule_read_byid (fp, sel, vi->varid, s[0], c[0], data);
1116
status = adios_schedule_read_byid (fp, sel, vi->varid, 0, 1, data);
1120
fprintf(stderr, "Error when scheduling variable %s for reading. errno=%d : %s \n", name, adios_errno, adios_errmsg());
1125
status = adios_perform_reads (fp, 1); // blocking read performed here
991
1127
fprintf(stderr, "Error when reading variable %s. errno=%d : %s \n", name, adios_errno, adios_errmsg());
996
if (verbose>2) printf(" read %lld bytes\n", bytes_read);
1132
//if (verbose>2) printf(" read %lld bytes\n", bytes_read);
999
print_dataset(data, vi->type, s, c, vi->ndim, vi->dims);
1135
print_dataset(data, vi->type, s, c, tdims);
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--) {
1006
1142
if (s[j]+c[j] == start_t[j]+count_t[j]) {
1007
1143
// reached the end of this dimension