Re: How to get the exact data type from a known file? "new "function problem

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed, 8 Jul 2009 10:26:32 -0600 (MDT)

On Wed, 8 Jul 2009, Yan Bao wrote:

> Hi,Every one
> I'd like to creat a file namelist in my directory, but I don't know what
> the type of the file name namelist, I have tried 'character','string',
> ' byte',
> all of them don't work. I got the error message like:
> fatal:Assignment type mismatch, right hand side can't be coerced to type of
> left hand side
> fatal:Execute: Error occurred at or near line 26 in file ght.time.ncl
>
> I want to use the type attribute from file_list1, I think they are the same,
> how can I do that?
> Thanks.

Yan,

You want to use "string":

However, you don't need to do "new" on "file_list3", and
you don't want it inside the do loop.

Use NCL's array syntax to create your array of strings in one call:

   file_list3 = "ght_A6."+year+"010100-"+year+"123123.nc"

"year" is an array of integers, so "file_list3" will be equal to:

   "ght_A6.1984010100-1984123123.nc"
   "ght_A6.1985010100-1985123123.nc"
   "ght_A6.1986010100-1986123123.nc"
    ...
   "ght_A6.2069010100-2069123123.nc"

Finally, you have:

   year = new(nfiles,integer)
   year =(/1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,2060,2061,2062,2063,2064,2065,2066,2067,2068,2069/)

Again, it is not necessary to do a "new" first, so remove the "year
new(nfiles,interger)" line.

--Mary

> Script:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
> begin
> file_home ="./"
> file_list1 = systemfunc("cd " + file_home+ " ; ls ta_A6.*nc ;")
> print(file_list1)
> file_list2 = systemfunc("cd " + file_home+ " ; ls hus_A6.*nc ;")
> print(file_list2)
> nfiles = dimsizes(file_list1)
> year = new(nfiles,integer)
> year
> =(/1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,2060,2061,2062,2063,2064,2065,2066,2067,2068,2069/)
>
> file_list3 =new(nfiles,byte)
> nf = nfiles-1
> do fil = 0, nf ; files numbers !from 1985
> a =addfile(file_home+file_list1(fil),"r")
> b =addfile(file_home+file_list2(fil),"r")
> file_list3(fil) ="ght_A6."+year+"010100-"+year+"123123.nc"
> print(file_list3(fil))
> end do
> end
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jul 08 2009 - 10:26:32 MDT

This archive was generated by hypermail 2.2.0 : Wed Jul 08 2009 - 14:48:16 MDT