I have three files with my input (param.in, pl.in, tp.in), i run a program (which is in fortran77, named swift_mvs) and i take three files with the output (dump_param.dat, dump_pl.dat and dump_tp.dat). I want to run the program for 144 times (12 months x 12 years) and each run to save the the 3 input files, the 3 output files (saved in: home/.../1st Year/1st Month etc.) and use the output of each run as the new input. I have done this already by hand and after two 2 weeks i realized that i had made a mistake, so i had to start form scratch. I made this script:
#! /bin/bash
for j in {1,12} # loop for the 12 years
do
for i in {1,11} # loop for the 12 month
do
./swift_mvs
cp dump_param.dat ""$j"ος Χρόνος"/""$i"ος Μήνας"/param"$i"Mon.dat
nano dump_param.dat
cp dump_param.dat param.in
cp dump_param.dat ""$j"ος Χρόνος"/""$((i+1))"ος Μήνας"/param"$((i+1))"Mon.in
cp dump_pl.dat ""$j"ος Χρόνος"/""$i"ος Μήνας"/pl"$i"Mon.dat
cp dump_pl.dat pl.in
cp dump_pl.dat ""$j"ος Χρόνος"/""$((i+1))"ος Μήνας"/pl"$((i+1))"Mon.in
cp dump_tp.dat ""$j"ος Χρόνος"/""$i"ος Μήνας"/tp"$i"Mon.dat
cp dump_tp.dat tp.in
cp dump_tp.dat ""$j"ος Χρόνος"/""$((i+1))"ος Μήνας"/tp"$((i+1))"Mon.in
done
./swift_mvs
cp dump_param.dat ""$(j)"ος Χρόνος"/'12ος Μήνας'/param12Mon.dat
cp dump_pl.dat ""$j"ος Χρόνος"/'12ος Μήνας'/pl12Mon.dat
cp dump_tp.dat ""$j"ος Χρόνος"/'12ος Μήνας'/tp12Mon.dat
nano dump_param.dat
cp dump_param.dat param.in
if [ j -lt 12 ]
then
cp dump_param.dat ""$((j+1))"ος Χρόνος"/'1ος Μήνας'/param1Mon.in
cp dump_pl.dat pl.in
cp dump_pl.dat ""$((j+1))"ος Χρόνος"/'1ος Μήνας'/pl1Mon.in
cp dump_tp.dat tp.in
cp dump_tp.dat ""$((j+1))"ος Χρόνος"/'1ος Μήνας'/tp1Mon.in
fi
done
for i=1,2 everything is good, but when i=3 the program doesn't cp the data, the files remain empty. I tried for i in {3,11} to see what will happen and after i=4 the files remain empty once again. The think is i dont get error messages. Any help would be useful. Thank you in advance.
Most important of all, you need {1..12} for j; not {1,12}. (It's dot-dot ".."; not comma.)
Similarly, for i also. You need {1..12} if you want 144.
Because you can try the following and you can get only two values there:
$ for j in {1,12}; do echo $j; done
1
12
This should help you with further debugging of your program.
Also, you need to create the folders first before copying.
I recommend to improve the indentation also. But, I'm not sure some part of your inner loop indentation are messed up during posting or not; even though it may be right in your source file itself. It's up to you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.