To be more specific, I do not have ncrcat on my system so I have to use the
second option, that of writing to one file. Everything works when I read in
only one file (8 timesteps), yet when I try to read in multiple files
I cannot loop through the time.
How can I get around this error called
fatal:Mul: operation not supported on type (string) ?
Sincerely,
Erik
(code and screen read out below)
ENOBLE_at_ATHENA: /usr/people/enoble/DATA/CMORPH> ncl
../../CMORPH_Read_Write_Mult2one.ncl
Copyright (C) 1995-2007 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 4.3.1
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
No match
Variable: day
Type: string
Total Size: 8 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
(0) 01
fatal:Mul: operation not supported on type (string)
fatal:Execute: Error occurred at or near line 52 in file
../../CMORPH_Read_Write_Mult2one.ncl
; NCL script that reads in ONE NOAA CMORH precipitation binary file
; 16 direct access binary ("big_endian") records, which are 2 variables at
3-hourly
; intervals for 1 day
;************************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
;************************************************
begin
DATADir = "/usr/people/enoble/DATA/CMORPH/"
; path to your data - must have trailing "/"
;=============================
; create lat and long coordinate variables
;============================
nlat = 480
mlon = 1440
lat = 59.875 - ispan(0,nlat-1,1)*0.25
lon = 0.125 + ispan(0,mlon-1,1)*0.25
lat!0 = "lat"
lat&lat = lat
lat_at_units = "degrees_north"
lon!0 = "lon"
lon&lon = lon
lon_at_units = "degrees_east"
;===============================
;Input data files
;===============================
; Also, using a do 'while (scalar_logical_expression)' loop (or several)
; can allow you to process multiple months or years
FILES = systemfunc("csh -c ' ls " + DATADir + "*_3hr-025deg_cpc+comb '")
; root of data file
numFILES = dimsizes(FILES)
finarr = new((/numFILES,nlat,mlon/),"float") ; predefine array for
month
do ifil = 0, numFILES-1 ; BIG FILES LOOP ; NEW file loop
;===================
; create time variable
;===================
year = 2006
month = 09
if((ifil .lt. 10)) then
day = "0"+(ifil+1)
else
day = (ifil+1)
end if
print(day)
yyyymmdd = year*10000 + month*100 + day
ntime = 8
time = yyyymmdd*100 + ispan(0,21,3)
time!0 = "time"
time_at_units = "yyyymmddhh"
time&time = time
print(time)
;=======================================
;Create Array of Variables in binary data
;=======================================
CMORPH = new ( (/ntime,nlat,mlon/), "float")
cpc_combined_MW = CMORPH
;========================================
;Read in Binary
;========================================
fName = FILES(ifil)
setfileoption ("bin", "ReadByteOrder", "BigEndian")
ntim = 1
do i = 0, 14,2 ; CMORPH binary file contains 16 records.
NCL starts at counting at 0
print ("====== Binary Record= "+(i+1) +"/ NCL Record Counter "+(i)+"
======")
cpc_combined_MW(i/2,:,:) =
fbindirread(fName,i,(/ntim,nlat,mlon/),"float")
print ("====== Binary Record= "+(i+2) +"/ NCL Record Counter "+(i+1)+"
======")
CMORPH(i/2,:,:) = fbindirread(fName, i+1,(/ntim,nlat,mlon/),"float")
end do
;=============================
; name dimensions of variables
;============================
cpc_combined_MW!0 = "time"
cpc_combined_MW!1 = "lat"
cpc_combined_MW!2 = "lon"
cpc_combined_MW&time = time
cpc_combined_MW&lat = lat
cpc_combined_MW&lon = lon
cpc_combined_MW_at_long_name = "merged microwave precipitation"
cpc_combined_MW_at_units = "mm/hr"
printVarSummary(cpc_combined_MW)
CMORPH!0 = "time"
CMORPH!1 = "lat"
CMORPH!2 = "lon"
CMORPH&time = time
CMORPH&lat = lat
CMORPH&lon = lon
CMORPH_at_long_name = "CMORPH"
CMORPH_at_units = "mm/hr"
printVarSummary(CMORPH)
;================================================
;Create Domain of interest from data (WEST AFRICA)
;This is not necessary if looking at Global Scale
;================================================
; the West African Domain is at Prime Meridian so need lonFlip
CMORPH = lonFlip(CMORPH)
cpc_combined_MW = lonFlip(cpc_combined_MW)
printVarSummary(CMORPH)
COMB_MW_WestAfrica = cpc_combined_MW(:,{-20:36},{-36:36})
CMORPH_WestAfrica = CMORPH(:,{-20:36},{-36:36})
printVarSummary(CMORPH_WestAfrica)
delete(CMORPH) ; delet global array
delete(cpc_combined_MW)
CMORPH=CMORPH_WestAfricaa
COMB_MW=COMB_MW_WestAfrica
;======================
; Create NetCDF Ouput File of day
;======================
;ncout = time+"_CMORPH_3hr-025deg.nc"
; system("/bin/rm -f "+ncout)
; a = addfile(ncout,"c") ; write netCDF file
; a_at_title = " CMORPH and Combined MW Precipitation 3-hourly data"
; a_at_source =
"ftp://ftp.cpc.ncep.noaa.gov/precip/global_CMORPH/3-hourly_025deg"
; filedimdef(a,"time",-1,True) ; make time an UNLIMITED dimension,
always recommended
;=============================
;Place Contents into NetCDF file
;=============================
;a->COMB_MW = COMB_MW
;a->CMORPH = CMORPH
;delete(ncout)
end do
; =========================
; Create Large Array for Month / year/ whatever
; =========================
LargeARR= new((/numFILES*ntime,nlat,nlon/),"float") ; predefine array
for large netcdf file
;======================
; Create NetCDF Ouput File of entire month
;======================
ncout = year+month+"_CMORPH_3hr-025deg"
system("/bin/rm -f "+ncout)
b = addfile(ncout,"c") ; write netCDF file
b_at_title = "CMORPH and Combined MW Precipitation 3-hourly data"
b_at_source =
"ftp://ftp.cpc.ncep.noaa.gov/precip/global_CMORPH/3-hourly_025deg"
filedimdef(b,"time",-1,True) ; make time an UNLIMITED dimension,
always recommended
;=============================
;Place Contents into NetCDF file
;=============================
b->COMB_MW = COMB_MW
b->CMORPH = CMORPH
delete(ncout)
end
On 7/16/08 11:21 PM, "Erik Noble" <enoble_at_giss.nasa.gov> wrote:
> Dear Dennis,
> This worked. Thank you. Now I am trying this with multiple files
> I'm having trouble.
>
> How is NCL to 'know' that you want a multiple binary files with 8 time steps
> in each file, say 30 days of September (at least where the first 9 days are
> double digit? 01,02,03,04,...09
> 200609##hh
> -Erik
>
> On 7/16/08 2:21 PM, "Dennis Shea" <shea_at_ucar.edu> wrote:
>
>> As Jamie has stated and the output print statements show,
>> you are overwriting the information each loop iteration.
>>
>> How is NCL to 'know' that you want a file with 8 time steps on it?
>>
>> [a]
>> You could create a single netCDF file for each time and use (say) ncrcat
>> to concatenate the files.
>>
>> [b]
>> You can preallocate arrays and then after the loop write to the file once.
>> Something like:
>>
>> ntim = 8
>> nlat = 480
>> mlon = 1440
>>
>> yyyymmdd = year*10000 + month*100 + day
>> time = yyyymmdd*100 + ispan(0,21,3)
>> time!0 = "time"
>> time_at_units = "yyyymmddhh"
>> time&time = time
>> print(time)
>>
>> CMORPH = new ( (/ntim,nlat,mlon/), "float")
>> pc_combined_MW = CMORPH
>>
>> fName = "./20060901_3hr-025deg_cpc+comb"
>>
>> do i = 0, 14,2
>> pc_combined_MW(i/2,:,:) =
>> fbindirread(fName,i,(/ntim,nlat,mlon/),"float")
>> CMORPH(i/2,:,:) = fbindirread(fName, i+1,(/ntim,nlat,mlon/),"float")
>> end do
>>
>> CMORPH!0 = "time"
>> CMORPH!1 = "lat"
>> CMORPH!2 = "lon"
>> CMORPH&time = time
>> CMORPH&lat = lat
>> CMORPH&lon = lon
>> CMORPH_at_long_name = "CMORPH"
>> CMORPH_at_units = "mm/hr"
>>
>> ; same for pc_combined_MW
>>
>>
>>
>> a = addfile("sample.nc","c") ; write netCDF file
>> a_at_title = "1 day of daily CMORPH precipitation data"
>> a_at_source =
>> "ftp://ftp.cpc.ncep.noaa.gov/precip/global_CMORPH/3-hourly_025deg"
>> filedimdef(a,"time",-1,True) ; make time an UNLIMITED
>>
>> a->CMORPH = CMORPH
>> a->COMB_MW = pc_combined_MW
>> end
>>
>>
>>
>>
>>
>>
>>
>>
>> Erik Noble wrote:
>>> Hi.
>>> You suggest eliminating the do loop, correct?
>>> -Erik
>>>
>>> On Wed, Jul 16, 2008 at 12:20 PM, Jamie Scott <James.D.Scott_at_noaa.gov>
>>> wrote:
>>>
>>>> Eric,
>>>> I think the problem is that the 2 variables you are writing to the netcdf
>>>> file
>>>> only contain one time step. Even though you are looping through time
>>>> and writing 8 times, I think you are just overwriting the 1st time step in
>>>> the
>>>> netcdf file each time.
>>>> Try making the variables you write (cpc_combined_mw, cmorph and time)
>>>> such that they contain all 8 time steps and write them only once.
>>>>
>>>> Jamie Scott
>>>>
>>>> NOAA/ESRL/PSD
>>>>
>>>> james.d.scott_at_noaa.gov
>>>>
>>>> On Jul 16, 2008, at 9:58 AM, ncl-talk-request_at_ucar.edu wrote:
>>>>
>>>> May I have some help? This is an update my earlier request for help
>>>> with getting time displayed in my netcdf file. I updated my code fromearlie
>>>> till getting incorrect time. When I do
>>>> "ncdump -h" on the my output netcdf file, I don't get the proper time
>>>> that should reflect 3-hourly intervals for 1 day.
>>>> (It says time = UNLIMITED ; // (1 currently). it should be time =
>>>> UNLIMITED ; // (8 currently)).
>>>> I'm reading in a binary file that I'm told is composed of 16 direct
>>>> access binary ("big_endian") records, which are 2 variables at
>>>> 3-hourly ntervals for 1 day, basically 8 pairs.
>>>>
>>>> I searched throughout previous posts about time coordinates before
>>>> posting this question ncl-talk. Its not clear whether i need to resort
>>>> to making up this variable (i.e. specifically make a variable time =
>>>> year*10000 + month*100 + day...etc) or if Its something even more
>>>> simple that I am overlooking.
>>>>
>>>> Could I have please have some advice on how to fix this? I have my
>>>> screen readouts and ncl code below.
>>>> -Erik
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk_at_ucar.edu
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk_at_ucar.edu
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jul 16 2008 - 23:29:09 MDT
This archive was generated by hypermail 2.2.0 : Fri Jul 18 2008 - 08:51:52 MDT