From 962704e5f79317a240c94fe85e1aec2455b3f95b Mon Sep 17 00:00:00 2001 From: ignis Date: Tue, 2 Jun 2026 17:27:48 +0000 Subject: [PATCH] refactor: resolve code smells ranked 1 to 6 (unused variables, local imports, wildcard imports, empty routines, pointer warning) --- code/Compact.f90 | 4 ++-- code/code_gen/code_gen.py | 20 ++++++++------------ code/code_gen/post.py | 17 +---------------- code/m_arrays.f90 | 7 ------- code/m_calculate.f90 | 6 ------ code/post.f90 | 2 +- code/print_build_info.c | 8 ++++---- code/pycompact/pycompact.py | 13 ++++--------- 8 files changed, 20 insertions(+), 57 deletions(-) diff --git a/code/Compact.f90 b/code/Compact.f90 index 6741278..2551773 100644 --- a/code/Compact.f90 +++ b/code/Compact.f90 @@ -267,7 +267,7 @@ SUBROUTINE nonp_lud(xyz,xx) - INTEGER :: i,xyz,xx + INTEGER :: xyz,xx real(real64), DIMENSION(xx) :: aa aa=3. aa(1)=0.5 ; aa(2)=4. @@ -287,7 +287,7 @@ SUBROUTINE p_lud(xyz,xx) - INTEGER :: i,xyz,xx + INTEGER :: xyz,xx real(real64) :: a a=3. ! first derivative IF (xyz.eq.1) CALL ptdlu(a,xx,lxf,wxf) ! x-direction diff --git a/code/code_gen/code_gen.py b/code/code_gen/code_gen.py index d46f0dd..daf1e67 100644 --- a/code/code_gen/code_gen.py +++ b/code/code_gen/code_gen.py @@ -1,7 +1,12 @@ - -import os, sys - +import os +import sys import argparse +import datetime +import subprocess as sp +from lark import Lark, Token +from jinja2 import Template +from post import Stage1, Stage2, Stage3, Stage4 +from resources.m_template import mod_form parser = argparse.ArgumentParser() parser.add_argument("term_file", help="name of file containing postprocessing term spec") @@ -10,12 +15,6 @@ parser.add_argument("-x", "--print-latex", action="store_true", help="print late parser.add_argument("-p", "--print-report", action="store_true", help="print code generation report instead of code") args = parser.parse_args() -from lark import Lark, Visitor, Transformer, v_args, Token - -from post import * - -from resources.m_template import mod_form - calc_grammar = """ ?varlist: "[" [NAME ("," NAME)*] "]" @@ -100,8 +99,6 @@ def tok_to_str(tok): class VersionInfo(object): def __init__ (self, input_raw): - import os, datetime - import subprocess as sp bd = 'build date: {}' bb = 'build base: {}' @@ -181,7 +178,6 @@ def test(terms_raw, report=False, latex=False): # print r"\end{equation}" print("}") else: - from jinja2 import Template print(Template(mod_form).render(**cdict)) diff --git a/code/code_gen/post.py b/code/code_gen/post.py index c7926b4..588c3f4 100644 --- a/code/code_gen/post.py +++ b/code/code_gen/post.py @@ -22,6 +22,7 @@ DNS Post-Processing Code Generator Core (post.py) 공통의 제한된 버퍼 배열(xyzbuffer0, xyzbuffer1, ...)을 나누어 사용(Array Pooling)하도록 할당하여 메모리 사용량을 최소화합니다. """ +import sys from lark import Lark, Visitor, Transformer, v_args, Token import warnings from jinja2 import Template @@ -373,8 +374,6 @@ class SympyOptimizer: after_heavy += h_val after_loads += self.count_3d_loads(reduced_expr, three_d_arrays) - import sys - def pct_str(before, after): if before == 0: return "0.0%" if after == 0 else "+inf%" @@ -732,12 +731,6 @@ class FieldBase (object): def depends_on (self, a): return (a in self.dep) - def is_primary (self): - return self.prime - - def not_primary (self): - return not self.prime - def is_fluctuation (self): return self.fluc @@ -1732,11 +1725,3 @@ close (200) print("l2 = ", json.dumps(self.pass2, indent=4), file=irf) print("avg1 = ", json.dumps(list(map(repr,self.avg1)), indent=4), file=irf) print("avg2 = ", json.dumps(list(map(repr,self.avg2)), indent=4), file=irf) - -class Stage5(): - """예비 단계: 확장된 루프 분할 및 연산 재정렬을 수행하는 플레이스홀더 클래스입니다.""" - pass - -class Stage6(): - """예비 단계: 최종 다이렉트 Fortran 기계 최적화 코드 출력 플레이스홀더 클래스입니다.""" - pass diff --git a/code/m_arrays.f90 b/code/m_arrays.f90 index 9bf3881..f5f64fa 100644 --- a/code/m_arrays.f90 +++ b/code/m_arrays.f90 @@ -54,12 +54,5 @@ DEALLOCATE(y) end subroutine m_arrays_finalize -subroutine m_arrays_calculate_instant - -integer :: i,j,k - -end subroutine m_arrays_calculate_instant - - end module m_arrays diff --git a/code/m_calculate.f90 b/code/m_calculate.f90 index 086f5e0..e30facc 100644 --- a/code/m_calculate.f90 +++ b/code/m_calculate.f90 @@ -79,9 +79,6 @@ contains real(real64), dimension(1,nxp), intent(in) :: src real(real64), dimension(1,nxp), intent(out) :: dst - integer :: i, j ,k - integer :: ju - call dfnonp(nxp, hxp, src, dst, 1, 1) end subroutine ddx1d @@ -171,9 +168,6 @@ contains real(real64), dimension(nxp), intent(in) :: src real(real64), dimension(nxp), intent(out) :: dst - integer :: i, j ,k - integer :: ju - call d2fnonp(nxp, hxp, src, dst, 1, 1) end subroutine d2dx1d diff --git a/code/post.f90 b/code/post.f90 index 120d64a..8cc163a 100644 --- a/code/post.f90 +++ b/code/post.f90 @@ -11,7 +11,7 @@ MODULE post INTEGER :: countnum INTEGER :: nprogress INTEGER :: ipass - INTEGER :: num_, dummyu_ ! hybrid + INTEGER :: num_ ! hybrid real(real64) :: tnow real(real64), DIMENSION(:,:,:,:), ALLOCATABLE :: old_scalar, new_scalar diff --git a/code/print_build_info.c b/code/print_build_info.c index 3d3d2a1..a3bdc87 100644 --- a/code/print_build_info.c +++ b/code/print_build_info.c @@ -8,12 +8,12 @@ extern const char _binary_latex_equations_txt_size []; int build_info_length_() { - return ((char*)&_binary_build_info_txt_end - (char*)&_binary_build_info_txt_start); + return ((char*)_binary_build_info_txt_end - (char*)_binary_build_info_txt_start); } int latex_length_() { - return ((char*)&_binary_latex_equations_txt_end - (char*)&_binary_latex_equations_txt_start); + return ((char*)_binary_latex_equations_txt_end - (char*)_binary_latex_equations_txt_start); } void string_copy ( char *s, unsigned long b, const char *p_start , const char *p_end ) @@ -34,10 +34,10 @@ void string_copy ( char *s, unsigned long b, const char *p_start , const char *p void cstr_( char *s, unsigned long b ) { - string_copy(s, b, &_binary_build_info_txt_start, &_binary_build_info_txt_end); + string_copy(s, b, _binary_build_info_txt_start, _binary_build_info_txt_end); } void eqnstr_( char *s, unsigned long b ) { - string_copy(s, b, &_binary_latex_equations_txt_start, &_binary_latex_equations_txt_end); + string_copy(s, b, _binary_latex_equations_txt_start, _binary_latex_equations_txt_end); } diff --git a/code/pycompact/pycompact.py b/code/pycompact/pycompact.py index e157f5f..3bb5dfe 100644 --- a/code/pycompact/pycompact.py +++ b/code/pycompact/pycompact.py @@ -1,3 +1,7 @@ +import os +import sys +import struct +import pprint import numpy as np from compact import compact @@ -61,7 +65,6 @@ class CompactScheme: def test_ludcmp (self): - import pprint pp = pprint.PrettyPrinter(indent=4) # First Derivative Non-periodic BC @@ -343,9 +346,6 @@ class CompactScheme: def read_old_data (fname): - import struct - import sys - import os with open(fname, 'rb') as f1 : f1.seek(0) @@ -389,9 +389,6 @@ def read_old_data (fname): return t, nx, ny, nz, u, v, w, Y0, Y1 def read_data (fname): - import struct - import sys - import os with open(fname, 'rb') as f1 : f1.seek(0) @@ -536,8 +533,6 @@ def validate_trigonometric(): def test_dns_data(): - import sys - file_name = "./fort.1000" answer = "./fort.2000"