comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to use SPAWN for creating multiple output files?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to use SPAWN for creating multiple output files? [message #88735] Wed, 11 June 2014 03:00 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have multiple *.nc files. I want to create SHA 256 checksum file for each of the datafile.

In linux shell, I get the checksum info as:
$ sha256sum XYZ_1000.nc'
89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa XYZ_1000.nc

So, I tried to use the same in IDL as below:

IDL> spawn, 'sha256sum XYZ_201304000.nc'
89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa XYZ_1000.nc

As I have created all the *.nc data files in IDL program, I would like to add few lines below to create respective checksum file (e.g., <myfile>.sha256 ).

I have my datafiles as - XYZ_1000.nc, XYZ_1001.nc, XYZ_1002.nc, ....
I would like to copy the checksum output

89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa

to the new file - XYZ_1000.sha256

I know it can be done directly on linux terminal but I want to create simultaneously in the IDL code.

Can anyone help me how I can do this in IDL using SPAWN command?

Thanks in advance,
Madhavan
Re: How to use SPAWN for creating multiple output files? [message #88736 is a reply to message #88735] Wed, 11 June 2014 05:40 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den onsdagen den 11:e juni 2014 kl. 12:00:57 UTC+2 skrev Madhavan Bomidi:
> Hello,
>
> I have multiple *.nc files. I want to create SHA 256 checksum file for each of the datafile.
>
> In linux shell, I get the checksum info as:
>
> $ sha256sum XYZ_1000.nc'
>
> 89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa XYZ_1000.nc
>
> So, I tried to use the same in IDL as below:
>
> IDL> spawn, 'sha256sum XYZ_201304000.nc'
>
> 89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa XYZ_1000.nc
>
> As I have created all the *.nc data files in IDL program, I would like to add few lines below to create respective checksum file (e.g., <myfile>.sha256 ).
>
> I have my datafiles as - XYZ_1000.nc, XYZ_1001.nc, XYZ_1002.nc, ....
>
> I would like to copy the checksum output
>
> 89654655f1a75fc398fb86c9f56c255bb991768eb223a6defa1f1d5d0ede f6aa
>
> to the new file - XYZ_1000.sha256
>
> I know it can be done directly on linux terminal but I want to create simultaneously in the IDL code.
>
> Can anyone help me how I can do this in IDL using SPAWN command?
>
> Thanks in advance,
>
> Madhavan

Something like this should work (untested):

IDL> myfile='XYZ_1000'
IDL> spawn, 'sha256sum '+myfile+'.nc > '+myfile+'.sha256'
Re: How to use SPAWN for creating multiple output files? [message #88738 is a reply to message #88735] Wed, 11 June 2014 06:02 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Here is a longer solution. Creating the file with ">" as Mats suggested is probably faster, but in this manner you can store the checksum into a variable in case you want to do something with it.

theFiles = file_search('XYZ_*.nc')
basename = file_basename(theFiles, '.nc')
dirname = file_dirname(theFiles)
output_filenames = filepath(basename + '.sha256', ROOT_DIR=dirname)

for i = 0, nFiles - 1 do begin
spawn, 'sha256sum ' + theFiles[i], checksum

openw, lun, output_filenames[i], /GET_LUN
printf, lun, checksum
free_lun, lun
endfor
Re: How to use SPAWN for creating multiple output files? [message #88739 is a reply to message #88738] Wed, 11 June 2014 07:24 Go to previous message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thank you both...

On Wednesday, June 11, 2014 3:02:06 PM UTC+2, Matthew Argall wrote:
> Here is a longer solution. Creating the file with ">" as Mats suggested is probably faster, but in this manner you can store the checksum into a variable in case you want to do something with it.
>
>
>
> theFiles = file_search('XYZ_*.nc')
>
> basename = file_basename(theFiles, '.nc')
>
> dirname = file_dirname(theFiles)
>
> output_filenames = filepath(basename + '.sha256', ROOT_DIR=dirname)
>
>
>
> for i = 0, nFiles - 1 do begin
>
> spawn, 'sha256sum ' + theFiles[i], checksum
>
>
>
> openw, lun, output_filenames[i], /GET_LUN
>
> printf, lun, checksum
>
> free_lun, lun
>
> endfor
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Avoiding redefinition of variable within loop.
Next Topic: Calculate median of stacks of images using IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:08:13 PDT 2025

Total time taken to generate the page: 0.00578 seconds