我有一个用于ncrcat
从多个.nc
文件中提取值的代码。在一个循环中,我要求这段代码一次从一个文件中提取。这些文件的名称存储在一个文本文件中。似乎由于这些文件存储在不同的目录中,因此即使我添加了路径,代码也无法读取它。这是代码:
#!/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
我遇到的问题是 I.txt 和 J.txt 文件中数字的格式。需要整数(
520
而不是5.2000000e+02
)一旦我改变了它(通过dlmwrite('myFile.txt', myMatrix);
在matlab中使用)我的代码看起来像这样并且可以工作: