[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading ascii file



Hi Patrick
G'day
You may also like to know about this package that can help to convert the various file formats to netcdf.

http://cms.ncas.ac.uk/documents/xconv/

Cheers, Saurabh

On Wed, Jan 20, 2021 at 3:05 AM Patrick Brockmann <patrick.brockmann@xxxxxxxxxxxx> wrote:
Re,

Replace
def axis/t/units=years tyears=v1[i=1]
by
def axis/t=01-JUL-`v1[i=1,l=1]`:01-JUL-`v1[i=1,l=($nblines)]`:1/units=years/cal=360_day tyears
for a correct time definition axis.

Patrick

--
Data Analytics and Visualization Engineer / Project Manager
LSCE/IPSL, CEA-CNRS-UVSQ laboratory
LSCE - Climate and Environment Sciences Laboratory
IPSL - Institut Pierre Simon Laplace
--


De: "Patrick Brockmann" <patrick.brockmann@xxxxxxxxxxxx>
À: "ferret users" <ferret_users@xxxxxxxx>
Cc: "Pierre Friedlingstein" <P.Friedlingstein@xxxxxxxxxxxx>
Envoyé: Mardi 19 Janvier 2021 16:53:19
Objet: Re: [ferret_users] Reading ascii file

Hi Pierre,

Here is a solution.
Haven't found simpler.

!####################################################################################################
def symb fileInput=($01%nbp.txt%)

def sym nblines=`{SPAWN:"cat ($fileInput) | wc -l"}`
def sym nbcolumns=`{SPAWN:"head -n 1 ($fileInput) | awk '{ print NF}'"}`

!====================================================
! Read file

def axis/x=1:($nbcolumns):1 xaxis
def axis/t=1:($nblines):1 taxis
def grid/x=xaxis/t=taxis mygrid
file/g=mygrid/column=($nbcolumns) "($fileInput)"

list v1

!====================================================
! First colum is a time axis

def axis/x=1:`($nbcolumns)-1`:1 regions
def axis/t/units=years tyears=v1[i=1]
def grid/t=tyears/x=regions myvargrid

let/title="nbp"/units="" nbp=reshape(v1[i=2:($nbcolumns)], x[g=myvargrid]*t[g=myvargrid])

list nbp
show grid nbp

shade/transpose nbp
!####################################################################################################


Regards
Patrick

--
Data Analytics and Visualization Engineer / Project Manager
LSCE/IPSL, CEA-CNRS-UVSQ laboratory
LSCE - Climate and Environment Sciences Laboratory
IPSL - Institut Pierre Simon Laplace
--


De: "Pierre Friedlingstein" <P.Friedlingstein@xxxxxxxxxxxx>
À: "ferret users" <ferret_users@xxxxxxxx>
Envoyé: Mardi 19 Janvier 2021 12:30:28
Objet: [ferret_users] Reading ascii file

Hi all
Simple question… 
I’m trying to read an ascii file  with 60 rows (each row is one year of data) and 19 columns : column 1 is year; columns 2 to 19 are the  same variable but different regions (18 regions).
I want to create one variable (nbp) with 18 levels, one per region.
Here is what I do, which doesn’t work :

define axis/T=1960:2019:1/units=year taxis
define axis/X=1:18:1 xaxis
define grid/T=taxis/X=xaxis mygrid

file/grid=mygrid/var= -,nbp "nbp.txt"


nbp.txt data set looks like:

1960 0.1057  0.1246  0.0017  0.0261  0.1735  0.0007  0.1255 -0.0361  0.1433  0.0259  0.2508  0.0715 -0.0019  0.0497  0.0097 -0.0506  0.0337  0.1155
1961 0.1384  0.0131  0.0600 -0.0145 -0.1744 -0.0061  0.0745  0.0995  0.0983  0.2071  0.1119 -0.0024 -0.0095  0.0683 -0.0033  0.1095  0.1027 -0.1360
1962 0.1392  0.1059 -0.0192  0.0475  0.1448 -0.1352  0.0794  0.0687  0.3754  0.0063  0.2532 -0.0055 -0.0132  0.1012  0.0167  0.0619  0.1222  0.0242
1963 0.0146  0.1110  0.0093  0.0423 -0.2498  0.0166  0.0950  0.1127  0.2832  0.1909  0.0421  0.0049  0.0688  0.0115  0.0124  0.0391 -0.0151  0.1944


When I do this I get the following, which is obviously not right.

yes? show data
     currently SET data sets:
    1> ./nbp.txt  (default)
 name     title                             I         J         K         L
 NBP      nbp                              1:18      ...       ...       1:60

 

yes? list nbp[i=1]
             VARIABLE : nbp
             FILENAME : nbp.txt
             SUBSET   : 3 points (T (YEAR))
             X        : 1
                1     
                 1
 1960   / 1:  0.1057
 1961   / 2:  0.1863
 1962   / 3:  0.2176

yes? list nbp[l=1]
             VARIABLE : nbp
             FILENAME : nbp.txt
             SUBSET   : 18 points (X)
             T (YEAR) : 1960
 1    /  1:  0.1057
 2    /  2:  0.1384
 3    /  3:  0.1392
 4    /  4:  0.0146
 5    /  5:  0.0676
 6    /  6:  0.2604
 7    /  7:  0.1093
 8    /  8:  0.1979
 9    /  9:  0.2648
 10   / 10:  0.1933
 11   / 11:  0.0309
 12   / 12:  0.0861
 13   / 13:  0.2020
 14   / 14:  0.2359
 15   / 15:  0.1868
 16   / 16:  0.2416
 17   / 17:  0.2037
 18   / 18: -0.0313



Thanks for you help.
Pierre






--


REGARDS

Saurabh Rathore
Research Scholar (PhD.)
Centre For Oceans, Rivers, Atmosphere & Land Science Technology
Indian Institute Of Technology, Kharagpur
contact :- 91- 8345984434

Attachment: xconv1.94_linux_x86_64.tar.gz
Description: application/gzip


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement