getc()とputc() ― 2014年09月23日 08:17
前回取り上げたcopyプログラムで使用している、getc()とputc()を紹介します。
まずは、getc()。RATFOR版は以下の通り。
# getc.r4 (simple version) -- get one characters from standard input character function getc(c) character c character buf(MAXLINE) integer i, lastc data lastc /MAXLINE/, buf(MAXLINE) /NEWLINE/ # note : MAXLINE = MACCARD + 1 lastc = lastc + 1 if (lastc > MAXLINE) { read(STDIN, 100,end=10) (buf(i),i = 1,MAXCARD) 100 format(MAXCARD a1) lastc = 1 } c = buf(lastc) getc = c return 10 c = EOF getc = EOF return end
RATFORのif文が出てきています。"{" -- "}"で複数の文をブロック化しています。
Watcom Fortran 77では、if文が、"if () then -- else -- endif"に拡張されています。
Watcom Fortran 77版では、character型がありますが、数値定数を代入することができません。 integer*1型に文字を格納することとします。
c getc.for -- (simple version) get character from standard input integer*1 function getc(c) integer*1 c integer col,lastc integer*1 buf(81) ! MAXLINE(81) data lastc/81/ ! MAXLINE(81) lastc = lastc + 1 if (lastc .gt. 81) then ! MAXLINE(81) read(5,100,end=999) (buf(col),col=1,80) ! MAXCARD(80) 100 format(80a1) ! MAXCARD(80) lastc = 1 endif c = buf(lastc) getc = buf(lastc) return 999 continue c = -1 ! EOF(-1) getc = -1 ! EOF(-1) return end
これで、良さそうなのですが、問題が一つあります。それは、本来の行末に空白文字が 追加され、1行が80文字になってしまうのです。この問題を回避したのが、次の版です。
c getc2.for -- (extended version) get character from standard input integer*1 function getc(c) integer*1 c integer col,lastc integer*1 buf(82) ! MAXLINE(81)+1 data lastc/81/ ! MAXLINE(81) data buf(81)/10/ ! MAXLINE(81) NEWLINE(10) data buf(82)/-2/ ! MAXLINE(81)+1 EOS(-2) lastc = lastc + 1 if (buf(lastc) .eq. -2) then ! EOS(-2) read(5,100,end=999) (buf(col),col=1,80) ! MAXCARD(80) 100 format(80A1) ! MAXCARD(80) lastc = 1 col = 80 while (buf(col) .eq. 32) do ! BLANK(32) col = col - 1 end while buf(col+1) = 10 ! NEWLINE(10) buf(col+2) = -2 ! EOS(-2) endif c = buf(lastc) getc = buf(lastc) return 999 continue c = -1 ! EOF(-1) getc = -1 ! EOF(-1) return end
一行読みとった後、行末から、行頭に向かって空白をスキャンし、空白以外の文字が出てきたら、 改めて、行末のマーキングをします。これで、余分な行末の空白の処理ができるようになりましたが、 一つ問題があります。全くの空白のみの行は、長さ0の行になってしまいます。今回は、これはまれな事とし、 めをつぶることとしました。
次は、サブルーチンputc()です。RATFOR版は次の通り。
# putc.r4 (simple version) -- put characters on standard output subroutine putc(c) character c character buf(MAXCARD) integer i,lastc data lastc /0/ if (lastc >= MAXCARD | c == NEWLINE) { for (i = lastc+1; i <= MAXCARD; i = i + 1) buf(i) = BLANK write(STDOUT,100) (buf(i), i = 1, MAXCARD) 100 format(MAXCARD a1) lastc = 0 } if (c != NEWLINE) lastc = lastc + 1 buf(lastc) = c } return end
for文が出てきています。これは、Watcom Fortran77にありません。 Cと同じように、初期設定、終了条件、再設定がコンパクトに書けます。 Watcom Fortran77では、while () do -- end whileを使用します。
c putc.for (simple version) -- put sharacter on standard output subroutine putc(c) integer*1 c integer*1 buf(80) ! MAXCARD(80) integer i,lastc data lastc/0/ if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10) i = lastc + 1 while (i .le. 80) do ! MAXCARD(80) buf(i) = 32 ! BLANK(32) i = i + 1 end while write(6,100) (buf(i),i=1,80) ! MAXCARD(80) 100 format(80a1) ! MAXCARD(80) lastc = 0 endif if (c .ne. 10) then ! NEWLINE(10) lastc = lastc + 1 buf(lastc) = c endif return end
一行80文字にするために、空白文字を詰め合わせています。これでは、元の空白文字なのか、 詰め物か判別できませんし、固定長レコードにする、意味がWindowsにはありません。 行末の無駄な空白文字を書き出さないよう、lastc文字分しか書き出さないように変更しました。
c putc2.for (extended version 1) -- put sharacter on standard output subroutine putc(c) integer*1 c integer*1 buf(80) ! MAXCARD(80) integer i,lastc data lastc/0/ if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10) write(6,100) (buf(i),i=1,lastc) 100 format(80a1) ! MAXCARD(80) lastc = 0 endif if (c .ne. 10) then ! NEWLINE(10) lastc = lastc + 1 buf(lastc) = c endif return end
コメント
_ Plentyofish ― 2015年10月18日 09:53
_ quest nutrition Bars Review ― 2015年10月19日 00:07
_ plenty of fish dating site of free dating ― 2015年11月06日 12:18
that I've really loved browsing your weblog posts.
In any case I'll be subscribing on your rss feed and I am hoping you
write again soon!
_ plenty of fish dating site of free dating ― 2015年11月06日 14:31
precisely what I'm looking for. Would you offer guest writers to
write content in your case? I wouldn't mind composing a post or elaborating on a few of the subjects you write in relation to here.
Again, awesome site!
_ plenty of fish dating site of free dating ― 2015年11月06日 21:06
but I by no means discovered any interesting article like yours.
It is pretty value enough for me. In my opinion, if all webmasters and bloggers made good content as you probably did, the web will
likely be a lot more useful than ever before.
_ quest bar ― 2015年11月18日 02:13
_ plenty of fish ― 2015年11月22日 06:09
this blog and I'm impressed! Very useful information specifically the last part :)
I care for such information much. I was seeking this certain info for a very long time.
Thank you and best of luck.
_ plenty of fish ― 2015年11月22日 14:43
that this write-up very forced me to try and do so! Your writing style has been surprised me.
Thanks, quite great post.
_ walmart black friday 2015 ― 2015年11月24日 14:49
This article has truly peaked my interest.
I am going to take a note of your site and keep checking for new details about once per week.
I subscribed to your Feed too.
_ plenty of fish dating site of free dating ― 2015年11月24日 14:58
that it is truly informative. I am going to watch out for brussels.
I will be grateful if you continue this in future.
Lots of people will be benefited from your writing. Cheers!
_ krogerfeedback.com ― 2015年12月04日 15:42
us. Please stay us up to date like this. Thank you for sharing.
_ kroger feedback survey ― 2015年12月06日 14:45
useful and it has aided me out loads. I am hoping to contribute & help different customers like its
helped me. Good job.
_ krogerfeedback.com ― 2015年12月06日 22:40
Stick with it!
_ tinyurl.com ― 2015年12月07日 17:36
After all I will be subscribing to your feed and I hope you write again very soon!
_ tinyurl.com ― 2015年12月07日 20:13
ask if you don't mind. I was curious to find out how you center
yourself and clear your mind prior to writing. I've had a tough time clearing
my mind in getting my ideas out. I do enjoy writing however it just seems like the
first 10 to 15 minutes are lost just trying to figure out how to
begin. Any suggestions or hints? Thank you!
_ plenty of fish dating site of Free dating plenty of fish dating site of free dating ― 2015年12月08日 09:02
on internet I found this website as a best site
for hottest updates.
_ tinyurl.com ― 2015年12月08日 10:21
favor”.I am trying to find things to enhance my website!I suppose its ok to use a few of your ideas!!
_ krogerfeedback ― 2015年12月09日 00:26
_ where to buy quest protein chips ― 2015年12月11日 20:57
I have always disliked the idea because of the costs.
But he's tryiong none the less. I've been using Movable-type on several websites for about a
year and am nervous about switching to another platform.
I have heard fantastic things about blogengine.net.
Is there a way I can transfer all my wordpress content into it?
Any kind of help would be really appreciated!
_ quest bars for sale cheap ― 2015年12月11日 21:04
be actually one thing which I feel I would never understand.
It sort of feels too complex and very vast for me. I'm having a
look ahead in your next publish, I will try to get the grasp of it!
_ plenty of fish dating site of free dating ― 2015年12月11日 21:12
Anyway I will be subscribing to your augment and even I achievement
you access consistently rapidly.
_ appdata minecraft ― 2015年12月12日 21:03
existing here at this web site, thanks admin of this
web site.
_ Descargar El Facebook ― 2015年12月19日 07:48
would never understand. It seems too complicated and extremely broad for me.
I am looking forward for your next post, I will try to get
the hang of it!
_ krogerfeedback.com !!! ― 2016年01月01日 02:07
break. I enjoy the information you provide here and can't wait to take a look when I get home.
I'm amazed at how quick your blog loaded on my cell phone ..
I'm not even using WIFI, just 3G .. Anyways, wonderful
blog!
_ quest bars ― 2016年02月09日 04:52
a comment is added I get three emails with the same comment.
Is there any way you can remove me from that service?
Appreciate it!
_ quest bars ― 2016年02月09日 12:37
_ quest bars ― 2016年02月09日 18:32
browsing your blog posts. In any case I'll be subscribing
to your feed and I hope you write again soon!
_ plenty of fish dating site of free dating ― 2016年02月23日 15:58
usual information an individual provide on your visitors?
Is going to be back ceaselessly to check out new posts
_ Bernie Sanders ― 2016年04月01日 22:26
is time to be happy. I've read this post and if I may I desire to suggest you few fascinating issues or
tips. Maybe you could write subsequent articles regarding this article.
I want to read more things about it!
_ www.krogerfeedback.com ― 2016年06月05日 23:44
_ quest Bars Cheap ― 2016年06月13日 08:51
to and you're just extremely fantastic. I really like what you've acquired here, certainly like what
you are saying and the way in which you say it. You make it enjoyable and
you still care for to keep it sensible. I can not wait to read much
more from you. This is really a tremendous website.
_ mincraft ― 2016年07月03日 02:54
Thanks!
_ Mincraft ― 2016年07月03日 03:59
Is anyone else having this problem or is it a issue on my end?
I'll check back later on and see if the problem still exists.
_ Mincraft ― 2016年07月03日 04:58
I'm planning to start my own blog soon but I'm a little lost on everything.
Would you propose starting with a free platform like Wordpress or go for a
paid option? There are so many options out there that I'm
completely overwhelmed .. Any recommendations? Kudos!
_ tinyurl.com ― 2016年07月09日 12:48
thanks.
_ www.krogerfeedback.com ― 2016年07月14日 19:32
require a lot of work? I have very little understanding of programming but I had been hoping to start my own blog in the near future.
Anyway, if you have any suggestions or techniques
for new blog owners please share. I know this is off subject however I simply needed to ask.
Thanks!
_ www.krogerfeedback.com ― 2016年07月26日 04:53
what if you added a little information? I mean, I don't
wish to tell you how to run your blog, but suppose you added something that makes people desire more?
I mean getc()とputc(): アナクロなコンピューターエンジニアのつぶやき is kinda vanilla.
You ought to glance at Yahoo's front page and watch how they create article titles to grab viewers to click.
You might add a video or a related pic or two to get people excited about everything've written. Just my opinion, it would make your posts a little bit more interesting.
_ kroger digital coupons ― 2016年07月28日 05:22
_ kroger digital coupons ― 2016年07月29日 15:10
out more details.
_ quest bars ― 2016年09月09日 17:54
keep it up.
_ Windows 10 Free Upgrade ― 2016年09月16日 12:16
Regards
_ quest bars ― 2016年09月24日 12:01
you can write or else it is complicated to
write.
_ minecraftsweet and awesome ― 2016年10月01日 04:04
Going through this post reminds me of my previous roommate!
He always kept talking about this. I most certainly
will forward this information to him. Pretty sure
he's going to have a great read. Thank you for sharing!
_ plenty of fish dating site of free dating ― 2016年10月04日 13:20
and it is time to be happy. I have read this post and if
I could I want to suggest you few interesting things or suggestions.
Perhaps you can write next articles referring to this
article. I desire to read even more things about it!
_ plenty of fish dating site of free dating ― 2016年10月05日 03:57
Your story-telling style is awesome, keep it up!
_ quest bars ― 2016年10月06日 09:14
Would you be interested in exchanging links or maybe guest
writing a blog post or vice-versa? My website goes over a lot of the same subjects as yours
and I believe we could greatly benefit from each other. If you might be interested feel free to shoot me an email.
I look forward to hearing from you! Wonderful blog by the way!
_ descargar minecraft launcher gratis ― 2016年10月12日 21:49
It appears as if some of the text within your content are running off the screen. Can somebody else please
comment and let me know if this is happening to them too?
This could be a problem with my internet browser because I've had this happen before.
Thanks
_ juegos de minecraft demo ― 2016年10月15日 02:41
_ gamefly 3 month free trial ― 2016年11月16日 00:26
website all the time because it presents quality contents, thanks gamefly 3 month free
trial
_ quest nutrition quest protein bar ― 2016年11月20日 00:18
was looking on Digg for something else, Regardless I am here now
and would just like to say cheers for a tremendous post
and a all round interesting blog (I also love the theme/design), I don't have time to go through it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time
I will be back to read much more, Please do keep
up the great job.
※コメントの受付件数を超えているため、この記事にコメントすることができません。
トラックバック
このエントリのトラックバックURL: http://kida.asablo.jp/blog/2014/09/23/7441242/tb
最近のコメント