for loop in GrADS - loops

I am a starter of GrADS.
I would like to set loop to convert many .ctl files into netcdf.
First, I succeeded to convert one file to netcdf using below script.
open surf_HFB_2K_MI_m102_203009_rain_subset.ctl
define rain = rain
set sdfwrite surf_HFB_2K_MI_m102_203009_rain_subset.nc
sdfwrite rain
"
Then, I tried to set loops using for / while, but the error which says "unknown command for (while)".
the code I tried is like:
for ctlfile in $(ls *.ctl); do
open $ctlfile
define rain = rain
set sdfwrite ${ctlfile%.*}.nc
sdfwrite rain
done
All .ctl files in the same folder like "m101" where I set as a current directory.
How can I use loop in GrADS?

Related

Windows batch file timestamp to string

I am using the following simple line in my windows batch file to get the current time stamp to a String format so that I can use it later in the batch file to create a folder with same name.
set TIME_STAMP=%DATE:/=-%_%TIME::=-%
I observed that when the time is single digits, say 9:31 AM, I get the String like this:
08-10-2015_ 9.31.52.57
Notice the space between the characters _ and 9.
When the system time is say 10:31 AM, it all works fine, like
08-10-2015_10.31.52.57
Is there something I can do to make the time stamp as
08-10-2015_09.31.52.57
when I have hours in single digits?
just do this
set TIME_STAMP=%DATE:/=-%_%TIME::=-%
echo %TIME_STAMP: =0%
Probably the simpliest approach:
set "TIME_STAMP=%DATE:/=-%_%TIME::=-%"
set "TIME_STAMP=%TIME_STAMP: =0%"
Result:
==> echo "%TIME_STAMP%"
"08.10.2015_07-42-08,18"
==>

Can't pass file path to a Batch file

I'm new to programming so apologies in advance if this is really simple.
I'm using PA File Sight to monitor a folder for open files. When a file is opened it starts a program (batch file in this case) and passes the entire file path to the variable: $Item(1)$
The batch file looks like this at the moment:
set FILE_PATH="$Item(1)$"
echo.>%FILE_PATH%_IS_OPEN
I'm trying to get the batch file to create a new file with IS_OPEN on the end of it so that users know that a file "is open"
Running the batch file creates the following in it's folder:
$Item(1)$_IS_OPEN
So it's not storing the path for some reason.
I'd suggest you try
set FILE_PATH="%~1"
echo. "%FILE_PATH%_IS_OPEN"
echo.>"%FILE_PATH%_IS_OPEN"
PAUSE
This should set FILE_PATH to the first parameter that the batch file sees - the ~ removes any enclosing quotes
The next line echoes the result to the console and may be removed if the test proves successful.
The third line encloses the proposed filename in quotes to allow the use of spaces in the filename generated.
The PAUSE holds the CMD window open until you press ENTER to allow you to see the results. It too can be removed if your results are as expected.
modified to replace the first 2 characters of the NAME portion with "AA"
set FILE_PATH="%~1"
FOR /f "delims=" %%i IN ("%file_path%") DO (SET dpi=%%~dpi&SET ni=%%~ni&SET xi=%%~xi)
SET file_path=%dpi%AA%ni:~2%%xi%
echo. "%FILE_PATH%_IS_OPEN"
echo.>"%FILE_PATH%_IS_OPEN"
PAUSE
This assumes that it's the first 2 characters that need to be replaced. It works by assuming that the literal-string in the variable file_path is a filename whic, miracle of miracles, it is. dpi is then set to the drive and path, ni to the name and xi to the extension. then the full name is reconstructed, substituting AA for the first 2 characters of the name (dpi (the path) + AA + ni:2 (the name from the second character to the end) + xi (the extension))
$Item(1)$ seems like a constant string. If $Item(1)$ is the name of an actual environment variable, your first line should be
set FILE_PATH="%$Item(1)$%"
Although that seems quite an odd name for a variable.

