~ubuntu-branches/ubuntu/vivid/adios/vivid-proposed

« back to all changes in this revision

Viewing changes to src/core/common_read.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2014-06-16 23:06:38 UTC
  • mfrom: (15.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20140616230638-cxryhot6b8ge32l6
Tags: 1.7.0-1
* New upstream release.
* Add adios.pc pkgconfig file. adios_config now uses this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    struct adios_read_hooks_struct * read_hooks; /* Save adios_read_hooks for each fopen for Matlab */
42
42
    
43
43
    /* Group view information *//* Actual method provides the group names */
44
 
    int     ngroups;
45
 
    char ** group_namelist;
46
 
    int   * nvars_per_group;     /* # of variables per each group */
47
 
    int   * nattrs_per_group;    /* # of attributes per each group */
48
 
    int     group_in_view;       /* 0..ngroups-1: selected group in view,
 
44
    int         ngroups;
 
45
    char     ** group_namelist;
 
46
    uint32_t  * nvars_per_group;     /* # of variables per each group */
 
47
    uint32_t  * nattrs_per_group;    /* # of attributes per each group */
 
48
    int         group_in_view;       /* 0..ngroups-1: selected group in view,
49
49
                                  -1: all groups */
50
 
    int     group_varid_offset;  /* offset of var IDs from specific group to full list
 
50
    uint64_t    group_varid_offset;  /* offset of var IDs from specific group to full list
51
51
                                    if a selected group is in view */
52
 
    int     group_attrid_offset;
53
 
    int     full_nvars;          /* fp->nvars to save here for a group view */
54
 
    char ** full_varnamelist;    /* fp->var_namelist to save here if one group is viewed */
55
 
    int     full_nattrs;         /* fp->nvars to save here for a group view */
56
 
    char ** full_attrnamelist;   /* fp->attr_namelist to save here if one group is viewed */
 
52
    uint64_t    group_attrid_offset;
 
53
    uint32_t    full_nvars;          /* fp->nvars to save here for a group view */
 
54
    char     ** full_varnamelist;    /* fp->var_namelist to save here if one group is viewed */
 
55
    uint32_t    full_nattrs;         /* fp->nvars to save here for a group view */
 
56
    char     ** full_attrnamelist;   /* fp->attr_namelist to save here if one group is viewed */
57
57
    qhashtbl_t *hashtbl_vars;    /* speed up search for var_namelist to varid  */
58
58
 
59
59
    // NCSU ALACRITY-ADIOS - Table of sub-requests issued by transform method
85
85
    // NCSU ALACRITY-ADIOS - Initialize transform methods
86
86
    adios_transform_read_init();
87
87
 
 
88
    if (!adios_read_hooks[method].adios_read_init_method_fn) {
 
89
        adios_error (err_invalid_read_method, 
 
90
            "Read method (=%d) passed to adios_read_init_method() is not provided "
 
91
            "by this build of ADIOS.\n", (int)method);
 
92
        return err_invalid_read_method;
 
93
    }
 
94
 
88
95
    // process common parameters here
89
96
    params = text_to_name_value_pairs (parameters);
90
97
    p = params;
148
155
    }
149
156
 
150
157
    // call method specific init 
151
 
    retval = adios_read_hooks[method].adios_init_method_fn (comm, params);
 
158
    retval = adios_read_hooks[method].adios_read_init_method_fn (comm, params);
152
159
    free_name_value_pairs (params);
153
160
    return retval;
154
161
}
155
162
 
 
163
static int calc_hash_size(unsigned int nvars) 
 
164
{
 
165
    int hash_size;
 
166
    if (nvars < 100) hash_size = nvars; // best speed for most codes
 
167
    else if (nvars < 1000)    hash_size = 100+nvars/10;   // 100..999 variables
 
168
    else if (nvars < 10000)   hash_size = 200+nvars/20;   // 1000..9999 
 
169
    else if (nvars < 100000)  hash_size = 200+nvars/20;  // 10k..99999
 
170
    else                      hash_size = 10000; // 100k..
 
171
    return hash_size;
 
172
}
156
173
 
157
174
int common_read_finalize_method(enum ADIOS_READ_METHOD method)
158
175
{
161
178
        adios_error (err_invalid_read_method, 
162
179
            "Invalid read method (=%d) passed to adios_read_finalize_method().\n", (int)method);
163
180
        return err_invalid_read_method;
164
 
    } 
 
181
    } else if (!adios_read_hooks[method].adios_read_finalize_method_fn) {
 
182
        adios_error (err_invalid_read_method, 
 
183
            "Read method (=%d) passed to adios_read_finalize_method() is not provided "
 
184
            "by this build of ADIOS.\n", (int)method);
 
185
        return err_invalid_read_method;
 
186
    }
165
187
 
166
 
    return adios_read_hooks[method].adios_finalize_method_fn ();
 
188
    return adios_read_hooks[method].adios_read_finalize_method_fn ();
167
189
}
168
190
 
169
191
 
175
197
{
176
198
    ADIOS_FILE * fp;
177
199
    struct common_read_internals_struct * internals; 
178
 
    int i;
 
200
    long i;
179
201
 
180
202
    if ((int)method < 0 || (int)method >= ADIOS_READ_METHOD_COUNT) {
181
203
        adios_error (err_invalid_read_method, 
191
213
    // NCSU ALACRITY-ADIOS - Initialize transform methods
192
214
    adios_transform_read_init();
193
215
 
 
216
    if (!adios_read_hooks[method].adios_read_open_fn) {
 
217
        adios_error (err_invalid_read_method, 
 
218
            "Read method (=%d) passed to adios_read_open() is not provided "
 
219
            "by this build of ADIOS.\n", (int)method);
 
220
        return NULL;
 
221
    }
 
222
 
194
223
    internals->method = method;
195
224
    internals->read_hooks = adios_read_hooks;
196
225
 
197
 
    fp = adios_read_hooks[internals->method].adios_open_fn (fname, comm, lock_mode, timeout_sec);
 
226
    fp = adios_read_hooks[internals->method].adios_read_open_fn (fname, comm, lock_mode, timeout_sec);
198
227
    if (!fp)
199
228
        return fp;
200
229
 
201
230
    // create hashtable from the variable names as key and their index as value
202
 
    int hashsize = fp->nvars;
203
 
    if (fp->nvars > 100) hashsize = 100;
 
231
    int hashsize = calc_hash_size(fp->nvars);
204
232
    internals->hashtbl_vars = qhashtbl(hashsize);
205
233
    for (i=0; i<fp->nvars; i++) {
206
234
        internals->hashtbl_vars->put (internals->hashtbl_vars, fp->var_namelist[i], 
207
 
                                       (void *)i+1); // avoid 0 for error checking later
 
235
                                       (void *)(i+1)); // avoid 0 for error checking later
208
236
    }
209
237
 
210
238
    //read mesh names from attributes for example the var is using a mesh named trimesh, 
283
311
{
284
312
    ADIOS_FILE * fp;
285
313
    struct common_read_internals_struct * internals; 
286
 
    int i;
 
314
    long i;
287
315
 
288
316
    if ((int)method < 0 || (int)method >= ADIOS_READ_METHOD_COUNT) {
289
317
        adios_error (err_invalid_read_method, 
290
318
            "Invalid read method (=%d) passed to adios_read_open_file().\n", (int)method);
291
319
        return NULL;
292
 
    } 
 
320
    }
 
321
 
293
322
 
294
323
    adios_errno = err_no_error;
295
324
    internals = (struct common_read_internals_struct *) 
302
331
    internals->method = method;
303
332
    internals->read_hooks = adios_read_hooks;
304
333
 
305
 
    fp = adios_read_hooks[internals->method].adios_open_file_fn (fname, comm);
 
334
    if (!adios_read_hooks[internals->method].adios_read_open_file_fn) {
 
335
        adios_error (err_invalid_read_method, 
 
336
            "Read method (=%d) passed to adios_read_open_file() is not provided "
 
337
            "by this build of ADIOS.\n", (int)method);
 
338
        return NULL;
 
339
    }
 
340
    fp = adios_read_hooks[internals->method].adios_read_open_file_fn (fname, comm);
306
341
    if (!fp)
307
342
        return fp;
308
343
    
309
344
    // create hashtable from the variable names as key and their index as value
310
 
    int hashsize = fp->nvars;
311
 
    if (fp->nvars > 100) hashsize = 100;
 
345
    int hashsize = calc_hash_size(fp->nvars);
312
346
    internals->hashtbl_vars = qhashtbl(hashsize);
313
347
    for (i=0; i<fp->nvars; i++) {
314
348
        internals->hashtbl_vars->put (internals->hashtbl_vars, fp->var_namelist[i], 
315
 
                                       (void *)i+1); // avoid 0 for error checking later
 
349
                                       (void *)(i+1)); // avoid 0 for error checking later
316
350
    }
317
351
 
318
352
    //read mesh names from attributes for example the var is using a mesh named trimesh, 
346
380
        {
347
381
            fp->mesh_namelist = (char **) realloc (tmp, sizeof (char *) * fp->nmeshes);
348
382
            assert (fp->mesh_namelist);
 
383
        } else {
 
384
            free (tmp);
349
385
        }
350
386
 
351
387
    }
393
429
            free(fp->mesh_namelist);
394
430
        }
395
431
                
396
 
        retval = internals->read_hooks[internals->method].adios_close_fn (fp);
 
432
        retval = internals->read_hooks[internals->method].adios_read_close_fn (fp);
397
433
        free_namelist (internals->group_namelist, internals->ngroups);
398
434
        free (internals->nvars_per_group);
399
435
        free (internals->nattrs_per_group);
428
464
    struct common_read_internals_struct * internals;
429
465
    int hashsize;
430
466
    int retval;
431
 
    int i;
 
467
    long i;
432
468
    
433
469
    adios_errno = err_no_error;
434
470
    if (fp) {
438
474
            // Re-create hashtable from the variable names as key and their index as value
439
475
            if (internals->hashtbl_vars)
440
476
                internals->hashtbl_vars->free (internals->hashtbl_vars);
441
 
            hashsize = fp->nvars;
442
 
            if (fp->nvars > 100) hashsize = 100;
 
477
            hashsize = calc_hash_size(fp->nvars);
443
478
            internals->hashtbl_vars = qhashtbl(hashsize);
444
479
            for (i=0; i<fp->nvars; i++) {
445
480
                internals->hashtbl_vars->put (internals->hashtbl_vars, fp->var_namelist[i], 
446
 
                        (void *)i+1); // avoid 0 for error checking later
 
481
                        (void *)(i+1)); // avoid 0 for error checking later
447
482
            }
