undef ("readpsdts") function readpsdts (filename[1]:string,myear:integer) begin years = asciiread(filename,(/1,2/),"integer") kystart=years(0,0) if(myear.gt.kystart)then kystart=myear end if nyears= (years(0,1)-years(0,0))+1 knyears=(years(0,1)-kystart)+1 if((years(0,1).lt.0).or.(years(0,1).gt.2050))then print("Your last year is not valid: you have "+years(0,1)) end if if((years(0,0).lt.0).or.(years(0,0).gt.2050))then print("Your first year is not valid: you have "+years(0,0)) end if if(years(0,0).gt.years(0,1))then print("Your first year is greater than your second") end if ; READ IN ARRAY. Actaul values astart at 3rd spot (index 2) ; READ PAST END tsoutin = asciiread(filename,-1,"float") command1 = "wc -l "+filename nrow = toint(systemfunc(command1)) ; "wc -l" returns the # nextra = nrow-nyears head = readAsciiHead(filename, nrow) nvalues = (nyears*12) nvaluesin = (nyears*13) knvalues = (knyears*12) tsout = tsoutin(3:knvalues+2) xmiss = tsoutin(nvaluesin+2) yy = new((/nvalues/),integer) mm = new((/nvalues/),integer) dd = new((/nvalues/),integer) hh = new((/nvalues/),integer) nn = new((/nvalues/),integer) ss = new((/nvalues/),integer) time = new ( (/nvalues /), double) timesh = new ( (/knvalues /), double) unitstr = "days since "+ sprinti("%0.4i", years(0,0)) +"-1-1 00:00:0.0" ; time@units = unitstr time_units_out = unitstr opt = 0 k = 0 do iy = kystart,years(0,1) yy(k:k+11) = iy mm(k:k+11) = (/1,2,3,4,5,6,7,8,9,10,11,12/) dd(k:k+11) = 1 hh(k:k+11) = 0 ss(k:k+11) = 0 nn(k:k+11) = 0 k=k+12 end do time = ut_inv_calendar (yy, mm,dd,hh,nn,ss, time_units_out, opt) it = 0 do iy = kystart,years(0,1) do im = 1 , 12 k = 2+(iy-years(0,0))*13+im kk = -1+(iy-years(0,0))*12+im tsout(it) = tsoutin(k) timesh(it) = time(kk) it = it+1 end do end do command="/usr/bin/perl -wln -e 'print if /units/' "+filename unitstr=systemfunc(command) if(.not.ismissing(unitstr))then strs = str_split(unitstr, "units=") unitstr1 = strs(0) tsout@units = unitstr1 else tsout@units = " " end if tsout!0 = "time" tsout@_FillValue = xmiss tsout@missing_value = xmiss tsout@First_year = kystart tsout@Last_year = years(0,1) tsout&time = timesh tsout@nextra=nextra-1 nextra=nextra-1 if(nextra.gt.2)then tsout@title = head(nyears+2) tsout@long_name = head(nyears+2) if(nextra.gt.3)then tsout@description1=head(nyears+3) end if if(nextra.gt.3)then tsout@description2=head(nyears+4) end if if(nextra.gt.4)then tsout@description3=head(nyears+5) end if if(nextra.gt.5)then tsout@description4=head(nyears+6) end if if(nextra.gt.6)then tsout@description5=head(nyears+7) end if else tsout@title = "not available" tsout@long_name = "not available" end if return(tsout) end