[Thread Prev][Thread Next][Index]
Re: [ferret_users] Looping over multiple input files to plot file variables and save to png
Paul,
Below is a quick example of how to loop over your filenames.
let filenames = {spawn:"ls basinmasks"} !Vector of filenames
let numfiles = `filenames,return=iend` !Number of files
can win/all
! Loop over list of filenames and make plot
repeat/range=1:`numfiles`/name=in (let filename = filenames[i=`in`] ; \
def sym filen basinmasks/`filename` ; \
use ($filen) ; \
set win/new ; \
shade temp[k=1] )
! Note:
! To test this example, I made a subdirectory, did a cd to that, and then
! made symolic links of 2 files (fileA.nc, fileB.nc), both to
! the same "levitus_climatology.cdf" file in the ferret distribution.
-- 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
Cheers,
P
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.
Cheers,
Russ
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?
Thanks,
P
--
LSCE/IPSL, Laboratoire des Sciences du Climat et de l'Environnement
CEA-CNRS-UVSQ
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