448
483
 
449
484
            /* Update group information too */
560
595
 
561
596
ADIOS_VARINFO * common_read_inq_var (const ADIOS_FILE *fp, const char * varname) 
562
597
{
563
 
    struct common_read_internals_struct * internals;
564
598
    ADIOS_VARINFO * retval;
565
599
 
566
600
    adios_errno = err_no_error;
567
601
    if (fp) {
568
 
        internals = (struct common_read_internals_struct *) fp->internal_data;
569
602
        int varid = common_read_find_var (fp, varname, 0);
570
603
        if (varid >= 0) {
571
604
            retval = common_read_inq_var_byid (fp, varid);
613
646
    if (vi == NULL)
614
647
        return NULL;
615
648
    
616
 
    vi->meshinfo = NULL;
617
 
 
618
649
    // NCSU ALACRITY-ADIOS - translate between original and transformed metadata if necessary
619
650
    ti = common_read_inq_transinfo(fp, vi); // No orig_blockinfo
620
651
    if (ti && ti->transform_type != adios_transform_none) {
642
673
            if (retval) {
643
674
                /* Translate real varid to the group varid presented to the user */
644
675
                retval->varid = varid;
 
676
                retval->meshinfo = NULL; // initialize here because it's a common layer addition
645
677
            }
646
678
        } else {
647
679
            adios_error (err_invalid_varid, 
798
830
 
799
831
void common_read_free_varinfo (ADIOS_VARINFO *vp)
800
832
{
801
 
    int i;
802
833
    if (vp) {
803
834
        common_read_free_blockinfo(&vp->blockinfo, vp->sum_nblocks);
804
835
 
894
925
                            int * size,
895
926
                            void ** data)
896
927
{
897
 
    struct common_read_internals_struct * internals;
898
928
    int retval;
899
929
 
900
930
    adios_errno = err_no_error;
901
931
    if (fp) {
902
 
        internals = (struct common_read_internals_struct *) fp->internal_data;
903
932
        int attrid = common_read_find_attr (fp->nattrs, fp->attr_namelist, attrname, 1);
904
933
        if (attrid > -1) {
905
934
            retval = common_read_get_attr_byid_mesh (fp, attrid, type, size, data);
1003
1032
    {
1004
1033
        if (!strcmp((char *)data, "point"))
1005
1034
        {
1006
 
            varinfo->meshinfo->centering = 1;      // point centering
 
1035
            varinfo->meshinfo->centering = point;
1007
1036
        }
1008
1037
        else if (!strcmp((char *)data, "cell"))
1009
1038
        {
1010
 
            varinfo->meshinfo->centering = 2;      // cell centering
 
1039
            varinfo->meshinfo->centering = cell;
1011
1040
        }
1012
1041
        else
1013
1042
        {
1022
1051
    return 0;
1023
1052
}
1024
1053
 
1025
 
 
 
1054
static double common_check_var_type_to_double (enum ADIOS_DATATYPES * type, void * value)
 
1055
{
 
1056
    double data;
 
1057
 
 
1058
    if (*type == adios_real)
 
1059
        data = *(float *)value;
 
1060
    else if (*type == adios_double)
 
1061
        data = *(double *)value;
 
1062
    else if (*type == adios_byte)
 
1063
        data = *(signed char *)value;
 
1064
    else if (*type == adios_unsigned_byte)
 
1065
        data = *(unsigned char *)value;
 
1066
    else if (*type == adios_short)
 
1067
        data = *(signed short *)value;
 
1068
    else if (*type == adios_unsigned_short)
 
1069
        data = *(unsigned short *)value;
 
1070
    else if (*type == adios_integer)
 
1071
        data = *(signed int *)value;
 
1072
    else if (*type == adios_unsigned_integer)
 
1073
        data = *(unsigned int *)value;
 
1074
    else if (*type == adios_long)
 
1075
        data = *(signed long long *)value;
 
1076
    else if (*type == adios_unsigned_long)
 
1077
        data = *(unsigned long long *)value;
 
1078
    else if (*type == adios_unknown)
 
1079
    {
 
1080
        adios_error (err_mesh_unifrom_invalid_var_type,
 
1081
                     "Provided var type is not supported. "
 
1082
                     "Var type only supports (unsigned) char, (unsigned) short, "
 
1083
                     "(unsigned) int,(unsigned) long long, float and double\n");
 
1084
    }
 
1085
    return data;
 
1086
}
 
1087
 
 
1088
static uint64_t common_check_var_type_to_uint64 (enum ADIOS_DATATYPES * type, void * value)
 
1089
{
 
1090
    uint64_t data;
 
1091
 
 
1092
    if (*type == adios_real)
 
1093
        data = *(float *)value;
 
1094
    else if (*type == adios_double)
 
1095
        data = *(double *)value;
 
1096
    else if (*type == adios_byte)
 
1097
        data = *(signed char *)value;
 
1098
    else if (*type == adios_unsigned_byte)
 
1099
        data = *(unsigned char *)value;
 
1100
    else if (*type == adios_short)
 
1101
        data = *(signed short *)value;
 
1102
    else if (*type == adios_unsigned_short)
 
1103
        data = *(unsigned short *)value;
 
1104
    else if (*type == adios_integer)
 
1105
        data = *(signed int *)value;
 
1106
    else if (*type == adios_unsigned_integer)
 
1107
        data = *(unsigned int *)value;
 
1108
    else if (*type == adios_long)
 
1109
        data = *(signed long long *)value;
 
1110
    else if (*type == adios_unsigned_long)
 
1111
        data = *(unsigned long long *)value;
 
1112
    else if (*type == adios_unknown)
 
1113
    {
 
1114
        adios_error (err_mesh_unifrom_invalid_var_type,
 
1115
                     "Provided var type is not supported. "
 
1116
                     "Var type only supports (unsigned) char, (unsigned) short, "
 
1117
                     "(unsigned) int,(unsigned) long long, float and double\n");
 
1118
    }
 
1119
    return data;
 
1120
}
 
1121
 
 
1122
static int common_check_var_type_to_int (enum ADIOS_DATATYPES * type, void * value)
 
1123
{
 
1124
    int data;
 
1125
 
 
1126
    if (*type == adios_real)
 
1127
        data = *(float *)value;
 
1128
    else if (*type == adios_double)
 
1129
        data = *(double *)value;
 
1130
    else if (*type == adios_byte)
 
1131
        data = *(signed char *)value;
 
1132
    else if (*type == adios_unsigned_byte)
 
1133
        data = *(unsigned char *)value;
 
1134
    else if (*type == adios_short)
 
1135
        data = *(signed short *)value;
 
1136
    else if (*type == adios_unsigned_short)
 
1137
        data = *(unsigned short *)value;
 
1138
    else if (*type == adios_integer)
 
1139
        data = *(signed int *)value;
 
1140
    else if (*type == adios_unsigned_integer)
 
1141
        data = *(unsigned int *)value;
 
1142
    else if (*type == adios_long)
 
1143
        data = *(signed long long *)value;
 
1144
    else if (*type == adios_unsigned_long)
 
1145
        data = *(unsigned long long *)value;
 
1146
    else if (*type == adios_unknown)
 
1147
    {
 
1148
        adios_error (err_mesh_unifrom_invalid_var_type,
 
1149
                     "Provided var type is not supported. "
 
1150
                     "Var type only supports (unsigned) char, (unsigned) short, "
 
1151
                     "(unsigned) int,(unsigned) long long, float and double\n");
 
1152
    }
 
1153
    return data;
 
1154
}
1026
1155
int adios_get_uniform_mesh_attr (ADIOS_FILE * fp, ADIOS_MESH *meshinfo, char * attrs)      //attr for origins-num(origins), spacings-num(spacings), maximums-num(maximums)
1027
1156
{
1028
 
    int i, j;
 
1157
    int i;
1029
1158
    enum ADIOS_DATATYPES attr_type;
1030
1159
    int attr_size;
1031
1160
    void * data = NULL;
1182
1311
                        ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
1183
1312
                        if (!strcmp (attrs, "origins"))
1184
1313
                        {
1185
 
                            if (v->type == adios_real)   
1186
 
                                meshinfo->uniform->origins[i] = *(float *)v->value;                        
1187
 
                            else if (v->type == adios_double)   
1188
 
                                meshinfo->uniform->origins[i] = *(double *)v->value;
1189
 
                            else if (v->type == adios_byte)
1190
 
                                meshinfo->uniform->origins[i] = *(signed char *)v->value;
1191
 
                            else if (v->type == adios_unsigned_byte)
1192
 
                                meshinfo->uniform->origins[i] = *(unsigned char *)v->value;
1193
 
                            else if (v->type == adios_short)
1194
 
                                meshinfo->uniform->origins[i] = *(signed short *)v->value;
1195
 
                            else if (v->type == adios_unsigned_short)
1196
 
                                meshinfo->uniform->origins[i] = *(unsigned short *)v->value;
1197
 
                            else if (v->type == adios_integer)
1198
 
                                meshinfo->uniform->origins[i] = *(signed int *)v->value;
1199
 
                            else if (v->type == adios_unsigned_integer)
1200
 
                                meshinfo->uniform->origins[i] = *(unsigned int *)v->value;
1201
 
                            else if (v->type == adios_long)
1202
 
                                meshinfo->uniform->origins[i] = *(signed long long *)v->value;
1203
 
                            else if (v->type == adios_unsigned_long)
1204
 
                                meshinfo->uniform->origins[i] = *(unsigned long long *)v->value;
1205
 
                            else
 
1314
                            adios_errno = err_no_error;
 
1315
                            meshinfo->uniform->origins[i] = common_check_var_type_to_double (&v->type, v->value);
 
1316
                            if (adios_errno < 0) 
1206
1317
                            {
1207
 
                                adios_error (err_mesh_unifrom_invalid_var_type,
1208
 
                                             "Uniform mesh %s origins support (unsigned) char, (unsigned) short, "
1209
 
                                             "(unsigned) int,(unsigned) long long, float and double\n", 
1210
 
                                             meshinfo->name);
1211
1318
                                meshinfo->uniform = NULL;
1212
1319
                                return -1;
1213
1320
                            }
1214
1321
                        }
1215
1322
                        else if (!strcmp (attrs, "maximums"))
1216
1323
                        {
1217
 
                            if (v->type == adios_real)    
1218
 
                                 meshinfo->uniform->maximums[i] = *(float *)v->value;
1219
 
                            else if (v->type == adios_double)   
1220
 
                                meshinfo->uniform->maximums[i] = *(double *)v->value;
1221
 
                            else if (v->type == adios_byte)
1222
 
                                meshinfo->uniform->maximums[i] = *(signed char *)v->value;
1223
 
                            else if (v->type == adios_unsigned_byte)
1224
 
                                meshinfo->uniform->maximums[i] = *(unsigned char *)v->value;
1225
 
                            else if (v->type == adios_short)
1226
 
                                meshinfo->uniform->maximums[i] = *(signed short *)v->value;
1227
 
                            else if (v->type == adios_unsigned_short)
1228
 
                                meshinfo->uniform->maximums[i] = *(unsigned short *)v->value;
1229
 
                            else if (v->type == adios_integer)
1230
 
                                meshinfo->uniform->maximums[i] = *(signed int *)v->value;
1231
 
                            else if (v->type == adios_unsigned_integer)
1232
 
                                meshinfo->uniform->maximums[i] = *(unsigned int *)v->value;
1233
 
                            else if (v->type == adios_long)
1234
 
                                meshinfo->uniform->maximums[i] = *(signed long long *)v->value;
1235
 
                            else if (v->type == adios_unsigned_long)
1236
 
                                meshinfo->uniform->maximums[i] = *(unsigned long long *)v->value;
1237
 
                            else
 
1324
                            adios_errno = err_no_error;
 
1325
                            meshinfo->uniform->maximums[i] = common_check_var_type_to_double (&v->type, v->value);
 
1326
                            if (adios_errno < 0)
1238
1327
                            {
1239
 
                                adios_error (err_mesh_unifrom_invalid_var_type,
1240
 
                                             "Uniform mesh %s maximums support (unsigned) char, (unsigned) short, "
1241
 
                                             "(unsigned) int, (unsigned) long long, float and double\n",
1242
 
                                             meshinfo->name);
1243
1328
                                meshinfo->uniform = NULL;
1244
1329
                                return -1;
1245
1330
                            }
1246
1331
                        }
1247
1332
                        else if (!strcmp (attrs, "spacings"))
1248
1333
                        {
1249
 
                            if (v->type == adios_real)    
1250
 
                                meshinfo->uniform->spacings[i] = *(float *)v->value;
1251
 
                            else if (v->type == adios_double)    
1252
 
                                meshinfo->uniform->spacings[i] = *(double *)v->value;
1253
 
                            else if (v->type == adios_byte)
1254
 
                                meshinfo->uniform->spacings[i] = *(signed char *)v->value;
1255
 
                            else if (v->type == adios_unsigned_byte)
1256
 
                                meshinfo->uniform->spacings[i] = *(unsigned char *)v->value;
1257
 
                            else if (v->type == adios_short)
1258
 
                                meshinfo->uniform->spacings[i] = *(signed short *)v->value;
1259
 
                            else if (v->type == adios_unsigned_short)
1260
 
                                meshinfo->uniform->spacings[i] = *(unsigned short *)v->value;
1261
 
                            else if (v->type == adios_integer)
1262
 
                                meshinfo->uniform->spacings[i] = *(signed int *)v->value;
1263
 
                            else if (v->type == adios_unsigned_integer)
1264
 
                                meshinfo->uniform->spacings[i] = *(unsigned int *)v->value;
1265
 
                            else if (v->type == adios_long)
1266
 
                                meshinfo->uniform->spacings[i] = *(signed long long *)v->value;
1267
 
                            else if (v->type == adios_unsigned_long)
1268
 
                                meshinfo->uniform->spacings[i] = *(unsigned long long *)v->value; 
1269
 
                            else 
 
1334
                            adios_errno = err_no_error;
 
1335
                            meshinfo->uniform->spacings[i] = common_check_var_type_to_double (&v->type, v->value);
 
1336
                            if (adios_errno < 0)
1270
1337
                            {
1271
 
                                adios_error (err_mesh_unifrom_invalid_var_type,
1272
 
                                             "Uniform mesh %s spacings support (unsigned) char, (unsigned) short, "
1273
 
                                             "(unsigned) int, (unsigned) long long, float and double\n",
1274
 
                                             meshinfo->name); 
1275
 
                                 meshinfo->uniform = NULL;
1276
 
                                 return -1;
 
1338
                                meshinfo->uniform = NULL;
 
1339
                                return -1;
1277
1340
                            }
1278
 
//                            printf ("meshinfo->uniform->spacings[%d] = %lf\n",i, meshinfo->uniform->spacings[i]);
1279
1341
                        }
1280
1342
                        common_read_free_varinfo (v);
1281
1343
                    }
1356
1418
    int attr_size;
1357
1419
    void * data = NULL;
1358
1420
    int  read_fail = 0;
1359
 
    int i, j, varid;
 
1421
//    int i, j, varid;
1360
1422
 
1361
1423
    ADIOS_MESH * meshinfo = (ADIOS_MESH *) malloc (sizeof(ADIOS_MESH));
1362
1424
    //mesh id
1389
1451
    common_read_get_attr_mesh (fp, mesh_attribute, &attr_type, &attr_size, &data);
1390
1452
    free (mesh_attribute);
1391
1453
    if ( !strcmp((char *)data, "uniform") )
1392
 
    {
1393
 
        bool have_spacing = 0;
1394
 
        bool have_max = 0;
1395
 
 
1396
1454
        meshinfo->type = ADIOS_MESH_UNIFORM;
 
1455
    else if ( !strcmp((char *)data, "rectilinear") )
 
1456
        meshinfo->type = ADIOS_MESH_RECTILINEAR;
 
1457
    else if ( !strcmp((char *)data, "structured") )
 
1458
        meshinfo->type = ADIOS_MESH_STRUCTURED;
 
1459
    else if ( !strcmp((char *)data, "unstructured") )
 
1460
        meshinfo->type = ADIOS_MESH_UNSTRUCTURED;
 
1461
 
 
1462
    //check if mesh structure is stored in the same file
 
1463
    char * meshfile = malloc ( strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/mesh-file")+1 );
 
1464
    strcpy (meshfile, "/adios_schema/");
 
1465
    strcat (meshfile, meshinfo->name);
 
1466
    strcat (meshfile, "/mesh-file");
 
1467
    read_fail = common_read_get_attr_mesh (fp, meshfile, &attr_type, &attr_size, &data);
 
1468
    free (meshfile);
 
1469
 
 
1470
    if (read_fail)
 
1471
    {
 
1472
        meshinfo->file_name = NULL; 
 
1473
        // get the mesh details now from this data file
 
1474
        common_read_complete_meshinfo (fp, fp, meshinfo);
 
1475
    }
 
1476
    else
 
1477
    {
 
1478
        meshinfo->file_name = strdup((char *)data);
 
1479
        // user has to open this file and call common_read_complete_meshinfo() again with both file pointers
 
1480
    }
 
1481
    return meshinfo;
 
1482
}
 
1483
 
 
1484
 
 
1485
int common_read_complete_meshinfo (ADIOS_FILE *fp, ADIOS_FILE *mp, ADIOS_MESH * meshinfo)
 
1486
{
 
1487
    enum ADIOS_DATATYPES attr_type;
 
1488
    int attr_size;
 
1489
    void * data = NULL;
 
1490
    int  read_fail = 0;
 
1491
    int i, j, varid;
 
1492
   
 
1493
    if (fp==NULL || mp==NULL)
 
1494
    { 
 
1495
        adios_error (err_mesh_file_missing,
 
1496
                     "Mesh file %s or mesh file does not exist. ",
 
1497
                     fp->path, mp->path);
 
1498
        return adios_errno;
 
1499
    }
 
1500
 
 
1501
//    if ( !strcmp((char *)data, "uniform") )
 
1502
    if (meshinfo->type == ADIOS_MESH_UNIFORM)
 
1503
    {
 
1504
//        meshinfo->type = ADIOS_MESH_UNIFORM;
1397
1505
        meshinfo->uniform = (MESH_UNIFORM * ) malloc (sizeof(MESH_UNIFORM));
1398
1506
 
1399
1507
        // initialize pointers that might not be set below
1426
1534
                    adios_error (err_mesh_unifrom_invalid_num_dims,
1427
1535
                                 "Uniform mesh %s has more than 10 dims!\n", 
1428
1536
                                 meshinfo->name);
1429
 
                    return NULL; 
 
1537
                    return adios_errno; 
1430
1538
                }
1431
1539
                i_digits = sprintf (i_buffer, "%d", i);
1432
1540
                //i_digits to reprent the number in dimensions0/dimensions1/... 
1444
1552
                    adios_error (err_mesh_unifrom_missing_one_dim,
1445
1553
                                 "Uniform mesh %s dimensions[%d] is not provided!\n", 
1446
1554
                                 meshinfo->name, i);
1447
 
                    return NULL; 
 
1555
                    return adios_errno; 
1448
1556
                }
1449
1557
                else
1450
1558
                {
1460
1568
                        varid = common_read_find_var (fp, dimensions_value_tmp, 1);
1461
1569
                        if (varid >= 0) {
1462
1570
                            ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
1463
 
                            if (v->type == adios_byte)
1464
 
                                meshinfo->uniform->dimensions[i] = *(signed char *)v->value;
1465
 
                            else if (v->type == adios_unsigned_byte)
1466
 
                                meshinfo->uniform->dimensions[i] = *(unsigned char *)v->value;
1467
 
                            else if (v->type == adios_short)
1468
 
                                meshinfo->uniform->dimensions[i] = *(signed short *)v->value;
1469
 
                            else if (v->type == adios_unsigned_short)
1470
 
                                meshinfo->uniform->dimensions[i] = *(unsigned short *)v->value;
1471
 
                            else if (v->type == adios_integer)
1472
 
                                meshinfo->uniform->dimensions[i] = *(signed int *)v->value;
1473
 
                            else if (v->type == adios_unsigned_integer)
1474
 
                                meshinfo->uniform->dimensions[i] = *(unsigned int *)v->value;
1475
 
                            else if (v->type == adios_long)
1476
 
                                meshinfo->uniform->dimensions[i] = *(signed long long *)v->value;
1477
 
                            else if (v->type == adios_unsigned_long)
1478
 
                                meshinfo->uniform->dimensions[i] = *(unsigned long long *)v->value;
1479
 
 
 
1571
                            adios_errno = err_no_error;
 
1572
                            meshinfo->uniform->dimensions[i] = common_check_var_type_to_uint64 (&v->type, v->value);
 
1573
                            if (adios_errno < 0)
 
1574
                            {
 
1575
                                adios_error (err_mesh_unifrom_invalid_dim,
 
1576
                                         "Uniform mesh %s dimensions%d var type is not support!\n",
 
1577
                                         meshinfo->name, i);
 
1578
                                return adios_errno;
 
1579
                            }
1480
1580
                            common_read_free_varinfo (v);
1481
1581
                        }
1482
1582
                        else
1484
1584
                            adios_error (err_mesh_unifrom_invalid_dim,
1485
1585
                                         "Uniform mesh %s dimensions%d var %s is not correct!\n", 
1486
1586
                                         meshinfo->name, i, (char *)data);
1487
 
                            return NULL; 
 
1587
                            return adios_errno; 
1488
1588
                        }
1489
1589
//                        free (dimensions_value_tmp);
1490
1590
                    }
1496
1596
            adios_error (err_mesh_unifrom_missing_dims,
1497
1597
                         "Uniform mesh %s dimension is required\n", 
1498
1598
                         meshinfo->name);
1499
 
            return NULL;            
 
1599
            return adios_errno;            
1500
1600
        }
1501
1601
 
1502
1602
        //start processing origins, origin is optional
1503
1603
        int have_origins;
1504
1604
        have_origins = adios_get_uniform_mesh_attr (fp, meshinfo, "origins");
1505
1605
        if (have_origins == -1)
1506
 
            return NULL;
 
1606
            return adios_errno;
1507
1607
//        for (i = 0; i < meshinfo->uniform->num_dimensions; i++ )
1508
1608
//            printf ("origins[%d] is %lf\n", i, meshinfo->uniform->origins[i]);
1509
1609
 
1511
1611
        int have_spacings;
1512
1612
        have_spacings = adios_get_uniform_mesh_attr (fp, meshinfo, "spacings");
1513
1613
        if (have_spacings == -1)
1514
 
            return NULL;
 
1614
            return adios_errno;
1515
1615
//        for (i = 0; i < meshinfo->uniform->num_dimensions; i++ )
1516
1616
//            printf ("spacings[%d] is %lf\n", i, meshinfo->uniform->spacings[i]);
1517
1617
 
1519
1619
        int have_maximums;
1520
1620
        have_maximums = adios_get_uniform_mesh_attr (fp, meshinfo, "maximums");
1521
1621
        if (have_maximums == -1)
1522
 
            return NULL;
 
1622
            return adios_errno;
1523
1623
//        for (int i = 0; i < meshinfo->uniform->num_dimensions; i++ )
1524
1624
//            printf ("maximums[%d] is %lf\n", i, meshinfo->uniform->maximums[i]);
1525
1625
 
1536
1636
                                 "provided spacing is %lf, calculated spacing is %lf\n", 
1537
1637
                                 meshinfo->name, meshinfo->uniform->spacings[i], 
1538
1638
                                 (meshinfo->uniform->maximums[i]-meshinfo->uniform->origins[i])/(double)(meshinfo->uniform->dimensions[i]-1));
1539
 
                    return NULL; 
 
1639
                    return adios_errno; 
1540
1640
                }
1541
1641
            }
1542
1642
        }
1543
1643
//end of uniform mesh 
1544
1644
    }
1545
 
    else if ( !strcmp((char *)data, "rectilinear") )   
 
1645
//    else if ( !strcmp((char *)data, "rectilinear") )   
 
1646
    else if  (meshinfo->type == ADIOS_MESH_RECTILINEAR)
1546
1647
    {
1547
 
        meshinfo->type = ADIOS_MESH_RECTILINEAR;
 
1648
//        meshinfo->type = ADIOS_MESH_RECTILINEAR;
1548
1649
        meshinfo->rectilinear = (MESH_RECTILINEAR * ) malloc (sizeof(MESH_RECTILINEAR));
1549
1650
        meshinfo->rectilinear->use_single_var = 0;    // default value 0 indicates using multi-var
1550
1651
 
1573
1674
                    adios_error (err_mesh_recti_invalid_num_dims,
1574
1675
                                 "Rectilinear mesh %s has more than 10 dims!\n", 
1575
1676
                                 meshinfo->name);
1576
 
                    return NULL; 
 
1677
                    return adios_errno; 
1577
1678
                }
1578
1679
                i_digits = sprintf (i_buffer, "%d", i);
1579
1680
                //i_digits to reprent the number in dimensions0/dimensions1/... 
1592
1693
                    adios_error (err_mesh_recti_missing_one_dim,
1593
1694
                                 "Rectilinear mesh %s dimensions[%d] is not provided!\n", 
1594
1695
                                 meshinfo->name, i);
1595
 
                    return NULL; 
 
1696
                    return adios_errno; 
1596
1697
                }
1597
1698
                else
1598
1699
                {
1608
1709
                        varid = common_read_find_var (fp, dimensions_value_tmp, 1);
1609
1710
                        if (varid >= 0) {
1610
1711
                            ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
1611
 
                            if (v->type == adios_byte)
1612
 
                                meshinfo->rectilinear->dimensions[i] = *(signed char *)v->value;
1613
 
                            else if (v->type == adios_unsigned_byte)
1614
 
                                meshinfo->rectilinear->dimensions[i] = *(unsigned char *)v->value;
1615
 
                            else if (v->type == adios_short)
1616
 
                                meshinfo->rectilinear->dimensions[i] = *(signed short *)v->value;
1617
 
                            else if (v->type == adios_unsigned_short)
1618
 
                                meshinfo->rectilinear->dimensions[i] = *(unsigned short *)v->value;
1619
 
                            else if (v->type == adios_integer)
1620
 
                                meshinfo->rectilinear->dimensions[i] = *(signed int *)v->value;
1621
 
                            else if (v->type == adios_unsigned_integer)
1622
 
                                meshinfo->rectilinear->dimensions[i] = *(unsigned int *)v->value;
1623
 
                            else if (v->type == adios_long)
1624
 
                                meshinfo->rectilinear->dimensions[i] = *(signed long long *)v->value;
1625
 
                            else if (v->type == adios_unsigned_long)  
1626
 
                                meshinfo->rectilinear->dimensions[i] = *(unsigned long long *)v->value;
1627
 
//                            meshinfo->rectilinear->dimensions[i] = *(uint64_t *)v->value;
 
1712
                            adios_errno = err_no_error;
 
1713
                            meshinfo->rectilinear->dimensions[i] = common_check_var_type_to_uint64 (&v->type, v->value);
 
1714
                            if (adios_errno < 0)
 
1715
                            {
 
1716
                                adios_error (err_mesh_recti_invalid_dim,
 
1717
                                         "Rectilinear mesh %s dimensions%d var type is not support!\n",
 
1718
                                         meshinfo->name, i);
 
1719
                                return adios_errno;
 
1720
                            }
1628
1721
                            common_read_free_varinfo (v);
1629
1722
                        }
1630
1723
                        else
1632
1725
                            adios_error (err_mesh_recti_invalid_dim,
1633
1726
                                         "Rectilinear mesh %s dimensions%d var %s is not correct!\n", 
1634
1727
                                         meshinfo->name, i, (char *)data);
1635
 
                            return NULL; 
 
1728
                            return adios_errno; 
1636
1729
                        }
1637
1730
                    }
1638
1731
                }
1643
1736
            adios_error (err_mesh_recti_missing_dims,
1644
1737
                         "Rectilinear mesh %s dimension is required\n", 
1645
1738
                         meshinfo->name);
1646
 
            return NULL; 
 
1739
            return adios_errno; 
1647
1740
        }
