10 ## Change the appropriate "system" command below to reflect your
11 ## NONMEM installation.
12 my $ver5_unix = '/export/home/nmv/util/nmfe5';
13 my $ver55_unix = '/export/home/nmv/util/nmfe55 -d -f -O';
14 my $ver6_unix = '/export/home/nmvi/util/nmfe6';
15 my $ver6_unix_spec = '/export/home/nmvi/util/nmfe -d -f -O';
16 my $ver5_win32 = 'nmfe5';
17 my $ver6_win32 = 'nmfe6';
22 $start = defined $start ?
$start : '.';
23 unless( defined $path ){
30 opendir DIRHANDLE
, $start or die "Unable to list directory $start\n";
31 my @dir_list = readdir(DIRHANDLE
);
34 foreach my $dir_or_file ( @dir_list ){
35 if( $dir_or_file =~ /^$path(\d+)/ ){
37 $max = $ending if( $ending > $max );
48 # find( { wanted => sub{ /^$path/ && $i++ }}, $start );
50 if( -e
$start . '/' . $path . $max ){
51 die "The directory ${start}${path}${max} is in the way.\n";
53 my ( $dir , $file ) = absolute_path
($start . '/' . $path . $max, '');
59 # path finding strategy:
61 # 1. If path is not given it is assumed to be the current working
62 # directory. If it is not absolute, it is assumed to be relative to
63 # the current working directory.
65 # 2. If filename is absolute, let that overide the directory
67 # 3. If the filename is relative, assume the path as base.
72 $file = File
::Spec
-> canonpath
($file);
75 $path = File
::Spec
-> canonpath
($path);
76 unless( File
::Spec
-> file_name_is_absolute
( $path ) ){
77 $path = File
::Spec
-> rel2abs
($path);
83 my ($path_volume,$path_directory, $path_file) = File
::Spec
-> splitpath
( $path, 1 );
84 my ($file_volume,$file_directory, $file_file) = File
::Spec
-> splitpath
( $file );
86 my @path_directory = File
::Spec
-> splitdir
( $path_directory );
87 my @file_directory = File
::Spec
-> splitdir
( $file_directory );
90 if( File
::Spec
-> file_name_is_absolute
( $file ) ){
91 $path_volume = $file_volume;
92 @directory = @file_directory;
94 @directory = (@path_directory, @file_directory);
97 for( my $i = 0; $i < $#directory; $i++ ){
98 if( $directory[$i] ne File
::Spec
-> updir
() and $directory[$i+1] eq File
::Spec
-> updir
() ){
99 @directory = (@directory[0..$i-1], @directory[$i+2..$#directory]);
104 $path = File
::Spec
-> catpath
( $path_volume, File
::Spec
-> catfile
( @directory,'' ), '' );
106 return ($path, $file_file);
108 # Below is old non portable code. I keep it for fun :) Kill it if it
111 # Step 1. Make the pathname absolute.
113 # if( defined $path ){
114 # if ( $Config{osname} eq 'MSWin32' ) {
115 # unless ( $path =~ /^\w\:[\\\/]/ ) {
116 # $path = getcwd() . '/' . $path;
118 # } else { # Assume os == unix
119 # unless( $path =~ /^\// ) {
120 # $path = getcwd() . '/' . $path;
126 # Step 2. Find out if filename is absolute
128 # if ( $Config{osname} eq 'MSWin32' ) {
129 # if( $file =~ /^\w\:[\\\/]/ ){
134 # } else { # Assume OS == unix
135 # if( $file =~ /^\// ){
142 # $path =~ s!\\!\/!g; # Flip slashes in path
144 # $file =~ s!\\!\/!g; # Flip slashes in filename
146 # unless( $path =~ /\/$/ ) { # append trailing slash
150 # while( $path =~ /[^\/]*\/\.\.\// ){
151 # $path =~ s![^\/]*\/\.\.\/!!g; # remove relative dots
153 # while( $file =~ /[^\/]*\/\.\.\// ){
154 # $file =~ s![^\/\.]*\/\.\.\/!!g; # remove relative dots
158 # $tmp =~ s![^\/]*$!!;
160 # if( $is_absolute ){
161 # unless( $path eq $tmp ){
162 # debug -> warn( level => 2,
163 # message => "path differs from file: $path ne $tmp, using $tmp" );
168 # while( $path =~ /[^\/]*\/\.\.\// ){
169 # $path =~ s!\/[^\/]*\/\.\.!!g;
173 # $path =~ s!([^\/]*)$!!;
176 # while( $path =~ m!\.\/! ){
177 # $path =~ s!\.\/!\/!; # remove singel dots
180 # while( $path =~ m!\/\/! ){
181 # $path =~ s!\/\/!\/!; # remove double slashes
184 # return ($path, $file);
190 my $modelfile = shift;
195 my $os = $Config{osname
};
198 $os = 'linux' unless ( $os eq 'MSWin32' );
200 if( $os eq 'linux' ){
201 ## Sometimes it is necessary to specify the shell under which NONMEM
202 ## executes. The shell needs to know where nmfe5 is. Example for csh:
203 #my $shell ='/bin/csh';
205 ## Change this line to specify the shell under which you want to
208 # PP_TODO Should this be a config option?
212 if ( $version eq '5' and $os eq 'linux' ) {
213 $command = $ver5_unix;
214 } elsif ( $version eq '55' and $os eq 'linux' ) {
215 $command = $ver55_unix;
216 } elsif ( $version eq '6' and $os eq 'linux' ) {
217 $command = $ver6_unix;
218 # $nm_opts = '-d -f -O'
219 } elsif ( $version eq '6_nmfe' and $os eq 'linux' ) {
220 $command = $ver6_unix_spec;
221 # $nm_opts = '-d -f -O'
222 } elsif ( $version eq '5' and $os eq 'MSWin32' ) {
223 $command = "$ver5_win32 $modelfile $outfile";
224 } elsif ( $version eq '6' and $os eq 'MSWin32' ) {
225 $command = "$ver6_win32 $modelfile $outfile";
227 debug
-> warn( level
=> 1,
228 message
=> "Could not determine platform. Assuming standard UNIX" );
229 ## You will have to specify the shell under which NONMEM
230 ## executes. The shell needs to know where nmfe5 is.
231 $shell = '/bin/csh -f';
232 $command = $ver5_unix;
235 $silent = $silent ?
">$silent" : '';
237 $command = "$shell nice -n $prio $command $nm_opts $modelfile $outfile $silent"
238 if ( $os eq 'linux' );
240 debug
-> warn( level
=> 2,
241 message
=> "$command" );
249 if ( $Config{osname
} eq 'MSWin32' ) {
251 @tmp = split(/\\/, $file );
252 $directory = join( "\\", @tmp[0..$#tmp-1] )."\\";
256 } else { # Assume OS == unix
258 @tmp = split(/\//, $file );
259 $directory = join( '/', @tmp[0..$#tmp-1] ).'/';
271 if ( $Config{osname
} eq 'MSWin32' ) {
273 @tmp = split(/\\/, $file );
274 $nopath = $tmp[$#tmp];
278 } else { # Assume OS == unix
280 @tmp = split(/\//, $file );
281 $nopath = $tmp[$#tmp];
293 open ( FILE
, $file );
295 if ( $Config{osname
} eq 'MSWin32' ) {
301 push( @content, $_ );