Re: Char array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Mar 31 2010 - 23:32:12 MDT

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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 31 23:32:35 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 01 2010 - 11:31:45 MDT