From bf94850976efab2edd8333be239376d928e27d22 Mon Sep 17 00:00:00 2001 From: Thomas Bolemann Date: Tue, 18 Oct 2016 16:41:49 +0200 Subject: [PATCH] Some code cleanup: Fix warnings originating from unused variables and 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. --- src/hopr.h | 15 +++++++++++++++ src/mesh/mesh_connect.f90 | 1 - src/output/output_vars.f90 | 2 +- src/output/output_vtk.f90 | 27 ++++++++++++++------------- src/readin/readin_CGNS.f90 | 2 +- src/readin/readin_hdf5.f90 | 6 ++++-- src/readin/readin_hdf5_old.f90 | 20 ++++++-------------- 7 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/hopr.h b/src/hopr.h index 9262459..bd53ae3 100644 --- a/src/hopr.h +++ b/src/hopr.h @@ -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) @@ -72,3 +86,4 @@ #if(PP_CGNS_INT==32) # define PP_CGNS_INT_TYPE INTEGER #endif + diff --git a/src/mesh/mesh_connect.f90 b/src/mesh/mesh_connect.f90 index 4f667e6..a1e41d1 100644 --- a/src/mesh/mesh_connect.f90 +++ b/src/mesh/mesh_connect.f90 @@ -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("~"))') diff --git a/src/output/output_vars.f90 b/src/output/output_vars.f90 index 130ef57..9c9e768 100644 --- a/src/output/output_vars.f90 +++ b/src/output/output_vars.f90 @@ -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 diff --git a/src/output/output_vtk.f90 b/src/output/output_vtk.f90 index 765ae4d..031b5e4 100644 --- a/src/output/output_vtk.f90 +++ b/src/output/output_vtk.f90 @@ -20,6 +20,7 @@ ! ! You should have received a copy of the GNU General Public License along with HOPR. If not, see . !================================================================================================================================= +#include "hopr.h" MODULE MOD_Output_VTK !=================================================================================================================================== @@ -104,15 +105,15 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin WRITE(TempStr1,'(I16)')nVTKElems WRITE(TempStr2,'(I16)')nVTKCells Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) + &NumberOfCells="'//TRIM(ADJUSTL(TempStr2))//'">'//lf;WRITE(ivtk) TRIM(Buffer) ! Specify point data Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) Offset=0 WRITE(StrOffset,'(I16)')Offset DO iVal=1,nVal Buffer=' '//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=' '//lf;WRITE(ivtk) TRIM(Buffer) @@ -121,25 +122,25 @@ SUBROUTINE WriteDataToVTK(dim1,nVal,NPlot,nElems,VarNames,Coord,Values,FileStrin ! Specify coordinate data Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) Buffer=' '//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=' '//lf;WRITE(ivtk) TRIM(Buffer) ! Specify necessary cell data Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) ! Connectivity Buffer=' '//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=' '//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=' '//lf;WRITE(ivtk) TRIM(Buffer) + &offset="'//TRIM(ADJUSTL(StrOffset))//'"/>'//lf;WRITE(ivtk) TRIM(Buffer) Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) Buffer=' '//lf;WRITE(ivtk) TRIM(Buffer) @@ -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 @@ -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 diff --git a/src/readin/readin_CGNS.f90 b/src/readin/readin_CGNS.f90 index 9c1668e..ded0329 100644 --- a/src/readin/readin_CGNS.f90 +++ b/src/readin/readin_CGNS.f90 @@ -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 ! ? diff --git a/src/readin/readin_hdf5.f90 b/src/readin/readin_hdf5.f90 index 314d073..a69e5f3 100644 --- a/src/readin/readin_hdf5.f90 +++ b/src/readin/readin_hdf5.f90 @@ -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 @@ -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 diff --git a/src/readin/readin_hdf5_old.f90 b/src/readin/readin_hdf5_old.f90 index ff75567..df46b90 100644 --- a/src/readin/readin_hdf5_old.f90 +++ b/src/readin/readin_hdf5_old.f90 @@ -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(:) @@ -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 --------------------------------------------------------------------------------------------------------------------- @@ -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 @@ -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 !---------------------------------------------------------------------------------------------------------------------------- @@ -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