copy text in square brackets in filemaker pro - filemaker

I am trying to do script in Filemaker Pro to copy any text in square brackets in a field.
The text will vary in length and position, can't seem to get anything to work.
Any ideas?
Thanks

You can extract the text inside the first pair of square brackets by using the following calculation =
Let ( [
start = Position ( YourField ; "[" ; 1 ; 1 ) + 1 ;
end = Position ( YourField ; "]" ; 1 ; 1 )
] ;
Middle ( YourField ; start ; end - start )
)
Note that this assumes your field contains at least one pair of square brackets.

Related

Matlab: Select a variable name and find the corresponding value

Can somebody explain me how i get some specific values after the = sign? The input File is a .subvar file format.
I dont know how to jump in the right row and column to get the value. Do you have a matlab tutorial link for such a problem.
I need for example two specific values (after the = sign):
The value of $_Wk1_lr_m and $_Wk1_voll_m
!file.version=1.543!
! Testautomatisch
subvargroup.begin ($G_Wk1)
subvar( $_Wk1_lr_C_x, str = ' 0.019 ' )
subvar( $_Wk1_lr_m, str = ' 15601 ' ) ! [kg] lr
subvar( $_Wk1_lr_C_y, str = '-0.007 ' )
subvar( $_Wk1_lr_C_z, str = ' 1.644 ' )
subvar( $_Wk1_voll_m, str = ' 33690 ' ) ! [kg] voll
subvargroup.end ($G_Wk1)
What are the first steps to get the right row and the right column? Thank you and stay at home :)
read the file line by line, match the line format and extract the values using regular expression regexp
fid=fopen('mydata.subvars','rt');
res=struct;
while(~feof(fid))
line=fgetl(fid);
if(regexp(line,'^\s*subvar\(','once'))
val=regexp(line,'\$_(\w+),\s*str\s*=\s*''\s*([0-9.-]+)\s*','tokens');
if(length([val{:}])==2)
res.(val{1}{1})=str2num(val{1}{2});
end
end
end
fclose(fid);
here is the result
>> res
res =
Wk1_lr_C_x: 0.0190
Wk1_lr_m: 15601
Wk1_lr_C_y: -0.0070
Wk1_lr_C_z: 1.6440
Wk1_voll_m: 33690

How can I modify a variable and it's corresponding dimension in a netcdf

I am running an idealized experiment with a atmospheric model with output in the format of netcdf. But the netcdf file header does not describe the variable and and dimension clearly. for example :
netcdf qc3d {
dimensions:
Time = UNLIMITED ; // (1453 currently)
bottom_top = 45 ;
south_north = 32 ;
west_east = 12288 ;
variables:
float Time(Time) ;
Time:axis = "Time" ;
Time:long_name = "Time" ;
Time:standard_name = "Time" ;
Time:units = "minutes since 1900-01-01 " ;
double zc(bottom_top) ;
zc:axis = "Z" ;
zc:long_name = "vertical height of model layers, MSL" ;
zc:standard_name = "altitude" ;
zc:units = "m" ;
zc:positive = "up" ;
double yc(south_north) ;
yc:axis = "Y" ;
yc:long_name = "y-coordinate of grid cell centers in Cartesian system" ;
yc:units = "m" ;
double xc(west_east) ;
xc:axis = "X" ;
xc:long_name = "x-coordinate of grid cell centers in Cartesian system" ;
xc:units = "m" ;
float qc(Time, bottom_top, south_north, west_east) ;
qc:long_name = "cloud water mixing ratio" ;
qc:standard_name = "cloud_water_mixing" ;
qc:units = "kg kg-1" ;
qc:_FillValue = 9.96921e+36f ;
qc:missing_value = 9.96921e+36f ;
// global attributes:
:model_tag = "CSU VVM" ;
:references = "http://kiwi.atmos.colostate.edu/pubs/joon-hee-tech_report.pdf" ;
:contact = "jung#atmos.colostate.edu" ;
:institution = "Colorado State University" ;
:VVM_casename = "GATE_PHASE_III " ;
}
there are 4 dimensions, Time(Time), zc(bottom_top), yc(south_north), xc(west_east) and 5 variable in which first 4 variables should be the dimension of the fifth variable, so called qc. But it seems not. The dimension is just a series number index from 1 to 45, 32 ...whatever else.
I would like to calculate some variable which is the function of pressure. in the CDO the script is like this
cdo expr,"pottemp=temp*((100000/clev(temp))^0.287);" ifile pottemp.nc
(this code is from here)
but I just obtain a series of index like 1 ,2 ,3 ... not the real pressure level when I use this function, clev(qv).
So how can I rewrite the variable dimension like qc from
qc(Time, bottom_top, south_north, west_east) ;
to
qc(Time, zc, yc, xc) ;
I think it's possible for me to finish this in matlab, but I just don't want to open this dataset because it's size is too large... so I am trying to find some tools like ncks or cdo, but still failed to do this.
thanks a lot.
With NCO try
ncap2 -s 'pottemp=temp*((100000/zc)^0.287)' in.nc out.nc
ncap2 documentation
extending answer to cover additional question below:
first use ncap2 to explicitly set zc to the values in the ascii file:
ncap2 -s 'zc[$zc]={1.5,900,2500,3500}' in.nc out.nc
(assuming zc is size 4 dimension). then define pottemp based on that zc.

How to Remove special characters from name-value pairs in the Webspeed URL?

