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

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

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

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

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


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

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

  return (attsp);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
38
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
39
cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
40
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
  cdi_att_t *attp;
42
  size_t attid;
43
44
  size_t slen;

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

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

  slen = strlen(name);

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

  return (NULL);
}

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

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

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

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

  slen = strlen(name);

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

85
  return (attp);
86
87
}

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
106
107
108
109
110
/*
@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
111
112
113
    @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
114
115
116
117
118
119

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

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

  vlistptr = vlist_to_pointer(vlistID);
  
  attsp = get_attsp(vlistptr, varID);
Deike Kleberg's avatar
Deike Kleberg committed
129
  xassert(attsp != NULL);
130
131
132
133
134
135

  *nattsp = attsp->nelems;

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
136
137
138
139
140
141
/*
@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
142
143
144
145
146
147
148
149
    @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
150
151

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

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

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

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Deike Kleberg's avatar
Deike Kleberg committed
168
  xassert(attsp != NULL);
169

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

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

  return (status);
}


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

  vlistptr = vlist_to_pointer(vlistID);

  attsp = get_attsp(vlistptr, varID);
Deike Kleberg's avatar
Deike Kleberg committed
201
  xassert(attsp != NULL);
202

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

  attsp->nelems = 0;

  return (status);
}


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

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

  return (status);
}

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

  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
241
  xassert(attsp != NULL);
242

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
static
254
int vlist_inq_att(int indtype, int vlistID, int varID, const char *name, size_t mxsz, void *xp)
255
256
{
  int status = CDI_NOERR;
257
  vlist_t *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259
  cdi_att_t *attp;
  cdi_atts_t *attsp;
260
261
262
263
264
265
266
267
268
269
  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
270
  xassert(attsp != NULL);
271

272
273
  attp = find_att(attsp, name);
  if ( attp != NULL ) /* name in use */
274
    {
275
276
277
278
279
280
281
282
283
284
285
      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);
	}
286
287
288
    }
  else
    {
289
      Warning("Internal problem, attribute %s not found!", name);
290
291
292
293
294
295
296
297
298
    }

  return (status);
}


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

  vlistptr1 = vlist_to_pointer(vlistID1);

  attsp1 = get_attsp(vlistptr1, varID_1);
Deike Kleberg's avatar
Deike Kleberg committed
307
  xassert(attsp1 != NULL);
308

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

  return (status);
}

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

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

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
325
326
327
328
329
330
    @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
331
332
333
334
335
336

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

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

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

  return (status);
}

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

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

@Parameter
Deike Kleberg's avatar
Deike Kleberg committed
353
354
355
356
357
358
    @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
359
360
361
362
363
364

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

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

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

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
374
375
376
377
378
379
380
/*
@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
381
382
383
384
385
    @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
386
387
388
389
390
391

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

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

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

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
401
402
403
404
405
406
/*
@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
407
408
409
410
411
    @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).
412

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

@EndFunction
*/
418
int vlistInqAttInt(int vlistID, int varID, const char *name, int mlen, int *ip)
419
{
Thomas Jahns's avatar
Thomas Jahns committed
420
421
422
423
  int status
    = vlist_inq_att(DATATYPE_INT, vlistID, varID, name,
                    mlen*sizeof(int), (void *) ip);
  return status;
424
425
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
426
427
428
429
430
431
/*
@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
432
433
434
435
436
    @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
437
438
439
440
441
442

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

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

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

  return (status);
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
452
453
454
455
456
457
/*
@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
458
459
460
461
462
    @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
463
464
465
466
467
468

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

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

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

  return (status);
}
477
478
479
480
481
482
483
484
485
486
487
488
489

#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;
490
  char text[1024];
491

Deike Kleberg's avatar
Deike Kleberg committed
492
493
  xassert(attsp = get_attsp(vlistptr, varID));
  xassert(attnum >= 0 && attnum < (int)attsp->nelems);
494
495
496
497
  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
498
  switch (attp->indtype)
499
500
501
502
503
504
505
506
507
508
509
  {
  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:
510
    sprintf( text, "Unknown datatype encountered in attribute %s: %d\n",
Thomas Jahns's avatar
Thomas Jahns committed
511
            attp->name, attp->indtype);
512
    xabort ( text );
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
  }
  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;
}

533
static void
534
535
536
537
538
539
540
541
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
542
543
  xassert(attsp = get_attsp(vlistptr, varID));
  xassert(attnum >= 0 && attnum < (int)attsp->nelems);
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  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:
563
564
    xabort("Unknown datatype encountered in attribute %s: %d\n",
           attp->name, attp->indtype);
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
  }
  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);
}

582
static void
583
584
585
586
587
588
589
590
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;
591

592
593
594
595
  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));
596
  attName[tempbuf[0]] = '\0';
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
  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:
612
613
    xabort("Unknown datatype encountered in attribute %s: %d\n",
           attName, tempbuf[2]);
614
615
616
617
618
619
620
621
622
623
624
  }
  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
625
                void * buf, int size, int *position, MPI_Comm comm)
626
627
628
629
630
631
632
633
634
635
636
637
{
  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
638
639
640
641
642
643
644
645
646
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */