Re: variable naming

From: Dennis Shea (shea AT cgd.ucar.edu)
Date: Thu Oct 14 2004 - 15:46:55 MDT

  • Next message: MUHTARJAN osman: "about build-in function "rtest""

    >>
    >> Hello all,
    >>
    >> I have read variables from a file using:
    >>
    >> vNames = getfilevarnames (inF)
    >>
    >> and looped through the various elements of vNames. I would like to
    >> rewrite the processed data to a netCDF file but using the original
    >> variable name (ie the individual string elements of vNames). I have
    >> problems creating this new variable for output using simple assignment
    >> along the lines of:
    >>
    >> $vName(n)$ = vAvgInt or, vName(n) = vAvgInt
    >>
    >> All suggestions appreciated!
    >>
    >> Regards,
    >>
    >> Maurice
    >
    >Hi Maurice,
    >
    >I think you are almost there. You can only use the "$vName$" syntax
    >when the "$...$" is used on the right side of the attribute symbol
    >"@", or a file pointer "->". For example:
    >
    > fnew = addfile("newfile.nc","c")
    > fnew->$vName(n)$ = vAvgInt
    >
    >If you need to store vName(n) temporarily, then you can attach it to
    >another variable using "@":
    >
    > tmp_attach = True ; Temp. variable to attach things to.
    > tmp_attach@$vName(0)$ = vAvgInt
    > tmp_attach@$vName(1)$ = vAvgStd
    > .
    > .
    > .
    >
    >Maybe somebody else has a more efficient method of doing this?
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    oops ... I accidently replied to just Maurice.
    I forgot to send to ncl-talk.
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    You say "rewrite" but then I get the idea you
    want to (1) read data, (2) process, (3) write data
    to another file. I assume the input/output files
    will be different.

     fout = addfile("output.nc","c") ; output file

     vNames = getfilevarnames(fin) ; extract ALL variable names
     nVar = dimsizes(nVar) ; loop through ALL the variables
     
     
     do i=0,nVar-1 ; loop over variables and copy
        
         var = f->$vNames(i)$
         var = 2.*var ; process [mult by 2]
         ncdf->$vNames(i)$ = var
         
         delete(var)
     end do

    =====
    u could make more elaborate

       var2process = (/ "T", "Q", "Z"/) ; var to be processed
       
     do i=0,nVar-1 ; loop over variables and copy
        if (any(var2process.eq.vNames(i)) then
       
            if(vNames(i).eq."T") then
               var = f->$vNames(i)$
               var = 1.8*var + 32.
               ncdf->$vNames(i)$ = var ; write processed data to file
            end if
            [snip]
            
         delete(var)
     end do
    =====

    good luck
    D

    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Fri Oct 15 2004 - 10:05:55 MDT