Project

General

Profile

shell script for using CDO codes

Added by nazanin tavakoli almost 4 years ago

Hello,
I am using the windows batch file of cygwin46 on windows 10 for my CDO code, but unfortunately, It is really hard for me to code in a windows batch file, because my codes are too long. Could anybody recommend me a shell script for using CDO in windows?


Replies (16)

RE: shell script for using CDO codes - Added by Brendan DeTracey almost 4 years ago

Try writing the script in bash (https://mywiki.wooledge.org/BashGuide) and run it from a cygwin terminal. It is either that, or using windows powershell to call the command from cygwin. I do not recommend the second option, unless you really want to learn powershell.

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

Installing a Linux terminal doesn't damage my system? I have Ubuntu 18.4 in my virtual box, too. But I am really comfortable using windows. If installing a Linux terminal doesn't damage my system, I will try it

RE: shell script for using CDO codes - Added by Brendan DeTracey almost 4 years ago

What is the "Windows batch file of cygwin"? I assumed that you already had cygwin installed on your PC. If not, you should instead install windows subsystem for linux (WSL1) and then install cdo using the anaconda distribution (https://code.mpimet.mpg.de/projects/cdo/wiki/Win32). Cygwin is a linux emulator that runs under windows. It probably runs faster than than running under (WSL1), but cygwin cdo has a bug that might prevent opening netcdf4 and netcdf 4 classic file types.

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

I have installed the terminal of ubuntu 18.04 on my windows. Does it have bugs with netcdf4? I am working on netcdf4

RE: shell script for using CDO codes - Added by Brendan DeTracey almost 4 years ago

I have used WSL1 Ubuntu 18.04 and cdo without problems. The only problem is that the Ubuntu 18.04 version of cdo will be old. That is why I suggested installing anaconda and using its conda package manager to install cdo. This will give you the most recent cdo version. If you do not care about age, install cdo from your Ubuntu terminal:

$ sudo apt install cdo

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

Thank you very much. Now, for running my cdo code, I use a bash script like the one I have sent it here, AND for running it I use sh cdoC.txt. The terminal shows me this:
cdo copy/selall : UNCHANGED_RECORD=0
cdo copy/selall : cdiGribDataScanningMode=0; lcopy=0

Is it s.th important?

cdoC.txt (100 Bytes) cdoC.txt

RE: shell script for using CDO codes - Added by Brendan DeTracey almost 4 years ago

I don't know. Do the output values look correct? You could try running the same command with the verbose option cdo -v ...

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

Thank you very much for your help.

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

Hi again,
I have a serious problem. I want to resample my data with the following code in a bash script (windows subsystem for Linux).

#!/etc/bash
cdo genbil,gridfile1.txt clay0_5.nc Tbil.nc
cdo remap,gridfile1.txt,Tbil.nc clay0_5.nc clay0_5bil.nc

cdo genbic,gridfile1.txt clay0_5.nc Tbic.nc
cdo remap,gridfile1.txt,Tbic.nc clay0_5.nc clay0_5bic.nc

cdo gennn,gridfile1.txt clay0_5.nc Tnn.nc
cdo remap,gridfile1.txt,Tnn.nc clay0_5.nc clay0_5nn.nc

cdo gendis,gridfile1.txt clay0_5.nc Tdis.nc
cdo remap,gridfile1.txt,Tbdis.nc clay0_5.nc clay0_5dis.nc

but, It shows me this error:

cdo genbil (Abort): Open failed on gridfile1.txt!

cdo remap (Abort): Open failed on gridfile1.txt!
: not found: code.txt:

cdo genbic (Abort): Open failed on gridfile1.txt!

cdo remap (Abort): Open failed on gridfile1.txt!
: not found: code.txt:

cdo gennn (Abort): Open failed on gridfile1.txt!

cdo remap (Abort): Open failed on gridfile1.txt!
: not found0: code.txt:

cdo gendis (Abort): Open failed on gridfile1.txt!

cdo remap (Abort): Open failed on gridfile1.txt!

could you please help me? I really need help.
I have sent my code, data, and gridfile1.txt here.

RE: shell script for using CDO codes - Added by Brendan DeTracey almost 4 years ago

You are getting close, my friend. First, re-read section 1.4.2.4 (https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-210001.4.2) paying close attention to the table. Your lonlat grid file is incorrect. You are missing nvertex, xbounds and ybounds i.e. the grid cell vertices. Second, the command line should be $ cdo remap,Tbil.nc,gridfile1.txt clay0_5.nc clay0_5bil.nc, i.e. the weight file is the first argument to the remap command (https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-6650002.12.8).

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

I have changed my lonlat gridfile, and also my code as you have mentioned in previous massage like below:
gridfile:

gridtype = lonlat
gridsize = 359253
xname = longitude
xlongname = longitude
xunits = degrees_east
yname = latitude
ylongname = latitude
yunits = degrees_north
xsize = 669
ysize = 537
xfirst = 140.6905
xinc = 0.021
yfirst = -39.2369
yinc = 0.021
nvertex=2
xbounds=1338
ybounds=1074

here is my code:

#!/usr/bin/env bash
$cdo genbil,gridfile1.txt clay0_5.nc Tbil.nc
$cdo remap,gridfile1.txt,Tbil.nc clay0_5.nc clay0_5bil.nc

$cdo genbic,gridfile1.txt clay0_5.nc Tbic.nc
$cdo remap,gridfile1.txt,Tbic.nc clay0_5.nc clay0_5bic.nc

$cdo gennn,gridfile1.txt clay0_5.nc Tnn.nc
$cdo remap,gridfile1.txt,Tnn.nc clay0_5.nc clay0_5nn.nc

$cdo gendis,gridfile1.txt clay0_5.nc Tdis.nc
$cdo remap,gridfile1.txt,Tbdis.nc clay0_5.nc clay0_5dis.nc

but I have this error:
code.txt: 2: code.txt: genbil,gridfile1.txt: not found
code.txt: 3: code.txt: remap,gridfile1.txt,Tbil.nc: not found
: not found: code.txt:
code.txt: 5: code.txt: genbic,gridfile1.txt: not found
code.txt: 6: code.txt: remap,gridfile1.txt,Tbic.nc: not found
: not found: code.txt:
code.txt: 8: code.txt: gennn,gridfile1.txt: not found
code.txt: 9: code.txt: remap,gridfile1.txt,Tnn.nc: not found
: not found0: code.txt:
code.txt: 11: code.txt: gendis,gridfile1.txt: not found
code.txt: 12: code.txt: remap,gridfile1.txt,Tbdis.nc: not found

RE: shell script for using CDO codes - Added by Ralf Mueller almost 4 years ago

I get strange error like this

do    genbil: Bilinear weights from lonlat (5734x4984) to lonlat (669x537) grid, with source mask (19757690)
cdo    genbil: Processed 28578256 values from 1 variable over 1 timestep [4.84s 4734MB].
cdo    remap: Processed 28578256 values from 1 variable over 1 timestep [0.93s 1277MB].
code.txt: line 4: $'\r': command not found
cdo    genbic: Bicubic weights from lonlat (5734x4984) to lonlat (669x537) grid, with source mask (19757690)
cdo    genbic: Processed 28578256 values from 1 variable over 1 timestep [5.38s 5388MB].

cdo    remap (Abort): nc_open failed on Tbic.nc! No such file or directory
code.txt: line 7: $'\r': command not found

I think you use windows style line endings in your text file, which may confuse the unix environment.

  • windows line end: \r\n
  • unix line end: \n

you can convert the code.txt file to unix with the command dos2unix. there should be a binary package with the same name provided by your package manager.

hth
ralf

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

I have used the command dos2unix in ubuntu 18 in the windows subsystem (dos2unix -n code.txt code_cdo.txt) but It shows me this error:
nazanin@DESKTOP-UQT97M1:/mnt/d/clayb$ dos2unix -n code.txt code_cdo.txt
dos2unix: converting file code.txt to file code_cdo.txt in Unix format...
nazanin@DESKTOP-UQT97M1:/mnt/d/clayb$ sh code_cdo.txt
code_cdo.txt: 2: code_cdo.txt: genbil,gridfile1.txt: not found
code_cdo.txt: 3: code_cdo.txt: remap,gridfile1.txt,Tbil.nc: not found
code_cdo.txt: 5: code_cdo.txt: genbic,gridfile1.txt: not found
code_cdo.txt: 6: code_cdo.txt: remap,gridfile1.txt,Tbic.nc: not found
code_cdo.txt: 8: code_cdo.txt: gennn,gridfile1.txt: not found
code_cdo.txt: 9: code_cdo.txt: remap,gridfile1.txt,Tnn.nc: not found
code_cdo.txt: 11: code_cdo.txt: gendis,gridfile1.txt: not found
code_cdo.txt: 12: code_cdo.txt: remap,gridfile1.txt,Tbdis.nc: not found

RE: shell script for using CDO codes - Added by Ralf Mueller almost 4 years ago

remove the '$' of $cdo

RE: shell script for using CDO codes - Added by nazanin tavakoli almost 4 years ago

it works. Thank you for your help

    (1-16/16)