#include <stdlib.h>
#include "nmd.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
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().
00005 { 00006 NMD_metadata nmd; NMDErrorCode ierr; 00007 NMDTruth flg; NMDDataType t; 00008 int *ii,*iir,len; double *rr; 00009 PetscFunctionBegin; 00010 PetscInitialize(&argc,&argv,0,0); 00011 00012 ierr = NMDCreateObject(&nmd); NMD_ERR_RETURN(ierr); 00013 00014 NMD_MALLOC(ii,5,int,"int array"); 00015 NMD_MALLOC(rr,2,double,"double array"); 00016 ii[2] = 15; rr[1] = 37.2; 00017 00018 ierr = NMDSetArrayValue 00019 (nmd,"ctg","i array",NMDIntarray,&ii,5); NMD_ERR_RETURN(ierr); 00020 ierr = NMDSetArrayValue 00021 (nmd,"ctg","r array",NMDRealarray,&rr,2); NMD_ERR_RETURN(ierr); 00022 00023 ierr = NMDGetArrayValue 00024 (nmd,"ctg","r array",NULL,NULL,&len,&flg); NMD_ERR_RETURN(ierr); 00025 if (!flg) NMD_ERR_REPORT("Could not get r array"); 00026 if (len!=2) NMD_ERR_REPORTi("r array length mismatch",len); 00027 00028 NMD_FREE(ii); 00029 00030 /* this should go wrong since the array was freed */ 00031 ierr = NMDGetArrayValue 00032 (nmd,"ctg","i array",&t,(void*)&iir,&len,&flg); NMD_ERR_RETURN(ierr); 00033 if (!flg) NMD_ERR_REPORT("Could not get i array"); 00034 if (len!=5) NMD_ERR_REPORTi("i array wrong length",len); 00035 if (t!=NMDIntarray) NMD_ERR_REPORTi("i array type mismatch",(int)t); 00036 printf("Error because of incorrect usage coming up:\n\n"); 00037 if (iir[2]!=15) NMD_ERR_REPORTi("i array value problem",iir[2]); 00038 00039 NMD_FREE(rr); 00040 ierr = NMDDestroyObject(nmd); NMD_ERR_RETURN(ierr); 00041 00042 PetscFinalize(); 00043 PetscFunctionReturn(0); 00044 }