New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
icutil.hpp in vendors/XIOS/current/src/interface/c – NEMO

source: vendors/XIOS/current/src/interface/c/icutil.hpp @ 3428

Last change on this file since 3428 was 3428, checked in by rblod, 12 years ago

importing initial XIOS vendor drop

File size: 1.9 KB
Line 
1/* ************************************************************************** *
2 *      Copyright © IPSL/LSCE, xios, Avril 2010 - Octobre 2011         *
3 * ************************************************************************** */
4
5
6#ifndef __ICUTIL_HPP__
7#define __ICUTIL_HPP__
8
9#include <string>
10#include <string.h>
11// ///////////////////////// Définitions/Déclarations /////////////////////// //
12
13inline bool cstr2string(const char * cstr, int cstr_size, std::string & str)
14{
15  std::string valtemp;
16  std::size_t d, f = 0;
17  if (cstr_size != -1) 
18  { 
19     valtemp.append (cstr, cstr_size);
20     d = valtemp.find_first_not_of(' ');
21     f = valtemp.find_last_not_of (' ');
22     str = valtemp.substr(d, f-d+1); 
23     return (true);
24  }
25  else
26  {
27     return (false);
28  } 
29}
30
31inline bool string_copy(const string& str, char* cstr,int cstr_size)
32{
33 
34  if (str.size()>cstr_size) return false ;
35  else
36  {
37    std::memset (cstr,' ',cstr_size);
38    str.copy(cstr,cstr_size) ;
39    return true ;
40  }
41}
42  template<class T>
43  inline  bool array_copy(ARRAY(T,1) array_in, T* array_out, size_t extent1)
44  {
45    if (array_in->num_elements() != extent1) return false ;
46    std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out);
47    return true ;
48  }
49
50  template<class T>
51  inline  bool array_copy(ARRAY(T,2) array_in, T* array_out, size_t extent1, size_t extent2)
52  {
53    if (array_in->num_elements() != extent1*extent2) return false ;
54    std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out);
55    return true ;
56  }
57
58  template<class T>
59  inline  bool array_copy(ARRAY(T,3) array_in, T* array_out, size_t extent1, size_t extent2, size_t extent3)
60  {
61    if (array_in->num_elements() != extent1*extent2*extent3) return false ;
62    std::copy(array_in->data(), array_in->data() + array_in->num_elements(), array_out);
63    return true ;
64  }       
65
66
67#endif // __ICUTIL_HPP__
Note: See TracBrowser for help on using the repository browser.