c Copyright (C) 2008-2014 Vincent Eymet c c KDISTRIBUTION is free software; you can redistribute it and/or modify c it under the terms of the GNU General Public License as published by c the Free Software Foundation; either version 3, or (at your option) c any later version. c KDISTRIBUTION is distributed in the hope that it will be useful, c but WITHOUT ANY WARRANTY; without even the implied warranty of c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the c GNU General Public License for more details. c You should have received a copy of the GNU General Public License c along with KDISTRIBUTION; if not, see c subroutine get_nlines(kfile,pindex,nl) implicit none include 'max.inc' c c Purpose: to get the number of lines in the provided file c c Inputs: c + kfile: file whose number of lines has to be retrieved c + pindex: index of the process that executes this routine c c Outputs: c + nl: number of lines in the "kfile" file; a value of zero indicates c the file does not exist c integer nl,pindex,ios character*(Nchar_mx) kfile,command,lfile character*3 ich c label integer strlen character*(Nchar_mx) label label='subroutine get_nlines' c Number of lines in the specified data file call num2str3(pindex,ich) c call idx2str(pindex,ich) lfile='./nlines_'//ich(1:strlen(ich)) command="wc -l < "//kfile(1:strlen(kfile))//" > "// & lfile(1:strlen(lfile)) c Debug c write(*,*) 'This is:',label(1:strlen(label)) c write(*,*) 'command=' c write(*,*) command(1:strlen(command)) c Debug call exec(command) open(10,file=lfile(1:strlen(lfile)),status='old',iostat=ios) if (ios.ne.0) then ! file not found write(*,*) 'Error from routine ',label(1:strlen(label)),' :' write(*,*) 'File not found:' write(*,*) lfile(1:strlen(lfile)) stop endif read(10,*) nl close(10) return end