1648
1741
//        for (int i = 0; i < meshinfo->rectilinear->num_dimensions; i++ )
1649
1742
//            printf ("dimensions[%d] is %d\n", i, meshinfo->rectilinear->dimensions[i]);
1671
1764
                    adios_error (err_mesh_recti_invalid_coords,
1672
1765
                                 "Rectilinear mesh %s coordinates dimension is 0\n", 
1673
1766
                                 meshinfo->name);
1674
 
                    return NULL; 
 
1767
                    return adios_errno; 
1675
1768
                }
1676
1769
                else                                   //vector, more than one dim
1677
1770
                {
1685
1778
                            adios_error (err_mesh_recti_invalid_coords,
1686
1779
                                         "Rectilinear mesh %s coordinates dimension %"PRIu64" does not match mesh dimension %"PRIu64"\n", 
1687
1780
                                         meshinfo->name, v->dims[0], dim_tmp*meshinfo->rectilinear->num_dimensions);
1688
 
                            return NULL; 
 
1781
                            return adios_errno; 
1689
1782
                        }
1690
1783
                        else
1691
1784
                            meshinfo->rectilinear->coordinates[0] = strdup (fp->var_namelist[varid]);
1700
1793
                                adios_error (err_mesh_recti_invalid_coords, 
1701
1794
                                             "Rectilinear mesh %s dimension[%d]= %d does not match coordinates dimension[%d]= %d\n",
1702
1795
                                             meshinfo->name, j, meshinfo->rectilinear->dimensions[j], j, v->dims[j] );
1703
 
                                return NULL; 
 
1796
                                return adios_errno; 
1704
1797
                            }
1705
1798
                        }
1706
1799
                        meshinfo->rectilinear->coordinates[0] = strdup (fp->var_namelist[varid]); 
1713
1806
                adios_error (err_mesh_recti_invalid_coords,    
1714
1807
                            "Rectilinear mesh %s coordinates var name %s not found\n",
1715
1808
                            meshinfo->name, coords_tmp );
1716
 
                return NULL; 
 
1809
                return adios_errno; 
1717
1810
            }
1718
1811
//            printf ("coordinates is %s\n", meshinfo->rectilinear->coordinates[0]);
1719
1812
        }
1734
1827
                    adios_error (err_mesh_recti_invalid_coords,
1735
1828
                                 "Rectilinear mesh %s number of coordinates %d is less than the number of dimensions %d!\n", 
1736
1829
                                 meshinfo->name, num_coordinates, meshinfo->rectilinear->num_dimensions);
1737
 
                    return NULL; 
 
1830
                    return adios_errno; 
1738
1831
                }
1739
1832
                if (num_coordinates > meshinfo->rectilinear->num_dimensions)
1740
1833
                {
1755
1848
                        adios_error (err_mesh_recti_invalid_num_coords, 
1756
1849
                                     "Rectilinear mesh %s has more than 10 coordinates!\n", 
1757
1850
                                     meshinfo->name);
1758
 
                        return NULL; 
 
1851
                        return adios_errno; 
1759
1852
                    }
1760
1853
                    i_digits = sprintf (i_buffer, "%d", i);
1761
1854
 //                   printf ("i digit is %d\n", i_digits); 
1774
1867
                        adios_error (err_mesh_recti_missing_one_coords,
1775
1868
                                     "Rectilinear mesh %s coordinate of coordinate[%d] is not provided!\n", 
1776
1869
                                     meshinfo->name, i);
1777
 
                        return NULL; 
 
1870
                        return adios_errno; 
1778
1871
                    }
1779
1872
 
1780
1873
                    char * coords_var_tmp = strdup((char *)data);
1788
1881
                                    "match coordinates dimension[%d] = %lld\n",
1789
1882
                                    meshinfo->name, i, meshinfo->rectilinear->dimensions[i], 
1790
1883
                                    i, v->dims[0] );
1791
 
                            return NULL; 
 
1884
                            return adios_errno; 
1792
1885
                        }
1793
1886
                        else
1794
1887
                        {
1804
1897
                adios_error (err_mesh_recti_missing_coords,
1805
1898
                             "Rectilinear mesh %s coordinate is not provided\n", 
1806
1899
                             meshinfo->name);
1807
 
                return NULL; 
 
1900
                return adios_errno; 
1808
1901
            }
1809
1902
//            for (int i = 0; i < meshinfo->rectilinear->num_dimensions; i++ )
1810
1903
//                printf ("coordinates[%d] is %s\n", i, meshinfo->rectilinear->coordinates[i]);
1811
1904
        }
1812
1905
    }
1813
 
    else if ( !strcmp((char *)data, "structured") )
 
1906
//    else if ( !strcmp((char *)data, "structured") )
 
1907
    else if (meshinfo->type == ADIOS_MESH_STRUCTURED)
1814
1908
    {
1815
 
        meshinfo->type = ADIOS_MESH_STRUCTURED;
 
1909
//        meshinfo->type = ADIOS_MESH_STRUCTURED;
1816
1910
        meshinfo->structured = (MESH_STRUCTURED* ) malloc (sizeof(MESH_STRUCTURED));
1817
1911
        meshinfo->structured->use_single_var = 0;        // default value 0 indicates using multi-var   
1818
1912
        meshinfo->structured->nspaces = meshinfo->structured->num_dimensions;   //default spaces = # of dims
1841
1935
                    adios_error (err_mesh_structured_invalid_num_dims,
1842
1936
                                 "Strctured mesh %s has more than 10 dimensions!\n", 
1843
1937
                                 meshinfo->name);
1844
 
                    return NULL; 
 
1938
                    return adios_errno; 
1845
1939
                }
1846
1940
                i_digits = sprintf (i_buffer, "%d", i);
1847
1941
                char * dimensions_value = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/dimensions")+i_digits+1 );
1857
1951
                    adios_error (err_mesh_structured_missing_one_dim,
1858
1952
                                 "Strctured mesh %s dimension of dimensions[%d] is not provided!\n", 
1859
1953
                                 meshinfo->name, i);
1860
 
                    return NULL; 
 
1954
                    return adios_errno; 
1861
1955
                }
1862
1956
                else
1863
1957
                {
1873
1967
                        varid = common_read_find_var (fp, dimensions_value_tmp, 1);
1874
1968
                        if (varid >= 0) {
1875
1969
                            ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
1876
 
                            if (v->type == adios_byte)
1877
 
                                meshinfo->structured->dimensions[i] = *(signed char *)v->value;
1878
 
                            else if (v->type == adios_unsigned_byte)
1879
 
                                meshinfo->structured->dimensions[i] = *(unsigned char *)v->value;
1880
 
                            else if (v->type == adios_short)
1881
 
                                meshinfo->structured->dimensions[i] = *(signed short *)v->value;
1882
 
                            else if (v->type == adios_unsigned_short)
1883
 
                                meshinfo->structured->dimensions[i] = *(unsigned short *)v->value;
1884
 
                            else if (v->type == adios_integer)
1885
 
                                meshinfo->structured->dimensions[i] = *(signed int *)v->value;
1886
 
                            else if (v->type == adios_unsigned_integer)
1887
 
                                meshinfo->structured->dimensions[i] = *(unsigned int *)v->value;
1888
 
                            else if (v->type == adios_long)
1889
 
                                meshinfo->structured->dimensions[i] = *(signed long long *)v->value;
1890
 
                            else if (v->type == adios_unsigned_long)
1891
 
                                meshinfo->structured->dimensions[i] = *(unsigned long long *)v->value;
1892
 
//                            meshinfo->structured->dimensions[i] = *(uint64_t *)v->value;
 
1970
                            adios_errno = err_no_error;
 
1971
                            meshinfo->structured->dimensions[i] = common_check_var_type_to_uint64 (&v->type, v->value);
 
1972
                            if( adios_errno < 0)
 
1973
                            {
 
1974
                                adios_error (err_mesh_structured_invalid_dim,
 
1975
                                         "Strctured mesh %s dimensions%d var type is not support!\n",
 
1976
                                         meshinfo->name, i);
 
1977
                                return adios_errno; 
 
1978
                            }
1893
1979
                            common_read_free_varinfo (v);
1894
1980
                        }
1895
1981
                        else
1897
1983
                            adios_error (err_mesh_structured_invalid_dim,
1898
1984
                                         "Strctured mesh %s dimensions%d var %s is not correct!\n", 
1899
1985
                                         meshinfo->name, i, (char *)data);
1900
 
                            return NULL; 
 
1986
                            return adios_errno; 
1901
1987
                        }
1902
1988
//                        free (dimensions_value_tmp);
1903
1989
                    }
1909
1995
            adios_error (err_mesh_structured_missing_dims, 
1910
1996
                         "Strctured mesh %s dimension is required\n", 
1911
1997
                         meshinfo->name);
1912
 
            return NULL; 
 
1998
            return adios_errno; 
1913
1999
        }
1914
2000
 
1915
2001
        // start processing structured mesh points
1934
2020
                    adios_error (err_mesh_structured_invaid_dim_points,
1935
2021
                                 "Strctured mesh %s points dimension is 0.\n", 
1936
2022
                                 meshinfo->name);
1937
 
                    return NULL; 
 
2023
                    return adios_errno; 
1938
2024
                }
1939
2025
                else                                   //vector, more than one dim
1940
2026
                {
1948
2034
                            adios_error (err_mesh_structured_invaid_points,
1949
2035
                                         "Strctured mesh %s points dimension %"PRIu64" does not match mesh dimension %"PRIu64"\n", 
1950
2036
                                         meshinfo->name, v->dims[0], dim_tmp*meshinfo->structured->num_dimensions);
1951
 
                            return NULL; 
 
2037
                            return adios_errno; 
1952
2038
                        }
1953
2039
                        else
1954
2040
                            meshinfo->structured->points[0] = strdup (fp->var_namelist[varid]);
1963
2049
                                adios_error (err_mesh_structured_invaid_points,
1964
2050
                                             "Strctured mesh %s dimension[%d]= %"PRIu64" does not match points dimension[%d]= %"PRIu64"\n",
1965
2051
                                             meshinfo->name, j, meshinfo->structured->dimensions[j], j, v->dims[j] );
1966
 
                                return NULL; 
 
2052
                                return adios_errno; 
1967
2053
                            }
1968
2054
                        }
1969
2055
                        meshinfo->structured->points[0] = strdup (fp->var_namelist[varid]);
1976
2062
                adios_error (err_mesh_structured_invaid_points,
1977
2063
                            "Strctured mesh %s points var name %s not found\n",
1978
2064
                            meshinfo->name, coords_tmp);
1979
 
                return NULL;
 
2065
                return adios_errno;
1980
2066
            }
1981
2067
        }
1982
2068
        else                    //use points-multi-var
1996
2082
                    adios_error (err_mesh_structured_invaid_dim_points,
1997
2083
                                 "Strctured mesh %s provided points dim %d is less than dims of mesh %d!\n",
1998
2084
                                 meshinfo->name, points_dim, meshinfo->structured->num_dimensions);
1999
 
                    return NULL; 
 
2085
                    return adios_errno; 
2000
2086
                }
2001
2087
                if (points_dim > meshinfo->structured->num_dimensions)
2002
2088
                {
2017
2103
                        adios_error (err_mesh_structured_invalid_num_points,
2018
2104
                                     "Structured mesh %s has than 10 points var!\n", 
2019
2105
                                     meshinfo->name);
2020
 
                        return NULL; 
 
2106
                        return adios_errno; 
2021
2107
                    }
2022
2108
                    i_digits = sprintf (i_buffer, "%d", i);
2023
2109
                    char * points_var = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/points-multi-var")+i_digits+1 );
2034
2120
                        adios_error (err_mesh_structured_missing_one_points,
2035
2121
                                     "Strctured mesh %s points of dim[%d] is not provided!\n", 
2036
2122
                                     meshinfo->name, i);
2037
 
                        return NULL; 
 
2123
                        return adios_errno; 
2038
2124
                    }
2039
2125
                    char * points_var_tmp = strdup((char *)data);
2040
2126
                    varid = common_read_find_var (fp, points_var_tmp, 1);
2053
2139
                                adios_error (err_mesh_structured_invaid_points,
2054
2140
                                             "Strctured mesh %s points dimension %"PRIu64" does not match mesh dimension %"PRIu64"\n", 
2055
2141
                                             meshinfo->name, v->dims[0], dim_tmp);
2056
 
                                return NULL; 
 
2142
                                return adios_errno; 
2057
2143
                            }
2058
2144
                            else
2059
2145
                                meshinfo->structured->points[i] = strdup (fp->var_namelist[varid]);
2069
2155
                                    adios_error (err_mesh_structured_invaid_points,
2070
2156
                                                 "Strctured mesh %s dimension[%d]= %"PRIu64" does not match points dimension[%d]= %"PRIu64"\n",
2071
2157
                                                 meshinfo->name, m, meshinfo->structured->dimensions[m], m, v->dims[m] );
2072
 
                                    return NULL; 
 
2158
                                    return adios_errno; 
2073
2159
                                }
2074
2160
                            }
2075
2161
                            meshinfo->structured->points[i] = strdup (fp->var_namelist[varid]);
2081
2167
                        adios_error (err_mesh_structured_missing_one_points,
2082
2168
                                     "Structured mesh %s var of points-multi-var%d is not provided.\n", 
2083
2169
                                     meshinfo->name, i); 
2084
 
                        return NULL; 
 
2170
                        return adios_errno; 
2085
2171
                    }
2086
2172
                }   // end of for loop i
2087
2173
            }  // end of if found attributes points-multi-var
2090
2176
                adios_error (err_mesh_structured_missing_points,
2091
2177
                             "Structured mesh %s point is not provided.\n", 
2092
2178
                             meshinfo->name);
2093
 
                return NULL; 
 
2179
                return adios_errno; 
2094
2180
            }
2095
2181
 
2096
2182
        }  // end of else use points-multi-var
2130
2216
                }
2131
2217
                else
2132
2218
                {
2133
 
                    log_warn ("Var %s for structured mesh %s nspace is not found. ", 
 
2219
                    log_warn ("Var %s for structured mesh %s nspace is not found. "
2134
2220
                              "We use num of dims %d for nspaces.\n",
2135
 
                              (char *)data, meshinfo->name, meshinfo->structured->num_dimensions);
 
2221
                              (char *)data, meshinfo->name, 
 
2222
                              meshinfo->structured->num_dimensions);
2136
2223
                }
2137
2224
            }
2138
2225
        } // end of structured mesh nspace
2139
2226
    }// end of structured mesh
2140
 
    else if ( !strcmp((char *)data, "unstructured") )
 
2227
//    else if ( !strcmp((char *)data, "unstructured") )
 
2228
    else if (meshinfo->type == ADIOS_MESH_UNSTRUCTURED)
2141
2229
    {
2142
 
        meshinfo->type = ADIOS_MESH_UNSTRUCTURED;
 
2230
//        meshinfo->type = ADIOS_MESH_UNSTRUCTURED;
2143
2231
        meshinfo->unstructured = (MESH_UNSTRUCTURED* ) malloc (sizeof(MESH_UNSTRUCTURED));
2144
2232
//        meshinfo->unstructured->use_single_var = 0;  // default value 0 indicates using multi-var
2145
2233
        meshinfo->unstructured->nvar_points = 1;
2160
2248
//            meshinfo->unstructured->use_single_var = 1;         // modify default value to 1
2161
2249
            char * coords_tmp = strdup((char *)data);
2162
2250
//            printf ("coords_tmp is %s\n", coords_tmp);
2163
 
            varid = common_read_find_var (fp, coords_tmp, 1);
 
2251
//            varid = common_read_find_var (fp, coords_tmp, 1);
 
2252
            varid = common_read_find_var (mp, coords_tmp, 1);
2164
2253
            if (varid >= 0)
2165
2254
            {
2166
 
                ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2255
//                ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2256
                ADIOS_VARINFO * v = common_read_inq_var(mp, mp->var_namelist[varid]);
2167
2257
                if (v->ndim == 0)                      //scalar
2168
2258
                {
2169
2259
                    adios_error (err_mesh_unstructured_invaid_points,
2170
2260
                                 "Unstructured mesh %s points dimension is 0.\n", 
2171
2261
                                 meshinfo->name);
2172
 
                    return NULL; 
 
2262
                    return adios_errno; 
2173
2263
                }
2174
2264
                else                                   //vector
2175
2265
                {
2179
2269
                    for (j=0; j<v->ndim; j++)
2180
2270
                        meshinfo->unstructured->npoints *= v->dims[j];         
2181
2271
                    meshinfo->unstructured->npoints /= v->ndim;               //unstructured mesh npoints init
2182
 
                    meshinfo->unstructured->points[0] = strdup (fp->var_namelist[varid]);
 
2272
//                    meshinfo->unstructured->points[0] = strdup (fp->var_namelist[varid]);
 
2273
                    meshinfo->unstructured->points[0] = strdup (mp->var_namelist[varid]);
2183
2274
                }
2184
2275
                common_read_free_varinfo (v);
2185
2276
            }
2188
2279
                adios_error (err_mesh_unstructured_invaid_points,
2189
2280
                             "Unstrctured mesh %s var %s for points-single-var is not found.\n", 
2190
2281
                             meshinfo->name, coords_tmp);
2191
 
                return NULL;
 
2282
                return adios_errno;
2192
2283
            }
2193
2284
        }
2194
2285
        else                    //use points-multi-var
2220
2311
                        adios_error (err_mesh_unstructured_invaid_num_points,
2221
2312
                                     "Structured mesh %s has more than 10 points.\n", 
2222
2313
                                     meshinfo->name);
2223
 
                        return NULL; 
 
2314
                        return adios_errno; 
2224
2315
                    }
2225
2316
                    i_digits = sprintf (i_buffer, "%d", i);
2226
2317
                    char * points_var = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/points-multi-var")+i_digits+1 );
2230
2321
                    strcat (points_var, i_buffer);
2231
2322
                    free (i_buffer);
2232
2323
                    data = NULL;
2233
 
                    read_fail = common_read_get_attr_mesh (fp, points_var, &attr_type, &attr_size, &data);
 
2324
//                    read_fail = common_read_get_attr_mesh (fp, points_var, &attr_type, &attr_size, &data);
 
2325
                    read_fail = common_read_get_attr_mesh (mp, points_var, &attr_type, &attr_size, &data);
2234
2326
                    free (points_var);
2235
2327
                    if (read_fail)
2236
2328
                    {
2237
2329
                        adios_error (err_mesh_unstructured_missing_one_points, 
2238
2330
                                     "Unstructured mesh %s points of dim[%d] is not provided.\n", 
2239
2331
                                     meshinfo->name, i);
2240
 
                        return NULL; 
 
2332
                        return adios_errno; 
2241
2333
                    }
2242
2334
                    char * points_var_tmp = strdup((char *)data);
2243
2335
//                    printf ( "points_var_tmp is %s\n", points_var_tmp);
2244
 
                    varid = common_read_find_var (fp, points_var_tmp, 1);
 
2336
//                    varid = common_read_find_var (fp, points_var_tmp, 1);
 
2337
                    varid = common_read_find_var (mp, points_var_tmp, 1);
2245
2338
                    if (varid >= 0)
2246
2339
                    {
2247
 
                        ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2340
//                        ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2341
                        ADIOS_VARINFO * v = common_read_inq_var(mp, mp->var_namelist[varid]);
2248
2342
                        if (first_dim)
2249
2343
                        {
2250
2344
                            first_match_var = strdup (points_var_tmp);
2262
2356
                                    adios_error (err_mesh_unstructured_invaid_dim_points,
2263
2357
                                                 "Unstructured mesh %s points-multi-var%d %"PRIu64" does not match points-multi-var0 %"PRIu64".\n", 
2264
2358
                                                 meshinfo->name, i, v->dims[0], meshinfo->unstructured->npoints);
2265
 
                                    return NULL; 
 
2359
                                    return adios_errno; 
2266
2360
                                }
2267
2361
                            }
2268
2362
                            else // v->ndim > 1, check if match for each dim
2269
2363
                            {
2270
 
                                ADIOS_VARINFO * v_first = common_read_inq_var(fp, first_match_var);
 
2364
//                                ADIOS_VARINFO * v_first = common_read_inq_var(fp, first_match_var);
 
2365
                                ADIOS_VARINFO * v_first = common_read_inq_var(mp, first_match_var);
2271
2366
                                if (v_first->ndim == 1)
2272
2367
                                {
2273
2368
                                    int k = 0;
2279
2374
                                        adios_error (err_mesh_unstructured_invaid_dim_points, 
2280
2375
                                                     "Unstructured mesh %s points-multi-var%d %"PRIu64" does not match points-multi-var0 %"PRIu64".\n",
2281
2376
                                                     meshinfo->name, i, var_dim_tmp, meshinfo->unstructured->npoints);
2282
 
                                        return NULL; 
 
2377
                                        return adios_errno; 
2283
2378
                                    }
2284
2379
                                }
2285
2380
                                else  //both v_first and v has more than 2 dims
2289
2384
                                        adios_error (err_mesh_unstructured_invaid_dim_points,
2290
2385
                                                     "Unstructured mesh %s points-multi-var%d dim does not match points-multi-var0 dim.\n",
2291
2386
                                                     meshinfo->name, i);
2292
 
                                        return NULL; 
 
2387
                                        return adios_errno; 
2293
2388
                                    }
2294
2389
                                    else
2295
2390
                                    {
2301
2396
                                                adios_error (err_mesh_unstructured_invaid_dim_points,
2302
2397
                                                             "Unstructured mesh %s points-multi-var%d dim%d does not match points-multi-var0 dim%d.\n",
2303
2398
                                                    meshinfo->name, i, k, k);
2304
 
                                                return NULL; 
 
2399
                                                return adios_errno; 
2305
2400
                                            }
2306
2401
                                        }
2307
2402
                                    }
2309
2404
                                common_read_free_varinfo (v_first);
2310
2405
                            }
2311
2406
                        }
2312
 
                        meshinfo->unstructured->points[i] = strdup (fp->var_namelist[varid]);
 
2407
//                        meshinfo->unstructured->points[i] = strdup (fp->var_namelist[varid]);
 
2408
                        meshinfo->unstructured->points[i] = strdup (mp->var_namelist[varid]);
2313
2409
                        common_read_free_varinfo (v);
2314
2410
                    }
2315
2411
                    else
2317
2413
                        adios_error (err_mesh_unstructured_missing_one_points,
2318
2414
                                     "Unstructured mesh %s var of points-multi-var%d is not provided.\n", 
2319
2415
                                     meshinfo->name, i);
2320
 
                        return NULL; 
 
2416
                        return adios_errno; 
2321
2417
                    }
2322
2418
                }   // end of for loop i
2323
2419
            }  // end of if found attributes points-multi-var
2326
2422
                adios_error (err_mesh_unstructured_missing_points,
2327
2423
                             "Unstructured mesh %s point is not provided.\n", 
2328
2424
                             meshinfo->name);
2329
 
                return NULL; 
 
2425
                return adios_errno; 
2330
2426
            }
2331
2427
 
2332
2428
        }  // end of else use points-multi-var
2364
2460
            else
2365
2461
            {
2366
2462
                char * points_var_tmp = strdup((char *)data);
2367
 
                varid = common_read_find_var (fp, points_var_tmp, 1);
 
2463
//                varid = common_read_find_var (fp, points_var_tmp, 1);
 
2464
                varid = common_read_find_var (mp, points_var_tmp, 1);
2368
2465
                if (varid >= 0)
2369
2466
                {
2370
 
                    ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
2371
 
                    if (v->type==adios_long || v->type==adios_unsigned_long) //long long or unsigned long long   
 
2467
//                    ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2468
                    ADIOS_VARINFO * v = common_read_inq_var(mp, mp->var_namelist[varid]);
 
2469
                    uint64_t match_points = 0;
 
2470
                    adios_errno = err_no_error;
 
2471
                    match_points = common_check_var_type_to_uint64 (&v->type, v->value);
 
2472
                    if (adios_errno < 0)
2372
2473
                    {
2373
 
                        if (meshinfo->unstructured->npoints != *(uint64_t *)v->value)
2374
 
                            log_warn ("Provided npoints %"PRIu64" does not match points calculated from points-var %"PRIu64". "
2375
 
                                      "We use calculated npoints from points-var %"PRIu64".\n",
2376
 
                                      *(uint64_t *)v->value, meshinfo->unstructured->npoints, meshinfo->unstructured->npoints);
 
2474
                        log_warn ("Unstructured mesh %s var type of npoints is not supported. "
 
2475
                                  "We use calculated default npoints %"PRIu64" from points-var\n",
 
2476
                                  meshinfo->name, meshinfo->unstructured->npoints);
2377
2477
                    }
2378
 
                    else      //int
2379
 
                    {
2380
 
                        if (meshinfo->unstructured->npoints != *(int *)v->value)
2381
 
                        log_warn ("Provided npoints %d does not match points calculated from points-var %"PRIu64". "
 
2478
                    if (meshinfo->unstructured->npoints != match_points)
 
2479
                        log_warn ("Provided npoints %"PRIu64" does not match points calculated from points-var %"PRIu64". "
2382
2480
                                  "We use calculated npoints from points-var %"PRIu64".\n",
2383
 
                                  *(int *)v->value, meshinfo->unstructured->npoints, meshinfo->unstructured->npoints);
2384
 
                    }
 
2481
                                  match_points, meshinfo->unstructured->npoints, meshinfo->unstructured->npoints);
2385
2482
                    common_read_free_varinfo (v);
2386
2483
                }
2387
2484
                else
2388
2485
                {
2389
 
                    log_warn ("Unstructured mesh %s var of npoints is not correct. "
2390
 
                              "We use calculated default npoints %"PRIu64" from points-var\n", 
2391
 
                              meshinfo->name, meshinfo->unstructured->npoints);
 
2486
                    // check attrubites if var is not found
 
2487
                    read_fail = common_read_get_attr_mesh (mp, points_var_tmp, &attr_type, &attr_size, &data);
 
2488
                    if (!read_fail)
 
2489
                    {
 
2490
                        adios_errno = err_no_error;
 
2491
                        meshinfo->unstructured->npoints = common_check_var_type_to_uint64 (&attr_size, data);
 
2492
                        if (adios_errno < 0)
 
2493
                        {
 
2494
                            log_warn ("Unstructured mesh %s var type of npoints is not supported. "
 
2495
                                      "We use calculated default npoints %"PRIu64" from points-var\n",
 
2496
                                      meshinfo->name, meshinfo->unstructured->npoints);
 
2497
                        }
 
2498
                    }
 
2499
                    else
 
2500
                        log_warn ("Unstructured mesh %s var of npoints is not correct. "
 
2501
                                  "We use calculated default npoints %"PRIu64" from points-var\n", 
 
2502
                                  meshinfo->name, meshinfo->unstructured->npoints);
2392
2503
                }
2393
2504
            }
2394
2505
        }
2425
2536
            else
2426
2537
            {
2427
2538
                char * spaces_var_tmp = strdup((char *)data);
2428
 
                varid = common_read_find_var (fp, spaces_var_tmp, 1);
 
2539
//                varid = common_read_find_var (fp, spaces_var_tmp, 1);
 
2540
                varid = common_read_find_var (mp, spaces_var_tmp, 1);
2429
2541
                if (varid >= 0)
2430
2542
                {
2431
 
                    ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2543
//                    ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2544
                    ADIOS_VARINFO * v = common_read_inq_var(mp,mp->var_namelist[varid]);
2432
2545
                    if (meshinfo->unstructured->nspaces > *(int *)v->value) {
2433
2546
                        log_warn ("Unstructured mesh %s: the provided nspaces %d "
2434
2547
                                  "is less than the points dim %d. "
2441
2554
                    common_read_free_varinfo (v);
2442
2555
                }
2443
2556
                else
2444
 
                    log_warn ("Unstructured mesh %s var of npoints is not correct, "
2445
 
                              " use points dim %d for nspaces\n",
2446
 
                              meshinfo->name, meshinfo->unstructured->nspaces);
 
2557
                {
 
2558
                    // check attrubites if var is not found
 
2559
                    read_fail = common_read_get_attr_mesh (mp, spaces_var_tmp, &attr_type, &attr_size, &data);
 
2560
                    if (!read_fail)
 
2561
                    {
 
2562
                        adios_errno = err_no_error;
 
2563
                        meshinfo->unstructured->nspaces = common_check_var_type_to_int (&attr_size, data);
 
2564
                        if (adios_errno < 0)
 
2565
                            log_warn ("Unstructured mesh %s var type of nspaces is not suported, "
 
2566
                                      "use points dim %d for nspaces\n",
 
2567
                                      meshinfo->name, meshinfo->unstructured->nspaces);
 
2568
                    }
 
2569
                    else
 
2570
                    {
 
2571
                        log_warn ("Unstructured mesh %s var of nspaces is not correct, "
 
2572
                                  "use points dim %d for nspaces\n",
 
2573
                                  meshinfo->name, meshinfo->unstructured->nspaces);
 
2574
                    }
 
2575
                }
2447
2576
            }
2448
2577
        }
2449
2578
 
2462
2591
            adios_error (err_mesh_unstructured_missing_ncsets, 
2463
2592
                        "Unstructured mesh %s ncsets is not provided, user should have "
2464
2593
                        "mixed-cells-count/uniform-cells in xml file\n", meshinfo->name);
2465
 
            return NULL;
 
2594
            return adios_errno;
2466
2595
        }
2467
2596
        else
2468
2597
        {
2480
2609
                adios_error (err_mesh_unstructured_invalid_ncsets, 
2481
2610
                            "Reading unstructured mesh %s ncsets failed\n", 
2482
2611
                            meshinfo->name);
2483
 
                return NULL;
 
2612
                return adios_errno;
2484
2613
 
2485
2614
            }
2486
2615
        }
2504
2633
                adios_error (err_mesh_unstructured_missing_ccount,
2505
2634
                            "Unstructured mesh %s number of cells (ccount) is required.\n", 
2506
2635
                            meshinfo->name);    
2507
 
                return NULL;
 
2636
                return adios_errno;
2508
2637
            }
2509
2638
            else
2510
2639
            {
2517
2646
                else
2518
2647
                {
2519
2648
                    char * ccount_tmp = strdup((char *)data);
2520
 
                    varid = common_read_find_var (fp, ccount_tmp, 1);
 
2649
//                    varid = common_read_find_var (fp, ccount_tmp, 1);
 
2650
                    varid = common_read_find_var (mp, ccount_tmp, 1);
2521
2651
                    if (varid >= 0)
2522
2652
                    {
2523
 
                        ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2653
//                        ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2654
                        ADIOS_VARINFO * v = common_read_inq_var(mp, mp->var_namelist[varid]);
2524
2655
                        if (v->type == adios_unsigned_long || v->type == adios_long)
2525
2656
                            meshinfo->unstructured->ccounts[0] = *(uint64_t *)v->value;
2526
2657
                        else
2532
2663
                        adios_error (err_mesh_unstructured_invalid_ccount,
2533
2664
                                    "Unstructured mesh %s var for ccount is invalid.\n", 
2534
2665
                                    meshinfo->name);
2535
 
                        return NULL;
 
2666
                        return adios_errno;
2536
2667
                    }
2537
2668
                }
2538
2669
            }    
2552
2683
                    adios_error (err_mesh_unstructured_invalid_ctypes,
2553
2684
                                "Unstructured mesh %s has more than 10 cell types.\n", 
2554
2685
                                meshinfo->name);
2555
 
                    return NULL;
 
2686
                    return adios_errno;
2556
2687
                }
2557
2688
                i_digits = sprintf (i_buffer, "%d", i);
2558
2689
                char * ccount_var = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/ccount")+i_digits+1 );
2562
2693
                strcat (ccount_var, i_buffer);
2563
2694
                free (i_buffer);
2564
2695
                data = NULL;
2565
 
                read_fail = common_read_get_attr_mesh (fp, ccount_var, &attr_type, &attr_size, &data);
 
2696
//                read_fail = common_read_get_attr_mesh (fp, ccount_var, &attr_type, &attr_size, &data);
 
2697
                read_fail = common_read_get_attr_mesh (mp, ccount_var, &attr_type, &attr_size, &data);
2566
2698
                free (ccount_var);
2567
2699
                if (read_fail)
2568
2700
                {
2569
2701
                    adios_error (err_mesh_unstructured_missing_ccount,
2570
2702
                                "Unstructured mesh %s ccount%d is not provided!\n", 
2571
2703
                                meshinfo->name, i);
2572
 
                    return NULL; 
 
2704
                    return adios_errno; 
2573
2705
                }
2574
2706
                else
