2014-07-03 177 views
0

我是shell脚本编程新手,我试图自动化一个进程。 我认为结构是好的,但我得到通知,我认为它不应该存在Bash-shell脚本修改和建议

# STEP 1# 
echo " Untar the file s" 
time tar -xf $tarfiles 
time tar -xf *.tar 

#STEP 2# 
fname=(wnd10m.gdas.2010*.grb2) 
echo " convert into .nc " 
cdo -f nc copy $fname $fname.nc 

#STEP 3# 
ofile1=$fname.nc 
echo "re-format into structured grid 0.5x0.5" 
cdo remapbil,r720x361 $ofile1 remap$R.nc 

#STEP 4# 
ofile2=$remapR.nc 
echo "produce desired mesh" 
cdo sellonlatbox,lon1,lon2,lat1,lat2 $ofile2 $grid.nc 

#STEP 5# 
ofile3=$grid.nc 
echo "merge the files based on tstep" 
cdo mergetime $ofile3 final$R.nc 

步骤1和2,尽管它只是操纵进行,并改变它被列入该文件的一个.tar文件。

方法到目前为止给出的步骤1 & 2,但在步骤3期间,我不其中R是这样产生的不与在先前步骤中产生的其它混淆的附加结束得到新的文件作为remap$R.nc

后,我运行它,这是我所得到的

convert into .nc 

cdo copy: Processed 987365376 values from 2 variables over 744 timesteps (234.66s) 
re-format into structured grid 0.5x0.5 

cdo remapbil: Processed 987365376 values from 2 variables over 744 timesteps (53.59s) 
produce desired mesh 

Error (cdo sellonlatbox) : Output file name .nc is equal to input file name on position 1! 

merge the files based on tstep 

cdo mergetime: Open failed on >.nc< 
No such file or directory 

我试图去想跟我的文件,但不知道我做错了,因为这个过程应该处理很多文件将其转换为每个阶段,我非常重视分配正确的和不同的fnames

如果你能看一看,并给我你的意见,我将不胜感激。

p.s. CDO是我使用的,所以你可以忽略它的代码,我的重点是过程本身

感谢

回答

1

比较这些:

cdo remapbil,r720x361 $ofile1 remap$R.nc 

ofile2=$remapR.nc 

这看起来像一个典型错字

+0

@Bushmils。我做了这种形式,以便在转换中为每个文件添加一个不同的结尾,然后将其用作下一组命令的输入文件 尽管我认为我弄糟了那部分,但我会改变它,跑。 – George

+0

没有改变,但结果是 CDO sellonlatbox:打开失败上> .NC < 没有这样的文件或目录 合并基于TSTEP CDO mergetime文件:打开失败上> .NC < 没有这样的文件或目录 – George

+0

“做了这种形式,以便为每个文件添加一个不同的结尾”我不明白。你没有给变量R分配任何东西,因此其内容未定义,或者你没有显示你分配的内容。 –

2

$remapRremap$R不同。移动你的美元符号。

您可以使用set -xv来调试您的脚本。

+0

在每组命令之前或在scipt开始时使用该命令吗? – George

+0

@George:它会影响在它之后执行的命令。 – choroba

0

您好所有的延续,这个问题我已经和用户@Bushmills帮我很多(谢谢!!!)

我附上的代码,我做了我得到的意见,我tes特德和它的作品,所以希望另一个用户(像我这样的新手)可能会觉得这很有用。

file="wnd10m.gdas." 
year='2010' 
month='01 02' 
ext="grb2" 

for((y=$year;y<=$year;y++)); 
do 
    for m in $month 
    do 
    fname=$file$y$m.$ext 

    #STEP 1# 
    cdo -f nc copy $fname $fname.nc 

    #STEP 2# 
    ofile1=$fname.nc 

    cdo remapbil,r720x361 $ofile1 R$ofile1 #produces a file with the name of the R+ofile1 

例如,如果一个文件被命名文件的命令会产生一个名为的RFile #步骤3# ofile2 =($ R * .NC) 使用所有文件的新文件开始有R

cdo sellonlatbox,$lon1,$lon2,$lat1,$lat2 $ofile2 grid_$ofile2 

    done 
done 

感谢您的帮助

+0

很高兴它为你工作。但是......“ofile2 =($ R * .nc)” - 你确定吗? (变量R仍然没有在任何地方定义) –

+0

@Bushmills是的,它的工作,我张贴它,也许有人有类似的问题可能会有所帮助,我编辑上面的代码来显示R是什么。希望它更清晰 – George

+0

现在我只剩下一个有点棘手的最后一步,但希望这段代码将在社区 – George