NMD
Functions
u10.c File Reference
#include <stdlib.h>
#include "nmd.h"
Include dependency graph for u10.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Test setting and getting of array values

Definition at line 5 of file u10.c.

References NMD_FREE, NMD_MALLOC, NMDCreateObject(), NMDDestroyObject(), NMDGetArrayValue(), NMDIntarray, NMDRealarray, and NMDSetArrayValue().

                               {
  NMD_metadata nmd; NMDErrorCode ierr; 
  NMDTruth flg; NMDDataType t;
  int *ii,*iir,len; double *rr;
  PetscFunctionBegin;
  PetscInitialize(&argc,&argv,0,0);

  ierr = NMDCreateObject(&nmd); NMD_ERR_RETURN(ierr);

  NMD_MALLOC(ii,5,int,"int array");
  NMD_MALLOC(rr,2,double,"double array");
  ii[2] = 15; rr[1] = 37.2;

  ierr = NMDSetArrayValue
    (nmd,"ctg","i array",NMDIntarray,&ii,5); NMD_ERR_RETURN(ierr);
  ierr = NMDSetArrayValue
    (nmd,"ctg","r array",NMDRealarray,&rr,2); NMD_ERR_RETURN(ierr);

  ierr = NMDGetArrayValue
    (nmd,"ctg","r array",NULL,NULL,&len,&flg); NMD_ERR_RETURN(ierr);
  if (!flg) NMD_ERR_REPORT("Could not get r array");
  if (len!=2) NMD_ERR_REPORTi("r array length mismatch",len);

  NMD_FREE(ii);

  /* this should go wrong since the array was freed */
  ierr = NMDGetArrayValue
    (nmd,"ctg","i array",&t,(void*)&iir,&len,&flg); NMD_ERR_RETURN(ierr);
  if (!flg) NMD_ERR_REPORT("Could not get i array");
  if (len!=5) NMD_ERR_REPORTi("i array wrong length",len);
  if (t!=NMDIntarray) NMD_ERR_REPORTi("i array type mismatch",(int)t);
  printf("Error because of incorrect usage coming up:\n\n");
  if (iir[2]!=15) NMD_ERR_REPORTi("i array value problem",iir[2]);

  NMD_FREE(rr);
  ierr = NMDDestroyObject(nmd); NMD_ERR_RETURN(ierr);

  PetscFinalize();
  PetscFunctionReturn(0);
}

Here is the call graph for this function: