Gina,
I suggest beginning to use a Fortran lib from within NCL to read and write
ascii data. I am pasting some of the code I use to read ascii files. You can
integrate this with NCL using WRAPIT.
Within NCL, you can read your data as follows (not tested)
external FortRead "./ascii_read_helper.so"
funit=10
FortRead::open_file(funit,"ims2008349_24km.asc")
header=""
nhead=30
do i = 0, nhead-1
FortRead::read_string(funit,header)
end do
var = new ( (/nrows,ncols/), "string")
FortRead:read_array(funit,var,nrows,ncols)
FortRead::close_file(funit)
Best wishes,
saji
--
1. save the below in a file named ascii_read_helper.f90
subroutine open_file(funit,fname)
implicit none
character(len=*) :: fname
integer :: funit
open(funit,file=fname,status="unknown",form="formatted")
return
end
subroutine read_string(funit,line)
implicit none
integer funit
character(len=*) :: line
read(funit,*) line
return
end
subroutine read_array(funit,val,nrow,ncol)
implicit none
integer, intent(in)::funit,nrow,ncol
real, intent(out) ::val(ncol,nrow)
integer ::i,j
do j=1,nrow
read(funit,*)(val(i,j),i=1,ncol)
enddo
return
end
subroutine close_file(funit)
implicit none
integer funit
close(funit)
return
end
2. save below in a file named ascii_read_helper.stub
C NCLFORTSTART
subroutine open_file(funit,fname)
implicit none
character*(*) fname
integer funit
c NCLEND
C NCLFORTSTART
subroutine read_string(funit,line)
implicit none
integer funit
character*(*) line
c NCLEND
C NCLFORTSTART
subroutine read_array(funit,val,nrow,ncol)
implicit none
integer funit,nrow,ncol
dimension val(nrow,ncol)
c NCLEND
C NCLFORTSTART
subroutine close_file(funit)
implicit none
integer funit
c NCLEND
On Wed, Aug 25, 2010 at 4:25 AM, Gina Henderson <ginah@udel.edu> wrote:
> Hi there,
>
> I am reading in ascii data but want to skip some header information.
> Previously I used the following to read a file with no header information
> and had no spaces so had to do some reformatting to read in correctly:
>
> ; The ascii data had no spaces so had to do some reformatting to read them
> correctly
> zero_offset = charactertoshort(stringtocharacter("0"))
>
> data_character = asciiread("ims2008349_24km.asc" ,(/nrows,ncols+1/),
> "character")
> data_string = charactertoshort(data_character(:,:ncols-1)) -
> zero_offset(0)
> delete(data_string@_FillValue)
>
>
> I want to do the same thing to a file with 30 lines of header information
> using readAsciiTable, so tried the following but got the error
> "fatal:_NclBuildArray: each element of a literal array must have the same
> dimension sizes, at least one item doesn't
> fatal:Execute: Error occurred at or near line 8073 in file
> $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl". I think this has to
> do with the fact that I am reading the data in as type character, but don't
> know how to get around it while dealing with the no spaces issue?
>
> ; The ascii data had no spaces so had to do some reformatting to read them
> correctly
> zero_offset = charactertoshort(stringtocharacter("0"))
>
> nhead = 30 ; no. of header lines at the beginning of the file
> data_character = readAsciiTable("ims2008349_24km.asc" ,(/nrows,ncols+1/),
> "character", nhead)
> data_string = charactertoshort(data_character(:,:ncols-1)) -
> zero_offset(0)
> delete(data_string@_FillValue)
>
> Any suggestions would be greatly appreciated.
> Thanks, Gina.
>
> _______________________________________________
> 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 Tue Aug 24 19:25:54 2010
This archive was generated by hypermail 2.1.8 : Wed Aug 25 2010 - 11:50:26 MDT