ncrcat
複数のファイルから値を抽出するコードがあります。.nc
ループは一度に1つのファイルから抽出するようにこのコードを要求します。これらのファイルの名前はテキストファイルに保存されます。ファイルが異なるディレクトリに保存されているため、パスを追加してもコードから読み取れないようです。コードは次のとおりです。
#!/bin/bash
outputNumber="$(wc -l Time122009.txt)" #"$(ls -lq *_??????.nc | wc -l)"
echo "the number of lines in the Time text file is ${outputNumber}"
# from all the netcdf files extract the vel_u (and eventually vel_v) with the indices that are in I.txt and J.txt
for ((index=1; index<=10; index++)) #for now only 10 loops were done, the 10 should eventually be replaced by outputNumber
do
arrI1=$(sed -n $index'p' I1.txt)
arrI2=$(sed -n $index'p' I2.txt)
arrJ1=$(sed -n $index'p' J1.txt)
arrJ2=$(sed -n $index'p' J2.txt)
Addition=`expr $index + 253` #I want it to start reading file Time122009.txt at position 253
Time=$(sed -n $Addition'p' Time122009.txt)
ncrcat -C -F -d nj_u,${arrJ1},${arrJ2} -d ni_u,${arrI1},${arrI2} -v vel_u $(../GRAPHIQUES/${Time}) $index.nc #extract from variable vel_u in dimensions nj_u and ni_u from file found in Time
done
I.txtとJ.txtの最初の値は次のとおりです。
5.2000000e+02
5.1000000e+02
4.9800000e+02
4.9200000e+02
4.8600000e+02
4.8000000e+02
4.7600000e+02
Time122009.txtは次のとおりです。
20091207_142???.nc
20091207_143???.nc
20091207_144???.nc
20091207_150???.nc
20091207_152???.nc
20091207_153???.nc
20091207_154???.nc
出力は次のとおりです。
the number of lines in the Time text file is 378 Time122009.txt
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_080725.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_082632.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_083???.nc: No such file or directory
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_084604.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_090511.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_092443.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_093???.nc: No such file or directory
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_094350.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_100257.nc: Permission denied
, neither exists locally nor matches remote filename patterns
./geknoei.sh: line 30: ../GRAPHIQUES/20091209_102229.nc: Permission denied
, neither exists locally nor matches remote filename patterns
一部のファイルが見つからないのは正常です(ファイルやディレクトリは存在しません)。
私のスクリプトのパスは次のとおりです。/home/elisev/SYMPHONIE2015/ROC_CONNECT/Scripts
私のファイルのパスは次のとおりです。/home/elisev/SYMPHONIE2015/ROC_CONNECT/GRAPHIQUES
必要な項目を正しく抽出できるように、これらのエラーが発生しないようにするにはどうすればよいですか。
編集:$()
周辺を削除すると、$(../GRAPHIQUES/${Time})
権限拒否エラーが削除されました。今、エラーは次のようになります。
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
, neither exists locally nor matches remote filename patterns
ベストアンサー1
私が経験している問題は、I.txtファイルとJ.txtファイルの数値形式です。整数でなければなりませ520
ん5.2000000e+02
。 matlabdlmwrite('myFile.txt', myMatrix);
でコードを変更すると、次のように動作します。
outputNumber="$(wc -l Time122009.txt)" #"$(ls -lq *_??????.nc | wc -l)"
echo "the number of lines in the Time text file is ${outputNumber}"
# from all the netcdf files extract the vel_u (and eventually vel_v) with the indices that are in I.txt and J.txt
for ((index=1; index<=10; index++)) #size de I.txt
do
arrI1=$(sed -n $index'p' I1.txt)
arrI2=$(sed -n $index'p' I2.txt)
arrJ1=$(sed -n $index'p' J1.txt)
arrJ2=$(sed -n $index'p' J2.txt)
Addition=`expr $index + 253`
Time=$(sed -n $Addition'p' Time122009.txt) #TempsModel.txt
echo $Addition
ncrcat -C -F -d nj_u,$arrJ2,$arrJ2 -d ni_u,$arrI1,$arrI2 -v vel_u /home/elisev/SYMPHONIE2015/ROC_CONNECT/GRAPHIQUES/${Time} $index.nc
echo "${Time}"
done