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 my @nmkeys = keys %{$PsN::config -> { 'nm_versions' }};
54 if ( $#nmkeys == 0 and
55 defined $nmkeys[0] and
56 defined $PsN::config -> { 'nm_versions' } -> {$nmkeys[0]} ) {
57 #print "Using ",$PsN::config -> { 'nm_versions' } -> {$nmkeys[0]}," instead\n";
58 my( $nmdir, $version ) = split(/,/,$PsN::config -> { 'nm_versions' } -> {$nmkeys[0]});;
62 $this -> {'nm_directory'} = $nmdir;
64 unless( defined $PsN::config -> {'compiler'} and defined $PsN::config -> {'compiler'} -> {'name'} ){
65 debug -> warn( level => 1,
66 message => "No compiler defined, assuming g77" );
67 $this -> {'compiler'} = 'g77';
69 $this -> {'compiler'} = $PsN::config -> {'compiler'} -> {'name'};
70 $this -> {'compiler_options'} = $PsN::config -> {'compiler'} -> {'options'};
82 my $version = $self -> {'version'};
83 my $nmdir = $self -> {'nm_directory'};
86 my $adaptive = $self -> {'adaptive'} ? '_adaptive' : '';
87 if( -e "$nmdir/util/nmlink5.exe" ){
88 $nmlink = "$nmdir/util/nmlink5.exe";
89 $self -> {'version'} = 5;
90 if( $self -> {'show_version'} ){
91 $version = $self -> {'version'};
95 } elsif ( -e "$nmdir/util/nmlink6.exe" ){
96 $self -> {'version'} = 6;
97 if( $self -> {'show_version'} ){
98 $version = $self -> {'version'};
102 $nmlink = "$nmdir/util/nmlink6.exe";
103 if( $Config{osname} eq 'MSWin32' ){
104 $includes = "-I$nmdir\\sizes";
106 $includes = "-I$nmdir/sizes";
109 my $err_version = ( defined $nmdir and $nmdir ne '' ) ? $nmdir : '[not configured]';
110 debug -> die( message => "Unable to find a supported version of NONMEM\n".
111 "The NONMEM installation directory is $err_version for version [".
112 $self -> {'version'}."] according to psn.conf." );
115 # first clean up from old compile
116 unlink( 'FLIB','FCON', 'FDATA', 'FREPORT','FSUBS', 'FSUBS.f','LINK.LNK','FSTREAM', 'PRDERR', 'nonmem.exe', 'nonmem', 'nonmem5', 'nonmem6', 'nonmem5_adaptive', 'nonmem6_adaptive' );
120 if( $Config{osname} eq 'MSWin32' ){
126 my $modelfile = $self -> {'modelfile'};
128 if( $Config{osname} eq 'MSWin32' ){
129 run3( "$nmdir/tr/nmtran.exe", $modelfile, \$self -> {'nmtran_message'}, \$self -> {'nmtran_message'} );
131 run3( 'nice -' . $self -> {'nice'} . " $nmdir/tr/nmtran.exe", $modelfile, \$self -> {'nmtran_message'}, \$self -> {'nmtran_message'} );
134 open( NMMSG, '>compilation_output.txt' );
135 print( NMMSG $self -> {'nmtran_message'}, "\n" );
137 unless(-e 'FREPORT'){
139 $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' or $self -> {'compiler'} eq 'g95' ){
152 rename("FSUBS", "FSUBS.f");
155 rename("FSUBS", "FSUBS.for");
160 if( defined $self -> {'fsubs'} and $self -> {'version'} != 6 ){
161 foreach my $sub ( @{$self -> {'fsubs'}} ){
166 open( FH, "<", 'LINK.LNK' );
181 if( $Config{osname} eq 'MSWin32' ){
182 @nmlib = ("$nm\\NONMEM.obj","$nm\\BLKDAT.obj","$nm\\nonmem.lib");
184 @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
186 $compile_command = "g77 " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
188 if( $self -> {'compiler'} eq 'g77' ){
190 $compile_command = "g77 " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
192 } elsif( $self -> {'compiler'} eq 'g95' ){
194 $compile_command = "g95 " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
196 } elsif( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
197 $compile_command = $self -> {'compiler'}." " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
199 } elsif( $self -> {'compiler'} eq 'ifort' ){
201 $compile_command = "ifort " . $self -> {'compiler_options'} . " -ononmem$version$adaptive $includes $fsub @link @nmlib 2>&1";
205 run3( "$compile_command", undef, \$compile_message, \$compile_message );
207 print( NMMSG $compile_message, "\n" );
211 unless(-e "nonmem.exe" or -e "nonmem$version$adaptive" ) {
212 $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
224 my $version = $self -> {'version'};
225 my $nmdir = $self -> {'nm_directory'};
226 my $outputfile = $self -> {'outputfile'};
227 my $adaptive = $self -> {'adaptive'} ? '_adaptive' : '';
229 my ( $start_time, $fin_time );
230 if( $Config{osname} eq 'MSWin32' ){
231 $start_time = `date /T`;
233 $start_time = $start_time.' '.`time /T`;
234 run3( "nonmem.exe", undef, \undef );
235 $fin_time = `date /T`;
237 $fin_time = $fin_time.' '.`time /T`;
239 cp( "output", $outputfile );
241 } elsif ( -e "OUTPUT" ) {
242 cp( "OUTPUT", $outputfile );
246 unless( $self -> {'show_version'} ){
249 $start_time = `date`;
250 if ( -e "/proc/self/lock" ) {
251 open (OUTFILE,">/proc/self/lock") || die "Could not unlock myself!\n";
255 run3( "nice -n " . $self -> {'nice'} . " ./nonmem$version$adaptive", "FCON", $outputfile );
256 if ( -e "/proc/self/lock" ) {
257 open (OUTFILE,">/proc/self/lock") || die "Could not unlock myself!\n";
263 open( OUT, '>>', $outputfile );
264 print( OUT "This file was created using the NONMEM version in directory $nmdir\n" );
265 print( OUT "Started $start_time" );
266 print( OUT "Finished $fin_time" );