YaDICs  V04.14.a
Yet another Digital Image Correlation software: platform dedicated to 2/3D Fluid and Solid kinematics field measurements.
 All Classes Files Functions Variables Pages
Cnetcdf.h
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (C) 2012, The YaDICs Project Developers.
3  * See the COPYRIGHT file at the top-level directory of this distribution ./COPYRIGHT.
4  * See ./COPYING file for copying and redistribution conditions.
5  *
6  * This file is part of YaDICs.
7  * YaDICs is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * YaDICs is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with YaDICs. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Information about how to use the software are provided at http://yadic.univ-lille1.fr/
21  **********************************************************************/
22 
23 
24 #ifndef CNETCDF
25 #define CNETCDF
26 
35 //--------------------------------------------------------------------
36 #include "netcdf.h"
37 #include <mpi.h>
38 #include <assert.h>
39 #include "hdf5.h"
40 #include <string.h>
41 #include <stdlib.h>
42 
43 #include <iostream>
44 #include <cmath>
45 #include <vector>
46 #include <fstream>
47 #include <ctime>
48 #include <cstdlib>
49 #include <stdio.h>
50 #include <sstream>
51 #include <unistd.h>
52  #define GetCurrentDir getcwd
53 
54 // #include "../CImg/CImg.h"
55 // using namespace cimg_library;
56 //--------------------------------------------------------------------
57 
58 
59 template<typename Timg>
60 class Cnetcdf
61 {
62 
63  public:
64 
65  Cimage()
66  {// constructor
67 
68  class_name = "Netcdf_loader";
69 
70  }
71 
72 
73  bool read_var()
74  {
75 
76  bool error;
77 
78  nc_open_par(const char *path, NC_NOCLOBBER || NC_NETCDF4, MPI_Comm comm, MPI_Info info,int *ncidp);
79 
80  return error;
81 
82  }
83 
84  subroutine read_var3d(file_name,var_name,var,mpid,inter)
85 ! -----------------------------------------------------------------------
86 ! io : read 3d variable in a netcdf file
87 ! -----------------------------------------------------------------------
88 ! Matthieu Marquillie
89 ! 04/2013
90 !
91  use mpi
92  use class_md
93  implicit none
94  character(len=*),intent(in) :: file_name,var_name
95  real(rk) :: var(:,:,:)
96  integer(ik) :: varid(1),i
97  integer(ik) :: ncid
98 
99  integer(ik),parameter :: ndim=3
100  type(mpi_data),optional :: mpid
101  integer(ik) :: dim_len(ndim),dimid(ndim),dim_len_check
102  integer(ik) :: dimt(3),coord(3,2)
103  integer(ik) :: startv(3),countv(3)
104  character(*),optional :: inter
105 
106  !-> open file
107  if (present(mpid)) then
108  call io_check(nf90_open(path=file_name,&
109 ! mode=IOR(NF90_WRITE,NF90_MPIPOSIX),ncid=ncid,&
110  mode=IOR(NF90_WRITE,NF90_MPIIO),ncid=ncid,&
111  comm=mpid%comm,info=MPI_INFO_NULL))
112  else
113  call io_check(nf90_open(path=file_name,mode=nf90_write,ncid=ncid))
114  endif
115 
116  !-> get variable id
117  call io_check(nf90_inq_varid(ncid,var_name,varid(1)))
118 
119  !-> recompute dimensions, start and count if mpi
120  if (present(mpid)) then
121  if (present(inter)) then
122  call md_mpi_global_coord(mpid,dimt,coord,inter=inter)
123  else
124  call md_mpi_global_coord(mpid,dimt,coord)
125  endif
126  startv=(/1,1,1/)
127  countv=(/1,1,1/)
128  do i=1,3
129  !if (dim_len(i)>1) then
130  dim_len(i)=dimt(i)
131  startv(i)=coord(i,1)
132  countv(i)=coord(i,2)
133  !endif
134  enddo
135  else
136  startv=(/1,1,1/)
137  countv=get_dim_size(var)
138  endif
139 
140  !-> read field variable
141 ! call io_check(nf90_get_var(ncid,varid(1),var))
142  call
143 io_check(nf90_get_var(ncid,varid(1),var,start=startv,count=countv))
144 
145  !-> close file
146  call io_check(nf90_close(ncid))
147 
148  end subroutine read_var3d
Definition: Cimage.h:57