Project

General

Profile

CDO ifthen with only one field in ifile1

Added by Christoph Kleinschmitt over 7 years ago

Hello,

I'm trying to select and process values of a larger number of fields in ifile2 under the condition that the single field in ifile1 is non-zero using "ifthen":

cdo vertsum -mul -ifthen ifile1 -selname,variableA ifile2 -selname,variableB ifile2 ofile

All fields have the same dimensions in space and time, but of course there are more variables per time step in ifile2 than in ifile1. According to the CDO user's guide it should work for only one variable in ifile1, but I get the error

cdo(4) ifthen (Abort): Input streams have different number of variables per timestep!

Does anyone know that problem and how to resolve it?
Thank you very much in advance for your help.

Kind regards,
Christoph


Replies (6)

RE: CDO ifthen with only one field in ifile1 - Added by Ralf Mueller over 7 years ago

hi Christoph!

as always: please upload the input files.

cheers
ralf

RE: CDO ifthen with only one field in ifile1 - Added by Christoph Kleinschmitt over 7 years ago

Hi Ralf,

sorry, I thought that it might be possible to answer my question without a specific file, but now I created and uploaded smaller test files. Now the command

cdo vertsum -mul -ifthen ifile1.nc -selname,BIN01,BIN02 ifile2.nc -selname,mass ifile2.nc ofile.nc

will result in the same error

cdo(4) ifthen (Abort): Input streams have different number of variables per timestep!

while it works fine with only one variable in both input files (e.g. -selname,BIN01 ifile2.nc).

Cheers,
Christoph

RE: CDO ifthen with only one field in ifile1 - Added by Christoph Kleinschmitt over 7 years ago

Hi Ralf,

do you get the same error when applying the command to the input files?

Thank you very much for your help,
Christoph

RE: CDO ifthen with only one field in ifile1 - Added by Christoph Kleinschmitt about 7 years ago

Hello,

could anyone please look into this issue again? It remains unresolved.
Thank you very much for your help.

Christoph

RE: CDO ifthen with only one field in ifile1 - Added by Ralf Mueller about 7 years ago

you could copy the mask into a second variable to have the same number if variables:

cdo vertsum -mul -ifthen -aexpr,press=pres ifile1.nc  -selname,BIN01,BIN02 ifile2.nc -selname,mass ifile2.nc ofile.nc

Lets check docu:

The number of fields in infile1 has either to be the same as in infile2 (not the case in your files, different number of variables) or the same as in one timestep of infile2 (not the case,too) or only one (not, because you have multiple timesteps)@

Hence (although it does not solve your problem) the call

cdo vertsum -mul -ifthen -seltimestep,1 -selname,pres ifile1.nc  -selname,BIN01,BIN02 ifile2.nc -selname,mass ifile2.nc ofile.nc
should work IMO, but fails with your error, too.

hth
ralf

ofile.nc (364 KB) ofile.nc my output file

RE: CDO ifthen with only one field in ifile1 - Added by Christoph Kleinschmitt about 7 years ago

Hi Ralf,

thank you for your answer. I read the documentation before and understood the condition "The number of fields in ifile1 has either to be [...] or only one" such that my ifile1.nc satisfies it with only one field (noting is said about the number of timesteps). And as you remarked, the same error occurs, if all the files have only one single timestep.
Therefore I would suggest either to remove the "or only one" from the documentation, or to fix this bug and make it work with one single field in ifile1 and multiple fields in ifile2. Personally, I would prefer the latter, because I would like to use the same mask for a large number of variables in a (very large) ifile2. Creating a mask file with the same large number of (identical) fields and then applying "ifthen" would be very costly.

Kind regards,
Christoph

    (1-6/6)