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

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Object structure cloning

Definition at line 6 of file u19.c.

References NMD_FREE, NMDCloneObjectStructure(), NMDCreateObject(), NMDDestroyObject(), NMDFalse, NMDGetValue(), NMDInt, NMDReportObject(), and NMDSetValue().

                               {
  NMD_metadata nmd1,nmd2,nmd3; NMDErrorCode ierr; NMDTruth flg;
  int i;
  PetscFunctionBegin;
  PetscInitialize(&argc,&argv,0,0);

  ierr = NMDCreateObject(&nmd1); NMD_ERR_RETURN(ierr);
  ierr = NMDCreateObject(&nmd2); NMD_ERR_RETURN(ierr);

  /*
   * objects 1 and 2 have components in different orders
   */
  i = 1;
  ierr = NMDSetValue(nmd1,"cat1","cmp1",NMDInt,&i); NMD_ERR_RETURN(ierr);
  ierr = NMDSetValue(nmd2,"cat1","cmp2",NMDInt,&i); NMD_ERR_RETURN(ierr);
  i = 2;
  ierr = NMDSetValue(nmd1,"cat1","cmp2",NMDInt,&i); NMD_ERR_RETURN(ierr);
  ierr = NMDSetValue(nmd2,"cat1","cmp1",NMDInt,&i); NMD_ERR_RETURN(ierr);

  ierr = NMDCloneObjectStructure(nmd1,&nmd3); NMD_ERR_RETURN(ierr);

  ierr = NMDGetValue
    (nmd3,"cat1","cmp1",NULL,(void*)&i,&flg); NMD_ERR_RETURN(ierr);
  if (flg) printf("ERROR: Cloned component cmp1 should not be set\n");

  i = 1;
  ierr = NMDSetValue(nmd3,"cat1","cmp2",NMDInt,&i); NMD_ERR_RETURN(ierr);
  i = 2;
  ierr = NMDSetValue(nmd3,"cat1","cmp1",NMDInt,&i); NMD_ERR_RETURN(ierr);

  {
    const char *s1,*s2,*s3;
    /*
     * Get the keys, s1 and s3 should be the same
     */
    ierr = NMDReportObject
      (nmd1,NMDFalse,&s1,NULL,'-',0,0); NMD_ERR_RETURN(ierr);
    ierr = NMDReportObject
      (nmd2,NMDFalse,&s2,NULL,'-',0,0); NMD_ERR_RETURN(ierr);
    ierr = NMDReportObject
      (nmd3,NMDFalse,&s3,NULL,'-',0,0); NMD_ERR_RETURN(ierr);
    if (strcmp(s1,s3)) {
      printf("s1 = <%s> s2 = <%s> s3 = <%s>\n",s1,s2,s3);
      NMD_ERR_REPORT(">>>> Error: s1, s3 should be the same\n");
    }
    NMD_FREE(s1); NMD_FREE(s2); NMD_FREE(s3);
    /*
     * Get the values, s1 and s2 should be the same
     */
    ierr = NMDReportObject(nmd1,NMDFalse,NULL,&s1,'-',0,0); NMD_ERR_RETURN(ierr);
    ierr = NMDReportObject(nmd2,NMDFalse,NULL,&s2,'-',0,0); NMD_ERR_RETURN(ierr);
    ierr = NMDReportObject(nmd3,NMDFalse,NULL,&s3,'-',0,0); NMD_ERR_RETURN(ierr);
    if (strcmp(s1,s2)) {
      printf("s1 = <%s> s2 = <%s> s3 = <%s>\n",s1,s2,s3);
      NMD_ERR_REPORT(">>>> Error: s1, s2 should be the same\n");
    }
    NMD_FREE(s1); NMD_FREE(s2); NMD_FREE(s3);
  }

  ierr = NMDDestroyObject(nmd1); NMD_ERR_RETURN(ierr);
  ierr = NMDDestroyObject(nmd2); NMD_ERR_RETURN(ierr);
  ierr = NMDDestroyObject(nmd3); NMD_ERR_RETURN(ierr);

  PetscFinalize();
  PetscFunctionReturn(0);
}

Here is the call graph for this function: