vlist_att.c 16.3 KB
Newer Older
1
2
3
4
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

5
6
7
8
#include <stdio.h>
#include <string.h>
#include <assert.h>

9
10
11
12
#ifdef USE_MPI
#include <mpi.h>
#endif

13
14
15
16
17
#include "dmemory.h"

#include "cdi.h"
#include "stream_int.h"
#include "vlist.h"
18
#include "pio_util.h"
19
20


Uwe Schulzweida's avatar
Uwe Schulzweida committed
21
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
22
cdi_atts_t *get_attsp(vlist_t *vlistptr, int varID)
23
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
  cdi_atts_t *attsp = NULL;
25
26
27
28
29
30
31

  if ( varID == CDI_GLOBAL )
    {
      attsp = &vlistptr->atts;
    }
  else
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
33
      if ( varID >= 0 && varID < vlistptr->nvars )
	attsp = &(vlistptr->vars[varID].atts);
34
35
36
37
38
    }

  return (attsp);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
40
cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
41
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
42
  cdi_att_t *attp;
43
  size_t attid;
44
45
46
47
48
49
50
51
  size_t slen;

  assert(attsp != NULL);

  if ( attsp->nelems == 0 ) return NULL;

  slen = strlen(name);

52
  for ( attid = 0; attid < attsp->nelems; attid++ )
53
    {
54
55
      attp = &(attsp->value[attid]);
      if ( attp->namesz == slen )
56
	if ( memcmp(attp->name, name, slen) == 0)
57
	  {
58
	    return (attp); /* Normal return */
59
60
61
62
63
64
	  }
    }

  return (NULL);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
65
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
66
cdi_att_t *new_att(cdi_atts_t *attsp, const char *name)
67
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
  cdi_att_t *attp;
69
70
71
72
73
74
75
  size_t slen;

  assert(attsp != NULL);
  assert(name  != NULL);

  if ( attsp->nelems == attsp->nalloc ) return (NULL);

76
  attp = &(attsp->value[attsp->nelems]);
77
78
79
80
  attsp->nelems++;

  slen = strlen(name);

81
82
83
  attp->name = (char *) malloc(slen+1);
  memcpy(attp->name, name, slen+1);
  attp->namesz = slen;
84
  attp->xvalue = NULL;
85

86
  return (attp);
87
88
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
89
static
90
void fill_att(cdi_att_t *attp, int indtype, int exdtype, size_t nelems, size_t xsz, const void *xvalue)
91
{
92
  assert(attp != NULL);
93

94
  attp->xsz = xsz;
95
96
97
  attp->indtype = indtype;
  attp->exdtype = exdtype;
  attp->nelems  = nelems;
98

99
100
  if ( xsz > 0 )
    {
101
      attp->xvalue = xrealloc(attp->xvalue, xsz);
102
103
      memcpy(attp->xvalue, xvalue, xsz);
    }
104
105
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
106
107
108
109
110
111
/*
@Function  vlistInqNatts
@Title     Get number of variable attributes

@Prototype int vlistInqNatts(int vlistID, int varID, int *nattsp)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
112
113
114
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  nattsp   Pointer to location for returned number of variable attributes.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
115
116
117
118
119
120

@Description
The function @func{vlistInqNatts} gets the number of variable attributes assigned to this variable.

@EndFunction
*/
121
122
123
int vlistInqNatts(int vlistID, int varID, int *nattsp)
{
  int status = CDI_NOERR;
124
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
125
  cdi_atts_t *attsp;
126
127
128
129

  vlistptr = vlist_to_pointer(vlistID);
  
  attsp = get_attsp(vlistptr, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
130
  assert(attsp != NULL);
131
132
133
134
135
136

  *nattsp = attsp->nelems;

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
138
139
140
141
142
/*
@Function  vlistInqAtt
@Title     Get information about an attribute

@Prototype int vlistInqAtt(int vlistID, int varID, int attnum, char *name, int *typep, int *lenp)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
143
144
145
146
147
148
149
150
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  attnum   Attribute number (from 0 to natts-1).
    @Item  name     Pointer to the location for the returned attribute name. The caller must allocate space for the 
                    returned string. The maximum possible length, in characters, of
                    the string is given by the predefined constant CDI_MAX_NAME.
    @Item  typep    Pointer to location for returned attribute type.
    @Item  lenp     Pointer to location for returned attribute number.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152

@Description
153
The function @func{vlistInqAtt} gets information about an attribute.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
155
156

@EndFunction
*/
157
int vlistInqAtt(int vlistID, int varID, int attnum, char *name, int *typep, int *lenp)
158
159
{
  int status = CDI_NOERR;
160
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162
  cdi_att_t *attp = NULL;
  cdi_atts_t *attsp;
163
164
165
166
167
168

  assert(name != NULL);

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
  assert(attsp != NULL);
170

171
172
  if ( attnum >= 0 && attnum < (int)attsp->nelems )
    attp = &(attsp->value[attnum]);
173

174
  if ( attp != NULL ) /* name in use */
175
    {
176
      memcpy(name, attp->name, attp->namesz+1);
177
      *typep  = attp->exdtype;
178
      *lenp   = attp->nelems;
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    }
  else
    {
      name[0] =  0;
      *typep  = -1;
      *lenp   =  0;
    }

  return (status);
}


int vlistDelAtts(int vlistID, int varID)
{
  int status = CDI_NOERR;
194
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
195
196
  cdi_att_t *attp = NULL;
  cdi_atts_t *attsp;
197
  int attid;
198
199
200
201

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
202
  assert(attsp != NULL);
203

204
  for ( attid = 0; attid < (int)attsp->nelems; attid++ )
205
    {
206
207
208
      attp = &(attsp->value[attid]);
      if ( attp->name   ) free(attp->name);
      if ( attp->xvalue ) free(attp->xvalue);
209
210
211
212
213
214
215
216
    }

  attsp->nelems = 0;

  return (status);
}


217
int vlistDelAtt(int vlistID, int varID, const char *name)
218
219
220
{
  int status = CDI_NOERR;

221
  fprintf(stderr, "vlistDelAtt not implemented!\n");
222
223
224
225

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
226
static
227
int vlist_def_att(int indtype, int exdtype, int vlistID, int varID, const char *name, size_t len, size_t xsz, const void *xp)
228
229
{
  int status = CDI_NOERR;
230
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
231
232
  cdi_att_t *attp;
  cdi_atts_t *attsp;
233
234
235
236
237
238
239
240
241

  if ( len != 0 && xp == NULL ) /* Null arg */
    {
      return (CDI_EINVAL);
    }

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
  assert(attsp != NULL);
243

244
  attp = find_att(attsp, name);
245
246
  if ( attp == NULL )
    attp = new_att(attsp, name);
247

248
  if ( attp != NULL )
249
    fill_att(attp, indtype, exdtype, len, xsz, xp);
250
  
251
252
253
  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
254
static
255
int vlist_inq_att(int indtype, int vlistID, int varID, const char *name, size_t mxsz, void *xp)
256
257
{
  int status = CDI_NOERR;
258
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
259
260
  cdi_att_t *attp;
  cdi_atts_t *attsp;
261
262
263
264
265
266
267
268
269
270
  size_t xsz;

  if ( mxsz != 0 && xp == NULL ) /* Null arg */
    {
      return (CDI_EINVAL);
    }

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
271
  assert(attsp != NULL);
272

273
274
  attp = find_att(attsp, name);
  if ( attp != NULL ) /* name in use */
275
    {
276
277
278
279
280
281
282
283
284
285
286
      if ( attp->indtype == indtype )
	{
	  xsz = attp->xsz;
	  if ( mxsz < xsz ) xsz = mxsz;
	  if ( xsz > 0 )
	    memcpy(xp, attp->xvalue, xsz);
	}
      else
	{
	  Warning("Attribute %s has wrong data type!", name);
	}
287
288
289
    }
  else
    {
290
      Warning("Internal problem, attribute %s not found!", name);
291
292
293
294
295
296
297
298
299
    }

  return (status);
}


int vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2)
{
  int status = CDI_NOERR;
300
  vlist_t *vlistptr1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
302
  cdi_att_t *attp = NULL;
  cdi_atts_t *attsp1;
303
  int attid;
304
305
306
307

  vlistptr1 = vlist_to_pointer(vlistID1);

  attsp1 = get_attsp(vlistptr1, varID_1);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
  assert(attsp1 != NULL);
309

310
  for ( attid = 0; attid < (int)attsp1->nelems; attid++ )
311
    {
312
      attp = &(attsp1->value[attid]);
313
      vlist_def_att(attp->indtype, attp->exdtype, vlistID2, varID_2, attp->name, attp->nelems, attp->xsz, attp->xvalue);
314
315
316
317
318
    }

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
320
321
322
/*
@Function  vlistDefAttInt
@Title     Define an integer attribute

323
@Prototype int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
325

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
326
327
328
329
330
331
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  type     External data type (DATATYPE_INT16 or DATATYPE_INT32).
    @Item  len      Number of values provided for the attribute.
    @Item  ip       Pointer to one or more integer values.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
332
333
334
335
336
337

@Description
The function @func{vlistDefAttInt} defines an integer attribute.

@EndFunction
*/
338
int vlistDefAttInt(int vlistID, int varID, const char *name, int type, int len, const int *ip)
339
340
341
{
  int status;

342
  status = vlist_def_att(DATATYPE_INT, type, vlistID, varID, name, (size_t) len, len*sizeof(int), (const void *) ip);
343
344
345
346

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
347
348
349
350
/*
@Function  vlistDefAttFlt
@Title     Define a floating point attribute

351
@Prototype int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
352
353

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
354
355
356
357
358
359
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  type     External data type (DATATYPE_FLT32 or DATATYPE_FLT64).
    @Item  len      Number of values provided for the attribute.
    @Item  dp       Pointer to one or more floating point values.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
360
361
362
363
364
365

@Description
The function @func{vlistDefAttFlt} defines a floating point attribute.

@EndFunction
*/
366
int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
367
368
369
{
  int status;

370
  status = vlist_def_att(DATATYPE_FLT, type, vlistID, varID, name, (size_t) len, len*sizeof(double), (const void *) dp);
371
372
373
374

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
375
376
377
378
379
380
381
/*
@Function  vlistDefAttTxt
@Title     Define a text attribute

@Prototype int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp)

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
382
383
384
385
386
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  len      Number of values provided for the attribute.
    @Item  tp       Pointer to one or more character values.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
387
388
389
390
391
392

@Description
The function @func{vlistDefAttTxt} defines a text attribute.

@EndFunction
*/
393
int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp)
394
395
396
{
  int status;

397
  status = vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t) len, len*sizeof(char), (const void *) tp);
398
399
400
401

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
402
403
404
405
406
407
/*
@Function  vlistInqAttInt
@Title     Get the value(s) of an integer attribute

@Prototype int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
408
409
410
411
412
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  mlen     Number of allocated values provided for the attribute.
    @Item  ip       Pointer location for returned integer attribute value(s).
413

Uwe Schulzweida's avatar
Uwe Schulzweida committed
414
415
416
417
418
@Description
The function @func{vlistInqAttInt} gets the values(s) of an integer attribute.

@EndFunction
*/
419
int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
420
421
422
{
  int status = CDI_NOERR;

423
  status = vlist_inq_att(DATATYPE_INT, vlistID, varID, name, mlen*sizeof(int), (void *) ip);
424
425
426
427

  return (CDI_NOERR);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
428
429
430
431
432
433
/*
@Function  vlistInqAttFlt
@Title     Get the value(s) of a floating point attribute

@Prototype int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, int *dp)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
434
435
436
437
438
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  mlen     Number of allocated values provided for the attribute.
    @Item  dp       Pointer location for returned floating point attribute value(s).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
439
440
441
442
443
444

@Description
The function @func{vlistInqAttFlt} gets the values(s) of a floating point attribute.

@EndFunction
*/
445
int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *dp)
446
447
448
{
  int status = CDI_NOERR;

449
  status = vlist_inq_att(DATATYPE_FLT, vlistID, varID, name, mlen*sizeof(double), (void *) dp);
450
451
452
453

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
454
455
456
457
458
459
/*
@Function  vlistInqAttTxt
@Title     Get the value(s) of a text attribute

@Prototype int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, int *tp)
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
460
461
462
463
464
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
    @Item  varID    Variable identifier, or CDI_GLOBAL for a global attribute.
    @Item  name     Attribute name.
    @Item  mlen     Number of allocated values provided for the attribute.
    @Item  tp       Pointer location for returned text attribute value(s).
Uwe Schulzweida's avatar
Uwe Schulzweida committed
465
466
467
468
469
470

@Description
The function @func{vlistInqAttTxt} gets the values(s) of a text attribute.

@EndFunction
*/
471
int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, char *tp)
472
473
474
{
  int status = CDI_NOERR;

475
  status = vlist_inq_att(DATATYPE_TXT, vlistID, varID, name, mlen*sizeof(char), (void *) tp);
476
477
478

  return (status);
}
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

#ifdef USE_MPI

enum {
  vlist_att_nints = 4,          /* namesz, exdtype, indtype, nelems */
};

static int
vlistAttGetSize(vlist_t *vlistptr, int varID, int attnum, MPI_Comm comm)
{
  int txsize = 0, txinc;
  cdi_atts_t *attsp;
  cdi_att_t *attp;

  assert(attsp = get_attsp(vlistptr, varID));
  assert(attnum >= 0 && attnum < (int)attsp->nelems);
  attp = &(attsp->value[attnum]);
  xmpi(MPI_Pack_size(vlist_att_nints, MPI_INT, comm, &txsize));
  xmpi(MPI_Pack_size(attp->namesz, MPI_CHAR, comm, &txinc));
  txsize += txinc;
Thomas Jahns's avatar
Thomas Jahns committed
499
  switch (attp->indtype)
500
501
502
503
504
505
506
507
508
509
510
511
  {
  case DATATYPE_FLT:
    xmpi(MPI_Pack_size((int)attp->nelems, MPI_DOUBLE, comm, &txinc));
    break;
  case DATATYPE_INT:
    xmpi(MPI_Pack_size((int)attp->nelems, MPI_INT, comm, &txinc));
    break;
  case DATATYPE_TXT:
    xmpi(MPI_Pack_size((int)attp->nelems, MPI_CHAR, comm, &txinc));
    break;
  default:
    fprintf(stderr, "Unknown datatype encountered in attribute %s: %d\n",
Thomas Jahns's avatar
Thomas Jahns committed
512
            attp->name, attp->indtype);
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
    xabort("");
  }
  txsize += txinc;
  return txsize;
}

int
vlistAttsGetSize(vlist_t *p, int varID, MPI_Comm comm)
{
  int numAtts, i;
  int txsize;
  cdi_atts_t *attsp = get_attsp(p, varID);
  numAtts = attsp->nelems;
  xmpi(MPI_Pack_size(1, MPI_INT, comm, &txsize));
  for (i = 0; i < numAtts; ++i)
  {
    txsize += vlistAttGetSize(p, varID, i, comm);
  }
  return txsize;
}

static int
vlistAttPack(vlist_t *vlistptr, int varID, int attnum,
             void * buf, int size, int *position, MPI_Comm comm)
{
  cdi_atts_t *attsp;
  cdi_att_t *attp;
  int tempbuf[vlist_att_nints];
  MPI_Datatype attVMPIDt;

  assert(attsp = get_attsp(vlistptr, varID));
  assert(attnum >= 0 && attnum < (int)attsp->nelems);
  attp = &(attsp->value[attnum]);
  tempbuf[0] = attp->namesz;
  tempbuf[1] = attp->exdtype;
  tempbuf[2] = attp->indtype;
  tempbuf[3] = attp->nelems;
  xmpi(MPI_Pack(tempbuf, vlist_att_nints, MPI_INT, buf, size, position, comm));
  xmpi(MPI_Pack(attp->name, attp->namesz, MPI_CHAR, buf, size, position, comm));
  switch (attp->indtype)
  {
  case DATATYPE_FLT:
    attVMPIDt = MPI_DOUBLE;
    break;
  case DATATYPE_INT:
    attVMPIDt = MPI_INT;
    break;
  case DATATYPE_TXT:
    attVMPIDt = MPI_CHAR;
    break;
  default:
    fprintf(stderr, "Unknown datatype encountered in attribute %s: %d\n",
            attp->name, attp->indtype);
    xabort("");
  }
  xmpi(MPI_Pack(attp->xvalue, (int)attp->nelems, attVMPIDt,
                buf, size, position, comm));
}

void
vlistAttsPack(vlist_t *p, int varID,
              void * buf, int size, int *position, MPI_Comm comm)
{
  int numAtts, i;
  cdi_atts_t *attsp = get_attsp(p, varID);
  numAtts = attsp->nelems;
  xmpi(MPI_Pack(&numAtts, 1, MPI_INT, buf, size, position, comm));
  for (i = 0; i < numAtts; ++i)
  {
    vlistAttPack(p, varID, i, buf, size, position, comm);
  }
}

static int
vlistAttUnpack(int vlistID, int varID,
               void * buf, int size, int *position, MPI_Comm comm)
{
  char *attName;
  int tempbuf[vlist_att_nints];
  MPI_Datatype attVMPIDt;
  int elemSize;
  void *attData;

  xmpi(MPI_Unpack(buf, size, position,
                  tempbuf, vlist_att_nints, MPI_INT, comm));
  attName = xmalloc(tempbuf[0] + 1);
  xmpi(MPI_Unpack(buf, size, position, attName, tempbuf[0], MPI_CHAR, comm));
600
  attName[tempbuf[0]] = '\0';
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
  switch (tempbuf[2])
  {
  case DATATYPE_FLT:
    attVMPIDt = MPI_DOUBLE;
    elemSize = sizeof(double);
    break;
  case DATATYPE_INT:
    attVMPIDt = MPI_INT;
    elemSize = sizeof(int);
    break;
  case DATATYPE_TXT:
    attVMPIDt = MPI_CHAR;
    elemSize = 1;
    break;
  default:
    fprintf(stderr, "Unknown datatype encountered in attribute %s: %d\n",
            attName, tempbuf[2]);
    xabort("");
  }
  attData = xmalloc(elemSize * tempbuf[3]);
  xmpi(MPI_Unpack(buf, size, position, attData, tempbuf[3], attVMPIDt, comm));
  vlist_def_att(tempbuf[2], tempbuf[1], vlistID, varID, attName,
                tempbuf[3], tempbuf[3] * elemSize, attData);
  free(attName);
  free(attData);
}

void
vlistAttsUnpack(int vlistID, int varID,
              void * buf, int size, int *position, MPI_Comm comm)
{
  int numAtts, i;
  xmpi(MPI_Unpack(buf, size, position, &numAtts, 1, MPI_INT, comm));
  for (i = 0; i < numAtts; ++i)
  {
    vlistAttUnpack(vlistID, varID, buf, size, position, comm);
  }
}



#endif
643
644
645
646
647
648
649
650
651
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */