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
);
33 foreach my $dir_or_file ( @dir_list ){
34 if( $dir_or_file =~ /^$path/ ){
39 # find( { wanted => sub{ /^$path/ && $i++ }}, $start );
41 if( -e
$start . '/' . $path . $i ){
42 die "The directory ${start}${path}${i} is in the way.\n";
44 my ( $dir , $file ) = absolute_path
($start . '/' . $path . $i, '');
50 # path finding strategy:
52 # 1. If path is not given it is assumed to be the current working
53 # directory. If it is not absolute, it is assumed to be relative to
54 # the current working directory.
56 # 2. If filename is absolute, let that overide the directory
58 # 3. If the filename is relative, assume the path as base.
63 $file = File
::Spec
-> canonpath
($file);
66 $path = File
::Spec
-> canonpath
($path);
67 unless( File
::Spec
-> file_name_is_absolute
( $path ) ){
68 $path = File
::Spec
-> rel2abs
($path);
74 my ($path_volume,$path_directory, $path_file) = File
::Spec
-> splitpath
( $path, 1 );
75 my ($file_volume,$file_directory, $file_file) = File
::Spec
-> splitpath
( $file );
77 my @path_directory = File
::Spec
-> splitdir
( $path_directory );
78 my @file_directory = File
::Spec
-> splitdir
( $file_directory );
81 if( File
::Spec
-> file_name_is_absolute
( $file ) ){
82 $path_volume = $file_volume;
83 @directory = @file_directory;
85 @directory = (@path_directory, @file_directory);
88 for( my $i = 0; $i < $#directory; $i++ ){
89 if( $directory[$i] ne File
::Spec
-> updir
() and $directory[$i+1] eq File
::Spec
-> updir
() ){
90 @directory = (@directory[0..$i-1], @directory[$i+2..$#directory]);
95 $path = File
::Spec
-> catpath
( $path_volume, File
::Spec
-> catfile
( @directory,'' ), '' );
97 return ($path, $file_file);
99 # Below is old non portable code. I keep it for fun :) Kill it if it
102 # Step 1. Make the pathname absolute.
104 # if( defined $path ){
105 # if ( $Config{osname} eq 'MSWin32' ) {
106 # unless ( $path =~ /^\w\:[\\\/]/ ) {
107 # $path = getcwd() . '/' . $path;
109 # } else { # Assume os == unix
110 # unless( $path =~ /^\// ) {
111 # $path = getcwd() . '/' . $path;
117 # Step 2. Find out if filename is absolute
119 # if ( $Config{osname} eq 'MSWin32' ) {
120 # if( $file =~ /^\w\:[\\\/]/ ){
125 # } else { # Assume OS == unix
126 # if( $file =~ /^\// ){
133 # $path =~ s!\\!\/!g; # Flip slashes in path
135 # $file =~ s!\\!\/!g; # Flip slashes in filename
137 # unless( $path =~ /\/$/ ) { # append trailing slash
141 # while( $path =~ /[^\/]*\/\.\.\// ){
142 # $path =~ s![^\/]*\/\.\.\/!!g; # remove relative dots
144 # while( $file =~ /[^\/]*\/\.\.\// ){
145 # $file =~ s![^\/\.]*\/\.\.\/!!g; # remove relative dots
149 # $tmp =~ s![^\/]*$!!;
151 # if( $is_absolute ){
152 # unless( $path eq $tmp ){
153 # debug -> warn( level => 2,
154 # message => "path differs from file: $path ne $tmp, using $tmp" );
159 # while( $path =~ /[^\/]*\/\.\.\// ){
160 # $path =~ s!\/[^\/]*\/\.\.!!g;
164 # $path =~ s!([^\/]*)$!!;
167 # while( $path =~ m!\.\/! ){
168 # $path =~ s!\.\/!\/!; # remove singel dots
171 # while( $path =~ m!\/\/! ){
172 # $path =~ s!\/\/!\/!; # remove double slashes
175 # return ($path, $file);
181 my $modelfile = shift;
186 my $os = $Config{osname
};
189 $os = 'linux' unless ( $os eq 'MSWin32' );
191 if( $os eq 'linux' ){
192 ## Sometimes it is necessary to specify the shell under which NONMEM
193 ## executes. The shell needs to know where nmfe5 is. Example for csh:
194 #my $shell ='/bin/csh';
196 ## Change this line to specify the shell under which you want to
199 # PP_TODO Should this be a config option?
203 if ( $version eq '5' and $os eq 'linux' ) {
204 $command = $ver5_unix;
205 } elsif ( $version eq '55' and $os eq 'linux' ) {
206 $command = $ver55_unix;
207 } elsif ( $version eq '6' and $os eq 'linux' ) {
208 $command = $ver6_unix;
209 # $nm_opts = '-d -f -O'
210 } elsif ( $version eq '6_nmfe' and $os eq 'linux' ) {
211 $command = $ver6_unix_spec;
212 # $nm_opts = '-d -f -O'
213 } elsif ( $version eq '5' and $os eq 'MSWin32' ) {
214 $command = "$ver5_win32 $modelfile $outfile";
215 } elsif ( $version eq '6' and $os eq 'MSWin32' ) {
216 $command = "$ver6_win32 $modelfile $outfile";
218 debug
-> warn( level
=> 1,
219 message
=> "Could not determine platform. Assuming standard UNIX" );
220 ## You will have to specify the shell under which NONMEM
221 ## executes. The shell needs to know where nmfe5 is.
222 $shell = '/bin/csh -f';
223 $command = $ver5_unix;
226 $silent = $silent ?
">$silent" : '';
228 $command = "$shell nice -n $prio $command $nm_opts $modelfile $outfile $silent"
229 if ( $os eq 'linux' );
231 debug
-> warn( level
=> 2,
232 message
=> "$command" );
240 if ( $Config{osname
} eq 'MSWin32' ) {
242 @tmp = split(/\\/, $file );
243 $directory = join( "\\", @tmp[0..$#tmp-1] )."\\";
247 } else { # Assume OS == unix
249 @tmp = split(/\//, $file );
250 $directory = join( '/', @tmp[0..$#tmp-1] ).'/';
262 if ( $Config{osname
} eq 'MSWin32' ) {
264 @tmp = split(/\\/, $file );
265 $nopath = $tmp[$#tmp];
269 } else { # Assume OS == unix
271 @tmp = split(/\//, $file );
272 $nopath = $tmp[$#tmp];
284 open ( FILE
, $file );
286 if ( $Config{osname
} eq 'MSWin32' ) {
292 push( @content, $_ );