text:
      SUBROUTINE cfnorm(mrad,is,it,nsol,nmatch,jtop,var,gc,fc,rc,rc2,
     +                  dx,gck,fck)
c...........................................................cfnorm
c wavefunctions normalization
c
      IMPLICIT NONE
c
C     .. Scalar Arguments ..
      INTEGER, INTENT (IN) :: mrad
      REAL dx
      INTEGER is,it,jtop,nmatch,nsol
C     ..
C     .. Array Arguments ..
      REAL fc(2,2,mrad),fck(2,2,mrad),gc(2,2,mrad),gck(2,2,mrad),
     +     rc(mrad),rc2(mrad),var(4)
C     ..
C     .. Local Scalars ..
      REAL xnorm
      INTEGER i,j,k,n
C     ..
C     .. Local Arrays ..
      REAL rint(mrad)
C     ..
C     .. External Functions ..
      REAL rsimp
      EXTERNAL rsimp
C     ..
C     .. Intrinsic Functions ..
      INTRINSIC sqrt
C     ..
      DO n = 1,mrad
         DO k = 1,nsol
            gck(k,is,n) = 0.0
            fck(k,is,n) = 0.0
         END DO
      END DO
C                         ---------------------------------
C--->                     NORMALIZE WAVEFUNCTIONS ACCORDING
C                               TO MATCHING CONDITIONS
C                         ---------------------------------
C                                    INWARD - SOLUTION
      DO 30 n = nmatch,jtop
         DO 20 j = 1,nsol
            DO 10 i = 1,nsol
               gc(i,j,n) = gc(i,j,n)*var(2)
               fc(i,j,n) = fc(i,j,n)*var(2)
   10       CONTINUE
   20    CONTINUE
   30 CONTINUE
c
      IF (nsol.EQ.2) THEN
C                                   OUTWARD - SOLUTION
         DO 50 n = 1, (nmatch-1)
            DO 40 i = 1,nsol
               gc(i,it,n) = gc(i,it,n)*var(3)
               fc(i,it,n) = fc(i,it,n)*var(3)
   40       CONTINUE
   50    CONTINUE
C                                    INWARD - SOLUTION
         DO 70 n = nmatch,jtop
            DO 60 i = 1,nsol
               gc(i,it,n) = gc(i,it,n)*var(4)
               fc(i,it,n) = fc(i,it,n)*var(4)
   60       CONTINUE
   70    CONTINUE
      END IF
C                                    SUM FOR EACH KAPPA
      DO n = 1,jtop
         DO k = 1,nsol
            gck(k,is,n) = 0.00
            fck(k,is,n) = 0.00
         END DO
      END DO
      DO n = 1,jtop
         DO k = 1,nsol
            DO j = 1,nsol
               gck(k,is,n) = gck(k,is,n) + gc(k,j,n)
               fck(k,is,n) = fck(k,is,n) + fc(k,j,n)
            END DO
         END DO
      END DO
C                       -----------------------------------
C                       CALCULATE  NORM  AND NORMALIZE TO 1
C                       -----------------------------------
      DO n = 1,jtop
         rint(n) = 0.00
         DO k = 1,nsol
            rint(n) = rint(n) + rc2(n)* (gck(k,is,n)**2+fck(k,is,n)**2)
         END DO
      END DO
      xnorm = rsimp(mrad,rint,rc,jtop,dx)
      xnorm = 1.00/sqrt(xnorm)
      DO n = 1,jtop
         DO k = 1,nsol
            gck(k,is,n) = gck(k,is,n)*xnorm
            fck(k,is,n) = fck(k,is,n)*xnorm
         END DO
      END DO
      RETURN
      END

ext: f

max_stars_repo_name: MRedies/FLEUR

max_issues_repo_name: MRedies/FLEUR

max_forks_repo_name: MRedies/FLEUR


text:
Village Bakery makes excellent breads bread, Cookies, Pastries, and Baked Goods pastries, and Pizza pizza. Located directly across from the Amtrak Station, the bakerys storefront easily goes unnoticed. There are three indoor tables and four outside, providing plenty of pleasant seating Outdoor Activities outside. Do not confuse them with their recently opened restaurant called Village Pizza and Grill on the corner of G Street and 4th Street.

After 2pm all muffins, scones, and croissants are $1

Pizza can be bought by the slice from 11amclosing; this may be the best pizza in all of Davis. They also deliver, but make sure to specify credit card when ordering. Slices are large and cost $2.25 for cheese, $2.50 for pepperoni, $2.75 for vegetarian options vegetarian, and $3 for veggie meat combo. There is usually a cheese, a pepperoni and some sort of vegetable combination (Vegetarian or Eggplant or any other veggie combo). This is excellent Cheap Food. Sometimes late in the day (i.e. dinner time) they will be sold out of pizza in the rotating glass case, in which case one should ask for another of (fill in the type) to be made and it can probably be made in around five minutes unless the pizza slaves are experiencing some sort of terrible nightmare of a rush in the back (case in point the night of January 5, 2007).

The Bakerys bread can also be bought onsite or at the Davis Food Coop a couple of blocks away, or in Sacramento at http://www.taylorsmarket.com/ Taylors Market on Freeport Boulevard.  Village Bakery supplies bread to a number of local restaurants, including buns for The Hotdogger, Delta of Venus, Enzos, Mishkas Cafe as well as all the Plutos locations. In the summer of 2005, Village Bakery opened a baking facility on Spafford Street in Mace Ranch and relocated all their commercial baking from the downtown store. This freed up the downtown location to focus on counter service and pizza. The Spafford location does not have a customer counter.

Several editors have complained about extra charges on their credit cards when used to purchase from Village Bakery, although this is supposed to happen as a normal part of an authorization hold, some have implied that it is more than that; caveat emptor.

Village Bakery used to provide the bread for the South Davis Nugget Nugget, some of which was wrapped with paper bags reading Village Bakery, others which have Nugget bags which match the Village Bakery ones.

The Village Bakery also has an espresso machine which has made the bakery a popular spot for train riders to get some caffeine before or after their trip. To accompany coffee are various muffins, pastries, and linzer tortes. Their Napoleons are filled with custard and are much easier to eat than traditional Napoleons because they are bunshaped instead of rectangular.

Plus the wait staff is really hot and they deliver.

Pizza Menu (baked  take n bake  by the slice) These prices are after tax.
 1. Cheese  with optional parmesan cheese & dry herb ($14)
 2. Pepperoni  Tasty, they are ($15)
 3. Sausage  ($15)
 4. Veggie  roasted red bell pepper, roasted onions, zucchini, mushrooms, feta ($17.50)
 5. Eggplant  with onion, Kalamata olive, roasted onions, feta ($17.50)
 6. Greek  Kalamata olive, feta cheese, fresh basil, tomato (note: does not include mozzarella unless otherwise specified) ($17.50)
 7. Artichoke  artichokes, Kalamata olives, goat cheese, on pesto/red/garlic sauce ($18.50)
 8. Chicken  roasted chicken breast, roasted onions on white garlic sauce ($17.50)
 9. Spinach  Garlic White/Pesto Sauce, Spinach, Tomatoes, mushrooms, Goat Cheese ($17.50)
 10. Margarita  Fresh Tomatoes, Parmesan, Basil, garlic, mozzarella ($15)
 11. Hawaiian  canadian bacon and pineapple ($17.50)
 11. Roasted Bell Pepper  with goat cheese ($17.50)
 12. Meat & Veggie Combo  pepperoni, sausage, green bell pepper, red onions, mushrooms, black olives, tomato ($18.50)

You can also customize your toppingsthey are $1 each:
pepperoni, salami, sausage, chicken, ham, roasted red peppers, artichoke hearts, eggplant, spinach, Kalamata olives, roasted onions, bell peppers, mushrooms, tomatoes, garlic, basil, feta, goat cheese, fresh mozarella, marinara sauce, pesto, white sauce.

Greek Salad  Romaine lettuce, tomatoes, feta, & olives (small  $2.50) Choice of Lemon Oil or Caesar Dressing

Large 14 pizza. Each extra topping $1.00. Delivery charge $5...this charge, however, is not a tip...that is separate. A good tip is $4...a $7 tip has been scientifically proven to make the delivery drivers love and worship you forever. Delivery is available after 5PM.

Menu pictures: click on thumbnail for full size.

  /2005 Reviews Reviews from 2005
  /2006 Reviews Reviews from 2006
  /2007 Reviews Reviews from 2007
  /2008 Reviews Reviews from 2008

 Recent Reviews

20090114 00:25:54 nbsp I dont know what it is about their pizza that makes it so good; it just is. If youve never been there, stop by and grab a bite to eat before you go on a train ride. Next time you have a dinner party or potluck, buy a roll of fresh bread from the Village Bakery.  Users/AmanpreetSingh

20090126 23:32:18 nbsp I am no pizza snob, but after trying all of the pizzas in Davis, Village Bakery emerges victorious. Symposium is a close second for deep dish pizza. Village Bakery pizzas always have high quality and fresh ingredients along with a great tasting crust. The staff are always super nice, too. Users/CoffeeSnobDavis

20090210 16:26:56 nbsp The pizza is at least heavenly, so much so that there are delays periodically; that seems natural to me, like how free ways are sometimes crowded about the fourth of July and such, people can deliver orders in rushes (by telephone included) and do a grand job at occasionallyoverwhelming the staff very much.  As for the illegal bussiness practices that are alleged to exist, specifically keeping in mind how undocumented or illegal workers might be underpaid, Id say that it is proper to be aware and on the lookout for such dealings, yet if anyone makes concrete (hard) accusations that such trouble exists then they had best have evidence just as solid otherwise that is slander or liable(depending) and that can be as damaging.  With the posts o LetJusticeBeServed and GeorgeBush in mind I have a mind to say that if Someone makes a Public Notice  Try having some proof to presentbecause how do You really know?Do you even?  Have you seen forged documents or even asked the employees any questions? What did they say?  When?  Have you gone by whats called, a wellknown fact throughout Davis(GeorgeBush) then?  Ive resided in Davis for about ten years; this is the first time Ive heard of that wellknow fact.  Then again, the pizza is delicious, and the desserts are too. I can attest to such truely, as Ive been in person; that was near to two months, too long, ago when my senses proved the like as sure as night is dark and day is light. Users/KhayyamShah

20090305 21:07:17 nbsp I used to always walk by here on my way to the Amtrak and wondered how their food tasted. After finally getting the chance, I was overjoyed!  Great tasting pizza, good prices, and wonderful service!  Two thumbs up :) Users/renee415

20090320 18:30:12 nbsp This is by far my favorite pizza place in Davis.  My Davisbornandraised husband is a loyal Woodstocks fan, but for me, Village Bakery has the best crust, sauce, and the Veggie slices have the perfect mix of flavor and texture.  It doesnt taste too greasy, and the vegetables arent overwhelmed by a sauce that tastes like tomato paste.  Mmmm...On occasion, when my husband orders from Woodstocks, Ive been known to place a separate order from Village Bakery.  Its made for an awkward moment when the delivery guys arrive at about the same time, but I think a few seconds of awkwardness is a small price to pay for marital harmony and satisfied taste buds. Users/MBriggs

20090415 11:54:44 nbsp Very good pizza, esp for the price.
One time I went there years ago as they were closing. I wanted one piece, and they had a whole fresh pizza that they would not sell by closing time. They gave all of it to me for the price of slice. It was AWESOME. Love them. Users/LotsofThoughts

20090524 16:17:09 nbsp I FINALLY tried village pizza the other day. My dad and I stopped in for a quick slice of pepperoni. All in all the pizza was good, but I wish it had more sauce. The crust was nice and chewy but slightly crispy on the bottom, and the cheese was PERFECT for pizza (I love when I take a bite and the cheese just stretches and stretches!) I would definitely go there again if I just wanted a slice, but other wise, I still prefer Steves. Users/BrookeB

20090529 16:17:52 nbsp Great news for anyone who loves Village Bakerys pizza as much as I do: The old house being remodeled on 4th and G just had a sign put up the other day reading Village Pizza and Grill in the same lettering style as the bakery. (opening in July) Im not sure if this restaurant is owned by Village Bakery (if anyone can confirm, that would be great!), but Id sure bet it is. I couldnt be more excited about this restaurant opening if my hunch is correct; I LOVE Village Bakerys pizza and would equally love enjoying it on an outdoor patio with a cold brew during the summer. Fingers crossed!  Users/chellebelle1685

20090529 19:21:18 nbsp I just called them and they said it really is Village Bakery, and the current location will also stay open. Yay! Village Bakery is awesome. Users/NickSchmalenberger

20090530 18:58:21 nbsp Correct.  Aziz, the owner of Village Bakery, is opening up the new restaurant.  It has been in planning for a long time and under construction for a bit.  I havent talked to him in a while, so I dont remember when the exact opening date is. Users/SunjeetBaadkar

20090607 17:47:22 nbsp Their lunch special is currently $5.50 (+tax, I imagine).  It includes a slice of pizza, a can of soda (or bottled juice), and a salad. The guy behind the counter told me the special is for anytime. Ive only had their vegetarian pizza. Its good.  I also like the tables outside, nice atmosphere this time of year (MayJune). Users/RonB

20090615 17:52:44 nbsp Looking forward to the new location, Village Bakery may have my favorite pizza in town! Highly recommend the Veggie. Users/JamesWaterhouse

20090617 17:14:17 nbsp My favorite pizza in town. cannot wait for the new location! Users/CreeSmithers

20090714 20:36:57 nbsp Desserts are to die for!  Great portions and awesome pricing! Users/davisgirl10

20090724 14:47:52 nbsp Does anyone have any new info on the new restaurant? Is it open yet, or opening soon? Users/jsogul

  Inside word is that he wants to open it within the next week, but I have a feeling it wont be until as late as the end of next month. Well see... Users/SunjeetBaadkar

20090726 19:54:24 nbsp Best pizza in davis by far!!!  if you havent had a slice, go now! Users/ADP

20090801 23:42:38 nbsp the best pizza in town bar none!
I hope they keep the lunch special at the new location. $5.50 slice salad drink.
Best in town. Users/jonjon

20090816 14:54:40 nbsp I read previous comments about the undocumented workers, that sucks for americans, but they still make some darn good pizza Users/lajolla4joya

20090826 10:26:02 nbsp Anyone go to the new location yet? Users/SonnyStack

20090909 16:50:51 nbsp I love this place  best pizza in town!  Check out review here:  http://sacfoodies.com/2009/09/09/pizzaweekcontinuedvillagebakery/ Users/ChristineSchunk

20090925 17:47:50 nbsp This is my favorite place to get pizza in Davis, BY FAR!
I went to their new location a few weeks after opening.  I wasnt very impressed by their service but I assume the bugs will get worked out soon.  The food was excellent and the wines are local!  I will be returning soon.     Users/UMDGrad

20091017 21:39:12 nbsp I ordered a pick up pizza from village bakery tonight. When I went to pick it up the nice lady at the front told me it had been burned a bit and offered to give me a discount ($3 off). The pizza wasnt that bad  just a little crispier than normal around the edges. This was an awesome gesture that she certainly didnt have to do and its a great example of the kind of customer service I wish I could see more often in Davis. Village bakery is the best pizza in Davis.  Users/ARWENNHOLD

20091221 09:51:56 nbsp I love the new location and menu. It is comparable to Burgers & Brew but with better seating and a larger menu. This is my new favorite place to eat out in Davis. Users/GJC02

Really???? I dont see how this can be compared it definitely does NOT have better seating.. perhaps wrong restaurant?

20100121 21:06:52 nbsp We wanted the asiago cheese bread but the Coop was out, so we went to VB  turns out they were out even earlier! Our whole family love those, especially sliced and toasted...mmm.. Users/LeeY

20100129 17:47:34 nbsp Stopped in today to have the lunch special, a slice, drink and salad. It was pretty good. Also got a piece of Tiramisu which was okay too. The pizza is good, but dont know that its the best Ive ever had. Very fresh, though. Users/redbike

20100205 10:16:37 nbsp Hands down the BEST pizza in Davis, the employees here have always been nice and friendly. Users/DagonJones

20100705 20:01:58 nbsp This is the best pizza in Davis. Davis needs Italian food and more pizza choices. Woodstocks doesnt quite match up to Round Table and RT isnt that good in this town. Luckily, there is some decent pizza. Nice bread (I miss Bouchon Bakery), and wonderful cream puffs for $1.25 apiece. My partner gives a rating of 8 or 9 /10.  Users/seesharp

20100716 17:17:08 nbsp Best pizza and scones, and cool atmosphere. Users/JasperD

20100803 03:42:53 nbsp I love this place, friendly staff and great pizza! Users/Saher

20101124 21:35:10 nbsp LOVE LOVE LOVE LOVE. You havent lived until youve tried one of their croissants. My son, who is 11, says he never wants to move from Davis because of Village Bakery. Users/JasperD

20110324 16:40:47 nbsp Took me years to figure out they have breakfast items like muffins and scones. Their blueberry muffins are soooo good! I am addicted :) Users/Ravyn

20110324 21:14:33 nbsp Great EPI bread!  Just dont make the same mistake I made and assume that when they open at 5:30 am they will have fresh baked goods...  I thought I would bring in goodies for the office, but they dont get delivery from their Spafford location until around 6:30ish. Users/BigGuy

20110412 20:27:18 nbsp When I graduate next year and leave Davis, this place will probably be the only thing I miss. The pizza is THAT good and their lunch deal makes it even better. Users/ElizabethWood

20110517 17:35:49 nbsp Tried pizza here for the first time last Friday (May 13,2011), and I must say everytime I am in need for a quick bite in Downtown Davis, I am heading over to this Village Bakery.
However the thing I really dont like is that they close super early because after I got off work I decided to go back for another couple of slices, and they were closed. :(
But props on the TASTY pizza.!
 Users/NikhilDahal

20110517 21:41:56 nbsp Also worth knowing that they have a presence at the Davis Farmers Market on a Saturday. Find them at the northwestern end of the covered bit. They dont sell pizza here, but they do have a range of breads. Users/KevinWeedon

20110627 21:49:15 nbsp The best pizza in Davis.  The bread is great too, but I consume more of the pizza.  Even their restaurant doesnt make the pizza as good.  I lived in NYC and it was nice finding a place that sells by the slice all day for a reasonable price.  Its simple, its good, try it. Users/BobJames

20110630 19:07:13 nbsp Usually I love this place but I got two slices of pizza (one cheese, one veggie) last night and they were both pretty bad. The dough was really tough and hard to chew. I got through about half of each piece and had to give up. They were also even greasier than usual.

I still think Village Bakery has the best pizza in Davis but they need to work on being consistent. They also might want to consider dropping the credit card fee.

I definitely recommend the roasted red bell pepper and goat cheese pizza  I wish they sold it by the slice. Users/MeggoWaffle

20110822 07:08:18 nbsp My favorite pizza in Davis. Everything is great here from the slices, to the great pizzas you can order, to the cheap delicious desserts. Users/KurtG

20111210 16:27:04 nbsp Best, best, best ever. Users/KarbonMeatson

20111216 17:05:15 nbsp Pizza here is AWESOME! and great prices! Users/JeffA

20120127 14:16:48 nbsp Best veggie pizza ever. Users/RoamingDavisite

20120316 06:17:54 nbsp Just went to this place for the first time today. and I have to say it was a disappointment, not the food but rather the lack of it. In my experience when a bakery opens it already has some pastries out of the oven and ready for sale. But if you are hoping to get something to eat that isnt dessert or leftovers when waiting for an early morning Amtrak. You will have to wait until at least 6:30 before they even have anything fresh. Another thing to point out, dont get their cappuccino unless your like your morning coffee to taste like hot dirt. Users/HGibson

20120409 22:57:19 nbsp Simply the best bakery in town. The most savory focaccia bread on the planet. And one of the best veggie pizzas ever tasted. Its awesome making a quick stop here and just chilling at their outside patio :)  Users/MelannieLavarias

20120717 08:35:01 nbsp Great place for an inexpensive yet delicious slice of pizza or a french baguette to go.   Users/Trena

20120813 01:00:13 nbsp To me, sitting outside the bench with a slice of their pizza, watching the A bus drive by and the Amtrak train make a stop at the station made Village Bakery a great stop to grab a slice.  Users/Davekhuh

20121115 19:13:38 nbsp Ordered from them tonight for delivery.  The person on the phone spoke very poor English.  Nonetheless, over the course of a 5 minute phone call (seriously), I gave him my phone number, address and credit card number.  I was told the pizza would take an hour.  Over an hour later, I got a call from them.  Another person, again who spoke barely a word of English, told me he needed my credit card number again.  It took some time to make sure he got the numbers, again.  I told him I was concerned that they didnt have my address since they had trouble w/ my card number (yet apparently had no problem with my phone number, which I chalk up to caller ID).  He asked me for my address to make sure.  I gave it to him again and he confirmed they had it.  I asked if my pizza was on the way.  He said it was.  20 minutes later, I get another call.  This time, yet a THIRD person, who again spoke almost no English, asked me for my address.  At this point, I was been frustrated, but again gave it to him, with difficulty.

Miraculously, 15 minutes later, the pizza showed up.  Unfortunately, it was definitely not hot, but still really good pizza.  I will just pick my pizza up from this place in the future. Users/JMattson

20130527 23:18:47 nbsp They have good pizza, I always buy a slice whenever Im in town. However dont buy with a credit or debit card if youre only buying a slice of pizza or any other small thing. Always pay with cash even if you have to walk ten blocks to the nearest atm.  Users/Adnil

20130528 06:32:19 nbsp Nvm, never coming here again.  Users/Adnil

20131026 22:29:29 nbsp Although this place is my favorite for ordering pizza; I have to agree with another reviewer about the credit card. First I picked up, paid in the store, and saw a credit card charge of $5 extra, took it up with the manager who was hard to get a hold of, and it was finally returned to my credit card a few days later. He wanted me to come in, stating he couldnt return it to my card which can be done, but since it wasnt my mistake I made them take care of it. Second time same thing happened but I just went to pick up the cash. Now tonight I order for delivery, they already added the delivery charge, I left the tip in cash, yet I look at my credit card online somebody charged me an extra $8. If they do not know how to enter a number or are trying to make extra money maybe they shouldnt take credit cards. If purchasing I would also avoid using your credit card or debit card, and strictly pay in cash. As good as their pizza is I will continue to buy it, however something shady is going on at this business. I cannot debate that their pizza and pastries are the best I have had for over a year, but I dont exactly trust the credit card stuff since this is the third incident in a few months, and never occurred before when I used cash. If you have to use a credit card please pay close attention to what they charge, by checking your credit charges, and keep the receipt as proof.
My advice: use cash, pickup is better than delivery, and try the veggie its the best.Users/Sean23

20131213 12:34:49 nbsp I love the food here but the last two times I ordered I was charged an additional dollar when using my credit card, ON TOP of the $0.50 fee they add for using one. I dont know if this is management policy or the employees trying to skim money (charging an extra buck then taking one from the register), but it is a huge turn off. The girl at the register wearing an SF hat was the one who rang me up both times.  Users/bordiga

20131215 18:26:05 nbsp I tried to resolve this with the owner but the manager has acted as a gate keeper between myself and the owner and would not put me in touch with him. My credit card was overcharged $6 on a order I picked up from the store. I did not tip the cashier as I walked in, paid her, and picked up my pizza. She acted a bit strange when I drew a line through the tip line and totaled my credit card slip with the base amount. It struck me odd enough that I kept my receipt to check against my online credit card activity the next day. I rarely save receipts. I checked the charge after it posted to my account and sure enough it was different than my receipt by $6. I called my credit card company and they gave me a credit and will handle it from there. We enjoy pizza from this location at least 10 time a month. I have dealt with the rude spanish speaking employees that take your order, bark a total, and hang up before I can confirm it with them. We always chaulked it up as part of the Village Bakery experience. This however will not be tolerated. If the manager would have just taken the time to help me with this, gave me a credit, and checked up with the employee who did it, I would have been satisfied. But now I wonder how many people fall prey to employees helping themselves to a tip knowing that most people wont catch it. Village Bakery has lost us as a customer forever and I will be putting this out on social media and our food blog in the coming days. Bad move guys.... Users/MikeGee

20140318 23:52:39 nbsp Best pizza in Davis. Hands down. Users/RomanRivilis

max_stars_repo_name: voflo/Search

max_issues_repo_name: voflo/Search

max_forks_repo_name: voflo/Search


text:
Sadly, Payphone project payphones http://payphoneproject.com everywhere are a dying breed. The university is phasing out payphones because they are losing money with the nearly ubiquitous presence of mobile phones.

(from Payphone Project)

There used to be a South Silo Phone as well.


text:
      SUBROUTINE QREADI( NIN, NOUT, SIN,
     &  MAXST,MAXCOL, ISTORE, RSTORE,
     &  MAXTXT, MAXLEN, TXTNO, TXTLEN, TXTPOS, TXTDIR, TXTSTR, LABORT,
     &  DOTAT, SWITCH)
      IMPLICIT NONE
C ********************************************************************
C *                                                                  *
C * This software is an unpublished work containing confidential and *
C * proprietary information of Birkbeck College. Use, disclosure,    *
C * reproduction and transfer of this work without the express       *
C * written consent of Birkbeck College are prohibited. This notice  *
C * must be attached to all copies or extracts of the software.      *
C *                                                                  *
C * (c) 1993 Oliver Smart & Birkbeck College, All rights reserved    *
C * (c) 1996 Oliver Smart & Birkbeck College, All rights reserved    *
C *                                                                  *
C ********************************************************************
C
C Modification history:
C
C Date	Author		Modification
C 12/93	O.S. Smart	Original public release in HOLE suite beta1.0
C
C
      SAVE
C this s/r is called by program qplot - deals with reading
C information from hydra/quanta plot file already opened
C to stream SIN.

C passed variables

C user input/output streams returned unchanged
      INTEGER                   NIN, NOUT

C hydra binary file stream number
C The input file has been opened to this stream
C before this s/r is called - returned unchanged
      INTEGER                   SIN

C the store for move draws read
C MAXCOL - stores the maximum number of colours and
C it is assigned a value that MUST not be changed
C MAXST - is the maximum number of move draws to be stored
C         this is set a parameter in qplot and MUST not be changed
C istore( 1 to MAXCOL) is returned with the number of move
C    draws read for each colour
C rstore is the store for moves/draws
      INTEGER                   MAXST,MAXCOL
      INTEGER                   ISTORE(MAXCOL)
      REAL                      RSTORE( MAXST, 0:3, MAXCOL)
C store for text strings
C txtno             the number of strings stored
C txtlen(*)         the length of string *
C txtpos(1 to 3, *) the position of its anchor point in angs space
C txtdir(*)         an integer to indicate where the string should be
C                   placed on page 1 indicates below to the left
C                                  2 ............... centred etc.
C                   key 789
C                       456 (like a numeric keypad)
C                       123
C txtstr(*)         the string to be written
C the maximum number of strings
      INTEGER                   MAXTXT
C the maximum numbers of characters in each text string
      INTEGER                   MAXLEN
      INTEGER                   TXTNO
      INTEGER                   TXTLEN( MAXTXT)
      REAL                      TXTPOS( 3, MAXTXT)
      INTEGER                   TXTDIR( MAXTXT)
      CHARACTER*(*)             TXTSTR( MAXTXT)

C an abort indicator
C if we find a problem in this s/r return true
      LOGICAL                   LABORT

C variables internal to this routine

C a vector to read lines from quanta file
      REAL                      QVEC(0:3)

C the colour which move/draws should be read into
C - between 1 & MAXCOL
      INTEGER                   ICOL

C line for input
      CHARACTER*80              LINE80
C vble which states the level of difficulty to
C be applied to the sub-routine
      CHARACTER *1              SWITCH

C Vble which passes on the information whether
C there are "dot at" records in the file:
C -55555     means dots are processed into 3d crosses in s/r qreadi
C -ve no     dots should be processed into open circles (white centre)
C 0.0        no dots in file
C +ve number the point size for circles to which dots processed
C n.b. only deal with circle option here - crosses done in s/r qreadi
      REAL                       DOTAT

C size in angstroms of a cross
C (length of line)
      REAL			SCROSS

C end of declarations ********** (declarations above, exe's below)

C default colour is one
       ICOL = 1

C should allow the user to abort by an EOF on read
       LABORT = .TRUE.

C will jump back to this line until the end of file is meet
C when we jump to line 20 further down the program.
10    CONTINUE
C read the 4-vector from binary file
C if there is a problem got error statements at the end of this s/r
	READ( SIN, ERR= 900, END= 20) QVEC

C Is this a change of colour?
       IF     (QVEC(0).EQ.1.0) THEN
C quanta 3.3 produces its own title and lines at the end of the
C file - can detect this by a change to colour 1 while
C colour is set to 14
          IF ( (ICOL.EQ.14) .AND. (QVEC(1).EQ.1.0)) THEN
            IF (SWITCH.EQ.'E') THEN
C ask user whether rest of file should be read
	      WRITE( NOUT, '(A)')
     &' Detected what I think is rubbish at end of file'
	      CALL PROMPT( NOUT,
     &' Do you want this? (y/n) <n>: ')
              READ( NIN, '(A1)') LINE80(1:1)
              IF ( (LINE80(1:1).NE.'Y') .AND.
     &             (LINE80(1:1).NE.'y')) THEN
                LABORT = .FALSE.
                GOTO 55555
              ENDIF
            ELSE
C amateur - default to stop read
              LABORT = .FALSE.
	      GOTO 55555
   	    ENDIF
          ENDIF
C 24/10/95 - allow alternative colours for hole objects 15 to 20
C these are indicated by a -55 as second number and are in third
          IF (INT(QVEC(2)).EQ.-55) THEN
	    ICOL = INT(QVEC(3))
          ELSE
	    ICOL = INT(QVEC(1))
          ENDIF

C override the colours only if the SWITCH mode
C permits this
       IF(SWITCH.EQ.'E') THEN
C change of colour read
	  WRITE( NOUT, '(A,I6)')
     &' Have read change of colour to number ', ICOL
C do you want to change the colour?
	  CALL PROMPT( NOUT,
     &' Do you want to change the colour?'//
     &                 ' Enter new colour no. <no change>: ')
C read reply into line - to allow default
          READ( NIN, '(A)', ERR= 55555, END= 55555) LINE80
C has the user specified a number?
	  IF (LINE80(1:6).NE.'     ')
     &       READ( LINE80, '(BN,I8)', ERR= 55555) ICOL

C If the read colour is exceeding the boundaries (1:MAXCOL), it is reset here
	    IF   (ICOL.GT.MAXCOL) THEN
	      WRITE(NOUT,'(A,I8/,A,I8)')
     &' Exceeding the maximum colour number:'//CHAR(7),MAXCOL,
     &' I have set the colour to:',MAXCOL
	      ICOL=MAXCOL
	    ELSEIF  (ICOL.LT.1) THEN
	      WRITE(NOUT,'(A)')
     &' The read colour is below the minimum accepted - 1'//CHAR(7),
     &' I have set the colour to: 1'
	      ICOL=1
	    ENDIF
C end of 'switch' test commands
          ENDIF
C a move to or draw to or a dot at ?
      ELSEIF ( QVEC(0).EQ.2.0 .OR. QVEC(0).EQ.3.0
     &         .OR. QVEC(0).EQ.4.0) THEN
C add one more record to store
	  ISTORE(ICOL) = ISTORE(ICOL) + 1
C task1 test to make sure array bound not exceeded here
	  IF  (ISTORE(ICOL).GT.MAXST)  THEN
	    WRITE( NOUT ,'(A,I8/A/A)')
     &' Exceeding the maximum moves draws allowed :'//CHAR(7),MAXST,
     &' Please increase value of MAXST and recompile the program',
     &' QPLOT aborted'
	    LABORT=.TRUE.
	    GOTO 55555
	  ENDIF
C    end of test
	  RSTORE( ISTORE(ICOL), 0, ICOL) = QVEC(0)
	  RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1)
	  RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2)
	  RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)

C do we have a "dot at" record?
          IF (QVEC(0).EQ.4.) THEN
            IF (DOTAT.EQ.0.) THEN
C first time dot at record encountered
C default option for dotat records is a 1 point open circle
              DOTAT = -1.5
              IF (SWITCH.EQ.'E') THEN
C does the user want to overide default?
                WRITE( NOUT, '(A)')
     &'  ',
     &' Have encountered a dotat record in file.',
     &'   How do you want dots to be output?',
     &'   Enter ''C '' for 3D cross or ''D'' for dot'
                CALL PROMPT( NOUT,
     & '  Cross or Dot? <dot>:')
                READ( NIN, '(A1)', ERR= 55555, END= 55555) LINE80(1:1)
                CALL UCASE(LINE80(1:1))
                IF (LINE80(1:1).EQ.'C') THEN
C cross
                  DOTAT = -55555.
C what size?
                  SCROSS = 0.2
                  CALL PROMPT( NOUT,
     & '  What length (in angs) do you the cross? <0.2>:')
                  READ( NIN, '(A)', ERR= 55555, END= 55555) LINE80
C has the user specified a number?
	          IF (LINE80(1:6).NE.'     ')
     &              READ( LINE80, '(BN,F10.0)', ERR= 55555) SCROSS
C                  write(*,*) 'debug scross ', scross
                ELSE
C want a dot what point size
                  CALL PROMPT( NOUT,
     &'  What size dots (in points)? -ve for open dots <-1.5>:')
                  READ( NIN, '(A)', ERR= 55555, END= 55555) LINE80
C has the user specified a number?
	          IF (LINE80(1:6).NE.'     ')
     &              READ( LINE80, '(BN,F10.0)', ERR= 55555) DOTAT
C                  write(*,*) 'debug dotat  ', dotat
C end of dot or cross?
                ENDIF
C end of override default option if not amateur
              ENDIF
C end of first time cross encountered
            ENDIF
C produce a cross?
            IF (DOTAT.EQ.-55555.) THEN
C draw three lines for point
C (n.b. do not test for istore exceeding limit
C            - a bit naughty - could be changed)
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 2.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1) - 0.5*SCROSS
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2)
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)
              ISTORE(ICOL) = ISTORE(ICOL) + 1
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 3.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1) + 0.5*SCROSS
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2)
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)
C line in y
              ISTORE(ICOL) = ISTORE(ICOL) + 1
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 2.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1)
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2) - 0.5*SCROSS
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)
              ISTORE(ICOL) = ISTORE(ICOL) + 1
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 3.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1)
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2) + 0.5*SCROSS
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)
C line in z
              ISTORE(ICOL) = ISTORE(ICOL) + 1
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 2.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1)
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2)
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3)- 0.5*SCROSS
              ISTORE(ICOL) = ISTORE(ICOL) + 1
	      RSTORE( ISTORE(ICOL), 0, ICOL) = 3.0
              RSTORE( ISTORE(ICOL), 1, ICOL) = QVEC(1)
              RSTORE( ISTORE(ICOL), 2, ICOL) = QVEC(2)
	      RSTORE( ISTORE(ICOL), 3, ICOL) = QVEC(3) + 0.5*SCROSS
            ENDIF
          ENDIF
C character record
	ELSEIF (QVEC(0).EQ.5.0) THEN
C do we have to many strings?
	  IF (TXTNO.EQ.MAXTXT) THEN
	    WRITE( NOUT, '()')
     &' Have exceed maximum no of text strings ', MAXTXT,
     &' Please increase parameter MAXTXT in program QPLOT'
	    LABORT = .TRUE.
	    GOTO 55555
	  ENDIF
	  TXTNO = TXTNO + 1
C the second record read (qvec(1)) is the
C number of characters in the string
	  TXTLEN(TXTNO) = NINT(QVEC(1))
C the position for the string is the last move/draw record read
	  TXTPOS(1,TXTNO) = RSTORE( ISTORE(ICOL), 1, ICOL)
	  TXTPOS(2,TXTNO) = RSTORE( ISTORE(ICOL), 2, ICOL)
	  TXTPOS(3,TXTNO) = RSTORE( ISTORE(ICOL), 3, ICOL)
C the integer control on the direction to place text relative
C to ancor point is read as QVEC(3)
	  TXTDIR(TXTNO) = NINT(QVEC(3))
C read string from binary file
	  READ( SIN, ERR= 900) TXTSTR(TXTNO)(1:TXTLEN(TXTNO))
C quanta files have rubbish at the eof - try to detect above
C but if that fails detected by the fact that
C a one character blank string is specified
          IF ( (TXTLEN(TXTNO).EQ.1) .AND.
     &         (TXTSTR(TXTNO)(1:1).EQ.' ') ) THEN
            IF (SWITCH.EQ.'E') THEN
C ask user whether rest of file should be read
              WRITE( NOUT, '(A)')
     &' Detected what I think is rubbish at end of file (blank string)'
              CALL PROMPT( NOUT,
     &' Do you want this? (y/n) <n>: ')
              READ( NIN, '(A1)') LINE80(1:1)
              IF ( (LINE80(1:1).NE.'Y') .AND.
     &             (LINE80(1:1).NE.'y')) THEN
C ignore the last string
                TXTNO = TXTNO - 1
                LABORT = .FALSE.
                GOTO 55555
              ENDIF
            ELSE
C amateur - default to stop read
C ignore the last string
              TXTNO = TXTNO - 1
              LABORT = .FALSE.
              GOTO 55555
            ENDIF
          ENDIF

C 16 record - rgb for iris no use to us
	ELSEIF (QVEC(0).EQ.16.0) THEN
          CONTINUE
	ELSE
C do not understand record
	  WRITE( NOUT, '(A/ 4F12.3, A)')
     &' Do not recognize record read from quanta file: ',
     & QVEC,
     &' Will ignore & try to proceed'//CHAR(7)
	ENDIF
C read next record
	GOTO 10
C got to the end of input file
20    CONTINUE

C normal return no error
      LABORT = .FALSE.

55555 RETURN
900   CONTINUE
C include bleep in error message with char(7)
      WRITE( NOUT, '(A)')
     &' ***error***'//CHAR(7),
     &' On reading from quanta/hydra binary file',
     &' Format wrong?',
     &' Aborting'
      LABORT = .TRUE.
      END


text:
!
!     CalculiX - A 3-dimensional finite element program
!     Copyright (C) 1998-2015 Guido Dhondt
!
!     This program is free software; you can redistribute it and/or
!     modify it under the terms of the GNU General Public License as
!     published by the Free Software Foundation(version 2);
!
!
!     This program is distributed in the hope that it will be useful,
!     but WITHOUT ANY WARRANTY; without even the implied warranty of
!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!     GNU General Public License for more details.
!
!     You should have received a copy of the GNU General Public License
!     along with this program; if not, write to the Free Software
!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
      subroutine preinitialnet(ieg,lakon,v,ipkon,kon,nflow,prop,ielprop,
     &     ielmat,ntmat_,shcon,nshcon,rhcon,nrhcon,mi,iponoel,inoel,
     &     itg,ntg)
!
!     this routine only applies to compressible networks
!
!     determination of initial values based on the boundary conditions
!     and the initial values given by the user by propagating these
!     through the network (using information on the mass flow direction
!     derived from unidirectional network elements or mass flow given
!     by the user (boundary conditions or initial conditions))
!
!     a mass flow with size 1.d-30 is used to propagate the sign
!     of the mass flow (in case only the sign and not the size is known)
!
!     it is assumed that pressures, temperatures and mass flows cannot
!     be identically zero (a zero pressure does not make sense,
!     temperature has to be the absolute temperature,
!     a zero mass flow leads to convergence problems).
!
      implicit none
!
      character*8 lakon(*)
!
      integer mi(*),ieg(*),nflow,i,ielmat(mi(3),*),ntmat_,node1,node2,
     &     nelem,index,nshcon(*),ipkon(*),kon(*),nodem,imat,ielprop(*),
     &     nrhcon(*),neighbor,ichange,iponoel(*),inoel(2,*),indexe,
     &     itg(*),ntg,j,node,imin,imax
!
      real*8 prop(*),shcon(0:3,ntmat_,*),xflow,v(0:mi(2),*),cp,r,
     &     dvi,rho,rhcon(0:1,ntmat_,*),kappa,cti,Ti,ri,ro,p1zp2,omega,
     &     p2zp1,xmin,xmax
!
c      write(*,*) 'preinitialnet '
c      do i=1,ntg
c         write(*,'(i10,3(1x,e11.4))') itg(i),(v(j,itg(i)),j=0,2)
c      enddo
!
      do
         ichange=0
!
!        propagation of the pressure through the network
!
         do i=1,nflow
            nelem=ieg(i)
            indexe=ipkon(nelem)
!
            node1=kon(indexe+1)
            if(node1.eq.0) cycle
            nodem=kon(indexe+2)
            node2=kon(indexe+3)
            if(node2.eq.0) cycle
!
!           at least one total pressure value unknown in the element
!
            if(((v(2,node1).ne.0.d0).and.(v(2,node2).eq.0.d0)).or.
     &         ((v(2,node1).eq.0.d0).and.(v(2,node2).ne.0.d0))) then
!
               if(lakon(nelem)(2:3).eq.'OR') then
!
!               directional elements: small slope
!
                  if(v(2,node1).eq.0.d0) then
                     v(2,node1)=v(2,node2)*1.01d0
                  else
                     v(2,node2)=v(2,node1)*0.99d0
                  endif
                  ichange=1
                  if(v(1,nodem).eq.0.d0) v(1,nodem)=1.d-30
               elseif(lakon(nelem)(2:3).eq.'VO') then
!
!                 vortex: pressure ratio can be determined
!                 from geometry
!
                  index=ielprop(nelem)
!
                  if(prop(index+1).lt.prop(index+2)) then
!
!                    r2 < r1
!
                     if(v(0,node2).ne.0.d0) then
                        ri=prop(index+1)
                        ro=prop(index+2)
                        Ti=v(0,node2)
                        if(lakon(nelem)(4:5).eq.'FO') then
                           omega=prop(index+5)
                        else
                           omega=prop(index+7)
                        endif
!
                        imat=ielmat(1,nelem)
                        call materialdata_tg(imat,ntmat_,Ti,shcon,
     &                       nshcon,cp,
     &                       r,dvi,rhcon,nrhcon,rho)
!
                        kappa=cp/(cp-r)
                        cti=omega*ri
!
                        if(lakon(nelem)(4:5).eq.'FO') then
!
!                          forced vortex
!
                           p1zp2=(1.d0+cti**2*((ro/ri)**2-1.d0)/
     &                           (2.d0*cp*Ti))**(kappa/(kappa-1.d0))
                        else
!
!                          free vortex
!
                           p1zp2=(1.d0+cti**2*(1.d0-(ri/ro)**2)/
     &                           (2.d0*cp*Ti))**(kappa/(kappa-1.d0))
                        endif
!
                        if(v(2,node1).eq.0.d0) then
                           v(2,node1)=v(2,node2)*p1zp2
                        else
                           v(2,node2)=v(2,node1)/p1zp2
                        endif
                        ichange=1
                     endif
                  else
!
!                    r1 <= r2
!
                     if(v(0,node1).ne.0.d0) then
                        ri=prop(index+2)
                        ro=prop(index+1)
                        Ti=v(0,node1)
                        if(lakon(nelem)(4:5).eq.'FO') then
                           omega=prop(index+5)
                        else
                           omega=prop(index+7)
                        endif
!
                        imat=ielmat(1,nelem)
                        call materialdata_tg(imat,ntmat_,Ti,shcon,
     &                       nshcon,cp,
     &                       r,dvi,rhcon,nrhcon,rho)
!
                        kappa=cp/(cp-r)
                        cti=omega*ri
!
                        if(lakon(nelem)(4:5).eq.'FO') then
!
!                          forced vortex
!
                           p2zp1=(1.d0+cti**2*((ro/ri)**2-1.d0)/
     &                           (2.d0*cp*Ti))**(kappa/(kappa-1.d0))
                        else
!
!                          free vortex
!
                           p2zp1=(1.d0+cti**2*(1.d0-(ri/ro)**2)/
     &                           (2.d0*cp*Ti))**(kappa/(kappa-1.d0))
                        endif
!
                        if(v(2,node1).eq.0.d0) then
                           v(2,node1)=v(2,node2)/p2zp1
                        else
                           v(2,node2)=v(2,node1)*p2zp1
                        endif
                        ichange=1
                     endif
                  endif
               elseif(v(1,nodem).ne.0.d0) then
!
!                 mass flow is given (either size or just the
!                 direction): small slope
!
                  if(v(1,nodem).gt.0.d0) then
                     if(v(2,node1).eq.0.d0) then
                        v(2,node1)=v(2,node2)*1.01d0
                     else
                        v(2,node2)=v(2,node1)*0.99d0
                     endif
                  else
                     if(v(2,node1).eq.0.d0) then
                        v(2,node1)=v(2,node2)*0.99d0
                     else
                        v(2,node2)=v(2,node1)*1.01d0
                     endif
                  endif
                  ichange=1
               endif
            endif
         enddo
!
!        propagation of the mass flow through the network
!
         do i=1,nflow
            nelem=ieg(i)
            indexe=ipkon(nelem)
            nodem=kon(indexe+2)
!
            if(dabs(v(1,nodem)).le.1.d-30) then
!
!              no initial mass flow given yet
!              check neighbors for mass flow (only if not
!              branch nor joint)
!
!              first end node
!
               node1=kon(indexe+1)
!
               if(node1.ne.0) then
                  index=iponoel(node1)
!
                  if(inoel(2,inoel(2,index)).eq.0) then
!
!                 no branch nor joint; determine neighboring element
!
                     if(inoel(1,index).eq.nelem) then
                        neighbor=inoel(1,inoel(2,index))
                     else
                        neighbor=inoel(1,index)
                     endif
!
!                 initial mass flow in neighboring element
!
                     xflow=v(1,kon(ipkon(neighbor)+2))
!
                     if(dabs(v(1,nodem)).gt.0.d0) then
!
!                    propagate initial mass flow
!
                        if(dabs(xflow).gt.1.d-30) then
                           v(1,nodem)=xflow
                           ichange=1
                           cycle
                        endif
                     else
!
!                    propagate only the sign of the mass flow
!
                        if(dabs(xflow).gt.0.d0) then
                           v(1,nodem)=xflow
                           ichange=1
                           cycle
                        endif
                     endif
                  endif
               endif
!
!              second end node
!
               node2=kon(indexe+3)
!
               if(node2.ne.0) then
                  index=iponoel(node2)
!
                  if(inoel(2,inoel(2,index)).eq.0) then
!
!                 no branch nor joint; determine neighboring element
!
                     if(inoel(1,index).eq.nelem) then
                        neighbor=inoel(1,inoel(2,index))
                     else
                        neighbor=inoel(1,index)
                     endif
!
!                 initial mass flow in neighboring element
!
                     xflow=v(1,kon(ipkon(neighbor)+2))
!
                     if(dabs(v(1,nodem)).gt.0.d0) then
!
!                    propagate initial mass flow
!
                        if(dabs(xflow).gt.1.d-30) then
                           v(1,nodem)=xflow
                           ichange=1
                           cycle
                        endif
                     else
!
!                    propagate only the sign of the mass flow
!
                        if(dabs(xflow).gt.0.d0) then
                           v(1,nodem)=xflow
                           ichange=1
                           cycle
                        endif
                     endif
                  endif
               endif
            endif
         enddo
!
!        propagation of the temperature
!
         do i=1,nflow
            nelem=ieg(i)
            indexe=ipkon(nelem)
            node1=kon(indexe+1)
            if(node1.eq.0) cycle
            node2=kon(indexe+3)
            if(node2.eq.0) cycle
