Skip to content

Commit

Permalink
Some code cleanup: Fix warnings originating from unused variables and…
Browse files Browse the repository at this point in the history
… line breaks. Fix most implicit integer conversion warnings and add check for safe conversion taken from Flexi. Replace SIZEOF which is no Fortran standard by SIZEOF_F macro which uses the Fortran function STORAGE_SIZE.
  • Loading branch information
tbole committed Oct 18, 2016
1 parent 2f5efdc commit bf94850
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/hopr.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
#endif
#define __STAMP__ __FILENAME__,__LINE__,__DATE__,__TIME__

#ifdef GNU
# define IEEE_IS_NAN ISNAN
#endif

#define SIZEOF_F(x) STORAGE_SIZE(x)/8

#ifdef GNU
#define CHECKSAFEINT(x,k) IF(x>HUGE(1_ k).OR.x<-HUGE(1_ k)) CALL ABORT(__STAMP__,'Integer conversion failed: out of range!')
#define CHECKSAFEREAL(x,k) IF(x>HUGE(1._ k).OR.x<-HUGE(1._ k)) CALL ABORT(__STAMP__,'Real conversion failed: out of range!')
#else
#define CHECKSAFEINT(x,k) IF(x>HUGE(1_ ## k).OR.x<-HUGE(1_ ## k)) CALL ABORT(__STAMP__,'Integer conversion failed: out of range!')
#define CHECKSAFEREAL(x,k) IF(x>HUGE(1._ ## k).OR.x<-HUGE(1._ ## k)) CALL ABORT(__STAMP__,'Real conversion failed: out of range!')
#endif

#define SDEALLOCATE(A) IF(ASSOCIATED(A)) DEALLOCATE(A)
#define ERRWRITE(a,b) WRITE(UNIT_errFile,b)
#define LOGWRITE(a,b) IF(Logging) WRITE(UNIT_logOut,b)
Expand Down Expand Up @@ -72,3 +86,4 @@
#if(PP_CGNS_INT==32)
# define PP_CGNS_INT_TYPE INTEGER
#endif

1 change: 0 additions & 1 deletion src/mesh/mesh_connect.f90
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ SUBROUTINE Connect()
INTEGER :: iNode,i ! ?
INTEGER :: nInner(2),nPeriodic(2) ! ?
INTEGER :: nBCSides,nTotalSides,nPeriodicSides,connectedSides ! ?
integer :: counter
!===================================================================================================================================
CALL Timer(.TRUE.)
WRITE(UNIT_stdOut,'(132("~"))')
Expand Down
2 changes: 1 addition & 1 deletion src/output/output_vars.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MODULE MOD_Output_Vars
INTEGER :: DebugVisuLevel !=0, only linear mesh, =1 + surfspline (default), =2 +volspline
REAL :: Visu_sJ_limit ! limit to visualize only curved elements with sJ<=Visu_sJ_limit
INTEGER :: outputFormat !=0: VTK, =1 tecplot ascii, =2 CGNS
CHARACTER(LEN=100) :: sfc_type ! morton or hilbert
CHARACTER(LEN=255) :: sfc_type ! morton or hilbert
LOGICAL :: doSortIJK
LOGICAL :: useSpaceFillingCurve
LOGICAL :: OutputInitDone
Expand Down
27 changes: 14 additions & 13 deletions src/output/output_vtk.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
!
! You should have received a copy of the GNU General Public License along with HOPR. If not, see <http://www.gnu.org/licenses/>.
!=================================================================================================================================
#include "hopr.h"

