Re: having trouble writing 2D var to new nc file

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 04 2011 - 07:56:37 MDT

Donna,

The problem may simply be with ncl_filedump, and not how you've written the file. The error message is co

Can you provide us with the file?

--Mary

On Mar 31, 2011, at 5:16 PM, donna Cote wrote:

> Howdy experts (y'all), I wonder if I have approached this correctly. I'm
> trying to take a string of 6 characters, use them to populate a 2D array
> of the 6 characters (per record in the file), and then write the 2D
> variable to a new netCDF file. In particular, I'm not sure my approach
> (where I have "questioning this portion") is a working one. Something
> isn't working because after the ncl script successfully runs, the new
> netCDF file gives me an error when I do:
> ncl_filedump -v stationidstr adcp-testcase.nc
>
> Thanks in advance, Donna
>
> READFN="testcase-adcp.txt"
> data = asciiread("/tmp/"+READFN,-1,"string")
> ndata = dimsizes(data)
> <snip>
> ST_ID_Str = new(ndata,"string","")
> <snip>
> ; arranged column numbers for column-formatted pre-processed file -dlc
> ST_ID_Str = str_get_cols(data,0,5)
> <snip>
> ST_ID_StrLen=max(strlen(ST_ID_Str)) + 1
> ; add 1 to account for the terminator character
> <snip>
>
> ;;;;;; questioning this portion
> nullChar = inttochar(0)
> ; could use nullChar to test a single char to see if it's null
> StationIDstr = new((/ndata,ST_ID_StrLen/),"character",nullChar)
> do ircd=0,ndata-1
> StationIDstr(ircd,:)=stringtochar(ST_ID_Str(ircd))
> end do
> ;;;;;;
>
> <snip, see "snippet A" below>
> <snip>
> filevardef(fout,"stationidstr","character",
> (/"recordcount","ST_ID_StrLen"/))
> fout->stationidstr@_FillValue = nullChar
> <snip>
> fout->stationidstr= (/StationIDstr/)
>
>
> After the nc file is created, integer and float variables look great.
> But not this string changed to characters 2D variable.
>
> I get the message:
> fatal:Argument type mismatch on argument (0) of (make_var2d) can not coerce
> fatal:Execute: Error occurred at or near line 135 in file
> /var/folders/g9/g9wihWJCFayhpNTWt06Ksk+++TU/-Tmp-/tmp1005.ncl
>
> P.S.
> Running with NCAR Command Language Version 5.2.1
>
> sample input file (where first six characters is the station ID) is:
> 423616 2010-06-01T00:06:00 27.55 -92.49 51.0 249 15.5 1 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 67.0 270 10.0 2 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 83.0 204 4.9 3 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 99.0 261 9.6 4 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 115.0 213 8.3 5 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 131.0 249 9.7 6 3 333393330
> 423616 2010-06-01T00:06:00 27.55 -92.49 147.0 279 10.1 7 3 333393330
> 423616 2010-06-27T18:16:00 27.55 -92.49 771.0 300 4.0 46 3 333393333
> 423616 2010-06-27T18:16:00 27.55 -92.49 787.0 333 1.1 47 3 333393333
> 423616 2010-06-27T18:16:00 27.55 -92.49 803.0 45 2.1 48 3 333393333
>
> < snippet A>
> WRITEFN = "adcp-testcase.nc" ; netCDF file to write.
> if(isfilepresent(diro+WRITEFN))
> system("/bin/rm -f " + diro + WRITEFN) ; remove any pre-existing file
> fout = addfile(diro+WRITEFN,"c")
> setfileoption(fout,"DefineMode",True) ; Enter predefine phase.
>
> ndims = 3
> string_FillValue = "-99999"
> integer_FillValue = -99999
> logical_FillValue = 0
>
> dimNames = new(ndims,"string",string_FillValue)
> dimSizes = new(ndims,"integer",integer_FillValue)
>
> dimNames(0) = "recordcount"
> dimNames(1) = "ST_TIME_StrLen"
> dimNames(2) = "ST_ID_StrLen"
>
> dimSizes(0) = ndata
> dimSizes(1) = ST_TIME_StrLen ; added 1 to account for the
> terminator character
> dimSizes(2) = ST_ID_StrLen ; added 1 to account for the
> terminator character
>
> filedimdef(fout,dimNames,dimSizes,(/False,False,False/))
>
> _______________________________________________
> 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 Mon Apr 4 07:56:43 2011

This archive was generated by hypermail 2.1.8 : Tue Apr 05 2011 - 09:01:21 MDT