みしょのねこごや

Diary - Comment書き込み - 2010年07月29日

書き込み対象の日記

gfortran + Flymake

最近,仕事の都合で,Fortranで数値計算をしている。CompilerとしてはGNU Fortranを使っているのだけど,GNU Fortranのerror出力が

test2.f:8.72:       COMMON/PYDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)                                                                       1Error: Unexpected COMMON statement at (1)test2.f:10.72:       CALL PY3ENT(0,1,21,-1,30D0,0.9D0,0.7D0)                                                                       1Warning: Procedure 'py3ent' called with an implicit interface at (1)

みたいな破滅したカンジになっているので,あの有名なFlymakeが使えない。いや,使えるんだけど,警告がerror扱いされてしまって非常に困る。

と言うわけで,このメッセージをいわゆる「Flymake的に正しい」形,具体的にはgccのエラー出力

foobar.c:1: error: expected identifier or ‘(’ before ‘%lt;’ tokenfoobar.c:98:46: warning: unknown escape sequence '\c'

みたいに翻訳してくれるscriptを書いた。

#!/usr/bin/perl  our @hold;our ($fname,$line,$ch); foreach(<STDIN>){  if($_ =~ "^ " || $_ =~ /^\s*$/){  # ignore     push(@hold,$_);  }  elsif($_ =~ /^(Warning|Error):/ and $fname && $line && $ch){ # The last line of Message-block    chomp($_);    print "$fname:$line: $_ (ch.$ch)\n";    &clear_all;  }  elsif($_ =~ /^(.+?):(\d+?)\.(\d+):(\s*)/){ # The first line of Message-block    push(@hold,$_);    ($fname,$line,$ch) = ($1,$2,$3);  }  else{ # just print the line if it seems not in a Message-block    push(@hold,$_);    print @hold;    &clear_all;  }}  print @hold; # print rest linesexit 0;  sub clear_all{  undef(@hold);  undef($fname);  undef($line);  undef($ch);}

これをerrwrapper.plとかで保存して,g77の標準error出力を標準出力に持っていった上でpipe使ってこいつに食わせてやると幸福が実現するんじゃないかと思います。つまりg77 -fsyntax-only test1.f 2>&1 | perl errwrapper.plとか。

で,こいつをflymakeに設定してやれば良いわけですね!


Fortran + Flymakeの設定をもう少し詳しく説明してみる

さて,Flymakeを使うには,makefileを使う方法と,.emacs中で直接commandを指定する方法の2通りが在りますが,このwrapperを使う方法はmakefileによる方法でしか使えません!!!

まぁもちろんみなさん当然makefileを使っているはずなので大丈夫でしょうが。

基本的に,.emacsの中に

;makefileがある場合にどういうcommandで文法確認をするかの設定(defun flymake-fortran-get-make-cmdline (source base-dir)  (setq source source)  (list "make"	(list "-s"	      "-C"	      base-dir	      (concat "CHK_SOURCES=" source)          "LANG=C"	      check-syntax-f)))  (defun flymake-fortran-init ()  (setq buffer-dir (file-name-directory buffer-file-name))  (if (file-readable-p (expand-file-name (concat buffer-dir "makefile")))      ;makefileがある場合      (flymake-simple-make-init-impl       'flymake-create-temp-inplace t t "makefile" 'flymake-fortran-get-make-cmdline)      ;makefileが無い場合      (let*          (           (temp-file   (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace))           (local-dir   buffer-dir)           (local-file  (file-relative-name temp-file local-dir)))        (list "gfortran" (list "-Wall" "-Wextra" "-fsyntax-only" local-file)))))  (defconst flymake-allowed-fortran-file-name-masks  '(("\\.f$" flymake-fortran-init flymake-simple-cleanup flymake-get-real-file-name)))  (setq flymake-allowed-file-name-masks flymake-allowed-fortran-file-name-masks)(flymake-mode t)

のような形でflymakeの設定をしていると思います。makefileがある場合にはcheck-syntax-fにより文法を確認する,という設定ですね。だから,makefileの中のこいつを,通常の

check-syntax-f:	$(FC) -fsyntax-only $(FFLAGS) -S ${CHK_SOURCES}

から

check-syntax-f:	$(FC) -fsyntax-only $(FFLAGS) -S ${CHK_SOURCES} 2>&1 | perl errwrapper.pl

に変更してやればよいだけです!簡単ですww

Comments

Commented by 名無しさん  at  2010/07/29(Thu) 23:50:49

ある家では、ペットボトルの天然水を毎月8本消費する。従来は全てスーパーで購入していたが、通信販売で6本入りケースを購入すると、1本当たり価格はスーパーの半額であり、別途、1回の配送につき、ケース数にかかわらず一律の配送料金がかかることが分かった。また、毎月、通信販売で1ケースを、スーパーで残り2本を購入すると月ごとの経費は従来より300円安くなり、3か月間に2回、通信販売で2ケースずつ購入すると月ごとの平均経費は従来より680円安くなることが分かった。この時、スーパーでの1本当たりの価格はいくらか。

1.160円

2.180円

3.200円

4.220円

5.240円

Commented by みしょ  at  2010/07/30(Fri) 12:26:02

中学校の宿題みたいだな……。

Commented by Erma Bowman  at  2017/11/09(Thu) 02:21:38

I am reaching out since we saw a link to your website and thought you would be a good candidate for our traffic service. We provide targeted website traffic to virtually any type of website. We target our visitors by both country and keywords that you either submit to us or we can do keyword research for you. We offer a seven day FREE trial period with free traffic so that you can try our service to make sure it will work for you. Which of your websites needs the most growth? Find out more here:http://segundaibc.com.br/go/1i Unsubscribe here: http://corta.co/f5m

Commented by Erma Bowman  at  2017/11/14(Tue) 02:43:27

I am reaching out since we saw a link to your website and thought you would be a good candidate for our traffic service. We provide targeted website traffic to virtually any type of website. We target our visitors by both country and keywords that you either submit to us or we can do keyword research for you. We offer a seven day FREE trial period with free traffic so that you can try our service to make sure it will work for you. Which of your websites needs the most growth? Find out more here:http://segundaibc.com.br/go/1i Unsubscribe here: http://priscilarodrigues.com.br/url/11

Erma Bowman http://priscilarodrigues.com.br/url/v

Commented by Virginia Williams  at  2017/11/20(Mon) 00:43:25

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE web traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/sdq Unsubscribe here: http://0nulu.com/nbz

Commented by Virginia Williams  at  2017/11/30(Thu) 05:20:40

This is a message to the Comment書き込み - Diary - みしょのねこごや webmaster. Your website is missing out on at least 300 visitors per day. Our traffic system will dramatically increase your traffic to your site: http://0nulu.com/sdq - We offer 500 free targeted visitors during our free trial period and we offer up to 30,000 targeted visitors per month. Hope this helps :) Unsubscribe here: http://0nulu.com/mvx

Commented by Virginia Williams  at  2017/12/05(Tue) 01:30:28

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/opx Unsubscribe here: http://0nulu.com/nbz

Commented by Virginia Williams  at  2017/12/08(Fri) 19:37:27

This is a comment to the Comment書き込み - Diary - みしょのねこごや webmaster. Your website is missing out on at least 300 visitors per day. Our traffic system will dramatically increase your traffic to your site: http://0nulu.com/csy - We offer 500 free targeted visitors during our free trial period and we offer up to 30,000 targeted visitors per month. Hope this helps :) Unsubscribe here: http://0nulu.com/mvx

Commented by Heidi Reynolds  at  2017/12/15(Fri) 01:03:31

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE web traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/sdq Unsubscribe here: http://0nulu.com/nbz

Commented by Heidi Reynolds  at  2017/12/23(Sat) 09:34:03

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/sdq Unsubscribe here: http://0nulu.com/mvx

Commented by Heidi Reynolds  at  2017/12/30(Sat) 04:47:55

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE web traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/sdq Unsubscribe here: http://0nulu.com/nbz

Commented by Heidi Reynolds  at  2018/01/05(Fri) 02:05:59

I discovered your Comment書き込み - Diary - みしょのねこごや page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. We can send you targeted traffic and we let you try it for free. Get over 1,000 targeted visitors per day to your website. Check it out here: http://0nulu.com/rjv Unsubscribe here: http://0nulu.com/nbz

Commented by Heidi Reynolds  at  2018/01/10(Wed) 23:51:05

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE website traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/csy Unsubscribe here: http://0nulu.com/mvx

Commented by Heidi Reynolds  at  2018/01/19(Fri) 01:49:05

I discovered your Comment書き込み - Diary - みしょのねこごや page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. We can send you targeted traffic and we let you try it for free. Get over 1,000 targeted visitors per day to your website. Check it out here: http://0nulu.com/sdq Unsubscribe here: http://0nulu.com/nbz

Commented by Website Traffic  at  2018/01/25(Thu) 10:30:12

I discovered your Comment書き込み - Diary - みしょのねこごや page and noticed you could have a lot more traffic. I have found that the key to running a website is making sure the visitors you are getting are interested in your subject matter. We can send you targeted traffic and we let you try it for free. Get over 1,000 targeted visitors per day to your website. Check it out here: http://0nulu.com/opx Unsubscribe here: http://0nulu.com/mvx

Commented by Website Traffic  at  2018/01/29(Mon) 00:43:40

I came across your Comment書き込み - Diary - みしょのねこごや website and wanted to let you know that we have decided to open our POWERFUL and PRIVATE web traffic system to the public for a limited time! You can sign up for our targeted traffic network with a free trial as we make this offer available again. If you need targeted traffic that is interested in your subject matter or products start your free trial today: http://0nulu.com/opx Unsubscribe here: http://0nulu.com/nbz

書き込みform

名前
(必須)
削除用 password
(必須)
内容 (HTML tag は使えません)

名前と削除passを保存する