List a directory folder to a variable

I felt it was better to ask this separately rather than expect an answer from my comment on my previous post.
I already have variables set for the directory number %jobn% which is unique is there a way I can search for the unknown element to add to another variable, I know via the command line I can run Dir D09854* and I will get a single report with the full name, can this be collected somehow and add to a named variable?
S:\SWDA\HBOS>dir d09854*
Volume in drive S is Images
Volume Serial Number is FE8F-38FE
Directory of S:\SWDA\HBOS
18/02/2013 10:29 <DIR> D09854_Parent Test
I want to add the elements after "_" to a variable %DirDesc% so I can create the full path by combining %jobn%%DirDesc% to get "D09854_Parent Test"
dir d09854* /b will recover the full folder name in one line, without the extra cruft, if that's any use? What are you writing this widget in?
Does it have to be Good Old Fashioned DOS, or can the newer Command extensions be used?
With limited old DOS, I can't think of a way to get that into a SET Variable without piping it to a temporary batch file, having first ECHO'd a set variable= into it, and using >> in the pipe to append to it... and then CALL the temporary batch file to execute the command!

Batch or VBS | How to check the bitrate of a music file?

I need to check the bitrate of a music file, I need to receive the number in digits like: 192000 (for 192 kbps), 320000 (for 32kbps) or (+)3000000 for wavs and uncompressed music. I mean I need exactly the number, If an MP3 is VBR and is compressed at 194 kbps, I need the 194000 number, not the current CBR 192000.
I was do this job with MEDIAINFO (x64) CLI Program, In Batch:
for /f "tokens=*" %%%% in ('mediainfo "%%a" "--Inform=General;%%BitRate/String%%"') do set "BitRate=%%~%%"
But I have 35.000+ files to check and then the comprobation of all files is more than 2 hours of time.
I need a simple code to check it, Not a program which need to execute it and to waste that lot of time...
Is very important that the code needs to recognize at least this filetypes (I mean the internal bitrate):
AIFF, FLAC, M4A, MP3, OGG, WAV, WMA.
And can't be a code for Ruby or Python, because I'll need to "compile" it and sure when is "compiled" waste a lot of time to check much files (Cause the uncompression of the .exe compiled).
More info: I thinked about store the results in a file and then do a comparision to chek only new added files, But I can't store the result to do a comparision at the next run cause sometimes I'll need to replace checked files (old files). By the way neither I can't handle this by file datestamps. Need to be one unique procediment to check ALL the files, Ever (Or this is what I think...).
I tried another method to check the bitrates, I'm really sure this is what I need but I can't get it run like I want...
This VBS uses the DBPowerAmp program API, And shows a window with info (included the bitrate), But with a window I can't do nothing... Maybe if I can redirect the windows info to a text file... And then set the variable "Bitrate" by reading the bitrate info in the text file... But I don't know how to do that:
' create shell object
Set WshShell = CreateObject("WScript.Shell")
' Create dMC Object
Set dMC = CreateObject("dMCScripting.Converter")
'Read audio properties of a file
Dim AudioProps
AudioProps = dMC.AudioProperties("C:\test.aac")
Call WshShell.Popup(AudioProps, , "Returned Audio Properties", 0)
I've tried to "convert" that code into Batch, like this, But don't run, I get nothing:
#echo off
rundll32.exe dMCScripting.Converter.AudioProperties("C:\Test.aac") > test.txt
exit
Oh and I've tried this too, but waste more time than mediainfo:
mplayer "test.aac" -frames 0 | findstr "kbit"
To give you an idea of what it is like in Ruby, audioinfo is just one of the many libraries doing such things.
require "audioinfo"
AudioInfo.open("R:/mp3/j/John Coltrane - I Think.mp3") do |info|
puts info.to_h
end
=>{"artist"=>"John Coltrane", "album"=>"John Coltrane", "title"=>"I Think", "tracknum"=>nil, "date"=>nil, "length"=>272, "bitrate"=>128}
Here a vbs script, works with mp3, the rest i didn't try
Set objPlayer = CreateObject("WMPlayer.OCX" )
Set colMediaCollection = objPlayer.mediaCollection
Set colMedia = colMediaCollection.getAll()
For i = 0 to colMedia.Count - 1
Set objItem = colMedia.Item(i)
Wscript.Echo objItem.Name & " : " & objItem.GetItemInfo("bitrate")
Next
See http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP+Get~Audio~File~Information.txt for a list of attributes you can use.

How to get a UNIVERSAL Windows batch file timestamp

I'm having trouble generating a timestamp in a Windows batch file, because I get diferent date formats on different Windows versions.
My machine:
>echo %date%
>Tue 11/17/2009
Friends machine:
>echo %date%
>11/17/2009
I guess there has to be some way of getting the date (11/17/2009) from both strings using for /f. I've been trying and googling and can't find the answer.
Is there another way to get a timestamp without using %date%?
Check out doff.exe. I use this a lot for getting timestamps for naming log files. From its web site:
DOFF prints a formatted date and time, with an optional date offset, (e.g -1 prints yesterday's date, +1 prints tomorrow's date). To view all the options available, execute "doff -h". I typically use this utility for renaming log files so that they include a timestamp, (see the third example below). This code should compile under Unix/Linux, as well as DOS.
Sample commands:
C:\>doff
19991108131135
With no parameters the output is the current date/time in the following format: yyyymmddhhmiss
C:\>doff mm/dd/yyyy
11/08/1999
In the above example a date format specification is given.
#echo off
for /f "tokens=1-3 delims=/ " %%a in ('doff mm/dd/yyyy -1') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)
rename httpd-access.log httpd-access-%yyyy%%mm%%dd%.log
The sample batch file above shows a neat way to rename a log file based on yesterday's date. The "for" command executes doff to print yesterday's date, (the "-1" parameter specifies yesterday), then extracts each component of the date into DOS batch file variables. The "rename" command renames "httpd-access.log" to "httpd-access-[yesterday's date].log"
Also check out Microsoft's now.exe, available in the Windows Server 2003 Resource Kit Tools. One bad thing I found out (the hard way) about it is it sets the ERRORLEVEL to the number of characters printed.
Looks like this:
c:\>now
Thu May 19 14:26:45 2011
Help:
NOW : Display Message with Current Date and Time
Usage : NOW [message to be printed with time-stamp]
NOW displays the current time, followed by its command-line arguments.
NOW is similar to the standard ECHO command, but with a time-stamp.
Use VBScript if you want to get independent date time settings:
thedate = Now
yr = Year(thedate)
mth = Month(thedate)
dy = Day(thedate)
hr = Hour(thedate)
min = Minute(thedate)
sec = Second(thedate)
WScript.Echo yr&mth&dy&hr&min&sec
Unfortunately, it can't be done directly, so you need to resort to hacks like GetDate.cmd.
There are lots of VBScript and small external commandline tools available too, which isn't something I'd take a dependency on unless you're already using something of that nature in your overall system.
Personally, I'd be trying to route around it by using PowerShell which neatly sidesteps the issue completely.
You don't need VBScript. You can do it with something like this:
echo %date:~-10,2%/%date:~-7,2%/%date:~-4,4%
Source
As I have posted in here:
Batch: Timestamp to UNIX Time
What about simple 1-line long C program returning UNIX timestamp? You can retrieve value from %errorlevel% in batch script.
#include <stdio.h>
#include <time.h>
int main(void)
{
return (int) time(NULL);
}
In my test in command prompt it worked:
C:\Users\dabaran\Desktop\cs50\src\C>.\time || echo %errorlevel% && set mytstamp=%errorlevel%
1419609373
C:\Users\dabaran\Desktop\cs50\src\C>echo %mytstamp%
1419609373

Resources