在Mac OSX上使用gfortran免费获取UVR数据 [英] Reading freely available UVR data using gfortran on mac OSX

查看:204
本文介绍了在Mac OSX上使用gfortran免费获取UVR数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用fortran来读取日本宇宙航空研究开发机构制作的紫外线辐射数据。这些数据每天和每月的时间分辨率从2000年到2010年,空间分辨率为5公里。这个问题值得回答,因为这些数据可能对许多环境/健康项目有用,并且可以免费获得,并适当承认来源和共享后续出版物的预印本:

ftp://suzaku.eorc.jaxa .jp / pub / GLI / glical / Global_05km / monthly / uvb /

有一个自述文件,提供如何使用数据读取fortran,如下所示:

_le文件说明

/ b>

 阅读标题(大小=像素大小* 2字节):
字符头* 14400

read(10,rec = 1)head
read(head,'(2i6,2f8.2,f8.4,2e12.5,a1,a8,a1,a40)')
& npixel,nline,lon_min,lat_max,reso,slope,offset,',',
& para,',',outfile

读取数据(例如fortran77)

 参数(nl = 7200,ml = 3601)

...以unformatted ,recl = nl * 2(byte)(bytereclen)

整数* 2 i2buf(nl,ml)
do m = 1,ml
read (10,rec = 1 + m)(i2buf(n,m),n = 1,nl)
do n = 1,nl
par = i2buf(n,m)* slope + offset
write(6,*)'PAR [Ein / m ^ 2 / day] =',par
enddo
enddo

斜率值

par__le:每日PAR [Ein / m ^ 2 / day] = DN * 0.01

dpar_le:直接PAR = DN * 0.01 b / b
swr__le:每日平均短波辐射[W / m ^ 2] = DN * 0.01

tip__le:中午瞬时PAR的透射率= DN * 0.0001

uva__le:每日平均UVA [W / m ^ 2] = DN * 0.001 bb
$ b日平均UVB [W / m ^ 2] = DN * 0.0001 p>

rpar_le:PAR范围表面反射率(冠层/实体表面的顶部)= DN * 0 .0001(仅限月数据)

错误值



-1作为签名短整数(int16)



65535作为无符号短整数(uint16)



/ strong>



我已经在mac OSX上成功下载并安装了gfortran。我下载了一个测试文件(MOD02SSH_A20000224Av6_v601_7200_3601_uvb__le.gz)并解压缩。我创建了一个程序文件:

  PROGRAM readuvr 
IMPLICIT NONE

!一些代码

END PROGRAM

我会在命令行中输入以下内容到创建一个可执行文件并运行它来提取数据。

  gfortran -o可执行文件

./executable

作为fortran的初学者,我的问题是:如何使用提供的指令来构建程序可以读取数据并将其输出到文本文件中?

解决方案

那么,该文件将扩大到51,868,800字节。这些注释意味着头部是14,400字节,这留下了51,854,400个字节的实际数据有效载荷。



似乎有7200行数据,这意味着每个字节有7202个字节线。似乎有2个字节(16位采样),所以如果我们假设2个字节/采样,则意味着每行有3601个采样,它与 ml = 3601 匹配。因此,基本上,你需要读取14,400字节的标题,然后读取7200行数据,每行包含3601个值,每一行包含2个字节的宽度......实际上,如果你对FORTRAN不熟悉,你可能喜欢用已经安装并且可以在OS X上使用的Perl来提取数据。我开始了一个非常简单的Perl程序,它读取dat并打印每行的前2个值:

 #!/ usr / bin / perl 
使用strict;
使用警告;

#读取头文件14,400字节
my $ buffer;
my $ nBytes = 14400;
my $ bytesRead = read(STDIN,$ buffer,$ nBytes);
my($ npixel,$ nline,$ lon_min,$ lat_max,$ reso,$ slope,$ offset,$ junk)= split('',$ buffer);
打印npixel:$ npixel\\\
;
printnline:$ nline \\\
;
打印lon_min:$ lon_min\\\
;
printlat_max:$ lat_max\\\
;
打印reso:$ reso \\\
;
printslope:$ slope \\\
;
$ offset =〜s /,.*//; #带尾随逗号和垃圾
打印offset:$ offset \\\
;

#读取实际的数据行
my $ line; ($ my $ m = 1; $ m< = $ nline; $ m ++){
read(STDIN,$ line,$ npixel * 2);

my $ x = $ npixel * 2;
my @ values = unpack(S $ x,$ line);
printfLine:%d,$ m; ($ my $ j = 0; $ j< 2; $ j ++){
printf,%f,$ values [$ j] * $ slope + $ offset;
;
}
printf\\\
; #newline
}

将它保存为 go.pl ,然后在终端中输入以下一次,使其可执行

  chmod + x go.pl 

然后像这样运行

  ./ go.pl< MOD02SSH_A20000224Av6_v601_7200_3601_uvb__le 

抽样输出摘录:

  npixel:7200 
nline:3601
lon_min:0.00
lat_max:90.00
reso:0.0500
斜率:0.10000E-03
抵消:0.00000E + 00
...
...
线路:3306,0.099800,0.099800
线路:3307,0.099900,0.099900
线路:3308,0.099400,0.074200
线路:3309,0.098900,0.098900
线路:3310,0.098400,0.098400
线路:3311,0.074300,0.074200
线路:3312,0.071300,0.071200


