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

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

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

13
14
15
#include "dmemory.h"

#include "cdi.h"
16
#include "cdi_int.h"
17
#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
  size_t slen;

Deike Kleberg's avatar
Deike Kleberg committed
46
  xassert(attsp != NULL);
47
48
49
50
51

  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
  size_t slen;

Deike Kleberg's avatar
Deike Kleberg committed
71
72
  xassert(attsp != NULL);
  xassert(name  != NULL);
73
74
75

  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
{
Deike Kleberg's avatar
Deike Kleberg committed
92
  xassert(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
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
113
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
114
    @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);
Deike Kleberg's avatar
Deike Kleberg committed
130
  xassert(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
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
144
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
145
146
147
    @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
148
                    the string is given by the predefined constant @func{CDI_MAX_NAME}.
Deike Kleberg's avatar
Deike Kleberg committed
149
150
    @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

Deike Kleberg's avatar
Deike Kleberg committed
164
  xassert(name != NULL);
165
166
167
168

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Deike Kleberg's avatar
Deike Kleberg committed
169
  xassert(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);
Deike Kleberg's avatar
Deike Kleberg committed
202
  xassert(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);
Deike Kleberg's avatar
Deike Kleberg committed
242
  xassert(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);
Deike Kleberg's avatar
Deike Kleberg committed
271
  xassert(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);
Deike Kleberg's avatar
Deike Kleberg committed
308
  xassert(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
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
327
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
328
    @Item  name     Attribute name.
329
    @Item  type     External data type (@func{DATATYPE_INT16} or @func{DATATYPE_INT32}).
Deike Kleberg's avatar
Deike Kleberg committed
330
331
    @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
  return vlist_def_att(DATATYPE_INT, type, vlistID, varID, name, (size_t) len, len*sizeof(int), (const void *) ip);
341
342
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
344
345
346
/*
@Function  vlistDefAttFlt
@Title     Define a floating point attribute

347
@Prototype int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
349

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
350
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
351
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
352
    @Item  name     Attribute name.
353
    @Item  type     External data type (@func{DATATYPE_FLT32} or @func{DATATYPE_FLT64}).
Deike Kleberg's avatar
Deike Kleberg committed
354
355
    @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
356
357
358
359
360
361

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

@EndFunction
*/
362
int vlistDefAttFlt(int vlistID, int varID, const char *name, int type, int len, const double *dp)
363
{
364
  return vlist_def_att(DATATYPE_FLT, type, vlistID, varID, name, (size_t) len, len*sizeof(double), (const void *) dp);
365
366
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
368
369
370
371
372
373
/*
@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
374
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
375
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
376
377
378
    @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
379
380
381
382
383
384

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

@EndFunction
*/
385
int vlistDefAttTxt(int vlistID, int varID, const char *name, int len, const char *tp)
386
{
387
  return vlist_def_att(DATATYPE_TXT, DATATYPE_TXT, vlistID, varID, name, (size_t) len, len*sizeof(char), (const void *) tp);
388
389
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
390
391
392
393
394
395
/*
@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
396
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
397
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
398
399
400
    @Item  name     Attribute name.
    @Item  mlen     Number of allocated values provided for the attribute.
    @Item  ip       Pointer location for returned integer attribute value(s).
401

Uwe Schulzweida's avatar
Uwe Schulzweida committed
402
403
404
405
406
@Description
The function @func{vlistInqAttInt} gets the values(s) of an integer attribute.

@EndFunction
*/
407
int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
408
{
409
  return vlist_inq_att(DATATYPE_INT, vlistID, varID, name, mlen*sizeof(int), (void *) ip);
410
411
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
412
413
414
415
/*
@Function  vlistInqAttFlt
@Title     Get the value(s) of a floating point attribute

416
@Prototype int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
417
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
418
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
419
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
420
421
422
    @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
423
424
425
426
427
428

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

@EndFunction
*/
429
int vlistInqAttFlt(int vlistID, int varID, const char *name, int mlen, double *dp)
430
{
431
  return vlist_inq_att(DATATYPE_FLT, vlistID, varID, name, mlen*sizeof(double), (void *) dp);
432
433
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
434
435
436
437
/*
@Function  vlistInqAttTxt
@Title     Get the value(s) of a text attribute

438
@Prototype int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
439
@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
440
    @Item  vlistID  Variable list ID, from a previous call to @fref{vlistCreate}.
441
    @Item  varID    Variable identifier, or @func{CDI_GLOBAL} for a global attribute.
Deike Kleberg's avatar
Deike Kleberg committed
442
443
444
    @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
445
446
447
448
449
450

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

@EndFunction
*/
451
int vlistInqAttTxt(int vlistID, int varID, const char *name, int mlen, char *tp)
452
{
453
  return vlist_inq_att(DATATYPE_TXT, vlistID, varID, name, mlen*sizeof(char), (void *) tp);
454
}
455
456
457
458
459
460
461
462
463
464
465
466
467

#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;
468
  char text[1024];
469

Deike Kleberg's avatar
Deike Kleberg committed
470
471
  xassert(attsp = get_attsp(vlistptr, varID));
  xassert(attnum >= 0 && attnum < (int)attsp->nelems);
472
473
474
475
  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
476
  switch (attp->indtype)
477
478
479
480
481
482
483
484
485
486
487
  {
  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:
488
    sprintf( text, "Unknown datatype encountered in attribute %s: %d\n",
Thomas Jahns's avatar
Thomas Jahns committed
489
            attp->name, attp->indtype);
490
    xabort ( text );
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
  }
  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;
}

511
static void
512
513
514
515
516
517
518
519
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;

Deike Kleberg's avatar
Deike Kleberg committed
520
521
  xassert(attsp = get_attsp(vlistptr, varID));
  xassert(attnum >= 0 && attnum < (int)attsp->nelems);
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
  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:
541
542
    xabort("Unknown datatype encountered in attribute %s: %d\n",
           attp->name, attp->indtype);
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
  }
  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);
}

560
static void
561
562
563
564
565
566
567
568
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;
569

570
571
572
573
  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));
574
  attName[tempbuf[0]] = '\0';
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
  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:
590
591
    xabort("Unknown datatype encountered in attribute %s: %d\n",
           attName, tempbuf[2]);
592
593
594
595
596
597
598
599
600
601
602
  }
  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,
Thomas Jahns's avatar
Thomas Jahns committed
603
                void * buf, int size, int *position, MPI_Comm comm)
604
605
606
607
608
609
610
611
612
613
614
615
{
  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
616
617
618
619
620
621
622
623
624
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */