文字から数値への変換2014年10月19日 19:22

さて、itoc()の逆の関数をctoi(c,i)を作っておきます。これは、文字配列cのi番目から数値に変換します。

RATFOR版は次の通り。

# ctoi.r4 -- convert string at in(i) to integer, increment i
      integer ctoi(in,i)
      character in(ARB)
      integer iindex
      integer d, i
      string digits "0123456789"

      while (in(i) == BLANK | in(i) == TAB)
          i = i + 1
      for (ctoi = 0; in(i) != EOS; i = i + 1) {
          d = iindex(digits, in(i))
          if (d == 0)         # non-digit
              break
          ctoi = ctoi * 10 + d - 1
          }
      return
      end

ここで、iindex(s,c)は、文字配列sの中から文字cを探しその位置を返します。Watcom Fortran77には、 同様の組み込み関数index()がありますが、引数がchracter型であるため使えません。作り直します。

RATFOR版は下記の通り。

# iindex.r4 -- find character c in string str
      integer function iindex(str,c)
      character c,str(ARB)
      
      for (iindex = 1; str(iindex) != EOS; iindex = iindex + 1)
         if (str(iindex) == c)
             return
      iindex = 0
      return
      end

ctoi()、iindex()のWatcom Fortran77版は、下記の通り。

c ctoi.for -- convert string at in(i) to integer, increment i
      integer function ctoi(in,i)
      integer*1 in(*)                   ! ARB(*)
      integer i, d
      integer iindex
      integer*1 digits(11)
      data digits/'0','1','2','3','4','5','6','7','8','9',-2/  ! EOS(-2)

      while ((in(i) .eq. 32) .or. (in(i) .eq. 9)) do ! BLANK(32) TAB(9)
          i = i + 1
      end while

      ctoi = 0
      while (in(i) .ne. -2) do          ! EOS(-2)
          d = iindex(digits,in(i))
          if (d .eq. 0) then
              exit
          end if
          ctoi = ctoi*10 + (d - 1)
          i = i + 1
      end while
      ctoi = ctoi
      return
      end
c iindex.for -- find charcter c instring str
      integer function iindex(str,c)
      integer*1 c,str(*)

      iindex = 1
      while (str(iindex) .ne. -2) do    ! EOS(-2)
         if (str(iindex) .eq. c) then
             return
         end if
         iindex = iindex + 1
      end while
      iindex = 0
      return
      end

"+"や"-"の付いた数字列を取り扱えるようにctoi()を拡張しておくのは、有意義なことです。拡張版は、次の通り。

c ctoi2.for -- (extended vertion 1) convert string at in(i) to integer, increment i
      integer function ctoi(in,i)
      integer*1 in(*)                   ! ARB(*)
      integer i
      integer iindex
      integer d, s
      integer*1 digits(11)
      data digits/'0','1','2','3','4','5','6','7','8','9',-2/    ! EOS(-2)

      while ((in(i) .eq. 32) .or. (in(i) .eq. 9)) do ! BLANK(32) TAB(9)
          i = i + 1
      end while

      ctoi = 0
      if (in(i) .eq. 43) then           ! PLUS(43)
          s = 1
          i = i + 1
      else if (in(i) .eq. 45) then      ! MINUS(45)
          s = -1
          i = i + 1
      else
          s = 1
      end if
      while (in(i) .ne. -2) do          ! EOS(-2)
          d = iindex(digits, in(i))
          if (d .eq. 0) then
              exit
          end if
          ctoi = ctoi * 10 + (d - 1)
          i = i + 1
      end while
      ctoi = s*ctoi
      return
      end

コメント

_ Plentyoffish.com Sign In ― 2015年10月18日 11:20

There's certainly a lot to learn about this issue. I like all of the points you've made.

_ quest protein bar where to buy ― 2015年10月18日 18:47

I am sure this paragraph has touched all the internet viewers, its really really good paragraph on building up new blog.

_ match free trial 3 days ― 2015年10月30日 07:46

Hi there! This is my first visit to your blog!

We are a group of volunteers and starting a new project in a community in the
same niche. Your blog provided us beneficial information to work on. You have done a wonderful job!

_ Dr Oz Weight Loss Forskolin ― 2015年11月03日 15:16

Saved as a favorite, I love your website!

_ plenty of fish dating site of free dating ― 2015年11月06日 03:28

Truly when someone doesn't understand afterward its up to
other people that they will assist, so here it occurs.

_ plenty of fish dating site of free dating ― 2015年11月06日 18:28

Hurrah, that's what I was seeking for, what a stuff! present here
at this website, thanks admin of this website.

_ plenty of fish dating site of free dating ― 2015年11月07日 00:11

I will right away seize your rss feed as I can not
in finding your e-mail subscription hyperlink or e-newsletter service.
Do you have any? Please let me recognise in order that I
may subscribe. Thanks.

_ justin bieber dating ― 2015年11月10日 01:38

Nice post. I used to be checking constantly this weblog and I'm inspired!
Very helpful information particularly the ultimate section :
) I care for such info a lot. I used to be looking for this particular information for a very lengthy time.
Thank you and good luck.

_ krogerfeedback ― 2015年12月06日 15:34

Hi there! I just want to offer you a huge thumbs up for the excellent info
you have right here on this post. I'll be coming back to your
blog for more soon.

_ plenty of fish dating site of free dating plenty of fish dating site of free dating ― 2015年12月08日 04:32

Yes! Finally something about plenty of fish dating site of
free dating plenty of fish dating site of free dating
plenty of fish dating site of free dating.

_ tinyurl.com ― 2015年12月08日 08:53

Highly descriptive blog, I loved that bit. Will there be a part 2?

_ Santa Ana California ― 2015年12月11日 05:37

Wow! In the end I got a blog from where I be capable of genuinely get valuable information regarding
my study and knowledge.

_ plenty of fish dating site of free dating ― 2015年12月11日 20:44

Greetings! I've been reading your site for a while now and finally got
the courage to go ahead and give you a shout out from Huffman Texas!

Just wanted to say keep up the good work!

_ quest nutrition coupon ― 2015年12月11日 21:46

My spouse and I absolutely love your blog and find most of
your post's to be just what I'm looking for. Does one offer guest writers
to write content for you personally? I wouldn't mind composing a post or elaborating on a number of the subjects you write related to here.
Again, awesome web log!

_ Quest Bars Sale ― 2015年12月11日 21:59

It's perfect time to make some plans for the long run and it's time to be happy.
I have learn this publish and if I could I wish to recommend you few fascinating issues or tips.
Perhaps you can write subsequent articles relating to this article.
I desire to read even more things approximately it!

_ appdata minecraft ― 2015年12月12日 16:35

I have been browsing online more than 2 hours today, yet I never found
any interesting article like yours. It's pretty worth enough for me.
In my opinion, if all website owners and bloggers made good content as you did, the internet
will be a lot more useful than ever before.

_ Plenty of Fish Dating Site of Free Dating ― 2015年12月16日 08:11

My spouse and I stumbled over here from a different web page and thought
I might check things out. I like what I see so now i'm following
you. Look forward to looking into your web page repeatedly.

_ Plenty of Fish Dating Site of Free Dating ― 2015年12月16日 12:40

It's truly a great and useful piece of info.
I am satisfied that you simply shared this helpful information with us.
Please stay us informed like this. Thank you for sharing.

_ kroger Feedback ― 2015年12月18日 00:58

Nice blog right here! Also your site a lot up fast!
What web host are you using? Can I get your associate hyperlink on your host?
I want my site loaded up as quickly as yours lol

_ descargar facebook ― 2015年12月19日 12:42

Interesting blog! Is your theme custom made or did you download
it from somewhere? A theme like yours with a few simple adjustements would
really make my blog shine. Please let me know where
you got your design. Appreciate it

_ descargar facebook para windows 10 ― 2015年12月23日 07:25

What's Happening i am new to this, I stumbled upon this I have found
It positively helpful and it has aided me out loads. I hope to contribute & aid other customers
like its helped me. Great job.

_ quest bars ― 2016年02月10日 02:05

I got this web page from my buddy who shared with me concerning this site and now
this time I am visiting this site and reading very informative posts at this
time.

_ quest bars ― 2016年02月10日 08:44

This blog was... how do I say it? Relevant!! Finally I have found something that helped me.
Kudos!

_ bernie sanders ― 2016年04月01日 02:14

Thanks for sharing your thoughts on bernie sanders. Regards

_ bernie sanders ― 2016年04月01日 17:19

Hi! Someone in my Myspace group shared this website with us so I came to give it a look.
I'm definitely loving the information. I'm book-marking and will be tweeting this to my followers!
Outstanding blog and excellent design and style.

_ shoe lifts to look taller ― 2016年09月12日 11:52

I am truly delighted to glance at this website
posts which contains plenty of useful facts, thanks for providing these
kinds of information.

_ how do you grow taller ― 2016年09月17日 18:30

Excᥱllent bog right hеrе! Аlso your website so much up fast!
What web host are yoou thе usage of? Can I get your affiliate hyperlink onn
yⲟur host? I wiѕh my site loaded up as quickly as
yours lol

_ manicure ― 2017年05月03日 13:08

Someone essentially lend a hand to make critically articles I'd state.
This is the first time I frequented your web page
and to this point? I surprised with the analysis you made to make this actual put up extraordinary.
Magnificent process!

_ choc ― 2018年05月02日 23:50

Amazing! Its truly remarkable piece of writing, I have got much clear idea about from this piece of writing.

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

名前:
メールアドレス:
URL:
コメント:

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2014/10/19/7462117/tb