I need to remove carriage return and linefeed characters that are present in Webspeed URL containing name-value pairs..How can that be done? any ideas please!
To replace characters you can use the REPLACE function
REPLACE function
Returns a string with specified substring replacements.
Syntax
REPLACE ( source-string , from-string , to-string )
Example:
DEFINE VARIABLE cTxt AS CHARACTER NO-UNDO FORMAT "x(20)".
DEFINE VARIABLE cNewTxt AS CHARACTER NO-UNDO FORMAT "x(20)".
cTxt = "abc123abc123abc123".
cNewTxt = REPLACE(cTxt, "a", "-").
DISPLAY cNewTxt .
You could target new lines using the control code ~n
REPLACE(cString, "~n", "replacing character").
Or target the individual %0d (decimal ascii code 13) and %0a's (decimal ascii code 10).
REPLACE(cString, CHR(13), "replacing character").
REPLACE(cString, CHR(10), "replacing character").
I have recently had a need to do something like this and found the following to be quite handy. This might be a bit drastic -- it removes all control codes and anything higher than ascii 126. But you can adjust those limits easily enough. (My usage is to populate text fields -- so all of that stuff is illegal input for me.)
define variable hd as character no-undo initial "0123456789ABCDEF".
function hex2char returns character ( h as character ):
define variable i as integer no-undo.
if length( h ) <> 2 or index( hd, substring( h, 1, 1 )) < 0 or index( hd, substring( h, 2, 1 )) < 0 then
return "".
i = ((( index( hd, substring( h, 1, 1 )) - 1 ) * 16 ) +
index( hd, substring( h, 2, 1 )) - 1
).
if i < 32 or i >= 127 then
return "".
else
return chr( i ).
end.
function url-decode returns character ( input url as character ):
define variable xurl as character no-undo.
define variable zurl as character no-undo.
define variable pct as integer no-undo.
/* fix known trouble makers
*/
assign
xurl = replace( url, "+", " " )
xurl = replace( xurl, "%0A%0D", "~n" ) /* <LF><CR> */
xurl = replace( xurl, "%0D%0A", "~n" ) /* <CR><LF> */
xurl = replace( xurl, "%0D", "~n" ) /* <CR> */
.
pct = index( xurl, "%" ).
do while pct > 0 and xurl > "":
assign
zurl = zurl + substring( xurl, 1, pct - 1 ) + hex2char( substring( xurl, pct + 1, 2 ))
xurl = substring( xurl, pct + 3 )
pct = index( xurl, "%" )
.
end.
return zurl + xurl.
end.
display url-decode( sampleUrl ) view-as editor size 60 by 25.

VBA Copy and paste a range of numbers

I'm trying to copy and paste a range, to create a 28 by 28 grid of numbers "rotating" the values so that each time the range is pasted into the next column, the range is moves down by one row and the last value "overflows" back to the top of the next row, I've got this far but am stumped on the overflow part (i' relative newbie to VBA)
Sub Test()
Dim oRange As Range
Set oRange = ActiveSheet.Range("A1:A28")
Dim i As Integer
For i = 1 To 28
oRange.Copy
oRange.Offset(i, i).PasteSpecial xlPasteAll
Next i
End Sub
Also I need to copy and paste values and formatting of the cells
Hope you guys can help
Thanks
Dan
Sub Test()
Dim oRange As Range
Dim startColumn As String
Dim rangeStart As Integer
Dim rangeEnd As Integer
Dim cellCount As Integer
Dim i As Integer
startColumn = "A"
rangeStart = 1
rangeEnd = 28
cellCount = rangeEnd - rangeStart + 1
For i = 1 To cellCount - 1
Set oRange = ActiveSheet.Range(startColumn & rangeStart & _
":" & startColumn & (rangeEnd - i))
oRange.Copy
oRange.Offset(i, i).PasteSpecial xlPasteAll
Set oRange = ActiveSheet.Range(startColumn & (rangeEnd - i + 1) & _
":" & startColumn & rangeEnd)
oRange.Copy
oRange.Offset((-1 * cellCount) + i, i).PasteSpecial xlPasteAll
Next i
End Sub
EDIT:
to insert a blanck row at index 'i':
Rows(i & ":" & i).Select
Selection.Insert Shift:=xlDown
to insert 5 rows at the top of the worksheet insert a row 5 times at index 1:
For i = 1 To 5
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Next

Formatting Formulas by Code?

I have the following formula as the grouping for a Cross Tab Report:
{Command.Year} & ' ' & {Command.RF Period}
Year is a SmallInt and Period is a TinyInt.
The problem is that it shows on the report as:
2,009.00 9.00
The database values are actually:
2009 9
I can't remove the decimal places via formatting because they are in the formula together.
Ultimately I'd like it to be:
2009 09
Edit:
I found this link: http://www.kenhamady.com/form15.shtml
Now my code looks like this for period:
WhileReadingRecords;
StringVar text := Totext ( {Command.RF Period} , 6 , "" ) ; //put your numeric field in this line
NumberVar end := length ( text ) ;
NumberVar clip :=
(if Val ( text [ end - 6 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 5 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 4 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 3 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 2 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 1 to end ] ) = 0 then 1 else 0 ) +
(if Val ( text [ end - 0 to end ] ) = 0 then 1 else 0 ) ;
text [ 1 to Length ( text ) - clip ]
However, I don't use Crystal Language, I use VB. How do I append a 0 in front of the period if it does not begin with a 1?
The problem now is that September (9) shows up after October, Nov, and Dec because aphabetically 9 comes after 1.
Anybody?
The ToText function is very useful for this kind of thing, no loops required. In Crystal's VB Syntax :
Formula = ToText({Command.Year}, 0, "") & " " & ToText({Command.RF Period}, "00")
This should work if {Command.Year} and {Command.RF Period} are integers as you describe.