/*!\file OptionUtilities.cpp * \brief: implementation of the options utilities */ /*Headers:*/ /*{{{*/ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif #include #include #include "../objects.h" #include "../../shared/shared.h" #include "../../Container/Container.h" #include "../../include/include.h" /*}}}*/ /*FUNCTION ColumnWiseDimsFromIndex{{{*/ int ColumnWiseDimsFromIndex(int* dims,int index,int* size,int ndims){ int i; int aprod=1; /*check for index too large */ for (i=0;i= aprod) _error2_("Index " << index << " exceeds number of elements " << aprod << "."); /*calculate the dimensions (being careful of integer division) */ for (i=ndims-1; i>=0; i--) { aprod=(int)(((IssmDouble)aprod+0.5)/(IssmDouble)size[i]); dims[i]=(int)floor(((IssmDouble)index+0.5)/(IssmDouble)aprod); index-=dims[i]*aprod; } return(0); }/*}}}*/ /*FUNCTION IndexFromColumnWiseDims{{{*/ int IndexFromColumnWiseDims(int* dims, int* size, int ndims) { int i; int index=0; /*check for any dimension too large */ for (i=0;i= size[i]) _error2_("Dimension " << i << " of " << dims[i] << " exceeds size of " << size[i] << "."); } /*calculate the index */ for (i=ndims-1; i>=0; i--){ index*=size[i]; index+=dims[i]; } return(index); }/*}}}*/ /*FUNCTION RowWiseDimsFromIndex{{{*/ int RowWiseDimsFromIndex(int* dims, int index, int* size, int ndims) { int i; int aprod=1; /*check for index too large */ for (i=0; i= aprod) _error2_("Index " << index << " exceeds number of elements " << aprod << "."); /*calculate the dimensions (being careful of integer division) */ for (i=0; i= size[i]) _error2_("Dimension " << i << " of " << dims[i] << " exceeds size of " << size[i] << "."); } /*calculate the index */ for (i=0; i