ITM Grid Service Library: Fortran 90

src/service/itm_grid_data.f90

Go to the documentation of this file.
00001 module itm_grid_data
00002 
00003   use itm_types , ITM_R8 => R8
00004   use euITM_schemas ! IGNORE
00005 
00006   implicit none
00007 
00008   interface gridWriteData
00009       module procedure gridWriteDataScalar, gridWriteDataVector, gridWriteDataMatrix
00010   end interface
00011 
00012 contains
00013 
00014   !> Write a scalar data field given as a scalar data representation to a generic CPO data field. 
00015   !>
00016   !> Note: the routine will make sure the required storage is allocated, and will deallocate
00017   !> and re-allocate fields as necessary.
00018 
00019   subroutine gridWriteDataScalar( cpoField, subgrid, data ) 
00020     type(type_complexgrid_scalar), intent(inout) :: cpofield
00021     integer, intent(in) :: subgrid
00022     real(ITM_R8), intent(in) :: data(:)
00023 
00024     ! set subgrid index
00025     cpoField % subgrid = subgrid
00026     
00027     ! Make sure the data field is properly allocated
00028     if ( associated(cpoField % scalar) ) then
00029         if ( .not. all( shape(cpoField % scalar) == shape(data) )) then
00030             deallocate( cpoField % scalar )
00031         end if
00032     end if
00033     ! If required, allocate storage
00034     if ( .not. associated(cpoField % scalar) ) then
00035         allocate(cpoField % scalar( size(data, 1) ))
00036     end if
00037 
00038     ! copy data
00039     cpoField % scalar = data
00040 
00041     ! clear unused fields
00042     if (associated( cpoField % vector )) deallocate(cpoField % vector)
00043     cpoField % vector => null()
00044     if (associated( cpoField % matrix )) deallocate(cpoField % matrix)
00045     cpoField % matrix => null()
00046 
00047   end subroutine gridWriteDataScalar
00048 
00049 
00050   !> Write a scalar data field given in a vector data representation to a generic CPO data field. 
00051   !>
00052   !> Note: the routine will make sure the required storage is allocated, and will deallocate
00053   !> and re-allocate fields as necessary.
00054 
00055   subroutine gridWriteDataVector( cpoField, subgrid, data ) 
00056     type(type_complexgrid_scalar), intent(inout) :: cpofield
00057     integer, intent(in) :: subgrid
00058     real(ITM_R8), intent(in) :: data(:,:)
00059 
00060     ! set subgrid index
00061     cpoField % subgrid = subgrid
00062     
00063     ! Make sure the data field is properly allocated
00064     if ( associated(cpoField % vector) ) then
00065         if ( .not. all( shape(cpoField % vector) == shape(data) )) then
00066             deallocate( cpoField % vector )
00067         end if
00068     end if
00069     ! If required, allocate storage
00070     if ( .not. associated(cpoField % vector) ) then
00071         allocate(cpoField % vector( size(data, 1), size(data, 2) ))
00072     end if
00073 
00074     ! copy data
00075     cpoField % vector = data
00076 
00077     ! clear unused fields
00078     if (associated( cpoField % scalar )) deallocate(cpoField % scalar)
00079     cpoField % scalar => null()
00080     if (associated( cpoField % matrix )) deallocate(cpoField % matrix)
00081     cpoField % matrix => null()
00082 
00083   end subroutine gridWriteDataVector
00084   
00085 
00086   !> Write a scalar data field given in a matrix data representation to a generic CPO data field. 
00087   !>
00088   !> Note: the routine will make sure the required storage is allocated, and will deallocate
00089   !> and re-allocate fields as necessary.
00090 
00091   subroutine gridWriteDataMatrix( cpoField, subgrid, data ) 
00092     type(type_complexgrid_scalar), intent(inout) :: cpofield
00093     integer, intent(in) :: subgrid
00094     real(ITM_R8), intent(in) :: data(:,:,:)
00095 
00096     ! set subgrid index
00097     cpoField % subgrid = subgrid
00098     
00099     ! Make sure the data field is properly allocated
00100     if ( associated(cpoField % matrix) ) then
00101         if ( .not. all( shape(cpoField % matrix) == shape(data) )) then
00102             deallocate( cpoField % matrix )
00103         end if
00104     end if
00105     ! If required, allocate storage
00106     if ( .not. associated(cpoField % matrix) ) then
00107         allocate(cpoField % matrix( size(data, 1), size(data, 2), size(data, 3) ))
00108     end if
00109 
00110     ! copy data
00111     cpoField % matrix = data
00112 
00113     ! clear unused fields
00114     if (associated( cpoField % scalar )) deallocate(cpoField % scalar)
00115     cpoField % scalar => null()
00116     if (associated( cpoField % vector )) deallocate(cpoField % vector)
00117     cpoField % vector => null()
00118 
00119   end subroutine gridWriteDataMatrix
00120 
00121 
00122 end module itm_grid_data
 All Classes Namespaces Files Functions Variables