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 $compile = $ARGV[4];
23 my $execute = $ARGV[5];
26 unless( $nonmem -> compile() ){
27 debug -> die( message => $nonmem -> error_message );
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,$version) = split(/,/ , $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 my( $nmdir, $version ) = split(/,/,$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( "nice -19 $nmdir/tr/nmtran.exe", $modelfile, \$self -> {'nmtran_message'}, \$self -> {'nmtran_message'} );
131 #$self -> {'nmtran_message'} = `nice -19 $nmdir/tr/nmtran.exe < $modelfile 2>&1`;
133 open( NMMSG, '>compilation_output.txt' );
134 print( NMMSG $self -> {'nmtran_message'}, "\n" );
136 unless(-e 'FREPORT'){
138 $self -> {'error_message'} = "NMtran failed: \n" . $self -> {'nmtran_message'} ;
144 run3( "$nmlink", undef, \$nmlink_message, \$nmlink_message );
146 print( NMMSG $nmlink_message, "\n" );
151 if( $self -> {'compiler'} eq 'g77' ){
152 rename("FSUBS", "FSUBS.f");
155 rename("FSUBS", "FSUBS.for");
160 if( defined $self -> {'fsubs'} ){
161 foreach my $sub ( @{$self -> {'fsubs'}} ){
166 open( FH, "<", 'LINK.LNK' );
179 if( $self -> {'compiler'} eq 'g77' ){
181 my @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
182 $compile_command = "g77 " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
184 } elsif( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
186 my @nmlib = ("$nm\\nonmem.obj", "$nm\\blkdat.obj", "$nm\\nonmem.lib");
187 $compile_command = $self -> {'compiler'}." " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
189 } elsif( $self -> {'compiler'} eq 'ifort' ){
190 my @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
191 $compile_command = "ifort " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
194 run3( "$compile_command", undef, \$compile_message, \$compile_message );
196 print( NMMSG $compile_message, "\n" );
199 unless(-e "nonmem.exe" or -e "nonmem$version$adaptive" ) {
200 $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
204 print( NMMSG "Compilation done\n" );
216 my $version = $self -> {'version'};
217 my $nmdir = $self -> {'nm_directory'};
218 my $outputfile = $self -> {'outputfile'};
219 my $adaptive = $self -> {'adaptive'} ? '_adaptive' : '';
221 my ( $start_time, $fin_time );
222 if( $Config{osname} eq 'MSWin32' ){
223 $start_time = `date /T`;
225 $start_time = $start_time.' '.`time /T`;
226 run3( "nonmem.exe", undef, \undef );
227 $fin_time = `date /T`;
229 $fin_time = $fin_time.' '.`time /T`;
231 cp( "output", $outputfile );
233 } elsif ( -e "OUTPUT" ) {
234 cp( "OUTPUT", $outputfile );
238 unless( $self -> {'show_version'} ){
241 $start_time = `date`;
242 run3( "nice -n " . $self -> {'nice'} . " ./nonmem$version$adaptive", "FCON", $outputfile );
245 open( OUT, '>>', $outputfile );
246 print( OUT "This file was created using the NONMEM version in directory $nmdir\n" );
247 print( OUT "Started $start_time" );
248 print( OUT "Finished $fin_time" );