NMD
u18.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "memory.h"
00003 #include "string.h"
00004 #include "nmd.h"
00005 
00006 /*! Object reporting */
00007 int main(int argc,char **argv) {
00008   NMD_metadata nmd; NMDErrorCode ierr; 
00009   int i;
00010 
00011   PetscFunctionBegin;
00012   PetscInitialize(&argc,&argv,0,0);
00013 
00014   ierr = NMDCreateObject(&nmd); NMD_ERR_RETURN(ierr);
00015 
00016   /*
00017    * create a bunch of components
00018    */
00019   for (i=0; i<37; i++) {
00020     char cname[6];
00021     memset(cname,0,6);
00022     sprintf(cname,"cmp%d",i);
00023     ierr = NMDSetValue(nmd,"cat",cname,NMDInt,&i); NMD_ERR_RETURN(ierr);
00024   }
00025 
00026   /* 
00027    * now count the keys & values
00028    */
00029   {
00030     const char *s1,*s2,*c; int n1,n2;
00031     ierr = NMDReportObject(nmd,NMDFalse,&s1,&s2,'\t',0,0); NMD_ERR_RETURN(ierr);
00032 
00033     c = strtok((char*)s1,"\t"); n1 = 0;
00034     while (c) {n1++; c = strtok(NULL,"\t");}
00035 
00036     c = strtok((char*)s2,"\t"); n2 = 0;
00037     while (c) {n2++; c = strtok(NULL,"\t");}
00038 
00039     if (n1!=n2) printf("Mismatch: %d columns in header, %d in values\n",n1,n2);
00040 
00041     NMD_FREE(s1);
00042     NMD_FREE(s2);
00043   }
00044 
00045   ierr = NMDDestroyObject(nmd); NMD_ERR_RETURN(ierr);
00046 
00047   PetscFinalize();
00048   PetscFunctionReturn(0);
00049 }