循環解壓縮文件

循環解壓縮文件

我有以下程式碼,它從 netcdf 檔案中提取數字,每個循環將它們放入另一個 netcdf 檔案中。

mapfile Latitude < <(tr -s ' ' '\n' < final_ADCP_Saved.matLatitude.txt) #tr is transform from to -s is squeeze. So look in the text files for all the spaces and replace them by newline '/n'
mapfile Longitude < <(tr -s ' ' '\n' < final_ADCP_Saved.matLongitude.txt)

echo "length of Lat is ${#Latitude[@]}"
echo "length of Lon is ${#Longitude[@]}"

outputNumber="$(ls -lq *_??????.nc | wc -l)"

echo "the number of output netcdf fles is ${outputNumber}"

valueI=`cat I.txt`
valueJ=`cat J.txt`
arrI=($valueI)
arrJ=($valueJ)

for ((i=1; i<=outputNumber; i++)) 
do
        echo "geknoei$i.nc"
        ncrcat -C -F -d nj_u,${arrJ[i]},${arrJ[i+1]} -d ni_u,${arrI[i]},${arrI[i+1]} -v vel_u *_??????.nc gekneoi$i.nc 

done

由於空間問題,我不得不壓縮輸入文件,並且此程式碼不再有效。我想知道是否可以編寫一個程式碼,在循環中解壓縮一個檔案(一次一個)提取我需要的內容,然後在循環結束時重新壓縮它。

因此,大致如下:

mapfile Latitude < <(tr -s ' ' '\n' < final_ADCP_Saved.matLatitude.txt) #tr is transform from to -s is search. So look in the text files for all the spaces and replace them by newline '/n'
    mapfile Longitude < <(tr -s ' ' '\n' < final_ADCP_Saved.matLongitude.txt)

echo "length of Lat is ${#Latitude[@]}"
echo "length of Lon is ${#Longitude[@]}"

outputNumber="$(ls -lq *_??????.nc | wc -l)"

echo "the number of output netcdf fles is ${outputNumber}"

valueI=`cat I.txt`
valueJ=`cat J.txt`
arrI=($valueI)
arrJ=($valueJ)

for ((i=1; i<=outputNumber; i++)) 
do
        echo "geknoei$i.nc"
        gunzip *_??????.nc.gz
        ncrcat -C -F -d nj_u,${arrJ[i]},${arrJ[i+1]} -d ni_u,${arrI[i]},${arrI[i+1]} -v vel_u *_??????.nc gekneoi$i.nc
        gzip *_??????.nc 

done

問題是這會一次解壓縮所有文件,這會佔用大量空間。如果我一次解壓縮一個文件,我的 ncrcat 程式碼將不再工作,因為它從所有可用的 -unzipped- .nc 文件中提取。

如何一次解壓縮一個 .nc 文件,同時仍使線路正常ncrcat -C -F -d nj_u,${arrJ[i]},${arrJ[i+1]} -d ni_u,${arrI[i]},${arrI[i+1]} -v vel_u *_??????.nc gekneoi$i.nc工作?

相關內容