Project

General

Profile

How to subtract multiple files of different models in a folder using KSH script?

Added by jyoti lodha almost 6 years ago

Hi
I am having 10 files of present and future of different models in a folder in with each file is starting with (pres) for present and fut(future). AS I want to read them different with there names and then I want to subtract it with there respective models present and future file. Can it be possible in cdo?
#!/bin/ksh

infile1=fut*.nc
infile=pres*.nc

for t in $infile1
do
for f in $infile
do

cdo sub ${t} ${f} sub_${t}${f}
done
done
exit

Error-
cdo sub: Processed 20712960 values from 2 variables over 744 timesteps ( 1.16s )

cdo sub (Abort): Grid size of the input parameters do not match!

cdo sub (Abort): Grid size of the input parameters do not match!
cdo sub: Processed 6094848 values from 2 variables over 744 timesteps ( 0.27s )

As it is giving me the right output of 2 files of present and future for two models, but it again using the present file of one model and future of other model and I am getting the error of grid size. SO how can i remove it , so that it subtract the correct future file with the correct model present file, As at the end I have to take ensmean(ensemebel mean ) of all model.
Waiting for a positive reply.


Replies (2)

RE: How to subtract multiple files of different models in a folder using KSH script? - Added by Ralf Mueller almost 6 years ago

hi!
which CDO version do you use? sub (refering to cdo-1.9.5) has two input and one output stream. So I don't understand, what

cdo -sub ${t} ${f} sub_${t} ${f}
should do. you seem to use ${f} as input AND output ?!?

cheers
ralf

RE: How to subtract multiple files of different models in a folder using KSH script? - Added by jyoti lodha almost 6 years ago

Hi
Thanks a lot . I tried another method and solved my issue. One thing I want to ask that can we make a FUNCTION in KSH script which can be called wherever we want in our script where FOR loop dose not work correctly. As we do in other language.

Like:

func_name <- function (argument) {
statement
}

:)

Wait for a positive reply

    (1-2/2)