*** empty log message ***
[PsN.git] / lib / nonmem_subs.pm
blob3a40b1c338c24619574b1f4364734965bc7bfdf0
1 # {{{ include statements
3 start include statements
4 use File::Copy 'cp';
5 use PsN;
6 use ext::Config::Tiny;
7 use ext::IPC::Run3;
8 use Config;
9 end include statements
11 # }}}
13 # {{{ new
15 start new
17 unless( defined $this -> {'outputfile'} ){
18 $this -> {'outputfile'} = $this -> {'modelfile'};
19 $this -> {'outputfile'} =~ s/\.mod$/\.lst/;
22 unless( defined $this -> {'nm_directory'} ){
23 my $nmdir = $PsN::config -> { 'nm_versions' } -> { $this -> {'version'} };
25 unless( defined $nmdir ){
26 print "Unknown NONMEM version ",$this -> {'version'}," specified.\n";
27 my @nmkeys = keys %{$PsN::config -> { 'nm_versions' }};
28 if ( $#nmkeys == 0 and
29 defined $nmkeys[0] and
30 defined $PsN::config -> { 'nm_versions' } -> {$nmkeys[0]} ) {
31 print "Using ",$PsN::config -> { 'nm_versions' } -> {$nmkeys[0]}," instead\n";
32 $nmdir = $PsN::config -> { 'nm_versions' } -> {$nmkeys[0]};
36 $this -> {'nm_directory'} = $nmdir;
38 unless( defined $PsN::config -> {'compiler'} and defined $PsN::config -> {'compiler'} -> {'name'} ){
39 debug -> warn( level => 1,
40 message => "No compiler defined, assuming g77" );
41 $this -> {'compiler'} = 'g77';
42 } else {
43 $this -> {'compiler'} = $PsN::config -> {'compiler'} -> {'name'};
44 $this -> {'compiler_options'} = $PsN::config -> {'compiler'} -> {'options'};
48 end new
50 # }}}
52 # {{{ compile
54 start compile
56 my $version = $self -> {'version'};
57 my $nmdir = $self -> {'nm_directory'};
58 my $includes;
59 my $nmlink;
61 if( -e "$nmdir/util/nmlink5.exe" ){
62 $nmlink = "$nmdir/util/nmlink5.exe";
63 $self -> {'version'} = 5;
64 if( $self -> {'show_version'} ){
65 $version = $self -> {'version'};
66 } else {
67 $version = '';
69 } elsif ( -e "$nmdir/util/nmlink6.exe" ){
70 $self -> {'version'} = 6;
71 if( $self -> {'show_version'} ){
72 $version = $self -> {'version'};
73 } else {
74 $version = '';
76 $nmlink = "$nmdir/util/nmlink6.exe";
77 if( $Config{osname} eq 'MSWin32' ){
78 $includes = "-I$nmdir\\sizes";
79 } else {
80 $includes = "-I$nmdir/sizes";
82 } else {
83 my $err_version = ( defined $nmdir and $nmdir ne '' ) ? $nmdir : 'undefined';
84 debug -> die( message => "Unable to find a supported version of NONMEM\n".
85 "The NONMEM installation directory is $err_version for version ".
86 $self -> {'version'}." according to psn.conf" );
89 # first clean up from old compile
90 unlink( 'FCON', 'FDATA', 'FREPORT','FSUBS', 'FSUBS.f','LINK.LNK','FSTREAM', 'PRDERR', 'nonmem.exe', 'nonmem' );
92 my $nm;
94 if( $Config{osname} eq 'MSWin32' ){
95 $nm="$nmdir\\nm";
96 } else {
97 $nm="$nmdir/nm";
100 my $modelfile = $self -> {'modelfile'};
102 run3( "$nmdir/tr/nmtran.exe", $modelfile, \$self -> {'nmtran_message'}, \$self -> {'nmtran_message'} );
104 #$self -> {'nmtran_message'} = `$nmdir/tr/nmtran.exe < $modelfile 2>&1`;
106 open( NMMSG, '>compilation_output.txt' );
107 print( NMMSG $self -> {'nmtran_message'}, "\n" );
109 unless(-e 'FREPORT'){
110 $self -> {'error_message'} = "NMtran failed: \n" . $self -> {'nmtran_message'} ;
111 return 0;
114 my $nmlink_message;
115 run3( "$nmlink", undef, \$nmlink_message, \$nmlink_message );
117 print( NMMSG $nmlink_message, "\n" );
119 my $fsub;
121 if(-e 'FSUBS'){
122 if( $self -> {'compiler'} eq 'g77' ){
123 cp("FSUBS", "FSUBS.f");
124 $fsub='FSUBS.f';
125 } else {
126 cp("FSUBS", "FSUBS.for");
127 $fsub='FSUBS.for';
131 if( defined $self -> {'fsubs'} ){
132 foreach my $sub ( @{$self -> {'fsubs'}} ){
133 $fsub .= " $sub";
137 open( FH, "<", 'LINK.LNK' );
138 my @link;
139 while( <FH> ){
140 my $tmp = $_;
141 $tmp =~ s/^\s+//;
142 $tmp =~ s/\s+$//;
143 push(@link, $tmp);
146 my $compile_message;
147 my $compile_command;
149 if( $self -> {'compiler'} eq 'g77' ){
151 my @nmlib = ("$nm/NONMEM.o", "$nm/BLKDAT.o", "$nm/nonmem.a");
152 $compile_command = "g77 " . $self -> {'compiler_options'} . " -ononmem$version $includes $fsub @link @nmlib 2>&1";
154 } elsif( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
156 my @nmlib = ("$nm\\nonmem.obj", "$nm\\blkdat.obj", "$nm\\nonmem.lib");
157 # <<<<<<< nonmem_subs.pm
158 # if( $fsub ){
159 # $compile_command = "df " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
160 # } else {
161 # $compile_command = "df " . $self -> {'compiler_options'} . " /Fenonmem @nmlib @link";
163 # } elsif( $self -> {'compiler'} eq 'fl32' ){
164 # my @nmlib = ("$nm\\nonmem.obj", "$nm\\blkdat.obj", "$nm\\nonmem.lib");
165 # if( $fsub ){
166 # $compile_command = "fl32 " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
167 # } else {
168 # $compile_command = "fl32 " . $self -> {'compiler_options'} . " /Fenonmem @nmlib @link";
170 # =======
171 $compile_command = $self -> {'compiler'}." " . $self -> {'compiler_options'} . " /Fenonmem $fsub @nmlib @link";
173 #>>>>>>> 1.27
176 run3( "$compile_command", undef, \$compile_message, \$compile_message );
178 print( NMMSG $compile_message, "\n" );
180 close( NMMSG );
182 if( $self -> {'compiler'} eq 'df' or $self -> {'compiler'} eq 'fl32' ){
183 unless(-e "nonmem.exe") {
184 $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
185 return 0;
187 } else {
188 unless(-e "nonmem$version") {
189 $self -> {'error_message'} = "Fortran Compilation failed: \n" . $compile_message ;
190 return 0;
194 end compile
196 # }}}
198 # {{{ execute
199 start execute
201 my $version = $self -> {'version'};
202 my $nmdir = $self -> {'nm_directory'};
203 my $outputfile = $self -> {'outputfile'};
205 if( $Config{osname} eq 'MSWin32' ){
206 run3( "nonmem.exe", undef, undef );
207 if ( -e "output" ) {
208 cp( "output", $outputfile );
209 unlink( "output" );
210 } elsif ( -e "OUTPUT" ) {
211 cp( "OUTPUT", $outputfile );
212 unlink( "OUTPUT" );
214 } else {
215 unless( $self -> {'show_version'} ){
216 $version = '';
218 run3( "nice -n " . $self -> {'nice'} . " ./nonmem$version", "FCON", $outputfile );
219 open( OUTPUTFILE, '>>', $outputfile );
220 print( OUTPUTFILE "This file was created using the NONMEM version in directory $nmdir\n" );
221 print( OUTPUTFILE `date`, "\n" );
222 close( OUTPUTFILE );
225 end execute
226 # }}}