begin ;------- data dirasc = "./" filasc = systemfunc("cd "+dirasc+" ; ls teste.csv") pthasc = dirasc+filasc nrows = numAsciiRow( pthasc) print(nrows) print("----") ;------- Read a date per time do j = 1, nrows-1 ; start from 1 because the line 0 is header ;------ Create grid coordinates lonW = (/-80.00d/) lonE = (/-30.00d/) latS = (/-30.00d/) latN = (/ 10.00d/) dgrad = 0.01d ;----- Read the values in as 1D array of strings data := asciiread(pthasc,-1,"string") ;----- Open variables y := stringtodouble( str_get_field(data(j), 1, "-") ) m := stringtodouble( str_get_field(data(j), 2, "-") ) d := stringtodouble( str_get_field(data(j), 3, "-") ) if (y .eq. 2018 .and. m .eq. 12 .and. d .eq. 30) then lat := stringtodouble( str_get_field(data(j), 3, ";") ) ; não pode colocar loop lon := stringtodouble( str_get_field(data(j), 4, ";") ) ; 1: é para pegar todos print(lon) print(lat) ;----- ii := ind(lat.ge.latS .and. lat.le.latN .and. \ lon.ge.lonW .and. lon.le.lonE ) lat := lat(ii) lon := lon(ii) var := lat var = 1 N = dimsizes(var) nlat = toint(abs(latN-latS)/dgrad)+1 mlon = toint(abs(lonE-lonW)/dgrad)+1 lat2 = fspan(latS,latN,nlat) lon2 = fspan(lonW,lonE,mlon) lat2@long_name = "latitude" lat2@units = "degrees_north" lat2!0 = "lat2" lat2&lat2 = lat2 lon2@long_name = "longitude" lon2@units = "degrees_east" lon2!0 = "lon2" lon2&lon2 = lon2 ;----- Create a new var new_data = new((/nlat,mlon/),"double", 1d20) new_data = 0 ; start new_data!0 = "lat2" new_data!1 = "lon2" new_data&lat2 = lat2 new_data&lon2 = lon2 ;----- Sum at each latitude/longitude point. do i=0,N-1 new_data({lat(i)},{lon(i)}) = new_data({lat(i)},{lon(i)})+(/var(i)/) end do ;------ All points that do not have lightning will be filled with missing data: new_data = where(new_data.gt.0, new_data,new_data@_FillValue) ;----- Double to float ---> reduz tamanho var := dble2flt(new_data) ;----- Nom necessary, just information data1d := ndtooned(new_data ) ivalid := ind(.not.ismissing(data1d)) xvalid := data1d(ivalid) print("Total cells valid of lightning: " +dimsizes(xvalid) ) WRITE_NETCDF = True varnames = (/"counts"/) if(WRITE_NETCDF) then fout = "rc_2018_12_30.nc" system("rm -f " + fout) ncdf = addfile(fout, "c") ncdf->$varnames(0)$ = var print("") print("Number of lightning saved to " + fout) end if end do end if end