!
            if(((v(0,node1).ne.0.d0).and.(v(0,node2).ne.0.d0)).or.
     &         ((v(0,node1).eq.0.d0).and.(v(0,node2).eq.0.d0))) cycle
!
            nodem=kon(indexe+2)
!
            if(v(1,nodem).eq.0.d0) then
!
!              direction of mass flow unknown in the element
!
               cycle
            elseif(v(1,nodem).gt.0.d0) then
!
!              positive mass flow (i.e. going from node1 to node2)
!
               if(v(0,node1).eq.0.d0) cycle
!
!              propagating the temperature to node2
!
               v(0,node2)=v(0,node1)
               ichange=1
               cycle
            else
!
!              negative mass flow (i.e. going from node2 to node1)
!
               if(v(0,node2).eq.0.d0) cycle
!
!              propagating the temperature to node1
!
               v(0,node1)=v(0,node2)
               ichange=1
               cycle
            endif
         enddo
c         write(*,*) 'preinitialnet '
c         do i=1,ntg
c            write(*,'(i10,3(1x,e11.4))') itg(i),(v(j,itg(i)),j=0,2)
c         enddo
         if(ichange.eq.0) exit
      enddo
!
!     set of mass flow of +-1.d-30 to zero
!
      do i=1,nflow
         nelem=ieg(i)
         indexe=ipkon(nelem)
         nodem=kon(indexe+2)
         if(dabs(v(1,nodem)).eq.1.d-30) v(1,nodem)=0.d0
      enddo
!
!     check the pressures: set pressures to zero (i.e. no initial condtion)
!     which lie in between the neighboring pressures => Laplace method
!     is applied in initialnet
!
      loop: do i=1,ntg
         node=itg(i)
