1 # {{{ include statements
3 start include statements
4 if( $0 =~ /nonmem.pm$/ ) {
9 #use ext::Config::Tiny;
12 if( $0 =~ /nonmem.pm$/ ) {
14 my $nonmem = nonmem -> new( 'modelfile' => $ARGV[0],
15 'outputfile' => $ARGV[1],
17 'version' => $ARGV[3],
18 'fsubs' => [split( /,/ , $ARGV[6] )],
19 'nm_directory' => $ARGV[7],
22 my $no_remote_compile = $ARGV[4];
23 my $no_remote_execution = $ARGV[5];
25 unless( $no_remote_compile ){
26 unless( $nonmem -> compile() ){
27 debug -> die( message => $nonmem -> error_message );
31 unless( $no_remote_execution ){
35 end include statements
43 unless( defined $this -> {'outputfile'} ){
44 $this -> {'outputfile'} = $this -> {'modelfile'};
45 $this -> {'outputfile'} =~ s/\.mod$/\.lst/;
48 unless( defined $this -> {'nm_directory'} ){
49 my $nmdir = $PsN::config -> { 'nm_versions' } -> { $this -> {'version'} };
51 unless( defined $nmdir ){
52 print "Unknown NONMEM version ",$this -> {'version'}," specified.\n";
53 print "Configuration file is ",$PsN::config_file,"\n";
54 my @nmkeys = keys %{$PsN::config -> { 'nm_versions' }};
55 if ( $#nmkeys == 0 and
56 defined $nmkeys[0] and
57 defined $PsN::config -> { 'nm_versions' } -> {$nmkeys[0]} ) {
58 print "Using the only defined version $nmkeys[0] in ",$PsN::config -> { 'nm_versions' } -> {$nmkeys[0]}," instead\n";
59 $nmdir = $PsN::config -> { 'nm_versions' } -> {$nmkeys[0]};
63 $this -> {'nm_directory'} = $nmdir;
65 unless( defined $PsN::config -> {'compiler'} and defined $PsN::config -> {'compiler'} -> {'name'} ){
66 debug -> warn( level => 1,
67 message => "No compiler defined, assuming g77" );
68 $this -> {'compiler'} = 'g77';
70 $this -> {'compiler'} = $PsN::config -> {'compiler'} -> {'name'};
71 $this -> {'compiler_options'} = $PsN::config -> {'compiler'} -> {'options'};
83 my $version = $self -> {'version'};
84 my $nmdir = $self -> {'nm_directory'};
87 my $adaptive = $self -> {'adaptive'} ? '_adaptive' : '';
88 if( -e "$nmdir/util/nmlink5.exe" ){
89 $nmlink = "$nmdir/util/nmlink5.exe";
90 $self -> {'version'} = 5;
91 if( $self -> {'show_version'} ){
92 $version = $self -> {'version'};
96 } elsif ( -e "$nmdir/util/nmlink6.exe" ){
97 $self -> {'version'} = 6;
98 if( $self -> {'show_version'} ){
99 $version = $self -> {'version'};
103 $nmlink = "$nmdir/util/nmlink6.exe";
104 if( $Config{osname} eq 'MSWin32' ){
105 $includes = "-I$nmdir\\sizes";
107 $includes = "-I$nmdir/sizes";
110 my $err_version = ( defined $nmdir and $nmdir ne '' ) ? $nmdir : '[not configured]';
111 debug -> die( message => "Unable to find a supported version of NONMEM\n".
112 "The NONMEM installation directory is $err_version for version [".
113 $self -> {'version'}."] according to psn.conf." );
116 # first clean up from old compile
117 unlink( 'FLIB','FCON', 'FDATA', 'FREPORT','FSUBS', 'FSUBS.f','LINK.LNK','FSTREAM', 'PRDERR', 'nonmem.exe', 'nonmem', 'nonmem5', 'nonmem6', 'nonmem5_adaptive', 'nonmem6_adaptive' );
121 if( $Config{osname} eq 'MSWin32' ){
127 my $modelfile = $self -> {'modelfile'};
129 run3( "$nmdir/tr/nmtran.exe", $modelfile, \$self -> {'nmtran_message'}, \$self -> {'nmtran_message'} );
131 #$self -> {'nmtran_message'} = `$nmdir/tr/nmtran.exe < $modelfile 2>&1`;
133 open( NMMSG, '>compilation_output.txt' );
134 print( NMMSG $self -> {'nmtran_message'}, "\n" );
136 unless(-e 'FREPORT'){
137 $self -> {'error_message'} = "NMtran failed: \n" . $self -> {'nmtran_message'} ;
142 run3( "$nmlink", undef, \$nmlink_message, \$nmlink_message );
144 print( NMMSG $nmlink_message, "\n" );
149 if( $self -> {'compiler'} eq 'g77' ){
150 rename("FSUBS", "FSUBS.f");
153 rename("FSUBS", "FSUBS.for");
158 if( defined $self -> {'fsubs'} ){
159 foreach my $sub ( @{$self -> {'fsubs'}} ){
164 open( FH, "<", 'LINK.LNK' );
177 if( $self -> {'compiler'} eq 'g77' ){
179 my @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
180 $compile_command = "g77 " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
182 } elsif( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
184 my @nmlib = ("$nm\\nonmem.obj", "$nm\\blkdat.obj", "$nm\\nonmem.lib");
185 $compile_command = $self -> {'compiler'}." " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
187 } elsif( $self -> {'compiler'} eq 'ifort' ){
188 my @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
189 $compile_command = "ifort " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
193 run3( "$compile_command", undef, \$compile_message, \$compile_message );
195 print( NMMSG $compile_message, "\n" );
199 # if( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
200 unless(-e "nonmem.exe" or -e "nonmem$version$adaptive" ) {
201 $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
205 # unless(-e "nonmem$version") {
206 # $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
219 my $version = $self -> {'version'};
220 my $nmdir = $self -> {'nm_directory'};
221 my $outputfile = $self -> {'outputfile'};
222 my $adaptive = $self -> {'adaptive'} ? '_adaptive' : '';
224 my ( $start_time, $fin_time );
225 if( $Config{osname} eq 'MSWin32' ){
226 $start_time = `date /T`;
228 $start_time = $start_time.' '.`time /T`;
229 run3( "nonmem.exe", undef, \undef );
230 $fin_time = `date /T`;
232 $fin_time = $fin_time.' '.`time /T`;
234 cp( "output", $outputfile );
236 } elsif ( -e "OUTPUT" ) {
237 cp( "OUTPUT", $outputfile );
241 unless( $self -> {'show_version'} ){
244 $start_time = `date`;
245 run3( "nice -n " . $self -> {'nice'} . " ./nonmem$version$adaptive", "FCON", $outputfile );
248 open( OUT, '>>', $outputfile );
249 print( OUT "This file was created using the NONMEM version in directory $nmdir\n" );
250 print( OUT "Started $start_time" );
251 print( OUT "Finished $fin_time" );