// windowing Hann http://stackoverflow.com/questions/24696122/calculating-the-power-spectral-density
for(i=0; i<windowsSize; i++){
multiplier =0.5*(1-cos(2*PI*i/(windowsSize-1)));
value[i]*= multiplier;
}
作者: PurpoolPoolObservatory
Multi-dimensional hashes in Perl
Multi dimensional hashes in Perl
编辑删除转载2016-06-07 06:57:28
标签:linux
from: http://perlmaven.com/multi-dimensional-hashes
perl中的结构体
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my %grades;
$grades{"Foo Bar"}{Mathematics} = 97;
$grades{"Foo Bar"}{Literature} = 67;
$grades{"Peti Bar"}{Literature} = 88;
$grades{"Peti Bar"}{Mathematics} = 82;
$grades{"Peti Bar"}{Art} = 99;
print Dumper \%grades;
print "----------------\n";
foreach my $name (sort keys %grades) {
foreach my $subject (keys %{ $grades{$name} }) {
print "$name, $subject: $grades{$name}{$subject}\n";
}
}
如何将TIFF格式的DEM数据转换成ASCII格式的数据
在linux下操作如下:
安装GDAL,使用gdal_translate,方法如下:
gdal_translate -of AAIGrid ASTGTM_N22E103_dem.tif test.asc
其中-of为指定输出格式,gdal_translate支持多种格式互转,AAIGrid为Arc/Info ASCII Grid数据,ASTGTM_N22E103_dem.tif为tiff格式的dem数据文件,test.asc为输出文件。
test.asc为文本文件,可以打开查看,其中包含有5~6行的头信息,主要内容如下:
ncols 3601 —》行数
nrows 3601 —》列数
xllcorner 102.999861111111 —》x轴起点坐标,单位°
yllcorner 21.999861111111 —》y轴起点坐标,单位°
cellsize 0.000277777778 —》采样间隔,单位°,精度大概30m
之后是按行存储的数据,每一行即是相同经度不同纬度并以空格分隔的高程数值,行与行之间用回车分开。
64位ubuntu运行32位程序
sudo apt-get install lib32z1
[GMT]已知相对于某固定点的方位角和距离,求该点位置
如题,已知某固定点A的经纬度lo1,la1,另已知某一点B相对于A的方位角az和距离dist,求B点的经纬度。用GMT的project命令。
project -Q -G10 -Clo1/la1 -Aaz -Ldist/10000
-Q指定结果按度输出
-G指定在该方向上的采样步长
-C指定中心点或起始点
-A方位角
-L起止长度
输出的第一行前两列即是所需结果
fortran tips
1. 先定义类型,再定义存储大小
character a
dimension a(10)
2. 获取当前时间
第一种方法
program when
integer*4 today(3), now(3)
call idate(today) ! today(1)=day, (2)=month, (3)=year
call itime(now) ! now(1)=hour, (2)=minute, (3)=second
write ( *, 1000 ) today(2), today(1), today(3), now
1000 format ( 'Date ', i2.2, '/', i2.2, '/', i4.4, '; time ', & i2.2, ':', i2.2, ':', i2.2 )
stop
end
第二种方法
program now_time
integer date_time(8)
character*10 b(3)
call date_and_time(b(1), b(2), b(3), date_time)
print *,’date_time array values:’
print *,’year=’,date_time(1)
print *,’month_of_year=’,date_time(2)
print *,’day_of_month=’,date_time(3)
print *,’time difference in minutes=’,date_time(4)
print *,’hour of day=’,date_time(5)
print *,’minutes of hour=’,date_time(6)
print *,’seconds of minute=’,date_time(7)
print *,’milliseconds of second=’,date_time(8)
print *, ’DATE=’,b(1)
print *, ’TIME=’,b(2)
print *, ’ZONE=’,b(3)
end
3. 数字转字符
program tran
integer i
character*3 a
i=500
write(a,'(i3)') i
print *, a // ' this is a test'
end
余纬度colatitude
https://en.wikipedia.org/wiki/Colatitude
In spherical coordinates, colatitude is the complementary angle of the latitude, i.e. the difference between 90° and the latitude,[1] where southern latitudes are denoted with a minus sign.
Examples
Latitude and colatitude sum up to 90°.
place latitude colatitude
north pole 90° 0°
equator 0° 90°
south pole -90° 180°
C语言结构体拷贝
定义了一个结构体数组,每个成员都想从另一个相同的结构体中拷贝过来,遂用了memcpy,比如
typedef struct cata *CATA, single_cata;
int size=sizeof(single_cata);
memcpy(CATA+i*size,&single_cata,size);
运行时发现除了结构体数组CATA的第一个值是正确的,后面的全错了,后来搜了一下,发现要如是改:
memcpy((char*)CATA+i*size,&single_cata,size);
perl求汉字字符串长度
perl在进行汉字操作之前要先转码,不然无法正确操作。
use Encode;
$s=’汉字’;
$str=decode ‘utf8’,$s; #######或者gb2312之类的
$len=length($str); ######这样就可以正确得到汉字字符串的长度了
c语言产生随机的高斯分布
参考http://www.cnblogs.com/tsingke/p/6194737.html
采用box-muller方法:
#include
#include
double gaussrand2(double mu,double sigma){
static double u,v;
static int phase=0;
double z;
if(phase==0){
u=rand()/(RAND_MAX+1.0);
v=rand()/(RAND_MAX+1.0);
z=sqrt(-2.0*log(u))*sin(2.0*pi*v);
}
else{
z=sqrt(-2.0*log(u))*cos(2.0*pi*v);
}
phase=1-phase;
return(mu+z*sigma);
}