Skip to content

Commit

Permalink
Merge pull request #10 from coprigent/feature/npy-inputs
Browse files Browse the repository at this point in the history
Fixed Fortran header generation; Added wrapping of MMG5_ARG_[\w*] as …
  • Loading branch information
Algiane authored Jul 27, 2023
2 parents 5e26759 + c06413b commit 51b57f1
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 18 deletions.
87 changes: 69 additions & 18 deletions scripts/genfort.pl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
my $formatbyval = "#define %-30s \%val(%d)";
my $definebyval = "#define MMG5_ARG_%-30s \%val(%d)\n";
my $definebyval_f = "#define MMG5_ARG_%s_F %s\n";
my $definebyval_h2t = "#define H2T_ARG_%s \%val(MMG5_ARG_%s_F)\n";
my $definebyval_new = "#define H2T_ARG_%s \%val(%s)\n";
my %opts;

###############################################################################
Expand Down Expand Up @@ -115,6 +115,66 @@ sub printTab # ($chaine, $tabcount, $comm)
}
print $chaine;
}
#
# Function: printMmgHeader
#
# Prints lines from mmg c header file containing
# definition of MMG5_ARG_[.*] macros and defines
# corresponding wrappings H2T_ARG_[.*].
#
sub printMmgHeader {

my $chaine;
my $line_mmg;
my $line_mmg2;
my $start_comm;
my $pos_start;
my $pos_end;
my $pos_tmp;

open (APImmg, $fichier_mmg);

foreach $line_mmg ( <APImmg> )
{
if ($line_mmg =~ /\#define MMG5_ARG_(\w*)\s+(.*)/)
{
$chaine = sprintf($definebyval_f,$1,$2);
printTab($chaine,1,0 );
}
}

close APImmg;
}
#
# Function: printNewMacro
#
# Returns lines defining new macros of the form
# H2T_ARG_[.*] converted into suitable Fortran format.
#
# Parameter:
# line - Input string to convert
#
# Returns:
# chaine - String to print
#
sub printNewMacro {

my ($line) = @_;
my $chaine;

if ($line =~ /\#define H2T_ARG_(\w*)\s+(.*)/) {
my $name = $1;
my $val = $2;

if ($val =~ /MMG5_ARG_(\w*)/) {
$val =~ s/MMG5_ARG_(\w*)/MMG5_ARG_$1_F/g;
}

$chaine = sprintf($definebyval_new,$name,$val);
}

return $chaine;
}

#
# Function: Convert
Expand All @@ -134,21 +194,7 @@ sub Convert {
my $tabcount = 0;
my $interfaceprinted = 0;
my $modulename;

open (APImmg, $fichier_mmg);

foreach my $line_mmg ( <APImmg> )
{
if ($line_mmg =~ /\#define MMG5_ARG_(\w*)\s+(.*)/)
{
$chaine = sprintf($definebyval_f,$1,$2);
printTab($chaine,1,0 );
$chaine = sprintf($definebyval_h2t,$1,$1);
printTab($chaine,1,0 );
}
}

close APImmg;
my $mmg_header = 0;

open (APIc, $fichier);

Expand Down Expand Up @@ -222,9 +268,14 @@ sub Convert {
}
elsif ($line =~ /\#define H2T_ARG_(\w*)\s+(.*)/)
{
$chaine = sprintf($definebyval_h2t,$1,$2);
if ($mmg_header == 0)
{
printMmgHeader();
$mmg_header = 1;
}
$chaine = printNewMacro($line);
printTab($chaine,1,0 );
}
}
elsif ($line =~ /\#define/)
{
printTab($line,1,0 );
Expand Down
104 changes: 104 additions & 0 deletions src/libhex2tet.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,110 @@ extern "C" {
* \remark we cannot use an enum because used in
* variadic functions).
*/
/**
* \def MMG5_ARG_start
*
* To begin a list of variadic arguments (mandatory first arg for all our
* variadic functions)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_start 1
/**
* \def H2T_ARG_ppMesh
*
* Pointer toward a MMG5_pMesh structure (for structure allocations purposes)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_ppMesh 2
/**
* \def H2T_ARG_ppLs
*
* Pointer toward a MMG5_pSol structure storing a level-set (for structure
* allocations purposes)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_ppLs 3
/**
* \def H2T_ARG_ppMet
*
* Pointer toward a MMG5_pSol structure storing a metric (for structure
* allocations purposes)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_ppMet 4
/**
* \def H2T_ARG_ppDisp
*
* Pointer toward a MMG5_pSol structure storing a displacement (for structure
* allocations purposes)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_ppDisp 5
/**
* \def H2T_ARG_ppSols
*
* Pointer toward an array of MMG5_Sol structures storing a list of solutions
* allocations purposes)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_ppSols 6
/**
* \def H2T_ARG_pMesh
*
* MMG5_pMesh structure
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_pMesh 7
/**
* \def H2T_ARG_pMet
*
* MMG5_pSol structure storing a metric field
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_pMet 8
/**
* \def H2T_ARG_pDisp
*
* MMG5_pSol structure storing a displacement field
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_pDisp 9
/**
* \def H2T_ARG_end
*
* To end a list of variadic argument (mandatory last argument for all our
* variadic functions)
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_end 10
/**
* \def H2T_ARG_phexa
*
* integer array storing list of hexahedra
*
* \remark we cannot use an enum because used in
* variadic functions).
*/
#define H2T_ARG_phexa (MMG5_ARG_end+1)
/**
* \param mmgMesh mesh structure with only vertices.
Expand Down

0 comments on commit 51b57f1

Please sign in to comment.