Re: Error occured when creating new files

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 04 2013 - 12:34:51 MST

Yiqi,

Could you please modify and try the script below:

Wei

----
;setfileoption("nc", "usenewhlfs", True)
 setfileoption("nc", "Format",  "NetCDF4")
 system("/bin/rm -f " + Outfilename)
 ncdf = addfile( Outfilename, "c" )
;ncdf->newco2 = newco2
;===================================================================
; explicitly declare file definition mode. Improve efficiency.
;===================================================================
 setfileoption(fo,"DefineMode",True)
;Uncomment this line if you want compression
;setfileoption(ncdf,"CompressionLevel", 6)
; create global attributes of the file
;===================================================================
;fAtt               = True            ; assign file attributes
;fAtt@title         = "NCL generated netCDF file"
;fAtt@source_file   = fn
;fAtt@Conventions   = "None"
;fAtt@creation_date = systemfunc ("date")
;fileattdef(ncdf, fAtt)      ; copy file attributes
;===================================================================
; predefine the coordinate variables and their dimensionality
; Note: to get an UNLIMITED record dimension, we set the dimensionality
; to -1 (or the actual size) and set the dimension name to True.
;===================================================================
 newco2 = new( (/N_Months, 31, nlevel, nlat, nlon/), "float")
 newco2!0 = "month"
 newco2!1 = "day"
 newco2!2 = "lev"
 newco2!3 = "lat"
 newco2!4 = "lon"
 month = ispan(MonthBegin, MonthEnd, 1)
 day = ispan(1,31,1)
;Change lev, lat, and lon to its real value
 lev = ispan(1,31,1)      ;may be: lev = f->level
 lat = ispan(1,31,1)      ;may be: lat = f->lat
 lon = ispan(1,31,1)      ;may be: lon = f->lon
 dimNames = (/"month", "day", "lev", "lat", "lon"/)
 dimSizes = (/ MonthEnd - MonthBegin + 1,   31,  nlevel,  nlat,  nlon /)
 dimUnlim = (/ True , False, False, False, False/)
 filedimdef(ncdf, dimNames, dimSizes, dimUnlim)
;===================================================================
 filevardef(fo, "month", typeof(month), getvardims(month))
;filevarattdef(fo,"month", month)
 filevardef(fo, "day", typeof(day), getvardims(day))
;filevarattdef(fo,"day", day)
 filevardef(fo, "lev", typeof(lev), getvardims(lev) )
;filevarattdef(fo,"lev", lev)                     ; copy lev attributes
 filevardef(fo, "lat", typeof(lat), getvardims(lat))
;filevarattdef(fo,"lat", lat)                     ; copy lat attributes
 filevardef(fo, "lon", typeof(lon), getvardims(lon))
;filevarattdef(fo,"lon", lon)                     ; copy lon attributes
 filevardef(ncdf, "newco2", typeof(newco2), getvardims(newco2))
;filevarattdef(ncdf,"newco2", t)                         ; copy T attributes
;filevarchunkdef(ncdf, "newco2", chunkSizes)
;===================================================================
 setfileoption(ncdf,"DefineMode",False)
 ncdf->month  = (/month/)
 ncdf->day    = (/day/)
 ncdf->lev    = (/lev/)
 ncdf->lat    = (/lat/)
 ncdf->lon    = (/lon/)
 ncdf->newco2 = (/newco2/)
 printVarSummary(newco2)
huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924
On Jan 3, 2013, at 9:37 PM, Yiqi Zheng wrote:
> Hi all,
> 
> I encountered the following problem when trying to create new files:
> 
> 	file: NclNewFile.c, line: 6839
> 	Could not get varnode->name: <month>
> 	file: NclNewFile.c, line: 6839
> 	Could not get varnode->name: <day>
> 	file: NclNewFile.c, line: 6839
> 	Could not get varnode->name: <level>
> 	file: NclNewFile.c, line: 6839
> 	Could not get varnode->name: <lat>
> Segmentation fault
> 
> The new file I want to create contains only 1 data (newco2), which has 5 dimensions (month, day, level, lat, lon). 
> 
> Could you help me with this error? Many thanks!
> 
> Best regards,
> Yiqi
> 
> 
> The major part of my code is as follows:
> 
>     newco2 = new( (/N_Months, 31, nlevel, nlat, nlon/), "float")
>     newco2!0 = "month"
>     newco2&month = ispan(MonthBegin, MonthEnd, 1)
>     newco2!1 = "day"
>     newco2&day = ispan(1,31,1)
> 
>     do M=0, 11
>         do D=0, 30
>             Infilename = ****
>             f = addfile(Infilename, "r")
>             co2 = f->co2
>             newco2(M,D,:,:,:) = dim_avg_n_Wrap(co2, 0)
>         end do   
>     end do    
> 
>     system("/bin/rm -f " + Outfilename)
>     ncdf = addfile( Outfilename, "c" )
>     ncdf->newco2 = newco2
> 
> 
> 
> 
> 
> 
> _______________________________________________
> 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 Fri Jan 4 12:35:12 2013

This archive was generated by hypermail 2.1.8 : Fri Jan 04 2013 - 15:34:10 MST