0

I'd like to do a trend analysis with ndvi data from 1982 til 2005. I am using the r.neighbors command to get first the spatial variance (then I would use r.series method=slope to get the actual trend) and in order to speed things up I'd like to do it using a loop... however it is not running :(
Here is my code... can someone help me?

for a in 
  1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 
  1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 ; do

  for i in 311 ; do
    r.neighbors
      input=AVHRR_NDVI_$aDOY$i
      output=AVHRR_NDVI_$aDOY$i.sp.var
      method=variance
      size=5
     echo "loop ends" ;
   done ;
 done
1

For a sequence, you can use "seq" and variables with trailing characters need to be defined with curly braces:

for a in `seq 1982 2005` ; do
    for i in 311 ; do
        r.neighbors input=AVHRR_NDVI_${a}DOY$i output=AVHRR_NDVI_${a}DOY$i.sp.var method=variance size=5
    done
done
  • i got it,see: for i in 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 ; do for a in 356 ; do r.neighbors input=AVHRR_NDVI_"$i"DOY$a output=AVHRR_NDVI_"$i"DOY$a.sp.var method=variance size=5 --o; echo "loop ends" ; done ; done. Just needed to enter quotationmarks after $i so that its not confused with DOY whihc is not a variable in this case.but thanks anyways. – Katrin May 8 '14 at 9:12
  • So, everything solved? – markusN May 8 '14 at 9:22
  • uuuuuuuuuuuuh yes – Katrin May 8 '14 at 9:38
0
for a in 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 ; do 
   for i in 311 ; do 
          r.neighbors input=AVHRR_NDVI_$aDOY$i output=AVHRR_NDVI_$aDOY$i.sp.var method=variance size=5 
          echo "loop ends" ; 
     done ; 
done

I would say, you are missing ";" before last "echo"

  • hmm no it still does not work, but thanks anyways. – Katrin May 8 '14 at 6:22
  • hmm no it still does not work, but thanks anyways. for whatever reason it is complaining "AVHRR_NDVI_311: command not found...I dont get why it is not taken the values for a..... – Katrin May 8 '14 at 6:27
  • You need to use curly braces for variables which are followed by a string: e.g. AVHRR_NDVI_$aDOY$i --> AVHRR_NDVI_${a}DOY$i. Then it will work. – markusN May 8 '14 at 6:40
  • @Jachym: I'll take liberty to repost your post :) – markusN May 8 '14 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.