;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Adapted from example csv_1.mcl as a nice example of how to ascii/csv files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; csv_1.ncl ; ; Concepts illustrated: ; - Reading a CSV file using two different methods ; - Using asciiread to read an ASCII file with delimiters ; - Using str_split_csv to read an ASCII file with delimiters ; - Reshaping a one-dimensional array ;*********************************************************** begin filename = "ascii.txt" ;---------------------------------------------------------------------- ; This method uses "asciiread" to read the data ;---------------------------------------------------------------------- ;---Read the values in as 1D array of strings to get rows and columns. data = asciiread(filename,-1,"string") ncols = dimsizes(str_split(data(0),",")) nrows = dimsizes(data) print("This file has a header-line, with " + (nrows-1) + " rows and " + ncols + " columns.") lats = stringtodouble( str_get_field(data(1:), 8, ",") ) ; skip the header line lons = stringtodouble( str_get_field(data(1:), 9, ",") ) ; " " " " elevs = new((/dimsizes(lats)/), double) elevs = 0. print(lons + ", " + lats) srcProj = "+proj=lonlat" dstProj = "+proj=eqc" transform_coordinate(srcProj, dstProj, lons, lats, elevs) print(lons + ", " + lats) end