Re: fatal error: reading multi dimension data with one dimension fixed

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Thu May 08 2014 - 17:57:51 MDT

Guangshan and Michael,

First, this is not a new problem, or a bug sneaked into 6.2.0, as this happened in 6.1.2 as well.

Here is what we find:

1. Your file has "lev, lat, lon" as coordinate variables,
2. But variable "U" has "lev, lat, lon" as attributes as well.
3. When NCL just read a slice of variable, NCL will create an attribute with the name of
        that (slice indexed) coordinate variable, and its value is the slice index.
4. Here comes the problem, as U already has lev, or lat, or lon as attributes,
        NCL sees this, and does not what do, so gives a fatal error.

To avoid this issue, you can do:

a) Make copy of your original file, as we are going to remove U's attributes first.

        cp test_uwind.nc uwind.nc

b) Create a script (say tst.ncl) cto write new attributes of U and then remove U's lev, lat, lon attributes.
 f = addfile("uwind.nc", "w")
 f->U@lon_ori = f->U@lon
 f->U@lat_ori = f->U@lat
 f->U@lev_ori = f->U@lev
 delete(f->U@lon)
 delete(f->U@lat)
 delete(f->U@lev)
 u0 = f->U(2,:,:,:)
;printVarSummary(u0)
 u1 = f->U(:,2,:,:)
;printVarSummary(u1)
 u2 = f->U(:,:,2,:)
;printVarSummary(u2)
 u3 = f->U(:,:,:,2)
 printVarSummary(u3)

c) run the script:
ncl tst.ncl
 Copyright (C) 1995-2014 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.2.1
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.

Variable: u3
Type: float
Total Size: 81920 bytes
            20480 values
Number of Dimensions: 3
Dimensions and sizes: [time | 40] x [lev | 4] x [lat | 128]
Coordinates:
            time: [ 31..14266]
            lev: [200..1000]
            lat: [-88.92773535229591..88.92773535229591]
Number Of Attributes: 10
  lon : 2.8125
  time_rep : Estimated from monthly modern calendar data
  missing_value : 9.96921e+36
  cell_method : time: mean
  long_name : Zonal wind
  units : m/s
  _FillValue : 9.96921e+36
  lon_ori : 49.21875
  lat_ori : 48.32636101818818
  lev_ori : 1000

You can see there is a new attribute "lon" then, in addition to "lev_ori, lat_ori, lon_ori", which we renamed.

Hope this explains all.

Please let me know if you need any help.

Thanks,

Wei

----
ncdump -h test_uwind.nc 
netcdf test_uwind {
dimensions:
        time = UNLIMITED ; // (40 currently)
        lev = 4 ;
        lat = 128 ;
        lon = 256 ;
variables:
        float U(time, lev, lat, lon) ;
                U:time_rep = "Estimated from monthly modern calendar data" ;
                U:missing_value = 9.96921e+36f ;
                U:lon = 49.21875 ;
                U:lat = 48.3263610181882 ;
                U:lev = 1000.f ;
                U:cell_method = "time: mean" ;
                U:long_name = "Zonal wind" ;
                U:units = "m/s" ;
                U:_FillValue = 9.96921e+36f ;
        double lat(lat) ;
                lat:long_name = "latitude" ;
                lat:units = "degrees_north" ;
        float lev(lev) ;
                lev:positive = "down" ;
                lev:units = "hPa" ;
                lev:long_name = "pressure" ;
        double lon(lon) ;
                lon:long_name = "longitude" ;
                lon:units = "degrees_east" ;
On May 8, 2014, at 1:38 PM, Michael Notaro <mnotaro@wisc.edu> wrote:
> I looked at it with Guangshan and definitely something is wrong 
> in the newer versions of NCL.  I included the ncdump from the file.
> If you try to retrieve U(:,2,:,:) or U(:,:,2,:) or U(:,:,:,2), it will give an error,
> but U(2,:,:,:) works ok.  
> 
> 
> 
> 
> 
> 
> 
> 
> [yslogin2]409%: ncdump -h isotag_t85_115.0k.cam2.h0.cel.plev.delta.611-650-ANN.nc
> netcdf isotag_t85_115.0k.cam2.h0.cel.plev.delta.611-650-ANN {
> dimensions:
> 	time = UNLIMITED ; // (40 currently)
> 	lat = 128 ;
> 	lon = 256 ;
> 	lev = 4 ;
> variables:
> 	float CLDHGH(time, lat, lon) ;
> 		CLDHGH:time_rep = "Estimated from monthly modern calendar data" ;
> 		CLDHGH:lon = 358.59375 ;
> 		CLDHGH:lat = 88.9277353522959 ;
> 		CLDHGH:units = "fraction" ;
> 		CLDHGH:long_name = "Vertically-integrated high cloud" ;
> 		CLDHGH:cell_method = "time: mean" ;
> 		CLDHGH:_FillValue = 9.96921e+36f ;
> 	float U(time, lev, lat, lon) ;
> 		U:time_rep = "Estimated from monthly modern calendar data" ;
> 		U:missing_value = 9.96921e+36f ;
> 		U:lon = 49.21875 ;
> 		U:lat = 48.3263610181882 ;
> 		U:lev = 1000.f ;
> 		U:cell_method = "time: mean" ;
> 		U:long_name = "Zonal wind" ;
> 		U:units = "m/s" ;
> 		U:_FillValue = 9.96921e+36f ;
> 
> On May 8, 2014, at 1:57 PM, Guangshan Chen wrote:
> 
>> Dear NCL developers,
>> 
>> I just notice that there is an error message popped out when I read multi dimension data with one dimension fixed.
>> 
>> I could not remember it was shown in the old-version NCL.
>> 
>> Here is what I did:
>> 
>> Opening a file containing zonal wind and read zonal wind
>> uwind = file_in->U(:,2,:,:)
>> 
>> The following error will come out:
>>  Copyright (C) 1995-2014 - All Rights Reserved
>>  University Corporation for Atmospheric Research
>>  NCAR Command Language Version 6.2.0
>>  The use of this software is governed by a License Agreement.
>>  See http://www.ncl.ucar.edu/ for more details.
>> fatal:Subscript out of range, error in subscript #0
>> 
>> But if you read the wind as this: uwind = file_in->U(:,:,:,:), there will be no error message.
>> 
>> However, even with the error message, it seems I still can get the wind at the level I want.
>> 
>> 
>> Any idea why this happens?
>> 
>> Thanks.
>> 
>> - Guangshan
>> 
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> 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

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu May 8 17:58:04 2014

This archive was generated by hypermail 2.1.8 : Fri May 09 2014 - 15:23:17 MDT