-1

I am trying to read data from files as:

test_50rg0_shear0.01_fric0.5.dat
test_50rg1_shear0.01_fric0.5.dat
test_50rg2_shear0.01_fric0.5.dat 

in a Fortran code and then use the data of the second column. My code is

do i=0,2
  write(filename_i,'(a,i1,a)')'../test_50rg',i,'_shear0.01_fric0.5.dat
  write(filename_o,'(a,i1,a)')'../dist_50rg',i,'_shear0.01_fric0.5.dat'
  call system("awk '{print $2}' filename_i > filename_o")
  .......
end do

for this I am getting error:

awk: cmd. line:1: fatal: cannot open file `filename_i' for reading (No such file or directory)

Please tell me why there is such error and any other method to do the job.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185

1 Answers1

1

You're passing the literal string "filename_i" to awk when you need to pass the variable, as stated by Klitos.

You should use:

call system("awk '{print $2' "//trim(filename_i)//" > "//trim(filename_o))

where the // command concatenates strings.

Ross
  • 2,130
  • 14
  • 25