I would like to use fortran to read ultraviolet radiation data that has been produced by the Japan Aerospace Exploration Agency. This data is at a daily and monthly temporal resolution from 2000-2010 at a ~5 km spatial resolution. This question is worth answering as the data could be useful for a number of environment/health projects and is freely available, with proper acknowledgement of source and sharing of preprint of any subsequent publications, from:

ftp://suzaku.eorc.jaxa.jp/pub/GLI/glical/Global_05km/monthly/uvb/

There is a readme file available, which provides instructions on how to read data using fortran as follows:

Instructions for _le files

Header

Read header (size= pixel size *2byte):
character head*14400

read(10,rec=1) head
read(head,'(2i6,2f8.2,f8.4,2e12.5,a1,a8,a1,a40)') 
     & npixel,nline,lon_min,lat_max,reso,slope,offset,',',
     & para,',',outfile

Read data (e.g., fortran77)

parameter(nl=7200, ml=3601)

... open file by "unformatted", "recl=nl*2(byte)" (,"bytereclen")

integer*2 i2buf(nl,ml)
do m=1,ml
 read(10,rec=1+m) (i2buf(n,m), n=1,nl)
 do n=1,nl
   par=i2buf(n,m)*slope+offset
   write(6,*) 'PAR[Ein/m^2/day]=',par
 enddo
enddo

slope values

par__le : daily PAR [Ein/m^2/day] = DN * 0.01

dpar_le : direct PAR = DN * 0.01

swr__le : daily mean shortwave radiation [W/m^2] = DN * 0.01

tip__le : transmittance of instantaneous PAR at noon = DN * 0.0001

uva__le : daily mean UVA [W/m^2] = DN * 0.001

uvb__le : daily mean UVB [W/m^2] = DN * 0.0001

rpar_le : PAR-range surface reflectance (TOP of canopy/solid surfaces) = DN * 0.0001 (monthly data only)

error values

-1 as signed short integer (int16)

65535 as unsigned short integer (uint16)

Progress so far

I have downloaded and installed gfortran successfully on mac OSX. I have downloaded a test file (MOD02SSH_A20000224Av6_v601_7200_3601_uvb__le.gz) and decompressed it. I have created a program file:

PROGRAM readuvr
IMPLICIT NONE

!some code

END PROGRAM

I will then type the following into the command line to create an executable and run it to extract the data.

gfortran -o executable

./executable

As a complete beginner to fortran, my question is: how can I use the instructions provided to build a program that can read the data and output it into a text file?

解决方案

Well, that file expands to 51,868,800 bytes. The comments imply the header is 14,400 bytes, which leaves 51,854,400 bytes of actual data payload.

There seem to be 7200 lines of data, so that means there are 7202 bytes per line. There seem to be 2 bytes (16-bit samples) so if we assume 2 bytes/sample, that means there are 3601 samples per line, which matches the ml=3601.

So basically, you need to read 14,400 bytes of header, then 7200 lines of data, each line consisting of 3601 values, each of those being 2 bytes wide...

Actually, if you are that unfamiliar with FORTRAN, you may like to extract the data with Perl which is already installed and available on OS X anyway. I have started a VERY SIMPLISTIC Perl program that reads the dat and prints the first 2 values on each line:

#!/usr/bin/perl
use strict;
use warnings;

# Read 14,400 bytes of header
my $buffer;
my $nBytes = 14400; 
my $bytesRead = read (STDIN, $buffer, $nBytes) ;
my ($npixel,$nline,$lon_min,$lat_max,$reso,$slope,$offset,$junk)=split(' ',$buffer);
print "npixel:$npixel\n";
print "nline:$nline\n";
print "lon_min:$lon_min\n";
print "lat_max:$lat_max\n";
print "reso:$reso\n";
print "slope:$slope\n";
$offset =~ s/,.*//; # strip trailing comma and junk
print "offset:$offset\n";

# Read actual lines of data
my $line;
for(my $m=1;$m<=$nline;$m++){
   read(STDIN,$line,$npixel*2);
   my $x=$npixel*2;
   my @values=unpack("S$x",$line);
   printf "Line: %d",$m;
   for(my $j=0;$j<2;$j++){
      printf ",%f",$values[$j]*$slope+$offset;
   }
   printf "\n"; # newline
}

Save it as go.pl and then in the Terminal, type the following once to make it executable

chmod +x go.pl

and then run it like this

./go.pl < MOD02SSH_A20000224Av6_v601_7200_3601_uvb__le

Sample output extract:

npixel:7200
nline:3601
lon_min:0.00
lat_max:90.00
reso:0.0500
slope:0.10000E-03
offset:0.00000E+00
...
...
Line: 3306,0.099800,0.099800
Line: 3307,0.099900,0.099900
Line: 3308,0.099400,0.074200
Line: 3309,0.098900,0.098900
Line: 3310,0.098400,0.098400
Line: 3311,0.074300,0.074200
Line: 3312,0.071300,0.071200

这篇关于在Mac OSX上使用gfortran免费获取UVR数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