Re: Char array

From: Lei Meng <dream916_at_nyahnyahspammersnyahnyah>
Date: Tue Apr 06 2010 - 14:03:31 MDT

Hi Mary,
   When using your code below, I got the warning message:
  warning:VarVarWrite: lhs has dimension name and rhs doesn't, deleting name
of lhs dimension number(1), use "(/../)" if this is not desired outcome
 warning:Execute: Error occurred at or near line 157 in file
interpolate_ocnsink.ncl.
  Using the loop in my original code did not have the warning message.
  Thanks,
   Lei

On Thu, Apr 1, 2010 at 11:16 PM, Mary Haley <haley@ucar.edu> wrote:

> You might be able to further simplify this by removing the loop:
>
> y = stringtocharacter(x)
> ylen = dimsizes(y)
>
> species_name(0,:ylen-2) = y(:ylen-2)
>
>
> On Apr 1, 2010, at 6:48 PM, Lei Meng wrote:
>
> Hi Mary,
> Thanks for your reply. I used the following lines to replace species
> name and it worked.
>
> x = "CH3CCL3 "
> y = stringtocharacter(x)
>
> a1 = new(1,character)
> do i=0,19
> a1 = y(i:i)
> species_name(0,i:i) = a1 ; not species_name(0,i)
> end do
> Thanks,
> Lei
>
> On Thu, Apr 1, 2010 at 1:32 AM, Mary Haley <haley@ucar.edu> wrote:
>
>> Lei,
>>
>> Without seeing the line that caused the error, I'm not sure how to tell
>> you to correct it.
>>
>> We have a "str_right_strip" function that strips off white space at the
>> end of a string. Did you give this a try?
>>
>> Here's an example:
>>
>>
>> species_name = (/"O3 ", \
>> "CO ", \
>> "CH4 ", \
>> "CH2O ", \
>> "CH3OOH ", \
>> "H2O2 ", \
>> "NO2 ", \
>> "HNO3 ", \
>> "PAN ", \
>> "CH3COCH3 ", \
>> "CH3COOOH ", \
>> "CH3CHO ", \
>> "CH3COCHO ", \
>> "NO ", \
>> "HNO4 ", \
>> "NH3 "/)
>>
>> print("species_name = '" + species_name + "'")
>>
>> new_species_name = str_right_strip(species_name) ; Strip off trailing
>> white space.
>>
>> print("new_species_name = '" + new_species_name + "'")
>>
>> Furthermore, if you need to replace the names with different names, you
>> can use str_sub_str. For example, if you have to replace "CH3" with "CH2",
>> you would do this:
>>
>>
>> sub_species_name = str_sub_str(new_species_name,"CH3","CH2")
>> print("species_name: old/new = '" + new_species_name + "'/'" +
>> sub_species_name + "'")
>>
>>
>> (0) species_name: old/new = 'O3'/'O3'
>> (1) species_name: old/new = 'CO'/'CO'
>> (2) species_name: old/new = 'CH4'/'CH4'
>> (3) species_name: old/new = 'CH2O'/'CH2O'
>> (4) species_name: old/new = 'CH3OOH'/'CH2OOH'
>> (5) species_name: old/new = 'H2O2'/'H2O2'
>> (6) species_name: old/new = 'NO2'/'NO2'
>> (7) species_name: old/new = 'HNO3'/'HNO3'
>> (8) species_name: old/new = 'PAN'/'PAN'
>> (9) species_name: old/new = 'CH3COCH3'/'CH2COCH2'
>> (10) species_name: old/new = 'CH3COOOH'/'CH2COOOH'
>> (11) species_name: old/new = 'CH3CHO'/'CH2CHO'
>> (12) species_name: old/new = 'CH3COCHO'/'CH2COCHO'
>> (13) species_name: old/new = 'NO'/'NO'
>> (14) species_name: old/new = 'HNO4'/'HNO4'
>> (15) species_name: old/new = 'NH3'/'NH3'
>>
>>
>> --Mary
>>
>>
>>
>> On Mar 30, 2010, at 2:53 PM, Lei Meng wrote:
>>
>> Hi,
>>> I tried to replace a char array (species_name in the following netCDF
>>> file) with different gas names. It always give me the error message "
>>> Assignment type mismatch, right hand side can't be coerced to type of left
>>> hand side". I tried different combinations such as stringtochar and
>>> chartostring and did not work.
>>> Thanks for your help in advance.
>>> Lei
>>> Here is the information from the netCDF file.
>>> -------------------------------
>>> dimensions:
>>> lon = 192 ;
>>> lat = 94 ;
>>> species = 16 ;
>>> land_types = 11 ;
>>> string_len = 20 ;
>>> time = UNLIMITED ; // (12 currently)
>>> variables:
>>> float lat(lat) ;
>>> lat:long_name = "Latitude of cell center" ;
>>> lat:units = "degrees" ;
>>> float lon(lon) ;
>>> lon:long_name = "Longitude of cell center" ;
>>> lon:units = "degrees" ;
>>> char species_name(species, string_len) ;
>>> species_name:long_name = " " ;
>>> species_name:units = " " ;
>>> int date(time) ;
>>> date:long_name = "YYYYMM" ;
>>> date:units = " " ;
>>> float fraction_land_type(land_types, lat, lon) ;
>>> fraction_land_type:long_name = "fraction of each land
>>> type" ;
>>> fraction_land_type:units = "%" ;
>>> float dvel(time, species, lat, lon) ;
>>> dvel:long_name = "deposition velocities" ;
>>> dvel:units = "m/s" ;
>>>
>>> species_name =
>>>
>>>
>>
>>
>>>
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>>
>
>
Received on Tue Apr 6 14:03:47 2010

This archive was generated by hypermail 2.1.8 : Wed Apr 07 2010 - 07:12:50 MDT