MODULE MOD_Output_VTK
!===================================================================================================================================
Expand Down Expand Up @@ -104,15 +105,15 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin
WRITE(TempStr1,'(I16)')nVTKElems
WRITE(TempStr2,'(I16)')nVTKCells
Buffer=' <Piece NumberOfPoints="'//TRIM(ADJUSTL(TempStr1))//'" &
NumberOfCells="'//TRIM(ADJUSTL(TempStr2))//'">'//lf;WRITE(ivtk) TRIM(Buffer)
&NumberOfCells="'//TRIM(ADJUSTL(TempStr2))//'">'//lf;WRITE(ivtk) TRIM(Buffer)
! Specify point data
Buffer=' <PointData>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=0
WRITE(StrOffset,'(I16)')Offset
DO iVal=1,nVal
Buffer=' <DataArray type="Float32" Name="'//TRIM(VarNames(iVal))//'" &
format="appended" offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF(INT)+nVTKElems*SIZEOF(FLOAT)
&format="appended" offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF_F(INT)+nVTKElems*SIZEOF_F(FLOAT)
WRITE(StrOffset,'(I16)')Offset
END DO
Buffer=' </PointData>'//lf;WRITE(ivtk) TRIM(Buffer)
Expand All @@ -121,25 +122,25 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin
! Specify coordinate data
Buffer=' <Points>'//lf;WRITE(ivtk) TRIM(Buffer)
Buffer=' <DataArray type="Float32" Name="Coordinates" NumberOfComponents="3" format="appended" &
offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF(INT)+3*nVTKElems*SIZEOF(FLOAT)
&offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF_F(INT)+3*nVTKElems*SIZEOF_F(FLOAT)
WRITE(StrOffset,'(I16)')Offset
Buffer=' </Points>'//lf;WRITE(ivtk) TRIM(Buffer)
! Specify necessary cell data
Buffer=' <Cells>'//lf;WRITE(ivtk) TRIM(Buffer)
! Connectivity
Buffer=' <DataArray type="Int32" Name="connectivity" format="appended" &
offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF(INT)+2**dim1*nVTKElems*SIZEOF(INT)
&offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF_F(INT)+2**dim1*nVTKElems*SIZEOF_F(INT)
WRITE(StrOffset,'(I16)')Offset
! Offsets
Buffer=' <DataArray type="Int32" Name="offsets" format="appended" &
offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF(INT)+nVTKElems*SIZEOF(INT)
&offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Offset=Offset+SIZEOF_F(INT)+nVTKElems*SIZEOF_F(INT)
WRITE(StrOffset,'(I16)')Offset
! Elem types
Buffer=' <DataArray type="Int32" Name="types" format="appended" &
offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
&offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer)
Buffer=' </Cells>'//lf;WRITE(ivtk) TRIM(Buffer)
Buffer=' </Piece>'//lf;WRITE(ivtk) TRIM(Buffer)
Buffer=' </UnstructuredGrid>'//lf;WRITE(ivtk) TRIM(Buffer)
Expand All @@ -150,7 +151,7 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin

! Write binary raw data into append section
! Point data
nBytes = nVTKElems*SIZEOF(FLOAT)
nBytes = nVTKElems*SIZEOF_F(FLOAT)
DO iVal=1,nVal
WRITE(ivtk) nBytes,REAL(Values(iVal,:,:),4)
END DO
Expand Down Expand Up @@ -202,11 +203,11 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin
NodeIDElem=NodeIDElem+NPlot_p1_3
END DO
END SELECT
nBytes = 2**dim1*nVTKElems*SIZEOF(INT)
nBytes = 2**dim1*nVTKElems*SIZEOF_F(INT)
WRITE(ivtk) nBytes
WRITE(ivtk) Vertex(:,:)
! Offset
nBytes = nVTKElems*SIZEOF(INT)
nBytes = nVTKElems*SIZEOF_F(INT)
WRITE(ivtk) nBytes
WRITE(ivtk) (Offset,Offset=2**dim1,2**dim1*nVTKElems,2**dim1)
! Elem type
Expand Down
2 changes: 1 addition & 1 deletion src/readin/readin_CGNS.f90
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ SUBROUTINE ReadCGNSMeshStruct(FirstElem_in,CGNSFile,CGNSBase,iZone,nZonesGlob,nN
PP_CGNS_INT_TYPE :: i,j,k,l,m,step,kk,ll,mm ! ?
PP_CGNS_INT_TYPE :: k2,k3 ! ?
PP_CGNS_INT_TYPE :: stepk,stepl,stepm ! ?
PP_CGNS_INT_TYPE :: nSkipk,nSkipl,nSkipm,whichdir ! ?
PP_CGNS_INT_TYPE :: whichdir ! ?
PP_CGNS_INT_TYPE :: nElems(3)
REAL :: dir(3,3),scalprod ! ?
INTEGER :: N_loc ! ?
Expand Down
6 changes: 4 additions & 2 deletions src/readin/readin_hdf5.f90
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ SUBROUTINE ReadMeshFromHDF5(FileString,doConnection)
CALL OpenHDF5File(FileString,create=.FALSE.)

CALL GetHDF5DataSize(File_ID,'ElemInfo',nDims,HSize)
nGlobalElems=HSize(2) !global number of elements
CHECKSAFEINT(HSize(2),4)
nGlobalElems=INT(HSize(2),4) ! global number of elements
DEALLOCATE(HSize)

nElems=nGlobalElems !local number of Elements
Expand Down Expand Up @@ -616,7 +617,8 @@ SUBROUTINE ReadBCs()
!===================================================================================================================================
! Read boundary names from HDF5 file
CALL GetHDF5DataSize(File_ID,'BCNames',nDims,HSize)
nBCs=HSize(1)
CHECKSAFEINT(HSize(1),4)
nBCs=INT(HSize(1),4)
DEALLOCATE(HSize)
ALLOCATE(BCNames(nBCs), BCMapping(nBCs))
CALL ReadArrayFromHDF5(File_ID,'BCNames',1,(/nBCs/),Offset,StrArray=BCNames) ! Type is a dummy type only
Expand Down
20 changes: 6 additions & 14 deletions src/readin/readin_hdf5_old.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ MODULE MOD_Readin_HDF5_OLD
CHARACTER(LEN=255), ALLOCATABLE:: BCNames(:)
!--- output_vars
INTEGER(HID_T) :: File_ID
CHARACTER(LEN=255) :: OutputFileName
INTEGER(HID_T) :: Plist_ID,info
INTEGER :: iError
INTEGER(SIZE_T) :: SizeSet

INTEGER :: nDims
INTEGER(HSIZE_T),POINTER :: HSize(:)
Expand All @@ -65,18 +62,14 @@ MODULE MOD_Readin_HDF5_OLD
INTEGER,PARAMETER :: SIDE_BCID=4

INTEGER,ALLOCATABLE :: ElemInfo(:,:),SideInfo(:,:),NodeInfo(:)
REAL,ALLOCATABLE :: ElemWeight(:)
REAL,ALLOCATABLE :: ElemBarycenters(:,:)
REAL,ALLOCATABLE :: NodeCoords(:,:)
INTEGER,ALLOCATABLE :: NodeMap(:)
INTEGER :: nGlobalElems
INTEGER :: nElems,nSides,nNodes,locnSides,locnNodes
INTEGER :: ElemCounter(11,2)
INTEGER :: offsetElem,offsetSideID,offsetNodeID,offsetSide,offsetNode
INTEGER :: iElem,iSide,iNode,i,j,k
INTEGER :: nSideIDs,nNodeIDs
INTEGER :: nBCs,BoundaryOrder_mesh
LOGICAL :: curvedfound
INTEGER :: nNodeIDs
INTEGER :: BoundaryOrder_mesh
LOGICAL :: initMesh=.FALSE.
!-----------------------------------------------------------------------------------------------------------------------------------
! Private Part ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -147,7 +140,8 @@ SUBROUTINE ReadMeshFromHDF5_OLD(FileString,ElemWeightFile_in)
CALL OpenHDF5File(ElemWeightFile,create=.FALSE.)

CALL GetHDF5DataSize(File_ID,'ElemWeight',nDims,HSize)
nGlobalElems=HSize(1) !global number of elements
CHECKSAFEINT(HSize(1),4)
nGlobalElems=INT(HSize(1),4) ! global number of elements
DEALLOCATE(HSize)
nElems=nGlobalElems !local number of Elements

Expand Down Expand Up @@ -198,9 +192,6 @@ SUBROUTINE ReadMeshFromHDF5_OLD(FileString,ElemWeightFile_in)
ALLOCATE(Elem%Node(Elem%nNodes))
END DO

!ALLOCATE(ElemBarycenters(nElems,3))
!WRITE(*,*)'READ ELEMENT BARYCENTERS'
!CALL ReadArrayFromHDF5(File_ID,'ElemBarycenters',2,(/nElems,3/),0,RealArray=ElemBarycenters)
!----------------------------------------------------------------------------------------------------------------------------
! NODES
!----------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -551,7 +542,8 @@ SUBROUTINE ReadBCs()
!===================================================================================================================================
! Read boundary names from HDF5 file
CALL GetHDF5DataSize(File_ID,'BCNames',nDims,HSize)
nBCs=HSize(1)
CHECKSAFEINT(HSize(1),4)
nBCs=INT(HSize(1),4)
DEALLOCATE(HSize)
ALLOCATE(BCNames(nBCs), BCMapping(nBCs))
CALL ReadArrayFromHDF5(File_ID,'BCNames',1,(/nBCs/),Offset,StrArray=BCNames) ! Type is a dummy type only
Expand Down

0 comments on commit bf94850

Please sign in to comment.