!
!        neighboring elements (excluding nodes which do not belong to
!        any network element or just to one network element (middle nodes)
!
         index=iponoel(node)
         if((index.eq.0).or.(inoel(2,index).eq.0)) cycle
!
         imin=node
         imax=node
         xmin=v(2,node)
         xmax=v(2,node)
!
         do
            nelem=inoel(1,index)
            if(lakon(nelem)(2:3).eq.'VO') cycle loop
            indexe=ipkon(nelem)
!
!           neighboring vertex node
!
            if(kon(indexe+1).ne.node) then
               neighbor=kon(indexe+1)
            else
               neighbor=kon(indexe+3)
            endif
            if(neighbor.eq.0) cycle loop
!
!           check its value
!
            if(dabs(v(2,neighbor)).lt.xmin) then
               xmin=dabs(v(2,neighbor))
               imin=neighbor
            elseif(dabs(v(2,neighbor)).gt.xmax) then
               xmax=dabs(v(2,neighbor))
               imax=neighbor
            endif
!
            index=inoel(2,index)
            if(index.eq.0) exit
         enddo
!
!        if value lies in between the neighboring values => assign a
!        negative sign as marker
!
         if((imin.ne.node).and.(imax.ne.node)) then
            v(2,node)=-v(2,node)
         endif
      enddo loop
!
!     set marked values to zero => Laplace equation will be used
!     in initialnet.f
!
      do i=1,ntg
         node=itg(i)
         index=iponoel(node)
         if((index.eq.0).or.(inoel(2,index).eq.0)) cycle
c         if(v(2,node).lt.0.d0) v(2,node)=0.d0
         if(v(2,node).lt.0.d0) v(2,node)=-v(2,node)
      enddo
c         write(*,*) 'preinitialnet end '
c         do i=1,ntg
c            write(*,'(i10,3(1x,e11.4))') itg(i),(v(j,itg(i)),j=0,2)
c         enddo
!
!     same for temperatures?
!
      return
      end

max_stars_repo_name: alleindrach/calculix-desktop

max_issues_repo_name: alleindrach/calculix-desktop

max_forks_repo_name: alleindrach/calculix-desktop


text:
I work at UC Davis and enjoy photography and scuba diving. I am married and have 3 dogs; Randolph, Wally and Rachel. I am especially interested in black and white, nature, abstract, and macro photography. I shot Canon for many years and recently switched to The Dark Side.

http://jaustin.zenfolio.com/img/v0/p2431420163.jpg

http://jaustin.zenfolio.com/img/v3/p7554914154.jpg

http://jaustin.zenfolio.com/img/v0/p9016329823.jpg

http://jaustin.zenfolio.com/img/v0/p10691621513.jpg


text:
      SUBROUTINE FBSINT (X,Y)
C
C     GIVEN THE DECOMPOSITION OF A REAL SYMMETRIC MATRIX, FBSINT WILL
C     SOLVE A SYSTEM OF SIMULTANEOUS LINEAR EQUATIONS BY FORWARD-
C     BACKWARD SUBSTITUTION
C
C     THIS ROUTINE IS SUITABLE FOR BOTH SINGLE AND DOUBLE PRECISION
C     OPERATION
C
      INTEGER         FILEL     ,IBLK(15)
      REAL            X(1)      ,Y(1)
      COMMON /INFBSX/ FILEL(7)
      COMMON /FBSX  / LFILE(7)
      EQUIVALENCE     (FILEL(3) ,NROW)
C
      NROW2 = NROW
      IF (FILEL(5) .EQ. 2) NROW2 = 2*NROW
      DO 100 I = 1,NROW2
      Y(I) = X(I)
  100 CONTINUE
      DO 120 I = 1,7
      LFILE(I) = FILEL(I)
  120 CONTINUE
      CALL REWIND (FILEL)
      CALL SKPREC (FILEL,1)
      IBLK(1) = FILEL(1)
      IF (FILEL(5) .EQ. 1) CALL FBS1 (IBLK,Y,Y,NROW2)
      IF (FILEL(5) .EQ. 2) CALL FBS2 (IBLK,Y,Y,NROW2)
      RETURN
      END


text:
C
C $Id: agkurv.f,v 1.9 2008-07-27 00:14:34 haley Exp $
C
C                Copyright (C)  2000
C        University Corporation for Atmospheric Research
C                All Rights Reserved
C
C The use of this Software is governed by a License Agreement.
C
      SUBROUTINE AGKURV (XVEC,IIEX,YVEC,IIEY,NEXY,SVAL)
C
      DIMENSION XVEC(1),YVEC(1)
C
C AGKURV plots the curve defined by the points ((X(I),Y(I)),I=1,NEXY),
C where
C
C    X(I)=XVEC(1+(I-1)*IIEX) (unless IIEX=0, in which case X(I)=I), and
C    Y(I)=YVEC(1+(I-1)*IIEY) (unless IIEY=0, in which case Y(I)=I).
C
C If, for some I, X(I)=SVAL or Y(I)=SVAL, curve line segments having
C (X(I),Y(I)) as an endpoint are omitted.
C
C No windowing is performed.
C
C Check first whether the number of curve points is properly specified.
C
      IF (NEXY.LE.0) GO TO 901
C
C Initialization.  Pretend that the last point was point number zero.
C Set the indices for the x and y vectors accordingly.  Clear the line-
C drawn-to-last-point flag.
C
      INDP=0
      INDX=1-IIEX
      INDY=1-IIEY
      LDLP=0
C
C Initialization.  Retrieve the current curve window, user window, and
C x/y linear/logarithmic flags.
C
      CALL GETSET (XLCW,XRCW,YBCW,YTCW,XLUW,XRUW,YBUW,YTUW,LTYP)
C
C Initialization.  Set linear/log flag and linear-window limits for
C x-axis values.
C
      IF (LTYP.EQ.1.OR.LTYP.EQ.2) THEN
        LLUX=0
        XLLW=XLUW
        XRLW=XRUW
      ELSE
        LLUX=1
        XLLW=ALOG10(XLUW)
        XRLW=ALOG10(XRUW)
      END IF
C
C Initialization.  Set linear/log flag and linear-window limits for
C y-axis values.
C
      IF (LTYP.EQ.1.OR.LTYP.EQ.3) THEN
        LLUY=0
        YBLW=YBUW
        YTLW=YTUW
      ELSE
        LLUY=1
        YBLW=ALOG10(YBUW)
        YTLW=ALOG10(YTUW)
      END IF
C
C Initialization.  Call SET, if necessary, to define a linear mapping.
C
      IF (LTYP.NE.1) THEN
        CALL PLOTIT (0,0,2)
        CALL SET (XLCW,XRCW,YBCW,YTCW,XLLW,XRLW,YBLW,YTLW,1)
      END IF
C
C Beginning of loop through points.  Update indices and determine the
C user-space coordinates of the next point.
C
  101 IF (INDP.EQ.NEXY) GO TO 102
      INDP=INDP+1
C
      INDX=INDX+IIEX
      XNXT=XVEC(INDX)
      IF (IIEX.EQ.0) XNXT=REAL(INDP)
      IF (LLUX.NE.0.AND.XNXT.LE.0.) XNXT=SVAL
C
      INDY=INDY+IIEY
      YNXT=YVEC(INDY)
      IF (IIEY.EQ.0) YNXT=REAL(INDP)
      IF (LLUY.NE.0.AND.YNXT.LE.0.) YNXT=SVAL
C
C Check whether (XNXT,YNXT) is a special-value point.  Handle that case.
C
      IF (XNXT.EQ.SVAL.OR.YNXT.EQ.SVAL) THEN
        IF (LDLP.EQ.0) GO TO 101
        IF (LDLP.EQ.1) CALL VECTD (XLST,YLST)
        CALL LASTD
        LDLP=0
        GO TO 101
      END IF
C
C If user space is not linear/linear, modify XNXT and YNXT accordingly.
C
      IF (LLUX.NE.0) XNXT=ALOG10(XNXT)
      IF (LLUY.NE.0) YNXT=ALOG10(YNXT)
C
C Start or continue line.
C
      IF (LDLP.EQ.0) THEN
        CALL FRSTD (XNXT,YNXT)
        XLST=XNXT
        YLST=YNXT
      ELSE
        CALL VECTD (XNXT,YNXT)
      END IF
C
      LDLP=LDLP+1
      GO TO 101
C
C Last point was final point.  Finish up.
C
  102 IF (LDLP.NE.0) THEN
        IF (LDLP.EQ.1) CALL VECTD (XLST,YLST)
        CALL LASTD
      END IF
C
C Restore logarithmic mapping, if appropriate.
C
      IF (LTYP.NE.1) THEN
        CALL PLOTIT (0,0,2)
        CALL SET (XLCW,XRCW,YBCW,YTCW,XLUW,XRUW,YBUW,YTUW,LTYP)
      END IF
C
C Return to caller.
C
      RETURN
C
C Error exit.
C
  901 CALL SETER ('AGKURV - NUMBER OF POINTS IS LESS THAN OR EQUAL TO ZE
     +RO',3,2)
C
      END

max_stars_repo_name: tenomoto/ncl

max_issues_repo_name: tenomoto/ncl

max_forks_repo_name: tenomoto/ncl


text:
      SUBROUTINE GRID
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INCLUDE 'SIZES'
************************************************************************
*
*  GRID CALCULATES THE ENERGY-SURFACE RESULTING FROM VARIATION OF
*       TWO COORDINATES. THE STEP-SIZE IS STEP1 AND STEP2, AND A 11
*       BY 11 GRID OF POINTS IS GENERATED
*
* 	This subroutine is extensively modified by Manyin Yi, Aug 1989.
*
* 	New features:
*      1. The input geometry definition should always be the upper-left
*	   corner(smallest coordinates) instead of the middle point;
*	2. The starting point for calculation can be one of the four
*	   corners by setting "+/-" STEP1/2;
*	3. The grid size(max 23*23) is controlled by POINT1/2,
*	   if POINT1/2 is omitted, then a size of 11*11 is assumed;
*	   kwd MAX sets the max size;
*	4. The upper-left corner of the plotting grid always corresponds
*	   to the smallest coordinates, the lower-right corner to the
*	   largest, no matter where the calculation starts;
*	5. Restartable.
*       6. Write out UNIMAP irregular data UMP.DAT
*
************************************************************************
      COMMON /GEOM  / GEO(3,NUMATM)
      COMMON /GEOVAR/ NVAR,LOC(2,MAXPAR), IDUMY, XPARAM(MAXPAR)
      COMMON /GRADNT/ GRAD(MAXPAR),GNORM
      COMMON /GRAVEC/ COSINE
      COMMON /MESH  / LATOM1, LPARA1, LATOM2, LPARA2
      COMMON /GPARAM/ CURRT1,CURRT2
      COMMON /IJLP  / IJLP, ILP, JLP, JLP1, IONE
      COMMON /SURF  / SURF
      COMMON /KEYWRD/ KEYWRD
      COMMON /TITLES/ KOMENT, TITLE
      CHARACTER KEYWRD*241, KOMENT*81, TITLE*81, GETNAM*80
      LOGICAL RESTRT
      DIMENSION GD(MAXPAR),XLAST(MAXPAR),MDFP(20),XDFP(20)
      DIMENSION SURFAC(23,23)
      DIMENSION SURF(23*23)
      DIMENSION UMPX(23),UMPY(23),UMPZ(23*23)
C
      STEP1=READA(KEYWRD,INDEX(KEYWRD,'STEP1')+6)
      STEP2=READA(KEYWRD,INDEX(KEYWRD,'STEP2')+6)
      NPTS1=11
      NPTS2=11
      IF (INDEX(KEYWRD,' MAX').NE.0) THEN
         NPTS1=23
         NPTS2=23
         GOTO 10
      ENDIF
      IF (INDEX(KEYWRD,'POINT1').NE.0)
     1 NPTS1=ABS(READA(KEYWRD,INDEX(KEYWRD,'POINT1')+7))
      IF (INDEX(KEYWRD,'POINT2').NE.0)
     1 NPTS2=ABS(READA(KEYWRD,INDEX(KEYWRD,'POINT2')+7))
   10 RESTRT=(INDEX(KEYWRD,'RESTART').NE.0)
C
C  THE TOP-LEFT VALUE OF THE FIRST AND SECOND DIMENSIONS ARE
C      GEO(LPARA1,LATOM1) AND GEO(LPARA2,LATOM2)
C
      UMPY(1)=GEO(LPARA1,LATOM1)
      UMPX(1)=GEO(LPARA2,LATOM2)
      DEGREE=180.D0/3.14159265359D0
      IF(LPARA1.NE.1)STEP1=STEP1/DEGREE
      IF(LPARA2.NE.1)STEP2=STEP2/DEGREE
C
C  NOW SET THE STARTING POINT TO THE DESIRED CORNER
C
      IF(STEP1.GT.0.0.AND.STEP2.GT.0.0) THEN
         START1=GEO(LPARA1,LATOM1)
         START2=GEO(LPARA2,LATOM2)
      ENDIF
C BOTTOM-LEFT
      IF(STEP1.LT.0.0.AND.STEP2.GT.0.0)THEN
         START1=GEO(LPARA1,LATOM1)+(NPTS1-1)*(ABS(STEP1))
         START2=GEO(LPARA2,LATOM2)
      ENDIF
C TOP-RIGHT
      IF(STEP1.GT.0.0.AND.STEP2.LT.0.0)THEN
         START1=GEO(LPARA1,LATOM1)
         START2=GEO(LPARA2,LATOM2)+ABS((NPTS2-1)*STEP2)
      ENDIF
C BOTTOM-RIGHT
      IF(STEP1.LT.0.0.AND.STEP2.LT.0.0)THEN
         START1=GEO(LPARA1,LATOM1)+ABS((NPTS1-1)*STEP1)
         START2=GEO(LPARA2,LATOM2)+ABS((NPTS2-1)*STEP2)
      ENDIF
C
C  NOW TO SWEEP THROUGH THE GRID OF POINTS LEFT TO RIGHT THEN RIGHT
C  TO LEFT OR VISA VERSA. THIS SHOULD AVOID THE GEOMETRY OR SCF GETTING
C  MESSED UP.
C
      IF(LPARA1.NE.1) THEN
         C1=DEGREE
      ELSE
         C1=1.D0
      ENDIF
      IF(LPARA2.NE.1) THEN
         C2=DEGREE
      ELSE
         C2=1.D0
      ENDIF
C   THESE PARAMETERS NEED TO BE DUMPED IN '.RES'
      CURRT1=START1
      CURRT2=START2
      IONE=-1.D0
      CPUTOT=0.0
      IJLP=0
      ILP=1
      JLP=1
      JLP1=1
      SURF(1)=0.D0
C
      IF (RESTRT) THEN
         MDFP(9)=0
         CALL DFPSAV(CPUTOT,XPARAM,GD,XLAST,ESCF,MDFP,XDFP)
      ENDIF
C
      GEO(LPARA1,LATOM1)=CURRT1
      GEO(LPARA2,LATOM2)=CURRT2
      DO 30 ILOOP=ILP,NPTS1
         IONE=-IONE
         DO 20 JLOOP=JLP,NPTS2
            JLOOP1=0
            IF(IONE.LT.0)JLOOP1=NPTS2+1
            IF(RESTRT) THEN
               JLOOP1=JLP1
               IONE=-IONE
               RESTRT=.FALSE.
            ELSE
               JLOOP1=JLOOP1+IONE
               JLP1=JLOOP1
            ENDIF
            CPU1=SECOND()
            CURRT1=GEO(LPARA1,LATOM1)
            CURRT2=GEO(LPARA2,LATOM2)
            CALL FLEPO(XPARAM, NVAR, ESCF)
            CPU2=SECOND()
            CPU3=CPU2-CPU1
            CPUTOT=CPUTOT+CPU3
            JLP=JLP+1
            IJLP=IJLP+1
            SURF(IJLP)=ESCF
            WRITE(6,'(/''       FIRST VARIABLE   SECOND VARIABLE
     1 FUNCTION'')')
            WRITE(6,'('' :'',F16.5,F16.5,F16.6)')GEO(LPARA1,LATOM1)*C1,
     1        GEO(LPARA2,LATOM2)*C2,ESCF
            CALL GEOUT(6)
            GEO(LPARA2,LATOM2)=GEO(LPARA2,LATOM2)+STEP2*IONE
   20    CONTINUE
         GEO(LPARA1,LATOM1)=GEO(LPARA1,LATOM1)+STEP1
         GEO(LPARA2,LATOM2)=GEO(LPARA2,LATOM2)-STEP2*IONE
         ILP=ILP+1
         JLP=1
   30 CONTINUE
      WRITE(6,'(/10X,''HORIZONTAL: VARYING SECOND PARAMETER,'',
     1          /10X,''VERTICAL:   VARYING FIRST PARAMETER'')')
      WRITE(6,'(/10X,''WHOLE OF GRID, SUITABLE FOR PLOTTING'',//)')
C
C  ARCHIVE
      OPEN(UNIT=12,FILE=GETNAM('FOR012'),STATUS='UNKNOWN')
      OPEN(UNIT=20,FILE=GETNAM('FOR020'),STATUS='NEW',ERR=31)
      GOTO 32
  31  OPEN(UNIT=20,FILE=GETNAM('FOR020'),STATUS='OLD')
  32  CONTINUE
      WRITE(12,40)
      CALL WRTTXT(12)
   40 FORMAT(' ARCHIVE FILE FOR GRID CALCULATION'/'GRID OF HEATS'/)
      WRITE(12,'(/'' TOTAL CPU TIME IN FLEPO : '',F10.3/)') CPUTOT
C
C  WRITE OUT THE GRIDS
      IONE=1.D0
      ILOOP=1
      JLOOP1=1
      DO 50 IJ=1,NPTS1*NPTS2
         SURFAC(JLOOP1,ILOOP)=SURF(IJ)
         N=IJ-(IJ/NPTS2)*NPTS2
         IF (N.EQ.0) THEN
            ILOOP=ILOOP+1
            JLOOP1=JLOOP1+IONE
            IONE=-IONE
         ENDIF
         JLOOP1=JLOOP1+IONE
   50 CONTINUE
C
      DO 60 I=2,NPTS1
   60 UMPY(I)=UMPY(1)+(I-1)*ABS(STEP1)
      DO 70 I=2,NPTS2
   70 UMPX(I)=UMPX(1)+(I-1)*ABS(STEP2)
      N=0
      IF(STEP1.GT.0.0.AND.STEP2.GT.0.0) THEN
         DO 90 I=1,NPTS1
            DO 80 J=1,NPTS2
               N=N+1
   80       UMPZ(N)=SURFAC(J,I)
            WRITE(6,'(11F7.2)')(SURFAC(J,I),J=1,NPTS2)
   90    WRITE(12,'(11F7.2)')(SURFAC(J,I),J=1,NPTS2)
      ENDIF
      IF(STEP1.LT.0.0.AND.STEP2.GT.0.0) THEN
         DO 110 I=NPTS1,1,-1
            DO 100 J=1,NPTS2
               N=N+1
  100       UMPZ(N)=SURFAC(J,I)
            WRITE(6,'(11F7.2)')(SURFAC(J,I),J=1,NPTS2)
  110    WRITE(12,'(11F7.2)')(SURFAC(J,I),J=1,NPTS2)
      ENDIF
      IF(STEP1.GT.0.0.AND.STEP2.LT.0.0) THEN
         DO 130 I=1,NPTS1
            DO 120 J=NPTS2,1,-1
               N=N+1
  120       UMPZ(N)=SURFAC(J,I)
            WRITE(6,'(11F7.2)')(SURFAC(J,I),J=NPTS2,1,-1)
  130    WRITE(12,'(11F7.2)')(SURFAC(J,I),J=NPTS2,1,-1)
      ENDIF
      IF(STEP1.LT.0.0.AND.STEP2.LT.0.0) THEN
         DO 150 I=NPTS1,1,-1
            DO 140 J=NPTS2,1,-1
               N=N+1
  140       UMPZ(N)=SURFAC(J,I)
            WRITE(6,'(11F7.2)')(SURFAC(J,I),J=NPTS2,1,-1)
  150    WRITE(12,'(11F7.2)')(SURFAC(J,I),J=NPTS2,1,-1)
      ENDIF
      DO 160 I=0,NPTS1-1
         DO 160 J=1,NPTS2
            N=I*NPTS2+J
  160 WRITE(20,'(3(1X,F8.3))')UMPX(J),UMPY(I+1),UMPZ(N)
      CLOSE(20)
      END

max_stars_repo_name: openmopac/MOPAC-archive

max_issues_repo_name: openmopac/MOPAC-archive

max_forks_repo_name: openmopac/MOPAC-archive


text:
Many colleges at UC Davis limit coursework (including transferred courses) to 225 units within a four year undergraduate career.  Registering for classes beyond the limit requires permission of the Deans dean. The easiest way to exceed the limit is to enter your twelfth quarter with no more than 224.5 units.  Getting permission to break the limit otherwise can be very difficult.

A hold is usually put on ones registration after completing 200 units.  A petition with a quarterbyquarter plan is required to remove the hold.  Even if the petition is granted, a hold will be placed on your registration every quarter to ensure adherence to the quarterbyquarter plan.  To get the hold removed, contact your deans office.  Even though you may be able to register for classes while a hold is on your record, if it is not cleared by the deadline you can be dropped from your classes.

The following colleges enforce the unit limit:
  Letters and Science
  College of Biological Sciences Biological Sciences
  College of Agricultural and Environmental Sciences Agricultural and Environmental Sciences

The College of Engineering does not enforce the unit limit, as majors are large and it can be difficult for students to get into the classes they need to graduate.

Advanced Placement^Tm^ exams do not count towards the unit limit, however they will still cause the 200 and 225 unit holds to be placed on a students record.

  Find out more about UC Davis Academics


text:
program Octal
  implicit none

  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0

! Will stop when n overflows from
! 9223372036854775807 to -92233720368547758078 (1000000000000000000000 octal)
  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program

max_issues_repo_name: seanwallawalla-forks/RosettaCodeData

max_forks_repo_name: seanwallawalla-forks/RosettaCodeData


text:
   program mpactxmf
   use hdf5
   use mod_hdftools
   implicit none
!=======================================================================
!
!  Program to read an existing MPACT HDF output file and
!   generate a mesh file and XMF file for plotting with VISIT or PARAVIEW
!
!  Copyright (c) 2014-2015 Core Physics, Inc.
!
!  Distributed under the MIT license.
!  See the LICENSE file in the main directory for details.
!
!=======================================================================
!
!  2014/07/18 - original file based on ctfxmf
!  2014/07/24 - moved grid to separate HDF file
!  2014/07/25 - added support for multiple statepoints
!  2014/07/26 - create multiple xmf files when multiple statepoints
!                are found so we can generate movies
!
!  Usage:
!    mpactxmf.exe [file.h5]
!
!  This will create two new files:
!     file.grid.h5
!     file.h5.xmf
!
!  If there are more than one statepoint, multiple xmf files will be generated
!
!  Open the xmf file in either visit or paraview
!
!=======================================================================

      character(len=120):: filename      ! HDF File name
      character(len=120):: gridfile      ! HDF grid File name
      character(len=40) :: dataset       ! dataset name

      integer(hid_t)    :: file_id       ! File identifier
      integer           :: idims(10)     ! Dataset dimensions (use with h5info)
      integer           :: ndim

      integer :: ll
      integer :: ia
      integer :: itype
      integer :: ierror

      logical :: ifxst

      integer :: naxial
      integer :: nassm
      integer :: npin
      integer :: nnrod    ! number of nodes in rod mesh
      integer :: nstate   ! number of statepoints

      real(8) :: xexp

      character(len=12) :: state_name

!--- Initialize HDF fortran interface.

      call h5open_f(ierror)
      if (ierror.ne.0) stop 'ierror: h5open_f'

!--- read existing HDF data filename from command line

      ia=iargc()
      if (ia.ne.1) stop 'usage: mpactxmf [file.h5]'
      call getarg(1,filename)

      ll=len_trim(filename)
      if (filename(ll-2:ll).ne.'.h5') then
        write (0,*) 'filename must end with .h5'
        stop 'invalid HDF filename'
      endif

      gridfile=filename(1:ll-3)//'.grid.h5'

!--- open HDF data file

      write (*,'(2a)') 'reading h5 file: ', trim(filename)
      inquire(file=filename, exist=ifxst)
      if (.not.ifxst) then
        write (*,'(3a)') 'error: input file ',trim(filename),' does not exist'
        stop
      endif
      call h5fopen_f (filename, H5F_ACC_RDONLY_F, file_id, ierror)
      if (ierror.lt.0) then
        write (*,'(3a)') 'error: H5 input file ',trim(filename), ' could not be opened'
        stop
      endif

!--- check if first statepoint exists (it should always exist)

      nstate=1
      call make_state_name(state_name, nstate)

      call h5lexists_f(file_id, state_name, ifxst, ierror)
      if (.not.ifxst) then
         stop 'statepoint data does not exist on file'
      endif

!--- read pin dimensions from pin power array

      dataset=trim(state_name)//'pin_powers'
      call h5info(file_id, dataset, itype, ndim, idims)

!d    write (*,*) 'idim: ', idims(1:ndim)

      nassm =idims(1)         ! order (nassm, naxial, npin, npin)
      naxial=idims(2)
      npin  =idims(4)

      write (*,20) 'ndim  ', ndim
      write (*,20) 'nassm ', nassm
      write (*,20) 'naxial', naxial
      write (*,20) 'npin  ', idims(3)
      write (*,20) 'npin  ', npin
   20 format (' debug pin: ', a, '=', i6)

      if (ndim.ne.4) stop 'invalid dimensions in pin data'
      if (npin.eq.0) stop 'invalid number of pins in pin data'
      if (idims(3).ne.idims(4)) stop 'invalid npin in pin data'

!--- write XMFMESH data to a separate grid file

      call coordinates(file_id, gridfile, nassm, naxial, npin, nnrod)

!--- find number of statepoints on file

      do

! read exposure value at this statepoint

        dataset=trim(state_name)//'exposure_efpd'
        call hdf5_read_double  (file_id, dataset, xexp)
        write (*,'(2a,f12.5)') trim(dataset), ' exposure ', xexp

! write xmf file

        call write_xmf(npin, npin, naxial, nassm, nnrod, filename, gridfile, nstate, xexp)

! check if the next state exists

        call make_state_name(state_name, nstate+1)
        call h5lexists_f(file_id, state_name, ifxst, ierror)
        if (.not.ifxst) exit
        nstate=nstate+1

      enddo
      write (*,*) 'nstate=', nstate

!--- close HDF file

      call h5fclose_f(file_id, ierror)
      write (*,'(2a)') ' finished reading HDF file: ', trim(filename)

!--- close fortran interface.

      call h5close_f(ierror)

!-----------------------------

      end
!=======================================================================
!
!  Subroutine to create a statepoint string in the form '/STATE_0000/'
!
!=======================================================================
      subroutine make_state_name(state_name, nstate)
      implicit none
      integer,          intent(in)  :: nstate
      character(len=*), intent(out) :: state_name

      state_name='/STATE_0000/'
      write (state_name(8:11),'(i4.4)') nstate

      return
      end subroutine make_state_name
!=======================================================================
!
!  Subroutine to write grid coordinates to XMFMESH group
!  Needed for xdmf plotting
!
!=======================================================================

      subroutine coordinates(file_id, gridfile, nassm, naxial, npin, nnrod)
      use hdf5
      use mod_hdftools
      implicit none
      integer(hid_t),   intent(in)  :: file_id       ! File identifier
      character(len=*), intent(in)  :: gridfile      ! grid file name
      integer,          intent(in)  :: nassm, naxial, npin
      integer,          intent(out) :: nnrod         ! output number of rod grids

!--- local

      integer :: i, j, k
      integer :: na              ! assembly number
      integer :: nn
      integer :: iasm, jasm      ! number of assemblies in x and y direction
      integer :: nkoff           ! axial node offset
      integer :: npl             ! number of nodes in a plane
      integer :: nnodes
      integer :: ia, ip, ja, jp
      integer :: ierror

      real(8) :: delta

      real(8), allocatable :: zbounds(:)      ! axial bounds (naxial+1)

      real,    allocatable :: xyz(:,:)        ! single precision
      real(8), allocatable :: xi(:)
      real(8), allocatable :: yi(:)
      integer, allocatable :: gg(:,:,:,:,:)   ! map nodes to cells
      integer, allocatable :: ijk(:,:,:,:)
      integer, allocatable :: mapassm(:,:)    ! assembly map
      integer, allocatable :: itemp(:,:)
      integer, allocatable :: nodemap(:,:)

      character(len=12) :: group_name
      character(len=40) :: dataset       ! Dataset name
      integer           :: idims(10)     ! Dataset dimensions
      integer(hid_t)    :: grid_id       ! Grid File identifier
      integer(hid_t)    :: group_id      ! Group identifier

      integer :: ndim
      integer :: itype
      integer :: itmp   ! temporary storage
      integer :: isym   ! core symmetry
      integer :: ioff   ! core symmetry

      logical :: ifxst

      nnodes=0
      nnrod=0

      delta=1.26d0  ! ************ temp fix: assumed pin pitch

!--- check if CORE exists, if not, do special fixup

      dataset='/CORE'
      call h5lexists_f(file_id, dataset, ifxst, ierror)
      if (.not.ifxst) then
        write (0,*) '*** CORE group does not exist - performing fixup ***'

        isym=1
        iasm=1
        jasm=1

        if (nassm.ne.1) then
          write (*,*) 'CORE fixup will only work with one assembly'
          stop 'CORE fixup will only work with one assembly'
        endif
        if (naxial.ne.1) then
          write (*,*) 'CORE fixup will only work with 2D problems'
          stop 'CORE fixup will only work with 2D problems'
        endif

        allocate (mapassm(iasm,jasm))    ! define assembly map
        mapassm(1,1)=1

        allocate (zbounds(0:naxial))
        zbounds(0)=0.0d0
        zbounds(1)=1.0d0

        goto 30
      endif

!--- read core symmetry

      dataset='/CORE/core_sym'
      call hdf5_read_integer (file_id, dataset, isym)

      write (*,*) 'core symmetry = ', isym

!--- read core map

      dataset='/CORE/core_map'
      call h5info(file_id, dataset, itype, ndim, idims)

      if (ndim.ne.2) then
        write (*,*) 'debug: ndim=', ndim
        write (*,*) 'debug: core_map dims ', idims(1:ndim)
        stop 'invalid core map dimensions'
      endif

      jasm=idims(1)   ! C-order
      iasm=idims(2)

      if (iasm.ne.jasm) stop 'only square cores are supported'

      allocate (mapassm(iasm,jasm))    ! define assembly map
      mapassm=0
      call hdf5_read_integer (file_id, dataset, jasm, iasm, mapassm)

!  map is in "C-order" so we need to transpose into "Fortran-order"

      na=0
      do j=1, jasm
        do i=1, iasm
           if (i.ne.j) then
             itmp=mapassm(i,j)      ! transpose
             mapassm(i,j)=mapassm(j,i)
             mapassm(j,i)=itmp
           endif
           na=max(na,mapassm(i,j))
        enddo
      enddo

      if (na.ne.nassm) stop 'error in assembly map numbers'

      write (*,*) 'full-core assembly map'
      do j=1, jasm
        write (*,'(3x,50i4)') (mapassm(i,j),i=1, iasm)
      enddo

!--- assembly map on file is always full-core
!--- decrease map size if qtr-symmetry

      if (isym.eq.4) then

        jasm=(iasm+1)/2    ! core must be square - reduce j but keep i the same
        ioff=iasm-jasm

        allocate (itemp(jasm,jasm))
        do j=1, jasm
          do i=1, jasm
            itemp(i,j)=mapassm(i+ioff,j+ioff)
          enddo
        enddo
        deallocate (mapassm)
        iasm=jasm   ! decrease i also
        allocate (mapassm(iasm,jasm))
        mapassm=itemp
        deallocate (itemp)

        write (*,*) 'qtr-core assembly map'
        do j=1, jasm
          write (*,'(3x,50i4)') (mapassm(i,j),i=1, iasm)
        enddo

      endif

!--- allocate and read axial cell heights

      allocate (zbounds(0:naxial))

      dataset='/CORE/axial_mesh'
      call hdf5_read_double(file_id, dataset, naxial+1, k, zbounds)
      if (k.ne.naxial+1) stop 'invalid axial_mesh size'

      write (*,*) 'debug: axial elevations [cm]'
      do k=naxial, 0, -1
         write (*,'(i4,f12.6)') k, zbounds(k)
      enddo

  30 continue   ! end of fix-up if CORE does not exist

!-----------------------------------------------------------------------
!    Create Rod Mesh
!-----------------------------------------------------------------------

!--- create 2D map of nodes - needed for ragged cores with missing assemblies on edges

      allocate (nodemap(0:npin*jasm,0:npin*iasm))   ! needs to be in C-order
      nodemap=0

      j=0
      do ja=1, jasm
        do jp=1, npin
          j=j+1

          i=0
          do ia=1, iasm
            do ip=1, npin
              i=i+1

              na=mapassm(ia,ja)
              if (na.gt.0) then
                nodemap(j-1,i-1)=1     ! flag node as used, we will number later
                nodemap(j-1,i  )=1
                nodemap(j  ,i-1)=1
                nodemap(j  ,i  )=1
              endif

            enddo  ! ip
          enddo    ! ia
        enddo  ! jp
      enddo    ! ja

!d    write (*,*) 'rod node map: (before numbering)'
!d    do j=0, npin*jasm
!d      write (*,'(2x,500i1)') (nodemap(j,i),i=0,npin*iasm)
!d    enddo

!  Number the nodes
!  nodes are across, then down

      nn=0
      do i=0, npin*iasm
        do j=0, npin*jasm
          if (nodemap(j,i).gt.0) then
            nn=nn+1
            nodemap(j,i)=nn
          endif
        enddo
      enddo

      write (*,*) 'number of rod nodes in one plane = ', nn

      npl=nn    ! save number of nodes in a plane (needed for offset later)

      if (nn.lt.350) then
        write (*,*) 'rod node map: (after numbering)'
        do j=0, npin*jasm
          write (*,'(2x,100i3)') (nodemap(j,i),i=0,npin*iasm)
        enddo
      endif

!--- write pin dimensions

!
!  (i,j) origin is in top left corner, i goes across, j goes down
!  (x,y) origin is in bottom left corner,  x goes across left to right, y goes up
!
!  mapping:  j goes down from top to bottom   (negative y direction)
!            i goes across from left to right (positive x direction)
!

! allocate pointer arrays

      nnodes=npl*(naxial+1)
      write (*,*) 'number of 3D nodes = ', nnodes

      nnrod=nnodes    ! save for output

      allocate (xyz(3,nnodes))
      allocate (gg(8,nassm,naxial,npin,npin))   ! 8 node numbers per cell
      xyz=-1000.0d0
      gg=-100

!--- fill xyz values for each node

      allocate (xi(0:npin*iasm))
      allocate (yi(0:npin*jasm))
      do i=0, npin*iasm
        xi(i)=i*delta              ! x aligns with i
      enddo
      do j=0, npin*iasm
        yi(j)=(npin*iasm-j)*delta   ! y aligns with j, but is the reverse direction
      enddo

      nkoff=0
      do k=0, naxial
        do j=0, npin*jasm
          do i=0, npin*iasm
            nn=nodemap(j,i)
            if (nn.gt.0) then
              xyz(1,nn+nkoff)=real(xi(i))
              xyz(2,nn+nkoff)=real(yi(j))
              xyz(3,nn+nkoff)=real(zbounds(k))
            endif
          enddo
        enddo
        nkoff=nkoff+npl
      enddo

      deallocate (xi,yi)

!--- fill element to node map (gg)

      nkoff=0

      do k=1, naxial

        j=0
        do ja=1, jasm
          do jp=1, npin
            j=j+1

            i=0
            do ia=1, iasm
              do ip=1, npin
                i=i+1

                na=mapassm(ia,ja)
                if (na.gt.0) then

          ! I'm using (ip,jp) instead of (jp,ip) in order to get the (i,j)
          ! coordinates to show up right in the plots

                  gg(1,na,k,ip,jp)=nodemap(j,  i-1)+nkoff      ! 1,0,0
                  gg(2,na,k,ip,jp)=nodemap(j,  i  )+nkoff      ! 1,1,0
                  gg(3,na,k,ip,jp)=nodemap(j-1,i  )+nkoff      ! 0,1,0
                  gg(4,na,k,ip,jp)=nodemap(j-1,i-1)+nkoff      ! 0,0,0

                  gg(5,na,k,ip,jp)=gg(1,na,k,ip,jp)+npl        ! 1,0,1
                  gg(6,na,k,ip,jp)=gg(2,na,k,ip,jp)+npl        ! 1,1,1
                  gg(7,na,k,ip,jp)=gg(3,na,k,ip,jp)+npl        ! 0,1,1
                  gg(8,na,k,ip,jp)=gg(4,na,k,ip,jp)+npl        ! 0,0,1

                endif  ! na

              enddo  ! ip
            enddo    ! ia

          enddo   ! jp
        enddo     ! ja

        nkoff=nkoff+npl    ! increment axial offset

      enddo  ! k

!--- sanity check coordinates and convert to zero based numbering

      do ip=1, npin
        do jp=1, npin
          do k=1, naxial
            do na=1, nassm
              do i=1, 8
                if (gg(i,na,k,ip,jp).lt.1)      stop 'invalid node number .lt.1'
                if (gg(i,na,k,ip,jp).gt.nnodes) stop 'invalid node number .gt.max'
                gg(i,na,k,ip,jp)=gg(i,na,k,ip,jp)-1
              enddo
            enddo
          enddo
        enddo
      enddo

!--- open HDF grid file

      call h5fcreate_f (gridfile, H5F_ACC_TRUNC_F, grid_id, ierror)
      if (ierror.lt.0) then
        write (*,'(3a)') 'error: H5 input file ',trim(gridfile), ' could not be created'
        stop
      endif

!--- create HDF group for XMFMESH data

      group_name='/XMFMESH/'
      write (*,*) 'create group: ', group_name

      call h5gcreate_f (grid_id, group_name, group_id, ierror)
      if (ierror.ne.0) stop 'error creating group'

!--- write mapping to HDF

      idims(:)=0     ! clear
      idims(1)=8
      idims(2)=nassm
      idims(3)=naxial
      idims(4)=npin
      idims(5)=npin

      dataset = trim(group_name)//'ggrod'
      call hwrite_integer(grid_id, dataset, idims, gg)

      idims(:)=0     ! clear
      idims(1)=3
      idims(2)=nnodes

      dataset = trim(group_name)//'xyzrod'
      call hwrite_real (grid_id, dataset, idims, xyz)

      deallocate (gg)
      deallocate (nodemap)
      deallocate (xyz)

!--- write (i,j,k) data for debug

      allocate (ijk(nassm,naxial,npin,npin))
      ijk=0

      do i=1, npin
        do j=1, npin
          do k=1, naxial
            do na=1, nassm
              ijk(na,k,j,i)=i
            enddo
          enddo
        enddo
      enddo

      idims(:)=0     ! clear
      idims(1)=nassm
      idims(2)=naxial
      idims(3)=npin
      idims(4)=npin

      dataset = trim(group_name)//'ipin'
      call hwrite_integer (grid_id, dataset, idims, ijk)

      do i=1, npin
        do j=1, npin
          do k=1, naxial
            do na=1, nassm
              ijk(na,k,j,i)=j
            enddo
          enddo
        enddo
      enddo

      dataset = trim(group_name)//'jpin'
      call hwrite_integer (grid_id, dataset, idims, ijk)

      do i=1, npin
        do j=1, npin
          do k=1, naxial
            do na=1, nassm
              ijk(na,k,j,i)=k
            enddo
          enddo
        enddo
      enddo

      dataset = trim(group_name)//'kcoord'
      call hwrite_integer (grid_id, dataset, idims, ijk)

      do i=1, npin
        do j=1, npin
          do k=1, naxial
            do na=1, nassm
              ijk(na,k,j,i)=na
            enddo
          enddo
        enddo
      enddo

      dataset = trim(group_name)//'nassm'
      call hwrite_integer (grid_id, dataset, idims, ijk)

      deallocate (ijk)

!-----------------------------------------------------------------------

      deallocate (mapassm)

!--- close XMFMESH group

      call h5gclose_f (group_id, ierror)
      if (ierror.ne.0) stop 'error closing group'

!--- close grid HDF file

      call h5fclose_f(grid_id, ierror)

      write (*,'(2a)') ' finished writing HDF grid file: ', trim(gridfile)

!--- return

      return
      end subroutine coordinates

!=======================================================================
!
!  Subroutine to write XMF file
!
!=======================================================================
      subroutine write_xmf(nx, ny, nz, nassm, nnrod, filename, gridname, nstate, xexp)
      implicit none
      integer, intent(in) :: nx, ny, nz, nassm, nnrod
      integer, intent(in) :: nstate    ! statepoint number
      real(8), intent(in) :: xexp      ! exposure
      character(len=*), intent(in) :: filename
      character(len=*), intent(in) :: gridname

      character(len=12) :: state_name
      character(len=10) :: label_xmf

      integer :: io=10
      integer :: idis

      integer, parameter :: maxdist=6    ! maximum number of distributions
      character(len=20) :: dist_label(maxdist)

      dist_label(1)='pin_powers'
      dist_label(2)='pin_fueltemps'
      dist_label(3)='pin_cladtemps'
      dist_label(4)='pin_modtemps'
      dist_label(5)='pin_moddens'
      dist_label(6)='pin_exposures'

      write (label_xmf,'(".",i0,".xmf")') nstate

      write (0,'(3a)') ' writing XMF file: ',trim(filename)//trim(label_xmf)

      open (io,file=trim(filename)//trim(label_xmf))

!--- write xml header

      write (io,20) '<?xml version="1.0" ?>'
      write (io,20) '<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>'
      write (io,20) '<Xdmf Version="2.0">'
      write (io,20) ' <Domain>'

!-----------------------------------------------------------------------
!--- write rod grid - hexahedron

      write (io,120) 'rod_mesh', nx, ny, nz, nassm, nx, ny, nz, nassm, trim(gridname), '/XMFMESH/ggrod'

  120 format ( '  <Grid Name="',a,'" GridType="Uniform">', &
            /,5x,'<Topology TopologyType="Hexahedron" Dimensions="',i0,1x,i0,1x,i0,1x,i0,'">', &
            /,6x,'  <DataItem Dimensions="',i0,1x,i0,1x,i0,1x,i0,' 8" NumberType="Int" Format="HDF">', &
            /,8x,a,':',a, &
            /,6x,'  </DataItem>', &
            /,5x,'</Topology>')

      write (io,125) xexp
  125 format (5x,'<Time Value="',f0.3,'" />')

!--- rod node coordinates

      write (io,130) nnrod, trim(gridname), '/XMFMESH/xyzrod'

  130 format (5x,'<Geometry Type="XYZ">', &
            /,8x,'<DataStructure Name="xyz" DataType="Float" Precision="4" ', &
                      'Dimensions="',i0,' 3" Format="HDF">', &
            /,8x,a,':',a, &
            /,8x,'</DataStructure>', &
            /,5x,'</Geometry>')

!--- rod cell data

!  the following four datasets are for debug purposes and can be removed

      if (nstate.eq.1) then

        write (io,80) 'ipin'
        write (io,32) nx, ny, nz, nassm        ! 32=integer array
        write (io,10) trim(gridname),'/XMFMESH/','ipin'
        write (io,20) '        </DataItem>'
        write (io,20) '     </Attribute>'

        write (io,80) 'jpin'
        write (io,32) nx, ny, nz, nassm        ! 32=integer array
        write (io,10) trim(gridname),'/XMFMESH/','jpin'
        write (io,20) '        </DataItem>'
        write (io,20) '     </Attribute>'

        write (io,80) 'kcoord'
        write (io,32) nx, ny, nz, nassm        ! 32=integer array
        write (io,10) trim(gridname),'/XMFMESH/','kcoord'
        write (io,20) '        </DataItem>'
        write (io,20) '     </Attribute>'

        write (io,80) 'nassm'
        write (io,32) nx, ny, nz, nassm        ! 32=integer array
        write (io,10) trim(gridname),'/XMFMESH/','nassm'
        write (io,20) '        </DataItem>'
        write (io,20) '     </Attribute>'

      endif

!  pin data

      call make_state_name(state_name, nstate)

      do idis=1, maxdist

        write (io,80) trim(dist_label(idis))
        write (io,30) nx, ny, nz, nassm
        write (io,10) trim(filename),trim(state_name),trim(dist_label(idis))
        write (io,20) '       </DataItem>'
        write (io,20) '     </Attribute>'

      enddo

!--- close grid

      write (io,20) '  </Grid>'

  10  format (8x,a,':',2a)
  20  format (a)

  30  format (8x,'<DataItem Dimensions="',i0,1x,i0,1x,i0,1x,i0,'" NumberType="Float" ', &
                       'Precision="8" Format="HDF">')

  32  format (8x,'<DataItem Dimensions="',i0,1x,i0,1x,i0,1x,i0,'" NumberType="Int" Format="HDF">')

  80  format (5x,'<Attribute Name="',a,'" Center="Cell">')

!-----------------------------------------------------------------------
!--- finished

      write (io,20) ' </Domain>'
      write (io,20) '</Xdmf>'
      close (io)

      return
      end
!=======================================================================
!=======================================================================

max_stars_repo_name: palmtag/VERAout-tools

max_issues_repo_name: palmtag/VERAout-tools

max_forks_repo_name: palmtag/VERAout-tools