Project

General

Profile

How to deal with many nc files when it needs mulc operator?

Added by Wi Du over 7 years ago

Hello, every one,

I know how to use cdo mulc,365 infile out file for the single nc file.
But now I have many nc files. So how to use mulc for saving time?
Thanks a lot!

Replies (4)

RE: How to deal with many nc files when it needs mulc operator? - Added by Ralf Mueller over 7 years ago

for file in $(ls *.nc); do
  echo "cdo -mulc $file $(dirname ${file})/mulc_$(basename ${file})" 
done | parallel -v -j 4

will process 4 files at once. you have to install GNU parallel first

RE: How to deal with many nc files when it needs mulc operator? - Added by Wi Du over 7 years ago

Thank you very much!

When I run the script:
#!/bin/bash
for file in $(ls *.nc); do
echo "cdo -mulc $file $(dirname ${file})/mulc_$(basename ${file})"
done

It could not work.
The results shows no changes, but just indicates
cdo mulc,320 n1.nc ./mulc_n1.nc
cdo mulc,320 n2.nc ./mulc_n2.nc
cdo mulc,320 n3.nc ./mulc_n3.nc
.....
.....
It did not run the cdo mulc operator.
But when only input cdo mulc,320 n1.nc ./mulc_n1.nc it run right.
So, is it impossible that cdo can not run in bash script?

Thanks a lot!

RE: How to deal with many nc files when it needs mulc operator? - Added by Ralf Mueller over 7 years ago

Wi Du wrote:

Thank you very much!

When I run the script:
#!/bin/bash
for file in $(ls *.nc); do
echo "cdo -mulc $file $(dirname ${file})/mulc_$(basename ${file})"
done

It could not work.
The results shows no changes, but just indicates
cdo mulc,320 n1.nc ./mulc_n1.nc
cdo mulc,320 n2.nc ./mulc_n2.nc
cdo mulc,320 n3.nc ./mulc_n3.nc
.....
.....
It did not run the cdo mulc operator.
But when only input cdo mulc,320 n1.nc ./mulc_n1.nc it run right.
So, is it impossible that cdo can not run in bash script?

run

#!/bin/bash
for file in $(ls *.nc); do
 cdo -mulc $file $(dirname ${file})/mulc_$(basename ${file})
done

and all cdo commands are run sequentially. You forgot the

 | parallel -v -j 4
after your loop (that's what makes the runs executed simultaniousliy)

the echo command just prints things - hence the CDO commands were not executed

RE: How to deal with many nc files when it needs mulc operator? - Added by Wi Du over 7 years ago

Yes!!!Ok, I forgot this. Will edit again.

Thanks a lot!

    (1-4/4)