⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alias.h

📁 The Spectral Toolkit is a C++ spectral transform library written by Rodney James and Chuck Panaccion
💻 H
字号:
//// spectral toolkit // copyright (c) 2005 university corporation for atmospheric research// licensed under the gnu general public license//#ifndef __alias__#define __alias__namespace spectral{  /// Function template to cast a 1-d array pointer to 1-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param P 1-d pointer of type T2 to cast  /// \returns 1-d pointer of type T1 referring to P  template <typename T1,typename T2>   T1 *alias(T2 *P)   {     return((T1*)(P));   }  /// Function template to cast a 2-d array pointer to 1-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param P 2-d pointer of type T2 to cast  /// \returns 1-d pointer of type T1 referring to P  template <typename T1,typename T2>   T1 *alias(T2 **P)   {     return((T1*)(P[0]));   }    /// Function template to cast a 3-d array pointer to 1-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param P 3-d pointer of type T2 to cast  /// \returns 1-d pointer of type T1 referring to P  template <typename T1,typename T2>   T1 *alias(T2 ***P)   {     return((T1*)(P[0][0]));   }    /// Function template to cast a 4-d array pointer to 1-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param P 4-d pointer of type T2 to cast  /// \returns 1-d pointer of type T1 referring to P  template <typename T1,typename T2>   T1 *alias(T2 ****P)   {     return((T1*)(P[0][0][0]));   }  /// Function template to deallocate 1-d array alias.  /// \param P pointer to 1-d array  template <typename T>   void dealias(T *P) {}    /// Function template to cast a 1-d array pointer to 2-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n2 first dimension of 2-d output array  /// \param n1 second dimension of 2-d output array  /// \param P 1-d pointer of type T2 to cast  /// \returns 2-d pointer of type T1 and dimension [n2][n1] referring to P  template <typename T1,typename T2>   T1 **alias(int n2,int n1,T2 *P)  {    int i;    T1 **p = new T1*[n2];    p[0] = (T1*)(P);    for(i=1;i<n2;i++)      p[i]=p[i-1]+n1;    return(p);  }    /// Function template to cast a 2-d array pointer to 2-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n2 first dimension of 2-d output array  /// \param n1 second dimension of 2-d output array  /// \param P 2-d pointer of type T2 to cast  /// \returns 2-d pointer of type T1 and dimension [n2][n1] referring to P  template <typename T1,typename T2>   T1 **alias(int n2,int n1,T2 **P)  {    int i;    T1 **p = new T1*[n2];    p[0] = (T1*)(P[0]);    for(i=1;i<n2;i++)      p[i]=p[i-1]+n1;    return(p);  }  /// Function template to cast a 3-d array pointer to 2-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n2 first dimension of 2-d output array  /// \param n1 second dimension of 2-d output array  /// \param P 3-d pointer of type T2 to cast  /// \returns 2-d pointer of type T1 and dimension [n2][n1] referring to P  template <typename T1,typename T2>   T1 **alias(int n2,int n1,T2 ***P)  {    int i;    T1 **p = new T1*[n2];    p[0] = (T1*)(P[0][0]);    for(i=1;i<n2;i++)      p[i]=p[i-1]+n1;    return(p);  }    /// Function template to cast a 4-d array pointer to 2-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n2 first dimension of 2-d output array  /// \param n1 second dimension of 2-d output array  /// \param P 4-d pointer of type T2 to cast  /// \returns 2-d pointer of type T1 and dimension [n2][n1] referring to P  template <typename T1,typename T2>   T1 **alias(int n2,int n1,T2 ****P)  {    int i;    T1 **p = new T1*[n2];    p[0] = (T1*)(P[0][0][0]);    for(i=1;i<n2;i++)      p[i]=p[i-1]+n1;    return(p);  }    /// Function template to deallocate 2-d array alias.  /// \param p pointer to 2-d array  /// deallocate 2d alias  template <typename T>   void dealias(T **p)   {     delete [] p;   }    /// Function template to cast a 1-d array pointer to 3-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n3 first dimension of 3-d output array  /// \param n2 second dimension of 3-d output array  /// \param n1 third dimension of 3-d output array  /// \param P 1-d pointer of type T2 to cast  /// \returns 3-d pointer of type T1 and dimension [n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ***alias(int n3,int n2, int n1,T2 *P)  {    int i,j,k;    T1 ***p = new T1**[n3];    p[0]= new T1*[n3*n2];    for(i=1;i<n3;i++)      p[i]=p[i-1]+n2;    p[0][0] = (T1*)(P);    for(k=1;k<n3;k++)      p[k][0]=p[k-1][0]+n1*n2;    for(k=0;k<n3;k++)      for(j=1;j<n2;j++)	p[k][j] = p[k][j-1]+n1;    return(p);  }    /// Function template to cast a 2-d array pointer to 3-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n3 first dimension of 3-d output array  /// \param n2 second dimension of 3-d output array  /// \param n1 third dimension of 3-d output array  /// \param P 2-d pointer of type T2 to cast  /// \returns 3-d pointer of type T1 and dimension [n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ***alias(int n3,int n2, int n1,T2 **P)  {    int i,j,k;    T1 ***p = new T1**[n3];    p[0]= new T1*[n3*n2];    for(i=1;i<n3;i++)      p[i]=p[i-1]+n2;    p[0][0] = (T1*)(P[0]);    for(k=1;k<n3;k++)      p[k][0]=p[k-1][0]+n1*n2;    for(k=0;k<n3;k++)      for(j=1;j<n2;j++)	p[k][j] = p[k][j-1]+n1;    return(p);  }   /// Function template to cast a 3-d array pointer to 3-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n3 first dimension of 3-d output array  /// \param n2 second dimension of 3-d output array  /// \param n1 third dimension of 3-d output array  /// \param P 3-d pointer of type T2 to cast  /// \returns 3-d pointer of type T1 and dimension [n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ***alias(int n3,int n2, int n1,T2 ***P)  {    int i,j,k;    T1 ***p = new T1**[n3];    p[0]= new T1*[n3*n2];    for(i=1;i<n3;i++)      p[i]=p[i-1]+n2;    p[0][0] = (T1*)(P[0][0]);    for(k=1;k<n3;k++)      p[k][0]=p[k-1][0]+n1*n2;    for(k=0;k<n3;k++)      for(j=1;j<n2;j++)	p[k][j] = p[k][j-1]+n1;    return(p);  }    /// Function template to cast a 4-d array pointer to 3-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n3 first dimension of 3-d output array  /// \param n2 second dimension of 3-d output array  /// \param n1 third dimension of 3-d output array  /// \param P 4-d pointer of type T2 to cast  /// \returns 3-d pointer of type T1 and dimension [n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ***alias(int n3,int n2, int n1,T2 ****P)  {    int i,j,k;    T1 ***p = new T1**[n3];    p[0]= new T1*[n3*n2];    for(i=1;i<n3;i++)      p[i]=p[i-1]+n2;    p[0][0] = (T1*)(P[0][0][0]);    for(k=1;k<n3;k++)      p[k][0]=p[k-1][0]+n1*n2;    for(k=0;k<n3;k++)      for(j=1;j<n2;j++)	p[k][j] = p[k][j-1]+n1;    return(p);  }    /// Function template to deallocate 3-d alias.  /// \param p pointer to 3-d array  template <typename T>   void dealias(T ***p)  {    delete [] p[0];    delete [] p;  }    /// Function template to cast a 1-d array pointer to 4-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n4 first dimension of 4-d output array  /// \param n3 second dimension of 4-d output array  /// \param n2 third dimension of 4-d output array  /// \param n1 fourth dimension of 4-d output array  /// \param P 1-d pointer of type T2 to cast  /// \returns 4-d pointer of type T1 and dimension [n4][n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ****alias(int n4,int n3,int n2, int n1,T2 *P)  {    int i,j,k,l;    T1 ****p = new T1***[n4];    p[0]= new T1**[n4*n3];    for(i=1;i<n4;i++)      p[i]=p[i-1]+n3;    p[0][0] = new T1*[n4*n3*n2];    for(k=1;k<n4;k++)      p[k][0]=p[k-1][0]+n2*n3;    for(k=0;k<n4;k++)      for(j=1;j<n3;j++)	p[k][j] = p[k][j-1]+n2;    p[0][0][0] = (T1*)(P);    for(l=1;l<n4;l++)      p[l][0][0]=p[l-1][0][0]+n1*n2*n3;    for(l=0;l<n4;l++)      for(k=1;k<n3;k++)	p[l][k][0]=p[l][k-1][0]+n1*n2;    for(l=0;l<n4;l++)      for(k=0;k<n3;k++)	for(j=1;j<n2;j++)	  p[l][k][j] = p[l][k][j-1]+n1;    return(p);  }    /// Function template to cast a 2-d array pointer to 4-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n4 first dimension of 4-d output array  /// \param n3 second dimension of 4-d output array  /// \param n2 third dimension of 4-d output array  /// \param n1 fourth dimension of 4-d output array  /// \param P 2-d pointer of type T2 to cast  /// \returns 4-d pointer of type T1 and dimension [n4][n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ****alias(int n4,int n3,int n2, int n1,T2 **P)  {    int i,j,k,l;    T1 ****p = new T1***[n4];    p[0]= new T1**[n4*n3];    for(i=1;i<n4;i++)      p[i]=p[i-1]+n3;    p[0][0] = new T1*[n4*n3*n2];    for(k=1;k<n4;k++)      p[k][0]=p[k-1][0]+n2*n3;    for(k=0;k<n4;k++)      for(j=1;j<n3;j++)	p[k][j] = p[k][j-1]+n2;    p[0][0][0] = (T1*)(P[0]);    for(l=1;l<n4;l++)      p[l][0][0]=p[l-1][0][0]+n1*n2*n3;    for(l=0;l<n4;l++)      for(k=1;k<n3;k++)	p[l][k][0]=p[l][k-1][0]+n1*n2;    for(l=0;l<n4;l++)      for(k=0;k<n3;k++)	for(j=1;j<n2;j++)	  p[l][k][j] = p[l][k][j-1]+n1;    return(p);  }  /// Function template to cast a 3-d array pointer to 4-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n4 first dimension of 4-d output array  /// \param n3 second dimension of 4-d output array  /// \param n2 third dimension of 4-d output array  /// \param n1 fourth dimension of 4-d output array  /// \param P 3-d pointer of type T2 to cast  /// \returns 4-d pointer of type T1 and dimension [n4][n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ****alias(int n4,int n3,int n2, int n1,T2 ***P)  {    int i,j,k,l;    T1 ****p = new T1***[n4];    p[0]= new T1**[n4*n3];    for(i=1;i<n4;i++)      p[i]=p[i-1]+n3;    p[0][0] = new T1*[n4*n3*n2];    for(k=1;k<n4;k++)      p[k][0]=p[k-1][0]+n2*n3;    for(k=0;k<n4;k++)      for(j=1;j<n3;j++)	p[k][j] = p[k][j-1]+n2;    p[0][0][0] = (T1*)(P[0][0]);    for(l=1;l<n4;l++)      p[l][0][0]=p[l-1][0][0]+n1*n2*n3;    for(l=0;l<n4;l++)      for(k=1;k<n3;k++)	p[l][k][0]=p[l][k-1][0]+n1*n2;    for(l=0;l<n4;l++)      for(k=0;k<n3;k++)	for(j=1;j<n2;j++)	  p[l][k][j] = p[l][k][j-1]+n1;    return(p);  }  /// Function template to cast a 4-d array pointer to 4-d array pointer.  /// Use dealias to deallocate an aliased array,  /// using dealloc will also deallocate the orginal array.  /// \param n4 first dimension of 4-d output array  /// \param n3 second dimension of 4-d output array  /// \param n2 third dimension of 4-d output array  /// \param n1 fourth dimension of 4-d output array  /// \param P 4-d pointer of type T2 to cast  /// \returns 4-d pointer of type T1 and dimension [n4][n3][n2][n1] referring to P  template <typename T1,typename T2>   T1 ****alias(int n4,int n3,int n2, int n1,T2 ****P)  {    int i,j,k,l;    T1 ****p = new T1***[n4];    p[0]= new T1**[n4*n3];    for(i=1;i<n4;i++)      p[i]=p[i-1]+n3;    p[0][0] = new T1*[n4*n3*n2];    for(k=1;k<n4;k++)      p[k][0]=p[k-1][0]+n2*n3;    for(k=0;k<n4;k++)      for(j=1;j<n3;j++)	p[k][j] = p[k][j-1]+n2;    p[0][0][0] = (T1*)(P[0][0][0]);    for(l=1;l<n4;l++)      p[l][0][0]=p[l-1][0][0]+n1*n2*n3;    for(l=0;l<n4;l++)      for(k=1;k<n3;k++)	p[l][k][0]=p[l][k-1][0]+n1*n2;    for(l=0;l<n4;l++)      for(k=0;k<n3;k++)	for(j=1;j<n2;j++)	  p[l][k][j] = p[l][k][j-1]+n1;    return(p);  }  /// Function template to deallocate 4-d array alias.  /// \param p pointer to 4-d array  template <typename T>   void dealias(T ****p)  {    delete [] p[0][0];    delete [] p[0];    delete [] p;  }}#endif// Local Variables:// mode:C++// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -