wrmccann
11-03-2009, 04:14 PM
I am trying to use "call system(cmd)" and am encountering a problem. I would like to execute a program in a given "root" folder, and start a loop to use "call system(cmd), where cmd="chdir a", execute some commands opening and writing files in that directory, and then return to the root directory by "call system(cmd)", where cmd="chdir ../"
My problem is the "call system(cmd)" does not execute, leaving me in the root directory.
Is the "call system" not designed to work with the DOS chdir command?
Program follows below:
c comah.for
c combine sepate ah files for a given event into one file
c
c start at obsr4 folder and chdir into each directory as given in filelist, read files, combine, write file and jump back to obsr4 folder
c
character*11 junk
character*5 junk5
character*6 chdir
character*1 files(19)
character*19 cmd
character*11 label(7)
real all (7),data(7)
equivalence (files(1),cmd)
open(1,file='filelist')
1 read(1,2,end=99)(files(i),i=7,19)
2 format(13a1)
files(1)='c'
files(2)='h'
files(3)='d'
files(4)='i'
files(5)='r'
files(6)=' '
c
c cmd ready, now change directory, read and combine files
c
print *,cmd
c
c the following call does not execute as expected
c
call system(cmd)
c
c the above call does not execute as expected
c
open(17,file='all.asc')
open(10,file='dm.asc')
open(11,file='hyh.asc')
open(12,file='hyl.asc')
open(13,file='ref.asc')
open(14,file='sph.asc')
open(15,file='spl.asc')
open(16,file='tim.asc')
do k=10,16
read(k,*)junk
read(k,*)label(k-9)
enddo
write(17,*)(label(k-9),k=10,16)
8 do l=10,16
7 read(l,6)junk5
6 format(a5)
enddo
if(junk5.ne.'data:')goto 8
c
c read data, combine, and write
c
do j=1,100000
do m=10,16
read(m,*,end=3)data(m-9)
enddo
write(17,*)(data(n),n=1,7)
enddo
3 close(10)
close(11)
close(12)
close(13)
close(14)
close(15)
close(16)
close(17)
files(7)='.'
files(8)='.'
files(9)='/'
do mm=10,19
files(mm)=' '
enddo
call system(cmd)
goto 1
99 end
My problem is the "call system(cmd)" does not execute, leaving me in the root directory.
Is the "call system" not designed to work with the DOS chdir command?
Program follows below:
c comah.for
c combine sepate ah files for a given event into one file
c
c start at obsr4 folder and chdir into each directory as given in filelist, read files, combine, write file and jump back to obsr4 folder
c
character*11 junk
character*5 junk5
character*6 chdir
character*1 files(19)
character*19 cmd
character*11 label(7)
real all (7),data(7)
equivalence (files(1),cmd)
open(1,file='filelist')
1 read(1,2,end=99)(files(i),i=7,19)
2 format(13a1)
files(1)='c'
files(2)='h'
files(3)='d'
files(4)='i'
files(5)='r'
files(6)=' '
c
c cmd ready, now change directory, read and combine files
c
print *,cmd
c
c the following call does not execute as expected
c
call system(cmd)
c
c the above call does not execute as expected
c
open(17,file='all.asc')
open(10,file='dm.asc')
open(11,file='hyh.asc')
open(12,file='hyl.asc')
open(13,file='ref.asc')
open(14,file='sph.asc')
open(15,file='spl.asc')
open(16,file='tim.asc')
do k=10,16
read(k,*)junk
read(k,*)label(k-9)
enddo
write(17,*)(label(k-9),k=10,16)
8 do l=10,16
7 read(l,6)junk5
6 format(a5)
enddo
if(junk5.ne.'data:')goto 8
c
c read data, combine, and write
c
do j=1,100000
do m=10,16
read(m,*,end=3)data(m-9)
enddo
write(17,*)(data(n),n=1,7)
enddo
3 close(10)
close(11)
close(12)
close(13)
close(14)
close(15)
close(16)
close(17)
files(7)='.'
files(8)='.'
files(9)='/'
do mm=10,19
files(mm)=' '
enddo
call system(cmd)
goto 1
99 end