2575
2707
                {
2582
2714
                    else
2583
2715
                    {
2584
2716
                        char * ccount_mix_tmp = strdup((char *)data);
2585
 
                        varid = common_read_find_var (fp, ccount_mix_tmp, 1);
 
2717
//                        varid = common_read_find_var (fp, ccount_mix_tmp, 1);
 
2718
                        varid = common_read_find_var (mp, ccount_mix_tmp, 1);
2586
2719
                        if (varid >= 0)
2587
2720
                        {
2588
 
                            ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2721
//                            ADIOS_VARINFO * v = common_read_inq_var(fp, fp->var_namelist[varid]);
 
2722
                            ADIOS_VARINFO * v = common_read_inq_var(mp, mp->var_namelist[varid]);
2589
2723
                            if (v->type == adios_long || v->type == adios_unsigned_long)
2590
2724
                                meshinfo->unstructured->ccounts[i] = *(uint64_t *)v->value;
2591
2725
                            else
2597
2731
                            adios_error (err_mesh_unstructured_invalid_ccount,
2598
2732
                                        "Unstructured mesh %s var for ccount%d is invalid\n", 
2599
2733
                                        meshinfo->name, i);
2600
 
                            return NULL; 
 
2734
                            return adios_errno; 
2601
2735
                        }
2602
2736
                    }
2603
2737
                }
2622
2756
                adios_error (err_mesh_unstructured_missing_cdata,
2623
2757
                            "Unstructured mesh %s cell data is required\n", 
2624
2758
                            meshinfo->name);
2625
 
                return NULL; 
 
2759
                return adios_errno; 
2626
2760
            }
2627
2761
            else
2628
2762
            {
2629
2763
                char * cdata_tmp = strdup((char *)data);
2630
 
                varid = common_read_find_var (fp, cdata_tmp, 1);
 
2764
//                varid = common_read_find_var (fp, cdata_tmp, 1);
 
2765
                varid = common_read_find_var (mp, cdata_tmp, 1);
2631
2766
                if (varid >= 0)
2632
 
                    meshinfo->unstructured->cdata[0] = strdup(fp->var_namelist[varid]);
 
2767
//                    meshinfo->unstructured->cdata[0] = strdup(fp->var_namelist[varid]);
 
2768
                    meshinfo->unstructured->cdata[0] = strdup(mp->var_namelist[varid]);
2633
2769
                else
2634
2770
                {
2635
2771
                    adios_error (err_mesh_unstructured_invalid_cdata,
2636
2772
                                "Unstructured mesh %s var for cdata is invalid\n", 
2637
2773
                                meshinfo->name);
2638
 
                    return NULL; 
 
2774
                    return adios_errno; 
2639
2775
                }
2640
2776
            }
2641
2777
        }
2654
2790
                    adios_error (err_mesh_unstructured_invalid_ctypes,
2655
2791
                                "Unstructured mesh %s has more than 10 cell types!\n",
2656
2792
                                meshinfo->name);
2657
 
                    return NULL; 
 
2793
                    return adios_errno; 
2658
2794
                }
2659
2795
                i_digits = sprintf (i_buffer, "%d", i);
2660
2796
                char * cdata_var = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/cdata")+i_digits+1 );
2671
2807
                    adios_error (err_mesh_unstructured_missing_cdata,
2672
2808
                                "Unstructured mesh %s cdata%d is not provided!\n", 
2673
2809
                                meshinfo->name, i);
2674
 
                    return NULL; 
 
2810
                    return adios_errno; 
2675
2811
                }
2676
2812
                else
2677
2813
                {
2678
2814
                    char * cdata_mix_tmp = strdup((char *)data);
2679
 
                    varid = common_read_find_var (fp, cdata_mix_tmp, 1);
 
2815
//                    varid = common_read_find_var (fp, cdata_mix_tmp, 1);
 
2816
                    varid = common_read_find_var (mp, cdata_mix_tmp, 1);
2680
2817
                    if (varid >= 0)
2681
 
                        meshinfo->unstructured->cdata[i] = strdup(fp->var_namelist[varid]);
 
2818
//                        meshinfo->unstructured->cdata[i] = strdup(fp->var_namelist[varid]);
 
2819
                        meshinfo->unstructured->cdata[i] = strdup(mp->var_namelist[varid]);
2682
2820
                    else
2683
2821
                    {
2684
2822
                        adios_error (err_mesh_unstructured_invalid_cdata,
2685
2823
                                    "Unstructured mesh %s var for cdata%d is not correct.\n", 
2686
2824
                                    meshinfo->name, i);
2687
 
                        return NULL; 
 
2825
                        return adios_errno; 
2688
2826
                    }
2689
2827
                }
2690
2828
            }
2707
2845
                adios_error (err_mesh_unstructured_missing_ctype,
2708
2846
                            "Unstructured mesh %s cells type is required.\n", 
2709
2847
                            meshinfo->name);
2710
 
                return NULL; 
 
2848
                return adios_errno; 
2711
2849
            } 
2712
2850
            else
2713
2851
            {
2732
2870
                                "we use line, triangle, quad, hex, prism, tet or tet for cell types. "
2733
2871
                                "please choose to use one of them. ",
2734
2872
                                 meshinfo->name, (char *)data, i);
2735
 
                    return NULL;
 
2873
                    return adios_errno;
2736
2874
                }
2737
2875
            }
2738
2876
//printf ("%d, cell type is %d\n", __LINE__, meshinfo->unstructured->ctypes[0]);
2752
2890
                    adios_error (err_mesh_unstructured_invalid_ctypes,
2753
2891
                                "Unstructured mesh %s has more than 10 cell types!\n",
2754
2892
                                meshinfo->name);
2755
 
                    return NULL; 
 
2893
                    return adios_errno; 
2756
2894
                }
2757
2895
                i_digits = sprintf (i_buffer, "%d", i);
2758
2896
                char * ctype_mix_var = malloc (strlen("/adios_schema/")+strlen(meshinfo->name)+strlen("/ctype")+i_digits+1 );
2769
2907
                    adios_error (err_mesh_unstructured_missing_ctype,
2770
2908
                                "Unstructured mesh %s ctype%d is not provided!\n", 
2771
2909
                                meshinfo->name, i);
2772
 
                    return NULL; 
 
2910
                    return adios_errno; 
2773
2911
                }
2774
2912
                else
2775
2913
                {
2794
2932
                                    "we use line, triangle, quad, hex, prism, tet or tet for cell types. "
2795
2933
                                    "please choose to use one of them. ", 
2796
2934
                                    meshinfo->name, (char *)data, i);
2797
 
                        return NULL;
 
2935
                        return adios_errno;
2798
2936
                        
2799
2937
                    }
2800
2938
                }
2805
2943
//    fp->attr_namelist[i]
2806
2944
//    common_read_get_attr_mesh (f, f->attr_namelist[i], &attr_type, &attr_size, &data);    
2807
2945
 
2808
 
    return meshinfo;
 
2946
    //return meshinfo;
 
2947
    return err_no_error;
2809
2948
}
2810
2949
 
2811
2950
void common_read_free_meshinfo (ADIOS_MESH * meshinfo)
2813
2952
    if(meshinfo)
2814
2953
    {
2815
2954
        int i = 0;
 
2955
        if (meshinfo->name)
 
2956
        {
 
2957
            free (meshinfo->name);
 
2958
            meshinfo->name = NULL;
 
2959
        }
 
2960
        if (meshinfo->file_name) 
 
2961
        {
 
2962
            free (meshinfo->file_name);
 
2963
            meshinfo->file_name = NULL;
 
2964
        }
2816
2965
        switch (meshinfo->type) {
2817
2966
            case ADIOS_MESH_UNIFORM:
2818
2967
                {
2893
3042
                               void                  * data)
2894
3043
 
2895
3044
{
2896
 
    struct common_read_internals_struct * internals;
2897
3045
    int retval;
2898
3046
    
2899
3047
    adios_errno = err_no_error;
2900
3048
    if (fp) {
2901
 
        internals = (struct common_read_internals_struct *) fp->internal_data;
2902
3049
        int varid = common_read_find_var (fp, varname,0);
2903
3050
        if (varid >= 0) {
2904
3051
            retval = common_read_schedule_read_byid (fp, sel, varid, from_steps, nsteps, param /* NCSU ALACRITY-ADIOS */, data);
2981
3128
#endif
2982
3129
            } else {
2983
3130
                // Old functionality
2984
 
            internals = (struct common_read_internals_struct *) fp->internal_data;
2985
 
            retval = internals->read_hooks[internals->method].adios_schedule_read_byid_fn (fp, sel, varid+internals->group_varid_offset, from_steps, nsteps, data);
 
3131
                common_read_free_transinfo (raw_varinfo, transinfo);
 
3132
                common_read_free_varinfo (raw_varinfo);
 
3133
 
 
3134
                internals = (struct common_read_internals_struct *) fp->internal_data;
 
3135
                retval = internals->read_hooks[internals->method].adios_schedule_read_byid_fn (fp, sel, varid+internals->group_varid_offset, from_steps, nsteps, data);
2986
3136
            }
2987
3137
        } else {
2988
3138
            adios_error (err_invalid_varid, 
3057
3207
            if (!*chunk) break; // If no more chunks are available, stop now
3058
3208
 
3059
3209
            // Process the chunk through a transform method, if necessary
3060
 
            adios_transform_process_read_chunk(internals->transform_reqgroups, chunk);
 
3210
            adios_transform_process_read_chunk(&internals->transform_reqgroups, chunk);
3061
3211
        } while (!*chunk); // Keep reading until we have a chunk to return
3062
3212
    } else {
3063
3213
        adios_error (err_invalid_file_pointer, "Null pointer passed as file to adios_check_reads()\n");
3090
3240
                          int * size, 
3091
3241
                          void ** data)
3092
3242
{
3093
 
    struct common_read_internals_struct * internals;
3094
3243
    int retval;
3095
3244
    
3096
3245
    adios_errno = err_no_error;
3097
3246
    if (fp) {
3098
 
        internals = (struct common_read_internals_struct *) fp->internal_data;
3099
3247
        int attrid = common_read_find_attr (fp->nattrs, fp->attr_namelist, attrname, 0);
3100
3248
        if (attrid > -1) {
3101
3249
            retval = common_read_get_attr_byid (fp, attrid, type, size, data);
3209
3357
        if (groupid >= 0 && groupid < internals->ngroups) {
3210
3358
            /* 1. save complete list if first done */
3211
3359
            if (internals->group_in_view == -1) {
3212
 
                internals->full_nvars = fp->nvars;
 
3360
                internals->full_nvars = (uint32_t) fp->nvars;
3213
3361
                internals->full_varnamelist = fp->var_namelist;
3214
 
                internals->full_nattrs = fp->nattrs;
 
3362
                internals->full_nattrs = (uint32_t) fp->nattrs;
3215
3363
                internals->full_attrnamelist = fp->attr_namelist;
3216
3364
            }
3217
3365
            /* Set ID offsets for easier indexing of vars/attrs in other functions */