[Thread Prev][Thread Next][Index]

Re: [ferret_users] Looping over multiple input files to plot file variables and save to png


Almost there. For your 2nd question, converting the output filename from .nc to .png, just use 'sed' with ferret's spawn command, as in the following loop (modified from my previous message):

! Loop over list of filenames and make plot (changing '.nc' to '.png')
  repeat/range=1:`numfiles`/name=in (let filename = filenames[i=`in`] ; \
        def sym filen basinmasks/`filename` ; \
	use ($filen)          ; \
        let filepng = {spawn:"echo ($filen) | sed s:.nc:.png:"} ; \
        def sym filep `filepng` ; \
	set win/new              ; \
	shade temp[k=1] )

! Then just use ($filep) in your shade command (or use `filepng` directly).

-- Jim

On Tue, 2 May 2017, Durack, Paul J. wrote:

Thanks Russ, so how do I then loop over the entries:


let filenames = SPAWN("/bin/ls -1 basinmask/*.nc")

! How do I loop over filenames?

!REPEAT/RANGE=1: ($filenames)


! Then plot

use ($filename)

set win 1

sha basinmask4

frame/file="($outpath)($filename).png" ! How to I replace *.nc in the filename with *.png?

cancel win 1






From: <owner-ferret_users@xxxxxxxx> on behalf of Russ Fiedler <russell.fiedler@xxxxxxxx>
Date: Monday, May 1, 2017 at 5:36 PM
To: "ferret_users@xxxxxxxx" <ferret_users@xxxxxxxx>
Subject: Re: [ferret_users] Looping over multiple input files to plot file variables and save to png


Hi Paul,

Rather than writing your filenames to a file you can create a variable using the SPAWN function directly.

let filenames = SPAWN("/bin/ls -1 basinmask/*.nc")

Another way would be to create the file as you are at the moment and read it in via a spawn and 'cat' command

let filenames = SPAWN("cat filenames.txt")

I'd prefer the first method.


On 02/05/17 08:20, Durack, Paul J. wrote:

      I have 51 netcdf files in a directory, and want to loop over each of these and for each plot the contents of a
      gridded variable and save this to a png file, using pyferret 7.1


      I’ve been struggling with syntax, and am getting “**TMAP ERR: non-existent or not on line  filenames.txt”, with the
      following partial code:


      spawn "ls basinmask/*.nc > filenames.txt" ! This is generating a file, but if I could create the filelist in memory
      this step could be removed

      FILE/FORMAT=DELIMITED/var="filenames" filenames.txt ! < This generates the error

      say "processing: ",($file) ! don’t get to here



      The plot and save command will be a simple:


      > sha basinmask4 ! Each file contains the same named variable

      > frame/file=”($mypath)($myfile).png”


      Can someone help me out to fill in the missing logic/syntax here?






LSCE/IPSL, Laboratoire des Sciences du Climat et de l'Environnement

LSCE/IPSL, CEA Saclay           http://www.ipsl.jussieu.fr/~jomce
Bat. 712 - Orme                 mailto:  James.Orr@xxxxxxxxxxxx
Point courrier 132
F-91191 Gif-sur-Yvette Cedex    Phone:   (33) (0)1 69 08 39 73
FRANCE                          Fax:     (33) (0)1 69 08 30 73

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

Privacy Policy | Disclaimer | Accessibility Statement