putget.c 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362
  1. /* Do not edit this file. It is produced from the corresponding .m4 source */
  2. /*
  3. * Copyright 1996, University Corporation for Atmospheric Research
  4. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  5. */
  6. /* $Id: putget.m4,v 2.79 2010/05/29 22:25:01 russ Exp $ */
  7. #include "config.h"
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <assert.h>
  11. #include "netcdf.h"
  12. #include "nc.h"
  13. #include "ncx.h"
  14. #include "fbits.h"
  15. #include "onstack.h"
  16. #ifdef LOCKNUMREC
  17. # include <mpp/shmem.h> /* for SGI/Cray SHMEM routines */
  18. # ifdef LN_TEST
  19. # include <stdio.h>
  20. # endif
  21. #endif
  22. #include "nc3dispatch.h"
  23. #undef MIN /* system may define MIN somewhere and complain */
  24. #define MIN(mm,nn) (((mm) < (nn)) ? (mm) : (nn))
  25. static int
  26. readNCv(const NC* ncp, const NC_var* varp, const size_t* start,
  27. const size_t nelems, void* value, const nc_type memtype);
  28. static int
  29. writeNCv(NC* ncp, const NC_var* varp, const size_t* start,
  30. const size_t nelems, const void* value, const nc_type memtype);
  31. /* #define ODEBUG 1 */
  32. #if ODEBUG
  33. #include <stdio.h>
  34. /*
  35. * Print the values of an array of size_t
  36. */
  37. void
  38. arrayp(const char *label, size_t count, const size_t *array)
  39. {
  40. (void) fprintf(stderr, "%s", label);
  41. (void) fputc('\t',stderr);
  42. for(; count > 0; count--, array++)
  43. (void) fprintf(stderr," %lu", (unsigned long)*array);
  44. (void) fputc('\n',stderr);
  45. }
  46. #endif /* ODEBUG */
  47. /* Begin fill */
  48. /*
  49. * This is tunable parameter.
  50. * It essentially controls the tradeoff between the number of times
  51. * memcpy() gets called to copy the external data to fill
  52. * a large buffer vs the number of times its called to
  53. * prepare the external data.
  54. */
  55. #if _SX
  56. /* NEC SX specific optimization */
  57. #define NFILL 2048
  58. #else
  59. #define NFILL 16
  60. #endif
  61. /*
  62. * Next 6 type specific functions
  63. * Fill a some memory with the default special value.
  64. * Formerly
  65. NC_arrayfill()
  66. */
  67. static int
  68. NC_fill_schar(
  69. void **xpp,
  70. size_t nelems) /* how many */
  71. {
  72. schar fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR];
  73. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  74. {
  75. schar *vp = fillp; /* lower bound of area to be filled */
  76. const schar *const end = vp + nelems;
  77. while(vp < end)
  78. {
  79. *vp++ = NC_FILL_BYTE;
  80. }
  81. }
  82. return ncx_putn_schar_schar(xpp, nelems, fillp);
  83. }
  84. static int
  85. NC_fill_char(
  86. void **xpp,
  87. size_t nelems) /* how many */
  88. {
  89. char fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR];
  90. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  91. {
  92. char *vp = fillp; /* lower bound of area to be filled */
  93. const char *const end = vp + nelems;
  94. while(vp < end)
  95. {
  96. *vp++ = NC_FILL_CHAR;
  97. }
  98. }
  99. return ncx_putn_char_char(xpp, nelems, fillp);
  100. }
  101. static int
  102. NC_fill_short(
  103. void **xpp,
  104. size_t nelems) /* how many */
  105. {
  106. short fillp[NFILL * sizeof(double)/X_SIZEOF_SHORT];
  107. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  108. {
  109. short *vp = fillp; /* lower bound of area to be filled */
  110. const short *const end = vp + nelems;
  111. while(vp < end)
  112. {
  113. *vp++ = NC_FILL_SHORT;
  114. }
  115. }
  116. return ncx_putn_short_short(xpp, nelems, fillp);
  117. }
  118. #if (SIZEOF_INT >= X_SIZEOF_INT)
  119. static int
  120. NC_fill_int(
  121. void **xpp,
  122. size_t nelems) /* how many */
  123. {
  124. int fillp[NFILL * sizeof(double)/X_SIZEOF_INT];
  125. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  126. {
  127. int *vp = fillp; /* lower bound of area to be filled */
  128. const int *const end = vp + nelems;
  129. while(vp < end)
  130. {
  131. *vp++ = NC_FILL_INT;
  132. }
  133. }
  134. return ncx_putn_int_int(xpp, nelems, fillp);
  135. }
  136. #elif SIZEOF_LONG == X_SIZEOF_INT
  137. static int
  138. NC_fill_int(
  139. void **xpp,
  140. size_t nelems) /* how many */
  141. {
  142. long fillp[NFILL * sizeof(double)/X_SIZEOF_INT];
  143. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  144. {
  145. long *vp = fillp; /* lower bound of area to be filled */
  146. const long *const end = vp + nelems;
  147. while(vp < end)
  148. {
  149. *vp++ = NC_FILL_INT;
  150. }
  151. }
  152. return ncx_putn_int_long(xpp, nelems, fillp);
  153. }
  154. #else
  155. #error "NC_fill_int implementation"
  156. #endif
  157. static int
  158. NC_fill_float(
  159. void **xpp,
  160. size_t nelems) /* how many */
  161. {
  162. float fillp[NFILL * sizeof(double)/X_SIZEOF_FLOAT];
  163. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  164. {
  165. float *vp = fillp; /* lower bound of area to be filled */
  166. const float *const end = vp + nelems;
  167. while(vp < end)
  168. {
  169. *vp++ = NC_FILL_FLOAT;
  170. }
  171. }
  172. return ncx_putn_float_float(xpp, nelems, fillp);
  173. }
  174. static int
  175. NC_fill_double(
  176. void **xpp,
  177. size_t nelems) /* how many */
  178. {
  179. double fillp[NFILL * sizeof(double)/X_SIZEOF_DOUBLE];
  180. assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
  181. {
  182. double *vp = fillp; /* lower bound of area to be filled */
  183. const double *const end = vp + nelems;
  184. while(vp < end)
  185. {
  186. *vp++ = NC_FILL_DOUBLE;
  187. }
  188. }
  189. return ncx_putn_double_double(xpp, nelems, fillp);
  190. }
  191. /*
  192. * Fill the external space for variable 'varp' values at 'recno' with
  193. * the appropriate value. If 'varp' is not a record variable, fill the
  194. * whole thing. For the special case when 'varp' is the only record
  195. * variable and it is of type byte, char, or short, varsize should be
  196. * ncp->recsize, otherwise it should be varp->len.
  197. * Formerly
  198. xdr_NC_fill()
  199. */
  200. int
  201. fill_NC_var(NC *ncp, const NC_var *varp, size_t varsize, size_t recno)
  202. {
  203. char xfillp[NFILL * X_SIZEOF_DOUBLE];
  204. const size_t step = varp->xsz;
  205. const size_t nelems = sizeof(xfillp)/step;
  206. const size_t xsz = varp->xsz * nelems;
  207. NC_attr **attrpp = NULL;
  208. off_t offset;
  209. size_t remaining = varsize;
  210. void *xp;
  211. int status = NC_NOERR;
  212. /*
  213. * Set up fill value
  214. */
  215. attrpp = NC_findattr(&varp->attrs, _FillValue);
  216. if( attrpp != NULL )
  217. {
  218. /* User defined fill value */
  219. if( (*attrpp)->type != varp->type || (*attrpp)->nelems != 1 )
  220. {
  221. return NC_EBADTYPE;
  222. }
  223. else
  224. {
  225. /* Use the user defined value */
  226. char *cp = xfillp;
  227. const char *const end = &xfillp[sizeof(xfillp)];
  228. assert(step <= (*attrpp)->xsz);
  229. for( /*NADA*/; cp < end; cp += step)
  230. {
  231. (void) memcpy(cp, (*attrpp)->xvalue, step);
  232. }
  233. }
  234. }
  235. else
  236. {
  237. /* use the default */
  238. assert(xsz % X_ALIGN == 0);
  239. assert(xsz <= sizeof(xfillp));
  240. xp = xfillp;
  241. switch(varp->type){
  242. case NC_BYTE :
  243. status = NC_fill_schar(&xp, nelems);
  244. break;
  245. case NC_CHAR :
  246. status = NC_fill_char(&xp, nelems);
  247. break;
  248. case NC_SHORT :
  249. status = NC_fill_short(&xp, nelems);
  250. break;
  251. case NC_INT :
  252. status = NC_fill_int(&xp, nelems);
  253. break;
  254. case NC_FLOAT :
  255. status = NC_fill_float(&xp, nelems);
  256. break;
  257. case NC_DOUBLE :
  258. status = NC_fill_double(&xp, nelems);
  259. break;
  260. default :
  261. assert("fill_NC_var invalid type" == 0);
  262. status = NC_EBADTYPE;
  263. break;
  264. }
  265. if(status != NC_NOERR)
  266. return status;
  267. assert(xp == xfillp + xsz);
  268. }
  269. /*
  270. * copyout:
  271. * xfillp now contains 'nelems' elements of the fill value
  272. * in external representation.
  273. */
  274. /*
  275. * Copy it out.
  276. */
  277. offset = varp->begin;
  278. if(IS_RECVAR(varp))
  279. {
  280. offset += (off_t)ncp->recsize * recno;
  281. }
  282. assert(remaining > 0);
  283. for(;;)
  284. {
  285. const size_t chunksz = MIN(remaining, ncp->chunk);
  286. size_t ii;
  287. status = ncio_get(ncp->nciop, offset, chunksz,
  288. RGN_WRITE, &xp);
  289. if(status != NC_NOERR)
  290. {
  291. return status;
  292. }
  293. /*
  294. * fill the chunksz buffer in units of xsz
  295. */
  296. for(ii = 0; ii < chunksz/xsz; ii++)
  297. {
  298. (void) memcpy(xp, xfillp, xsz);
  299. xp = (char *)xp + xsz;
  300. }
  301. /*
  302. * Deal with any remainder
  303. */
  304. {
  305. const size_t rem = chunksz % xsz;
  306. if(rem != 0)
  307. {
  308. (void) memcpy(xp, xfillp, rem);
  309. /* xp = (char *)xp + xsz; */
  310. }
  311. }
  312. status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED);
  313. if(status != NC_NOERR)
  314. {
  315. break;
  316. }
  317. remaining -= chunksz;
  318. if(remaining == 0)
  319. break; /* normal loop exit */
  320. offset += chunksz;
  321. }
  322. return status;
  323. }
  324. /* End fill */
  325. /*
  326. * Add a record containing the fill values.
  327. */
  328. static int
  329. NCfillrecord(NC *ncp, const NC_var *const *varpp, size_t recno)
  330. {
  331. size_t ii = 0;
  332. for(; ii < ncp->vars.nelems; ii++, varpp++)
  333. {
  334. if( !IS_RECVAR(*varpp) )
  335. {
  336. continue; /* skip non-record variables */
  337. }
  338. {
  339. const int status = fill_NC_var(ncp, *varpp, (*varpp)->len, recno);
  340. if(status != NC_NOERR)
  341. return status;
  342. }
  343. }
  344. return NC_NOERR;
  345. }
  346. /*
  347. * Add a record containing the fill values in the special case when
  348. * there is exactly one record variable, where we don't require each
  349. * record to be four-byte aligned (no record padding).
  350. */
  351. static int
  352. NCfillspecialrecord(NC *ncp, const NC_var *varp, size_t recno)
  353. {
  354. int status;
  355. assert(IS_RECVAR(varp));
  356. status = fill_NC_var(ncp, varp, ncp->recsize, recno);
  357. if(status != NC_NOERR)
  358. return status;
  359. return NC_NOERR;
  360. }
  361. /*
  362. * It is advantageous to
  363. * #define TOUCH_LAST
  364. * when using memory mapped io.
  365. */
  366. #if TOUCH_LAST
  367. /*
  368. * Grow the file to a size which can contain recno
  369. */
  370. static int
  371. NCtouchlast(NC *ncp, const NC_var *const *varpp, size_t recno)
  372. {
  373. int status = NC_NOERR;
  374. const NC_var *varp = NULL;
  375. {
  376. size_t ii = 0;
  377. for(; ii < ncp->vars.nelems; ii++, varpp++)
  378. {
  379. if( !IS_RECVAR(*varpp) )
  380. {
  381. continue; /* skip non-record variables */
  382. }
  383. varp = *varpp;
  384. }
  385. }
  386. assert(varp != NULL);
  387. assert( IS_RECVAR(varp) );
  388. {
  389. const off_t offset = varp->begin
  390. + (off_t)(recno-1) * (off_t)ncp->recsize
  391. + (off_t)(varp->len - varp->xsz);
  392. void *xp;
  393. status = ncio_get(ncp->nciop, offset, varp->xsz,
  394. RGN_WRITE, &xp);
  395. if(status != NC_NOERR)
  396. return status;
  397. (void)memset(xp, 0, varp->xsz);
  398. status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED);
  399. }
  400. return status;
  401. }
  402. #endif /* TOUCH_LAST */
  403. /*
  404. * Ensure that the netcdf file has 'numrecs' records,
  405. * add records and fill as neccessary.
  406. */
  407. static int
  408. NCvnrecs(NC *ncp, size_t numrecs)
  409. {
  410. int status = NC_NOERR;
  411. #ifdef LOCKNUMREC
  412. ushmem_t myticket = 0, nowserving = 0;
  413. ushmem_t numpe = (ushmem_t) _num_pes();
  414. /* get ticket and wait */
  415. myticket = shmem_short_finc((shmem_t *) ncp->lock + LOCKNUMREC_LOCK,
  416. ncp->lock[LOCKNUMREC_BASEPE]);
  417. #ifdef LN_TEST
  418. fprintf(stderr,"%d of %d : ticket = %hu\n",
  419. _my_pe(), _num_pes(), myticket);
  420. #endif
  421. do {
  422. shmem_short_get((shmem_t *) &nowserving,
  423. (shmem_t *) ncp->lock + LOCKNUMREC_SERVING, 1,
  424. ncp->lock[LOCKNUMREC_BASEPE]);
  425. #ifdef LN_TEST
  426. fprintf(stderr,"%d of %d : serving = %hu\n",
  427. _my_pe(), _num_pes(), nowserving);
  428. #endif
  429. /* work-around for non-unique tickets */
  430. if (nowserving > myticket && nowserving < myticket + numpe ) {
  431. /* get a new ticket ... you've been bypassed */
  432. /* and handle the unlikely wrap-around effect */
  433. myticket = shmem_short_finc(
  434. (shmem_t *) ncp->lock + LOCKNUMREC_LOCK,
  435. ncp->lock[LOCKNUMREC_BASEPE]);
  436. #ifdef LN_TEST
  437. fprintf(stderr,"%d of %d : new ticket = %hu\n",
  438. _my_pe(), _num_pes(), myticket);
  439. #endif
  440. }
  441. } while(nowserving != myticket);
  442. /* now our turn to check & update value */
  443. #endif
  444. if(numrecs > NC_get_numrecs(ncp))
  445. {
  446. #if TOUCH_LAST
  447. status = NCtouchlast(ncp,
  448. (const NC_var *const*)ncp->vars.value,
  449. numrecs);
  450. if(status != NC_NOERR)
  451. goto common_return;
  452. #endif /* TOUCH_LAST */
  453. set_NC_ndirty(ncp);
  454. if(!NC_dofill(ncp))
  455. {
  456. /* Simply set the new numrecs value */
  457. NC_set_numrecs(ncp, numrecs);
  458. }
  459. else
  460. {
  461. /* Treat two cases differently:
  462. - exactly one record variable (no padding)
  463. - multiple record variables (each record padded
  464. to 4-byte alignment)
  465. */
  466. NC_var **vpp = (NC_var **)ncp->vars.value;
  467. NC_var *const *const end = &vpp[ncp->vars.nelems];
  468. NC_var *recvarp = NULL; /* last record var */
  469. int numrecvars = 0;
  470. size_t cur_nrecs;
  471. /* determine how many record variables */
  472. for( /*NADA*/; vpp < end; vpp++) {
  473. if(IS_RECVAR(*vpp)) {
  474. recvarp = *vpp;
  475. numrecvars++;
  476. }
  477. }
  478. if (numrecvars != 1) { /* usual case */
  479. /* Fill each record out to numrecs */
  480. while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs)
  481. {
  482. status = NCfillrecord(ncp,
  483. (const NC_var *const*)ncp->vars.value,
  484. cur_nrecs);
  485. if(status != NC_NOERR)
  486. {
  487. break;
  488. }
  489. NC_increase_numrecs(ncp, cur_nrecs +1);
  490. }
  491. if(status != NC_NOERR)
  492. goto common_return;
  493. } else { /* special case */
  494. /* Fill each record out to numrecs */
  495. while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs)
  496. {
  497. status = NCfillspecialrecord(ncp,
  498. recvarp,
  499. cur_nrecs);
  500. if(status != NC_NOERR)
  501. {
  502. break;
  503. }
  504. NC_increase_numrecs(ncp, cur_nrecs +1);
  505. }
  506. if(status != NC_NOERR)
  507. goto common_return;
  508. }
  509. }
  510. if(NC_doNsync(ncp))
  511. {
  512. status = write_numrecs(ncp);
  513. }
  514. }
  515. common_return:
  516. #ifdef LOCKNUMREC
  517. /* finished with our lock - increment serving number */
  518. (void) shmem_short_finc((shmem_t *) ncp->lock + LOCKNUMREC_SERVING,
  519. ncp->lock[LOCKNUMREC_BASEPE]);
  520. #endif
  521. return status;
  522. }
  523. /*
  524. * Check whether 'coord' values are valid for the variable.
  525. */
  526. static int
  527. NCcoordck(NC *ncp, const NC_var *varp, const size_t *coord)
  528. {
  529. const size_t *ip;
  530. size_t *up;
  531. if(varp->ndims == 0)
  532. return NC_NOERR; /* 'scalar' variable */
  533. if(IS_RECVAR(varp))
  534. {
  535. if(*coord > X_UINT_MAX) /* rkr: bug fix from previous X_INT_MAX */
  536. return NC_EINVALCOORDS; /* sanity check */
  537. if(NC_readonly(ncp) && *coord >= NC_get_numrecs(ncp))
  538. {
  539. if(!NC_doNsync(ncp))
  540. return NC_EINVALCOORDS;
  541. /* else */
  542. {
  543. /* Update from disk and check again */
  544. const int status = read_numrecs(ncp);
  545. if(status != NC_NOERR)
  546. return status;
  547. if(*coord >= NC_get_numrecs(ncp))
  548. return NC_EINVALCOORDS;
  549. }
  550. }
  551. ip = coord + 1;
  552. up = varp->shape + 1;
  553. }
  554. else
  555. {
  556. ip = coord;
  557. up = varp->shape;
  558. }
  559. #ifdef CDEBUG
  560. fprintf(stderr," NCcoordck: coord %ld, count %d, ip %ld\n",
  561. coord, varp->ndims, ip );
  562. #endif /* CDEBUG */
  563. for(; ip < coord + varp->ndims; ip++, up++)
  564. {
  565. #ifdef CDEBUG
  566. fprintf(stderr," NCcoordck: ip %p, *ip %ld, up %p, *up %lu\n",
  567. ip, *ip, up, *up );
  568. #endif /* CDEBUG */
  569. /* cast needed for braindead systems with signed size_t */
  570. if((unsigned long) *ip >= (unsigned long) *up )
  571. return NC_EINVALCOORDS;
  572. }
  573. return NC_NOERR;
  574. }
  575. /*
  576. * Check whether 'edges' are valid for the variable and 'start'
  577. */
  578. /*ARGSUSED*/
  579. static int
  580. NCedgeck(const NC *ncp, const NC_var *varp,
  581. const size_t *start, const size_t *edges)
  582. {
  583. const size_t *const end = start + varp->ndims;
  584. const size_t *shp = varp->shape;
  585. if(varp->ndims == 0)
  586. return NC_NOERR; /* 'scalar' variable */
  587. if(IS_RECVAR(varp))
  588. {
  589. start++;
  590. edges++;
  591. shp++;
  592. }
  593. for(; start < end; start++, edges++, shp++)
  594. {
  595. /* cast needed for braindead systems with signed size_t */
  596. if((unsigned long) *edges > *shp ||
  597. (unsigned long) *start + (unsigned long) *edges > *shp)
  598. {
  599. return(NC_EEDGE);
  600. }
  601. }
  602. return NC_NOERR;
  603. }
  604. /*
  605. * Translate the (variable, coord) pair into a seek index
  606. */
  607. static off_t
  608. NC_varoffset(const NC *ncp, const NC_var *varp, const size_t *coord)
  609. {
  610. if(varp->ndims == 0) /* 'scalar' variable */
  611. return varp->begin;
  612. if(varp->ndims == 1)
  613. {
  614. if(IS_RECVAR(varp))
  615. return varp->begin +
  616. (off_t)(*coord) * (off_t)ncp->recsize;
  617. /* else */
  618. return varp->begin + (off_t)(*coord) * (off_t)varp->xsz;
  619. }
  620. /* else */
  621. {
  622. off_t lcoord = (off_t)coord[varp->ndims -1];
  623. off_t *up = varp->dsizes +1;
  624. const size_t *ip = coord;
  625. const off_t *const end = varp->dsizes + varp->ndims;
  626. if(IS_RECVAR(varp))
  627. up++, ip++;
  628. for(; up < end; up++, ip++)
  629. lcoord += (off_t)(*up) * (off_t)(*ip);
  630. lcoord *= varp->xsz;
  631. if(IS_RECVAR(varp))
  632. lcoord += (off_t)(*coord) * ncp->recsize;
  633. lcoord += varp->begin;
  634. return lcoord;
  635. }
  636. }
  637. static int
  638. putNCvx_char_char(NC *ncp, const NC_var *varp,
  639. const size_t *start, size_t nelems, const char *value)
  640. {
  641. off_t offset = NC_varoffset(ncp, varp, start);
  642. size_t remaining = varp->xsz * nelems;
  643. int status = NC_NOERR;
  644. void *xp;
  645. if(nelems == 0)
  646. return NC_NOERR;
  647. assert(value != NULL);
  648. for(;;)
  649. {
  650. size_t extent = MIN(remaining, ncp->chunk);
  651. size_t nput = ncx_howmany(varp->type, extent);
  652. int lstatus = ncio_get(ncp->nciop, offset, extent,
  653. RGN_WRITE, &xp);
  654. if(lstatus != NC_NOERR)
  655. return lstatus;
  656. lstatus = ncx_putn_char_char(&xp, nput, value);
  657. if(lstatus != NC_NOERR && status == NC_NOERR)
  658. {
  659. /* not fatal to the loop */
  660. status = lstatus;
  661. }
  662. (void) ncio_rel(ncp->nciop, offset,
  663. RGN_MODIFIED);
  664. remaining -= extent;
  665. if(remaining == 0)
  666. break; /* normal loop exit */
  667. offset += extent;
  668. value += nput;
  669. }
  670. return status;
  671. }
  672. static int
  673. putNCvx_schar_schar(NC *ncp, const NC_var *varp,
  674. const size_t *start, size_t nelems, const schar *value)
  675. {
  676. off_t offset = NC_varoffset(ncp, varp, start);
  677. size_t remaining = varp->xsz * nelems;
  678. int status = NC_NOERR;
  679. void *xp;
  680. if(nelems == 0)
  681. return NC_NOERR;
  682. assert(value != NULL);
  683. for(;;)
  684. {
  685. size_t extent = MIN(remaining, ncp->chunk);
  686. size_t nput = ncx_howmany(varp->type, extent);
  687. int lstatus = ncio_get(ncp->nciop, offset, extent,
  688. RGN_WRITE, &xp);
  689. if(lstatus != NC_NOERR)
  690. return lstatus;
  691. lstatus = ncx_putn_schar_schar(&xp, nput, value);
  692. if(lstatus != NC_NOERR && status == NC_NOERR)
  693. {
  694. /* not fatal to the loop */
  695. status = lstatus;
  696. }
  697. (void) ncio_rel(ncp->nciop, offset,
  698. RGN_MODIFIED);
  699. remaining -= extent;
  700. if(remaining == 0)
  701. break; /* normal loop exit */
  702. offset += extent;
  703. value += nput;
  704. }
  705. return status;
  706. }
  707. static int
  708. putNCvx_schar_uchar(NC *ncp, const NC_var *varp,
  709. const size_t *start, size_t nelems, const uchar *value)
  710. {
  711. off_t offset = NC_varoffset(ncp, varp, start);
  712. size_t remaining = varp->xsz * nelems;
  713. int status = NC_NOERR;
  714. void *xp;
  715. if(nelems == 0)
  716. return NC_NOERR;
  717. assert(value != NULL);
  718. for(;;)
  719. {
  720. size_t extent = MIN(remaining, ncp->chunk);
  721. size_t nput = ncx_howmany(varp->type, extent);
  722. int lstatus = ncio_get(ncp->nciop, offset, extent,
  723. RGN_WRITE, &xp);
  724. if(lstatus != NC_NOERR)
  725. return lstatus;
  726. lstatus = ncx_putn_schar_uchar(&xp, nput, value);
  727. if(lstatus != NC_NOERR && status == NC_NOERR)
  728. {
  729. /* not fatal to the loop */
  730. status = lstatus;
  731. }
  732. (void) ncio_rel(ncp->nciop, offset,
  733. RGN_MODIFIED);
  734. remaining -= extent;
  735. if(remaining == 0)
  736. break; /* normal loop exit */
  737. offset += extent;
  738. value += nput;
  739. }
  740. return status;
  741. }
  742. static int
  743. putNCvx_schar_short(NC *ncp, const NC_var *varp,
  744. const size_t *start, size_t nelems, const short *value)
  745. {
  746. off_t offset = NC_varoffset(ncp, varp, start);
  747. size_t remaining = varp->xsz * nelems;
  748. int status = NC_NOERR;
  749. void *xp;
  750. if(nelems == 0)
  751. return NC_NOERR;
  752. assert(value != NULL);
  753. for(;;)
  754. {
  755. size_t extent = MIN(remaining, ncp->chunk);
  756. size_t nput = ncx_howmany(varp->type, extent);
  757. int lstatus = ncio_get(ncp->nciop, offset, extent,
  758. RGN_WRITE, &xp);
  759. if(lstatus != NC_NOERR)
  760. return lstatus;
  761. lstatus = ncx_putn_schar_short(&xp, nput, value);
  762. if(lstatus != NC_NOERR && status == NC_NOERR)
  763. {
  764. /* not fatal to the loop */
  765. status = lstatus;
  766. }
  767. (void) ncio_rel(ncp->nciop, offset,
  768. RGN_MODIFIED);
  769. remaining -= extent;
  770. if(remaining == 0)
  771. break; /* normal loop exit */
  772. offset += extent;
  773. value += nput;
  774. }
  775. return status;
  776. }
  777. static int
  778. putNCvx_schar_int(NC *ncp, const NC_var *varp,
  779. const size_t *start, size_t nelems, const int *value)
  780. {
  781. off_t offset = NC_varoffset(ncp, varp, start);
  782. size_t remaining = varp->xsz * nelems;
  783. int status = NC_NOERR;
  784. void *xp;
  785. if(nelems == 0)
  786. return NC_NOERR;
  787. assert(value != NULL);
  788. for(;;)
  789. {
  790. size_t extent = MIN(remaining, ncp->chunk);
  791. size_t nput = ncx_howmany(varp->type, extent);
  792. int lstatus = ncio_get(ncp->nciop, offset, extent,
  793. RGN_WRITE, &xp);
  794. if(lstatus != NC_NOERR)
  795. return lstatus;
  796. lstatus = ncx_putn_schar_int(&xp, nput, value);
  797. if(lstatus != NC_NOERR && status == NC_NOERR)
  798. {
  799. /* not fatal to the loop */
  800. status = lstatus;
  801. }
  802. (void) ncio_rel(ncp->nciop, offset,
  803. RGN_MODIFIED);
  804. remaining -= extent;
  805. if(remaining == 0)
  806. break; /* normal loop exit */
  807. offset += extent;
  808. value += nput;
  809. }
  810. return status;
  811. }
  812. static int
  813. putNCvx_schar_float(NC *ncp, const NC_var *varp,
  814. const size_t *start, size_t nelems, const float *value)
  815. {
  816. off_t offset = NC_varoffset(ncp, varp, start);
  817. size_t remaining = varp->xsz * nelems;
  818. int status = NC_NOERR;
  819. void *xp;
  820. if(nelems == 0)
  821. return NC_NOERR;
  822. assert(value != NULL);
  823. for(;;)
  824. {
  825. size_t extent = MIN(remaining, ncp->chunk);
  826. size_t nput = ncx_howmany(varp->type, extent);
  827. int lstatus = ncio_get(ncp->nciop, offset, extent,
  828. RGN_WRITE, &xp);
  829. if(lstatus != NC_NOERR)
  830. return lstatus;
  831. lstatus = ncx_putn_schar_float(&xp, nput, value);
  832. if(lstatus != NC_NOERR && status == NC_NOERR)
  833. {
  834. /* not fatal to the loop */
  835. status = lstatus;
  836. }
  837. (void) ncio_rel(ncp->nciop, offset,
  838. RGN_MODIFIED);
  839. remaining -= extent;
  840. if(remaining == 0)
  841. break; /* normal loop exit */
  842. offset += extent;
  843. value += nput;
  844. }
  845. return status;
  846. }
  847. static int
  848. putNCvx_schar_double(NC *ncp, const NC_var *varp,
  849. const size_t *start, size_t nelems, const double *value)
  850. {
  851. off_t offset = NC_varoffset(ncp, varp, start);
  852. size_t remaining = varp->xsz * nelems;
  853. int status = NC_NOERR;
  854. void *xp;
  855. if(nelems == 0)
  856. return NC_NOERR;
  857. assert(value != NULL);
  858. for(;;)
  859. {
  860. size_t extent = MIN(remaining, ncp->chunk);
  861. size_t nput = ncx_howmany(varp->type, extent);
  862. int lstatus = ncio_get(ncp->nciop, offset, extent,
  863. RGN_WRITE, &xp);
  864. if(lstatus != NC_NOERR)
  865. return lstatus;
  866. lstatus = ncx_putn_schar_double(&xp, nput, value);
  867. if(lstatus != NC_NOERR && status == NC_NOERR)
  868. {
  869. /* not fatal to the loop */
  870. status = lstatus;
  871. }
  872. (void) ncio_rel(ncp->nciop, offset,
  873. RGN_MODIFIED);
  874. remaining -= extent;
  875. if(remaining == 0)
  876. break; /* normal loop exit */
  877. offset += extent;
  878. value += nput;
  879. }
  880. return status;
  881. }
  882. static int
  883. putNCvx_schar_longlong(NC *ncp, const NC_var *varp,
  884. const size_t *start, size_t nelems, const longlong *value)
  885. {
  886. off_t offset = NC_varoffset(ncp, varp, start);
  887. size_t remaining = varp->xsz * nelems;
  888. int status = NC_NOERR;
  889. void *xp;
  890. if(nelems == 0)
  891. return NC_NOERR;
  892. assert(value != NULL);
  893. for(;;)
  894. {
  895. size_t extent = MIN(remaining, ncp->chunk);
  896. size_t nput = ncx_howmany(varp->type, extent);
  897. int lstatus = ncio_get(ncp->nciop, offset, extent,
  898. RGN_WRITE, &xp);
  899. if(lstatus != NC_NOERR)
  900. return lstatus;
  901. lstatus = ncx_putn_schar_longlong(&xp, nput, value);
  902. if(lstatus != NC_NOERR && status == NC_NOERR)
  903. {
  904. /* not fatal to the loop */
  905. status = lstatus;
  906. }
  907. (void) ncio_rel(ncp->nciop, offset,
  908. RGN_MODIFIED);
  909. remaining -= extent;
  910. if(remaining == 0)
  911. break; /* normal loop exit */
  912. offset += extent;
  913. value += nput;
  914. }
  915. return status;
  916. }
  917. static int
  918. putNCvx_short_schar(NC *ncp, const NC_var *varp,
  919. const size_t *start, size_t nelems, const schar *value)
  920. {
  921. off_t offset = NC_varoffset(ncp, varp, start);
  922. size_t remaining = varp->xsz * nelems;
  923. int status = NC_NOERR;
  924. void *xp;
  925. if(nelems == 0)
  926. return NC_NOERR;
  927. assert(value != NULL);
  928. for(;;)
  929. {
  930. size_t extent = MIN(remaining, ncp->chunk);
  931. size_t nput = ncx_howmany(varp->type, extent);
  932. int lstatus = ncio_get(ncp->nciop, offset, extent,
  933. RGN_WRITE, &xp);
  934. if(lstatus != NC_NOERR)
  935. return lstatus;
  936. lstatus = ncx_putn_short_schar(&xp, nput, value);
  937. if(lstatus != NC_NOERR && status == NC_NOERR)
  938. {
  939. /* not fatal to the loop */
  940. status = lstatus;
  941. }
  942. (void) ncio_rel(ncp->nciop, offset,
  943. RGN_MODIFIED);
  944. remaining -= extent;
  945. if(remaining == 0)
  946. break; /* normal loop exit */
  947. offset += extent;
  948. value += nput;
  949. }
  950. return status;
  951. }
  952. static int
  953. putNCvx_short_uchar(NC *ncp, const NC_var *varp,
  954. const size_t *start, size_t nelems, const uchar *value)
  955. {
  956. off_t offset = NC_varoffset(ncp, varp, start);
  957. size_t remaining = varp->xsz * nelems;
  958. int status = NC_NOERR;
  959. void *xp;
  960. if(nelems == 0)
  961. return NC_NOERR;
  962. assert(value != NULL);
  963. for(;;)
  964. {
  965. size_t extent = MIN(remaining, ncp->chunk);
  966. size_t nput = ncx_howmany(varp->type, extent);
  967. int lstatus = ncio_get(ncp->nciop, offset, extent,
  968. RGN_WRITE, &xp);
  969. if(lstatus != NC_NOERR)
  970. return lstatus;
  971. lstatus = ncx_putn_short_uchar(&xp, nput, value);
  972. if(lstatus != NC_NOERR && status == NC_NOERR)
  973. {
  974. /* not fatal to the loop */
  975. status = lstatus;
  976. }
  977. (void) ncio_rel(ncp->nciop, offset,
  978. RGN_MODIFIED);
  979. remaining -= extent;
  980. if(remaining == 0)
  981. break; /* normal loop exit */
  982. offset += extent;
  983. value += nput;
  984. }
  985. return status;
  986. }
  987. static int
  988. putNCvx_short_short(NC *ncp, const NC_var *varp,
  989. const size_t *start, size_t nelems, const short *value)
  990. {
  991. off_t offset = NC_varoffset(ncp, varp, start);
  992. size_t remaining = varp->xsz * nelems;
  993. int status = NC_NOERR;
  994. void *xp;
  995. if(nelems == 0)
  996. return NC_NOERR;
  997. assert(value != NULL);
  998. for(;;)
  999. {
  1000. size_t extent = MIN(remaining, ncp->chunk);
  1001. size_t nput = ncx_howmany(varp->type, extent);
  1002. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1003. RGN_WRITE, &xp);
  1004. if(lstatus != NC_NOERR)
  1005. return lstatus;
  1006. lstatus = ncx_putn_short_short(&xp, nput, value);
  1007. if(lstatus != NC_NOERR && status == NC_NOERR)
  1008. {
  1009. /* not fatal to the loop */
  1010. status = lstatus;
  1011. }
  1012. (void) ncio_rel(ncp->nciop, offset,
  1013. RGN_MODIFIED);
  1014. remaining -= extent;
  1015. if(remaining == 0)
  1016. break; /* normal loop exit */
  1017. offset += extent;
  1018. value += nput;
  1019. }
  1020. return status;
  1021. }
  1022. static int
  1023. putNCvx_short_int(NC *ncp, const NC_var *varp,
  1024. const size_t *start, size_t nelems, const int *value)
  1025. {
  1026. off_t offset = NC_varoffset(ncp, varp, start);
  1027. size_t remaining = varp->xsz * nelems;
  1028. int status = NC_NOERR;
  1029. void *xp;
  1030. if(nelems == 0)
  1031. return NC_NOERR;
  1032. assert(value != NULL);
  1033. for(;;)
  1034. {
  1035. size_t extent = MIN(remaining, ncp->chunk);
  1036. size_t nput = ncx_howmany(varp->type, extent);
  1037. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1038. RGN_WRITE, &xp);
  1039. if(lstatus != NC_NOERR)
  1040. return lstatus;
  1041. lstatus = ncx_putn_short_int(&xp, nput, value);
  1042. if(lstatus != NC_NOERR && status == NC_NOERR)
  1043. {
  1044. /* not fatal to the loop */
  1045. status = lstatus;
  1046. }
  1047. (void) ncio_rel(ncp->nciop, offset,
  1048. RGN_MODIFIED);
  1049. remaining -= extent;
  1050. if(remaining == 0)
  1051. break; /* normal loop exit */
  1052. offset += extent;
  1053. value += nput;
  1054. }
  1055. return status;
  1056. }
  1057. static int
  1058. putNCvx_short_float(NC *ncp, const NC_var *varp,
  1059. const size_t *start, size_t nelems, const float *value)
  1060. {
  1061. off_t offset = NC_varoffset(ncp, varp, start);
  1062. size_t remaining = varp->xsz * nelems;
  1063. int status = NC_NOERR;
  1064. void *xp;
  1065. if(nelems == 0)
  1066. return NC_NOERR;
  1067. assert(value != NULL);
  1068. for(;;)
  1069. {
  1070. size_t extent = MIN(remaining, ncp->chunk);
  1071. size_t nput = ncx_howmany(varp->type, extent);
  1072. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1073. RGN_WRITE, &xp);
  1074. if(lstatus != NC_NOERR)
  1075. return lstatus;
  1076. lstatus = ncx_putn_short_float(&xp, nput, value);
  1077. if(lstatus != NC_NOERR && status == NC_NOERR)
  1078. {
  1079. /* not fatal to the loop */
  1080. status = lstatus;
  1081. }
  1082. (void) ncio_rel(ncp->nciop, offset,
  1083. RGN_MODIFIED);
  1084. remaining -= extent;
  1085. if(remaining == 0)
  1086. break; /* normal loop exit */
  1087. offset += extent;
  1088. value += nput;
  1089. }
  1090. return status;
  1091. }
  1092. static int
  1093. putNCvx_short_double(NC *ncp, const NC_var *varp,
  1094. const size_t *start, size_t nelems, const double *value)
  1095. {
  1096. off_t offset = NC_varoffset(ncp, varp, start);
  1097. size_t remaining = varp->xsz * nelems;
  1098. int status = NC_NOERR;
  1099. void *xp;
  1100. if(nelems == 0)
  1101. return NC_NOERR;
  1102. assert(value != NULL);
  1103. for(;;)
  1104. {
  1105. size_t extent = MIN(remaining, ncp->chunk);
  1106. size_t nput = ncx_howmany(varp->type, extent);
  1107. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1108. RGN_WRITE, &xp);
  1109. if(lstatus != NC_NOERR)
  1110. return lstatus;
  1111. lstatus = ncx_putn_short_double(&xp, nput, value);
  1112. if(lstatus != NC_NOERR && status == NC_NOERR)
  1113. {
  1114. /* not fatal to the loop */
  1115. status = lstatus;
  1116. }
  1117. (void) ncio_rel(ncp->nciop, offset,
  1118. RGN_MODIFIED);
  1119. remaining -= extent;
  1120. if(remaining == 0)
  1121. break; /* normal loop exit */
  1122. offset += extent;
  1123. value += nput;
  1124. }
  1125. return status;
  1126. }
  1127. static int
  1128. putNCvx_short_longlong(NC *ncp, const NC_var *varp,
  1129. const size_t *start, size_t nelems, const longlong *value)
  1130. {
  1131. off_t offset = NC_varoffset(ncp, varp, start);
  1132. size_t remaining = varp->xsz * nelems;
  1133. int status = NC_NOERR;
  1134. void *xp;
  1135. if(nelems == 0)
  1136. return NC_NOERR;
  1137. assert(value != NULL);
  1138. for(;;)
  1139. {
  1140. size_t extent = MIN(remaining, ncp->chunk);
  1141. size_t nput = ncx_howmany(varp->type, extent);
  1142. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1143. RGN_WRITE, &xp);
  1144. if(lstatus != NC_NOERR)
  1145. return lstatus;
  1146. lstatus = ncx_putn_short_longlong(&xp, nput, value);
  1147. if(lstatus != NC_NOERR && status == NC_NOERR)
  1148. {
  1149. /* not fatal to the loop */
  1150. status = lstatus;
  1151. }
  1152. (void) ncio_rel(ncp->nciop, offset,
  1153. RGN_MODIFIED);
  1154. remaining -= extent;
  1155. if(remaining == 0)
  1156. break; /* normal loop exit */
  1157. offset += extent;
  1158. value += nput;
  1159. }
  1160. return status;
  1161. }
  1162. static int
  1163. putNCvx_int_schar(NC *ncp, const NC_var *varp,
  1164. const size_t *start, size_t nelems, const schar *value)
  1165. {
  1166. off_t offset = NC_varoffset(ncp, varp, start);
  1167. size_t remaining = varp->xsz * nelems;
  1168. int status = NC_NOERR;
  1169. void *xp;
  1170. if(nelems == 0)
  1171. return NC_NOERR;
  1172. assert(value != NULL);
  1173. for(;;)
  1174. {
  1175. size_t extent = MIN(remaining, ncp->chunk);
  1176. size_t nput = ncx_howmany(varp->type, extent);
  1177. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1178. RGN_WRITE, &xp);
  1179. if(lstatus != NC_NOERR)
  1180. return lstatus;
  1181. lstatus = ncx_putn_int_schar(&xp, nput, value);
  1182. if(lstatus != NC_NOERR && status == NC_NOERR)
  1183. {
  1184. /* not fatal to the loop */
  1185. status = lstatus;
  1186. }
  1187. (void) ncio_rel(ncp->nciop, offset,
  1188. RGN_MODIFIED);
  1189. remaining -= extent;
  1190. if(remaining == 0)
  1191. break; /* normal loop exit */
  1192. offset += extent;
  1193. value += nput;
  1194. }
  1195. return status;
  1196. }
  1197. static int
  1198. putNCvx_int_uchar(NC *ncp, const NC_var *varp,
  1199. const size_t *start, size_t nelems, const uchar *value)
  1200. {
  1201. off_t offset = NC_varoffset(ncp, varp, start);
  1202. size_t remaining = varp->xsz * nelems;
  1203. int status = NC_NOERR;
  1204. void *xp;
  1205. if(nelems == 0)
  1206. return NC_NOERR;
  1207. assert(value != NULL);
  1208. for(;;)
  1209. {
  1210. size_t extent = MIN(remaining, ncp->chunk);
  1211. size_t nput = ncx_howmany(varp->type, extent);
  1212. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1213. RGN_WRITE, &xp);
  1214. if(lstatus != NC_NOERR)
  1215. return lstatus;
  1216. lstatus = ncx_putn_int_uchar(&xp, nput, value);
  1217. if(lstatus != NC_NOERR && status == NC_NOERR)
  1218. {
  1219. /* not fatal to the loop */
  1220. status = lstatus;
  1221. }
  1222. (void) ncio_rel(ncp->nciop, offset,
  1223. RGN_MODIFIED);
  1224. remaining -= extent;
  1225. if(remaining == 0)
  1226. break; /* normal loop exit */
  1227. offset += extent;
  1228. value += nput;
  1229. }
  1230. return status;
  1231. }
  1232. static int
  1233. putNCvx_int_short(NC *ncp, const NC_var *varp,
  1234. const size_t *start, size_t nelems, const short *value)
  1235. {
  1236. off_t offset = NC_varoffset(ncp, varp, start);
  1237. size_t remaining = varp->xsz * nelems;
  1238. int status = NC_NOERR;
  1239. void *xp;
  1240. if(nelems == 0)
  1241. return NC_NOERR;
  1242. assert(value != NULL);
  1243. for(;;)
  1244. {
  1245. size_t extent = MIN(remaining, ncp->chunk);
  1246. size_t nput = ncx_howmany(varp->type, extent);
  1247. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1248. RGN_WRITE, &xp);
  1249. if(lstatus != NC_NOERR)
  1250. return lstatus;
  1251. lstatus = ncx_putn_int_short(&xp, nput, value);
  1252. if(lstatus != NC_NOERR && status == NC_NOERR)
  1253. {
  1254. /* not fatal to the loop */
  1255. status = lstatus;
  1256. }
  1257. (void) ncio_rel(ncp->nciop, offset,
  1258. RGN_MODIFIED);
  1259. remaining -= extent;
  1260. if(remaining == 0)
  1261. break; /* normal loop exit */
  1262. offset += extent;
  1263. value += nput;
  1264. }
  1265. return status;
  1266. }
  1267. static int
  1268. putNCvx_int_int(NC *ncp, const NC_var *varp,
  1269. const size_t *start, size_t nelems, const int *value)
  1270. {
  1271. off_t offset = NC_varoffset(ncp, varp, start);
  1272. size_t remaining = varp->xsz * nelems;
  1273. int status = NC_NOERR;
  1274. void *xp;
  1275. if(nelems == 0)
  1276. return NC_NOERR;
  1277. assert(value != NULL);
  1278. for(;;)
  1279. {
  1280. size_t extent = MIN(remaining, ncp->chunk);
  1281. size_t nput = ncx_howmany(varp->type, extent);
  1282. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1283. RGN_WRITE, &xp);
  1284. if(lstatus != NC_NOERR)
  1285. return lstatus;
  1286. lstatus = ncx_putn_int_int(&xp, nput, value);
  1287. if(lstatus != NC_NOERR && status == NC_NOERR)
  1288. {
  1289. /* not fatal to the loop */
  1290. status = lstatus;
  1291. }
  1292. (void) ncio_rel(ncp->nciop, offset,
  1293. RGN_MODIFIED);
  1294. remaining -= extent;
  1295. if(remaining == 0)
  1296. break; /* normal loop exit */
  1297. offset += extent;
  1298. value += nput;
  1299. }
  1300. return status;
  1301. }
  1302. static int
  1303. putNCvx_int_float(NC *ncp, const NC_var *varp,
  1304. const size_t *start, size_t nelems, const float *value)
  1305. {
  1306. off_t offset = NC_varoffset(ncp, varp, start);
  1307. size_t remaining = varp->xsz * nelems;
  1308. int status = NC_NOERR;
  1309. void *xp;
  1310. if(nelems == 0)
  1311. return NC_NOERR;
  1312. assert(value != NULL);
  1313. for(;;)
  1314. {
  1315. size_t extent = MIN(remaining, ncp->chunk);
  1316. size_t nput = ncx_howmany(varp->type, extent);
  1317. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1318. RGN_WRITE, &xp);
  1319. if(lstatus != NC_NOERR)
  1320. return lstatus;
  1321. lstatus = ncx_putn_int_float(&xp, nput, value);
  1322. if(lstatus != NC_NOERR && status == NC_NOERR)
  1323. {
  1324. /* not fatal to the loop */
  1325. status = lstatus;
  1326. }
  1327. (void) ncio_rel(ncp->nciop, offset,
  1328. RGN_MODIFIED);
  1329. remaining -= extent;
  1330. if(remaining == 0)
  1331. break; /* normal loop exit */
  1332. offset += extent;
  1333. value += nput;
  1334. }
  1335. return status;
  1336. }
  1337. static int
  1338. putNCvx_int_double(NC *ncp, const NC_var *varp,
  1339. const size_t *start, size_t nelems, const double *value)
  1340. {
  1341. off_t offset = NC_varoffset(ncp, varp, start);
  1342. size_t remaining = varp->xsz * nelems;
  1343. int status = NC_NOERR;
  1344. void *xp;
  1345. if(nelems == 0)
  1346. return NC_NOERR;
  1347. assert(value != NULL);
  1348. for(;;)
  1349. {
  1350. size_t extent = MIN(remaining, ncp->chunk);
  1351. size_t nput = ncx_howmany(varp->type, extent);
  1352. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1353. RGN_WRITE, &xp);
  1354. if(lstatus != NC_NOERR)
  1355. return lstatus;
  1356. lstatus = ncx_putn_int_double(&xp, nput, value);
  1357. if(lstatus != NC_NOERR && status == NC_NOERR)
  1358. {
  1359. /* not fatal to the loop */
  1360. status = lstatus;
  1361. }
  1362. (void) ncio_rel(ncp->nciop, offset,
  1363. RGN_MODIFIED);
  1364. remaining -= extent;
  1365. if(remaining == 0)
  1366. break; /* normal loop exit */
  1367. offset += extent;
  1368. value += nput;
  1369. }
  1370. return status;
  1371. }
  1372. static int
  1373. putNCvx_int_longlong(NC *ncp, const NC_var *varp,
  1374. const size_t *start, size_t nelems, const longlong *value)
  1375. {
  1376. off_t offset = NC_varoffset(ncp, varp, start);
  1377. size_t remaining = varp->xsz * nelems;
  1378. int status = NC_NOERR;
  1379. void *xp;
  1380. if(nelems == 0)
  1381. return NC_NOERR;
  1382. assert(value != NULL);
  1383. for(;;)
  1384. {
  1385. size_t extent = MIN(remaining, ncp->chunk);
  1386. size_t nput = ncx_howmany(varp->type, extent);
  1387. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1388. RGN_WRITE, &xp);
  1389. if(lstatus != NC_NOERR)
  1390. return lstatus;
  1391. lstatus = ncx_putn_int_longlong(&xp, nput, value);
  1392. if(lstatus != NC_NOERR && status == NC_NOERR)
  1393. {
  1394. /* not fatal to the loop */
  1395. status = lstatus;
  1396. }
  1397. (void) ncio_rel(ncp->nciop, offset,
  1398. RGN_MODIFIED);
  1399. remaining -= extent;
  1400. if(remaining == 0)
  1401. break; /* normal loop exit */
  1402. offset += extent;
  1403. value += nput;
  1404. }
  1405. return status;
  1406. }
  1407. static int
  1408. putNCvx_float_schar(NC *ncp, const NC_var *varp,
  1409. const size_t *start, size_t nelems, const schar *value)
  1410. {
  1411. off_t offset = NC_varoffset(ncp, varp, start);
  1412. size_t remaining = varp->xsz * nelems;
  1413. int status = NC_NOERR;
  1414. void *xp;
  1415. if(nelems == 0)
  1416. return NC_NOERR;
  1417. assert(value != NULL);
  1418. for(;;)
  1419. {
  1420. size_t extent = MIN(remaining, ncp->chunk);
  1421. size_t nput = ncx_howmany(varp->type, extent);
  1422. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1423. RGN_WRITE, &xp);
  1424. if(lstatus != NC_NOERR)
  1425. return lstatus;
  1426. lstatus = ncx_putn_float_schar(&xp, nput, value);
  1427. if(lstatus != NC_NOERR && status == NC_NOERR)
  1428. {
  1429. /* not fatal to the loop */
  1430. status = lstatus;
  1431. }
  1432. (void) ncio_rel(ncp->nciop, offset,
  1433. RGN_MODIFIED);
  1434. remaining -= extent;
  1435. if(remaining == 0)
  1436. break; /* normal loop exit */
  1437. offset += extent;
  1438. value += nput;
  1439. }
  1440. return status;
  1441. }
  1442. static int
  1443. putNCvx_float_uchar(NC *ncp, const NC_var *varp,
  1444. const size_t *start, size_t nelems, const uchar *value)
  1445. {
  1446. off_t offset = NC_varoffset(ncp, varp, start);
  1447. size_t remaining = varp->xsz * nelems;
  1448. int status = NC_NOERR;
  1449. void *xp;
  1450. if(nelems == 0)
  1451. return NC_NOERR;
  1452. assert(value != NULL);
  1453. for(;;)
  1454. {
  1455. size_t extent = MIN(remaining, ncp->chunk);
  1456. size_t nput = ncx_howmany(varp->type, extent);
  1457. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1458. RGN_WRITE, &xp);
  1459. if(lstatus != NC_NOERR)
  1460. return lstatus;
  1461. lstatus = ncx_putn_float_uchar(&xp, nput, value);
  1462. if(lstatus != NC_NOERR && status == NC_NOERR)
  1463. {
  1464. /* not fatal to the loop */
  1465. status = lstatus;
  1466. }
  1467. (void) ncio_rel(ncp->nciop, offset,
  1468. RGN_MODIFIED);
  1469. remaining -= extent;
  1470. if(remaining == 0)
  1471. break; /* normal loop exit */
  1472. offset += extent;
  1473. value += nput;
  1474. }
  1475. return status;
  1476. }
  1477. static int
  1478. putNCvx_float_short(NC *ncp, const NC_var *varp,
  1479. const size_t *start, size_t nelems, const short *value)
  1480. {
  1481. off_t offset = NC_varoffset(ncp, varp, start);
  1482. size_t remaining = varp->xsz * nelems;
  1483. int status = NC_NOERR;
  1484. void *xp;
  1485. if(nelems == 0)
  1486. return NC_NOERR;
  1487. assert(value != NULL);
  1488. for(;;)
  1489. {
  1490. size_t extent = MIN(remaining, ncp->chunk);
  1491. size_t nput = ncx_howmany(varp->type, extent);
  1492. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1493. RGN_WRITE, &xp);
  1494. if(lstatus != NC_NOERR)
  1495. return lstatus;
  1496. lstatus = ncx_putn_float_short(&xp, nput, value);
  1497. if(lstatus != NC_NOERR && status == NC_NOERR)
  1498. {
  1499. /* not fatal to the loop */
  1500. status = lstatus;
  1501. }
  1502. (void) ncio_rel(ncp->nciop, offset,
  1503. RGN_MODIFIED);
  1504. remaining -= extent;
  1505. if(remaining == 0)
  1506. break; /* normal loop exit */
  1507. offset += extent;
  1508. value += nput;
  1509. }
  1510. return status;
  1511. }
  1512. static int
  1513. putNCvx_float_int(NC *ncp, const NC_var *varp,
  1514. const size_t *start, size_t nelems, const int *value)
  1515. {
  1516. off_t offset = NC_varoffset(ncp, varp, start);
  1517. size_t remaining = varp->xsz * nelems;
  1518. int status = NC_NOERR;
  1519. void *xp;
  1520. if(nelems == 0)
  1521. return NC_NOERR;
  1522. assert(value != NULL);
  1523. for(;;)
  1524. {
  1525. size_t extent = MIN(remaining, ncp->chunk);
  1526. size_t nput = ncx_howmany(varp->type, extent);
  1527. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1528. RGN_WRITE, &xp);
  1529. if(lstatus != NC_NOERR)
  1530. return lstatus;
  1531. lstatus = ncx_putn_float_int(&xp, nput, value);
  1532. if(lstatus != NC_NOERR && status == NC_NOERR)
  1533. {
  1534. /* not fatal to the loop */
  1535. status = lstatus;
  1536. }
  1537. (void) ncio_rel(ncp->nciop, offset,
  1538. RGN_MODIFIED);
  1539. remaining -= extent;
  1540. if(remaining == 0)
  1541. break; /* normal loop exit */
  1542. offset += extent;
  1543. value += nput;
  1544. }
  1545. return status;
  1546. }
  1547. static int
  1548. putNCvx_float_float(NC *ncp, const NC_var *varp,
  1549. const size_t *start, size_t nelems, const float *value)
  1550. {
  1551. off_t offset = NC_varoffset(ncp, varp, start);
  1552. size_t remaining = varp->xsz * nelems;
  1553. int status = NC_NOERR;
  1554. void *xp;
  1555. if(nelems == 0)
  1556. return NC_NOERR;
  1557. assert(value != NULL);
  1558. for(;;)
  1559. {
  1560. size_t extent = MIN(remaining, ncp->chunk);
  1561. size_t nput = ncx_howmany(varp->type, extent);
  1562. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1563. RGN_WRITE, &xp);
  1564. if(lstatus != NC_NOERR)
  1565. return lstatus;
  1566. lstatus = ncx_putn_float_float(&xp, nput, value);
  1567. if(lstatus != NC_NOERR && status == NC_NOERR)
  1568. {
  1569. /* not fatal to the loop */
  1570. status = lstatus;
  1571. }
  1572. (void) ncio_rel(ncp->nciop, offset,
  1573. RGN_MODIFIED);
  1574. remaining -= extent;
  1575. if(remaining == 0)
  1576. break; /* normal loop exit */
  1577. offset += extent;
  1578. value += nput;
  1579. }
  1580. return status;
  1581. }
  1582. static int
  1583. putNCvx_float_double(NC *ncp, const NC_var *varp,
  1584. const size_t *start, size_t nelems, const double *value)
  1585. {
  1586. off_t offset = NC_varoffset(ncp, varp, start);
  1587. size_t remaining = varp->xsz * nelems;
  1588. int status = NC_NOERR;
  1589. void *xp;
  1590. if(nelems == 0)
  1591. return NC_NOERR;
  1592. assert(value != NULL);
  1593. for(;;)
  1594. {
  1595. size_t extent = MIN(remaining, ncp->chunk);
  1596. size_t nput = ncx_howmany(varp->type, extent);
  1597. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1598. RGN_WRITE, &xp);
  1599. if(lstatus != NC_NOERR)
  1600. return lstatus;
  1601. lstatus = ncx_putn_float_double(&xp, nput, value);
  1602. if(lstatus != NC_NOERR && status == NC_NOERR)
  1603. {
  1604. /* not fatal to the loop */
  1605. status = lstatus;
  1606. }
  1607. (void) ncio_rel(ncp->nciop, offset,
  1608. RGN_MODIFIED);
  1609. remaining -= extent;
  1610. if(remaining == 0)
  1611. break; /* normal loop exit */
  1612. offset += extent;
  1613. value += nput;
  1614. }
  1615. return status;
  1616. }
  1617. static int
  1618. putNCvx_float_longlong(NC *ncp, const NC_var *varp,
  1619. const size_t *start, size_t nelems, const longlong *value)
  1620. {
  1621. off_t offset = NC_varoffset(ncp, varp, start);
  1622. size_t remaining = varp->xsz * nelems;
  1623. int status = NC_NOERR;
  1624. void *xp;
  1625. if(nelems == 0)
  1626. return NC_NOERR;
  1627. assert(value != NULL);
  1628. for(;;)
  1629. {
  1630. size_t extent = MIN(remaining, ncp->chunk);
  1631. size_t nput = ncx_howmany(varp->type, extent);
  1632. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1633. RGN_WRITE, &xp);
  1634. if(lstatus != NC_NOERR)
  1635. return lstatus;
  1636. lstatus = ncx_putn_float_longlong(&xp, nput, value);
  1637. if(lstatus != NC_NOERR && status == NC_NOERR)
  1638. {
  1639. /* not fatal to the loop */
  1640. status = lstatus;
  1641. }
  1642. (void) ncio_rel(ncp->nciop, offset,
  1643. RGN_MODIFIED);
  1644. remaining -= extent;
  1645. if(remaining == 0)
  1646. break; /* normal loop exit */
  1647. offset += extent;
  1648. value += nput;
  1649. }
  1650. return status;
  1651. }
  1652. static int
  1653. putNCvx_double_schar(NC *ncp, const NC_var *varp,
  1654. const size_t *start, size_t nelems, const schar *value)
  1655. {
  1656. off_t offset = NC_varoffset(ncp, varp, start);
  1657. size_t remaining = varp->xsz * nelems;
  1658. int status = NC_NOERR;
  1659. void *xp;
  1660. if(nelems == 0)
  1661. return NC_NOERR;
  1662. assert(value != NULL);
  1663. for(;;)
  1664. {
  1665. size_t extent = MIN(remaining, ncp->chunk);
  1666. size_t nput = ncx_howmany(varp->type, extent);
  1667. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1668. RGN_WRITE, &xp);
  1669. if(lstatus != NC_NOERR)
  1670. return lstatus;
  1671. lstatus = ncx_putn_double_schar(&xp, nput, value);
  1672. if(lstatus != NC_NOERR && status == NC_NOERR)
  1673. {
  1674. /* not fatal to the loop */
  1675. status = lstatus;
  1676. }
  1677. (void) ncio_rel(ncp->nciop, offset,
  1678. RGN_MODIFIED);
  1679. remaining -= extent;
  1680. if(remaining == 0)
  1681. break; /* normal loop exit */
  1682. offset += extent;
  1683. value += nput;
  1684. }
  1685. return status;
  1686. }
  1687. static int
  1688. putNCvx_double_uchar(NC *ncp, const NC_var *varp,
  1689. const size_t *start, size_t nelems, const uchar *value)
  1690. {
  1691. off_t offset = NC_varoffset(ncp, varp, start);
  1692. size_t remaining = varp->xsz * nelems;
  1693. int status = NC_NOERR;
  1694. void *xp;
  1695. if(nelems == 0)
  1696. return NC_NOERR;
  1697. assert(value != NULL);
  1698. for(;;)
  1699. {
  1700. size_t extent = MIN(remaining, ncp->chunk);
  1701. size_t nput = ncx_howmany(varp->type, extent);
  1702. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1703. RGN_WRITE, &xp);
  1704. if(lstatus != NC_NOERR)
  1705. return lstatus;
  1706. lstatus = ncx_putn_double_uchar(&xp, nput, value);
  1707. if(lstatus != NC_NOERR && status == NC_NOERR)
  1708. {
  1709. /* not fatal to the loop */
  1710. status = lstatus;
  1711. }
  1712. (void) ncio_rel(ncp->nciop, offset,
  1713. RGN_MODIFIED);
  1714. remaining -= extent;
  1715. if(remaining == 0)
  1716. break; /* normal loop exit */
  1717. offset += extent;
  1718. value += nput;
  1719. }
  1720. return status;
  1721. }
  1722. static int
  1723. putNCvx_double_short(NC *ncp, const NC_var *varp,
  1724. const size_t *start, size_t nelems, const short *value)
  1725. {
  1726. off_t offset = NC_varoffset(ncp, varp, start);
  1727. size_t remaining = varp->xsz * nelems;
  1728. int status = NC_NOERR;
  1729. void *xp;
  1730. if(nelems == 0)
  1731. return NC_NOERR;
  1732. assert(value != NULL);
  1733. for(;;)
  1734. {
  1735. size_t extent = MIN(remaining, ncp->chunk);
  1736. size_t nput = ncx_howmany(varp->type, extent);
  1737. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1738. RGN_WRITE, &xp);
  1739. if(lstatus != NC_NOERR)
  1740. return lstatus;
  1741. lstatus = ncx_putn_double_short(&xp, nput, value);
  1742. if(lstatus != NC_NOERR && status == NC_NOERR)
  1743. {
  1744. /* not fatal to the loop */
  1745. status = lstatus;
  1746. }
  1747. (void) ncio_rel(ncp->nciop, offset,
  1748. RGN_MODIFIED);
  1749. remaining -= extent;
  1750. if(remaining == 0)
  1751. break; /* normal loop exit */
  1752. offset += extent;
  1753. value += nput;
  1754. }
  1755. return status;
  1756. }
  1757. static int
  1758. putNCvx_double_int(NC *ncp, const NC_var *varp,
  1759. const size_t *start, size_t nelems, const int *value)
  1760. {
  1761. off_t offset = NC_varoffset(ncp, varp, start);
  1762. size_t remaining = varp->xsz * nelems;
  1763. int status = NC_NOERR;
  1764. void *xp;
  1765. if(nelems == 0)
  1766. return NC_NOERR;
  1767. assert(value != NULL);
  1768. for(;;)
  1769. {
  1770. size_t extent = MIN(remaining, ncp->chunk);
  1771. size_t nput = ncx_howmany(varp->type, extent);
  1772. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1773. RGN_WRITE, &xp);
  1774. if(lstatus != NC_NOERR)
  1775. return lstatus;
  1776. lstatus = ncx_putn_double_int(&xp, nput, value);
  1777. if(lstatus != NC_NOERR && status == NC_NOERR)
  1778. {
  1779. /* not fatal to the loop */
  1780. status = lstatus;
  1781. }
  1782. (void) ncio_rel(ncp->nciop, offset,
  1783. RGN_MODIFIED);
  1784. remaining -= extent;
  1785. if(remaining == 0)
  1786. break; /* normal loop exit */
  1787. offset += extent;
  1788. value += nput;
  1789. }
  1790. return status;
  1791. }
  1792. static int
  1793. putNCvx_double_float(NC *ncp, const NC_var *varp,
  1794. const size_t *start, size_t nelems, const float *value)
  1795. {
  1796. off_t offset = NC_varoffset(ncp, varp, start);
  1797. size_t remaining = varp->xsz * nelems;
  1798. int status = NC_NOERR;
  1799. void *xp;
  1800. if(nelems == 0)
  1801. return NC_NOERR;
  1802. assert(value != NULL);
  1803. for(;;)
  1804. {
  1805. size_t extent = MIN(remaining, ncp->chunk);
  1806. size_t nput = ncx_howmany(varp->type, extent);
  1807. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1808. RGN_WRITE, &xp);
  1809. if(lstatus != NC_NOERR)
  1810. return lstatus;
  1811. lstatus = ncx_putn_double_float(&xp, nput, value);
  1812. if(lstatus != NC_NOERR && status == NC_NOERR)
  1813. {
  1814. /* not fatal to the loop */
  1815. status = lstatus;
  1816. }
  1817. (void) ncio_rel(ncp->nciop, offset,
  1818. RGN_MODIFIED);
  1819. remaining -= extent;
  1820. if(remaining == 0)
  1821. break; /* normal loop exit */
  1822. offset += extent;
  1823. value += nput;
  1824. }
  1825. return status;
  1826. }
  1827. static int
  1828. putNCvx_double_double(NC *ncp, const NC_var *varp,
  1829. const size_t *start, size_t nelems, const double *value)
  1830. {
  1831. off_t offset = NC_varoffset(ncp, varp, start);
  1832. size_t remaining = varp->xsz * nelems;
  1833. int status = NC_NOERR;
  1834. void *xp;
  1835. if(nelems == 0)
  1836. return NC_NOERR;
  1837. assert(value != NULL);
  1838. for(;;)
  1839. {
  1840. size_t extent = MIN(remaining, ncp->chunk);
  1841. size_t nput = ncx_howmany(varp->type, extent);
  1842. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1843. RGN_WRITE, &xp);
  1844. if(lstatus != NC_NOERR)
  1845. return lstatus;
  1846. lstatus = ncx_putn_double_double(&xp, nput, value);
  1847. if(lstatus != NC_NOERR && status == NC_NOERR)
  1848. {
  1849. /* not fatal to the loop */
  1850. status = lstatus;
  1851. }
  1852. (void) ncio_rel(ncp->nciop, offset,
  1853. RGN_MODIFIED);
  1854. remaining -= extent;
  1855. if(remaining == 0)
  1856. break; /* normal loop exit */
  1857. offset += extent;
  1858. value += nput;
  1859. }
  1860. return status;
  1861. }
  1862. static int
  1863. putNCvx_double_longlong(NC *ncp, const NC_var *varp,
  1864. const size_t *start, size_t nelems, const longlong *value)
  1865. {
  1866. off_t offset = NC_varoffset(ncp, varp, start);
  1867. size_t remaining = varp->xsz * nelems;
  1868. int status = NC_NOERR;
  1869. void *xp;
  1870. if(nelems == 0)
  1871. return NC_NOERR;
  1872. assert(value != NULL);
  1873. for(;;)
  1874. {
  1875. size_t extent = MIN(remaining, ncp->chunk);
  1876. size_t nput = ncx_howmany(varp->type, extent);
  1877. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1878. RGN_WRITE, &xp);
  1879. if(lstatus != NC_NOERR)
  1880. return lstatus;
  1881. lstatus = ncx_putn_double_longlong(&xp, nput, value);
  1882. if(lstatus != NC_NOERR && status == NC_NOERR)
  1883. {
  1884. /* not fatal to the loop */
  1885. status = lstatus;
  1886. }
  1887. (void) ncio_rel(ncp->nciop, offset,
  1888. RGN_MODIFIED);
  1889. remaining -= extent;
  1890. if(remaining == 0)
  1891. break; /* normal loop exit */
  1892. offset += extent;
  1893. value += nput;
  1894. }
  1895. return status;
  1896. }
  1897. #ifdef NOTUSED
  1898. static int
  1899. putNCvx_schar_uint(NC *ncp, const NC_var *varp,
  1900. const size_t *start, size_t nelems, const uint *value)
  1901. {
  1902. off_t offset = NC_varoffset(ncp, varp, start);
  1903. size_t remaining = varp->xsz * nelems;
  1904. int status = NC_NOERR;
  1905. void *xp;
  1906. if(nelems == 0)
  1907. return NC_NOERR;
  1908. assert(value != NULL);
  1909. for(;;)
  1910. {
  1911. size_t extent = MIN(remaining, ncp->chunk);
  1912. size_t nput = ncx_howmany(varp->type, extent);
  1913. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1914. RGN_WRITE, &xp);
  1915. if(lstatus != NC_NOERR)
  1916. return lstatus;
  1917. lstatus = ncx_putn_schar_uint(&xp, nput, value);
  1918. if(lstatus != NC_NOERR && status == NC_NOERR)
  1919. {
  1920. /* not fatal to the loop */
  1921. status = lstatus;
  1922. }
  1923. (void) ncio_rel(ncp->nciop, offset,
  1924. RGN_MODIFIED);
  1925. remaining -= extent;
  1926. if(remaining == 0)
  1927. break; /* normal loop exit */
  1928. offset += extent;
  1929. value += nput;
  1930. }
  1931. return status;
  1932. }
  1933. static int
  1934. putNCvx_schar_ulonglong(NC *ncp, const NC_var *varp,
  1935. const size_t *start, size_t nelems, const ulonglong *value)
  1936. {
  1937. off_t offset = NC_varoffset(ncp, varp, start);
  1938. size_t remaining = varp->xsz * nelems;
  1939. int status = NC_NOERR;
  1940. void *xp;
  1941. if(nelems == 0)
  1942. return NC_NOERR;
  1943. assert(value != NULL);
  1944. for(;;)
  1945. {
  1946. size_t extent = MIN(remaining, ncp->chunk);
  1947. size_t nput = ncx_howmany(varp->type, extent);
  1948. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1949. RGN_WRITE, &xp);
  1950. if(lstatus != NC_NOERR)
  1951. return lstatus;
  1952. lstatus = ncx_putn_schar_ulonglong(&xp, nput, value);
  1953. if(lstatus != NC_NOERR && status == NC_NOERR)
  1954. {
  1955. /* not fatal to the loop */
  1956. status = lstatus;
  1957. }
  1958. (void) ncio_rel(ncp->nciop, offset,
  1959. RGN_MODIFIED);
  1960. remaining -= extent;
  1961. if(remaining == 0)
  1962. break; /* normal loop exit */
  1963. offset += extent;
  1964. value += nput;
  1965. }
  1966. return status;
  1967. }
  1968. static int
  1969. putNCvx_short_uint(NC *ncp, const NC_var *varp,
  1970. const size_t *start, size_t nelems, const uint *value)
  1971. {
  1972. off_t offset = NC_varoffset(ncp, varp, start);
  1973. size_t remaining = varp->xsz * nelems;
  1974. int status = NC_NOERR;
  1975. void *xp;
  1976. if(nelems == 0)
  1977. return NC_NOERR;
  1978. assert(value != NULL);
  1979. for(;;)
  1980. {
  1981. size_t extent = MIN(remaining, ncp->chunk);
  1982. size_t nput = ncx_howmany(varp->type, extent);
  1983. int lstatus = ncio_get(ncp->nciop, offset, extent,
  1984. RGN_WRITE, &xp);
  1985. if(lstatus != NC_NOERR)
  1986. return lstatus;
  1987. lstatus = ncx_putn_short_uint(&xp, nput, value);
  1988. if(lstatus != NC_NOERR && status == NC_NOERR)
  1989. {
  1990. /* not fatal to the loop */
  1991. status = lstatus;
  1992. }
  1993. (void) ncio_rel(ncp->nciop, offset,
  1994. RGN_MODIFIED);
  1995. remaining -= extent;
  1996. if(remaining == 0)
  1997. break; /* normal loop exit */
  1998. offset += extent;
  1999. value += nput;
  2000. }
  2001. return status;
  2002. }
  2003. static int
  2004. putNCvx_short_ulonglong(NC *ncp, const NC_var *varp,
  2005. const size_t *start, size_t nelems, const ulonglong *value)
  2006. {
  2007. off_t offset = NC_varoffset(ncp, varp, start);
  2008. size_t remaining = varp->xsz * nelems;
  2009. int status = NC_NOERR;
  2010. void *xp;
  2011. if(nelems == 0)
  2012. return NC_NOERR;
  2013. assert(value != NULL);
  2014. for(;;)
  2015. {
  2016. size_t extent = MIN(remaining, ncp->chunk);
  2017. size_t nput = ncx_howmany(varp->type, extent);
  2018. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2019. RGN_WRITE, &xp);
  2020. if(lstatus != NC_NOERR)
  2021. return lstatus;
  2022. lstatus = ncx_putn_short_ulonglong(&xp, nput, value);
  2023. if(lstatus != NC_NOERR && status == NC_NOERR)
  2024. {
  2025. /* not fatal to the loop */
  2026. status = lstatus;
  2027. }
  2028. (void) ncio_rel(ncp->nciop, offset,
  2029. RGN_MODIFIED);
  2030. remaining -= extent;
  2031. if(remaining == 0)
  2032. break; /* normal loop exit */
  2033. offset += extent;
  2034. value += nput;
  2035. }
  2036. return status;
  2037. }
  2038. static int
  2039. putNCvx_int_uint(NC *ncp, const NC_var *varp,
  2040. const size_t *start, size_t nelems, const uint *value)
  2041. {
  2042. off_t offset = NC_varoffset(ncp, varp, start);
  2043. size_t remaining = varp->xsz * nelems;
  2044. int status = NC_NOERR;
  2045. void *xp;
  2046. if(nelems == 0)
  2047. return NC_NOERR;
  2048. assert(value != NULL);
  2049. for(;;)
  2050. {
  2051. size_t extent = MIN(remaining, ncp->chunk);
  2052. size_t nput = ncx_howmany(varp->type, extent);
  2053. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2054. RGN_WRITE, &xp);
  2055. if(lstatus != NC_NOERR)
  2056. return lstatus;
  2057. lstatus = ncx_putn_int_uint(&xp, nput, value);
  2058. if(lstatus != NC_NOERR && status == NC_NOERR)
  2059. {
  2060. /* not fatal to the loop */
  2061. status = lstatus;
  2062. }
  2063. (void) ncio_rel(ncp->nciop, offset,
  2064. RGN_MODIFIED);
  2065. remaining -= extent;
  2066. if(remaining == 0)
  2067. break; /* normal loop exit */
  2068. offset += extent;
  2069. value += nput;
  2070. }
  2071. return status;
  2072. }
  2073. static int
  2074. putNCvx_int_ulonglong(NC *ncp, const NC_var *varp,
  2075. const size_t *start, size_t nelems, const ulonglong *value)
  2076. {
  2077. off_t offset = NC_varoffset(ncp, varp, start);
  2078. size_t remaining = varp->xsz * nelems;
  2079. int status = NC_NOERR;
  2080. void *xp;
  2081. if(nelems == 0)
  2082. return NC_NOERR;
  2083. assert(value != NULL);
  2084. for(;;)
  2085. {
  2086. size_t extent = MIN(remaining, ncp->chunk);
  2087. size_t nput = ncx_howmany(varp->type, extent);
  2088. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2089. RGN_WRITE, &xp);
  2090. if(lstatus != NC_NOERR)
  2091. return lstatus;
  2092. lstatus = ncx_putn_int_ulonglong(&xp, nput, value);
  2093. if(lstatus != NC_NOERR && status == NC_NOERR)
  2094. {
  2095. /* not fatal to the loop */
  2096. status = lstatus;
  2097. }
  2098. (void) ncio_rel(ncp->nciop, offset,
  2099. RGN_MODIFIED);
  2100. remaining -= extent;
  2101. if(remaining == 0)
  2102. break; /* normal loop exit */
  2103. offset += extent;
  2104. value += nput;
  2105. }
  2106. return status;
  2107. }
  2108. static int
  2109. putNCvx_float_uint(NC *ncp, const NC_var *varp,
  2110. const size_t *start, size_t nelems, const uint *value)
  2111. {
  2112. off_t offset = NC_varoffset(ncp, varp, start);
  2113. size_t remaining = varp->xsz * nelems;
  2114. int status = NC_NOERR;
  2115. void *xp;
  2116. if(nelems == 0)
  2117. return NC_NOERR;
  2118. assert(value != NULL);
  2119. for(;;)
  2120. {
  2121. size_t extent = MIN(remaining, ncp->chunk);
  2122. size_t nput = ncx_howmany(varp->type, extent);
  2123. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2124. RGN_WRITE, &xp);
  2125. if(lstatus != NC_NOERR)
  2126. return lstatus;
  2127. lstatus = ncx_putn_float_uint(&xp, nput, value);
  2128. if(lstatus != NC_NOERR && status == NC_NOERR)
  2129. {
  2130. /* not fatal to the loop */
  2131. status = lstatus;
  2132. }
  2133. (void) ncio_rel(ncp->nciop, offset,
  2134. RGN_MODIFIED);
  2135. remaining -= extent;
  2136. if(remaining == 0)
  2137. break; /* normal loop exit */
  2138. offset += extent;
  2139. value += nput;
  2140. }
  2141. return status;
  2142. }
  2143. static int
  2144. putNCvx_float_ulonglong(NC *ncp, const NC_var *varp,
  2145. const size_t *start, size_t nelems, const ulonglong *value)
  2146. {
  2147. off_t offset = NC_varoffset(ncp, varp, start);
  2148. size_t remaining = varp->xsz * nelems;
  2149. int status = NC_NOERR;
  2150. void *xp;
  2151. if(nelems == 0)
  2152. return NC_NOERR;
  2153. assert(value != NULL);
  2154. for(;;)
  2155. {
  2156. size_t extent = MIN(remaining, ncp->chunk);
  2157. size_t nput = ncx_howmany(varp->type, extent);
  2158. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2159. RGN_WRITE, &xp);
  2160. if(lstatus != NC_NOERR)
  2161. return lstatus;
  2162. lstatus = ncx_putn_float_ulonglong(&xp, nput, value);
  2163. if(lstatus != NC_NOERR && status == NC_NOERR)
  2164. {
  2165. /* not fatal to the loop */
  2166. status = lstatus;
  2167. }
  2168. (void) ncio_rel(ncp->nciop, offset,
  2169. RGN_MODIFIED);
  2170. remaining -= extent;
  2171. if(remaining == 0)
  2172. break; /* normal loop exit */
  2173. offset += extent;
  2174. value += nput;
  2175. }
  2176. return status;
  2177. }
  2178. static int
  2179. putNCvx_double_uint(NC *ncp, const NC_var *varp,
  2180. const size_t *start, size_t nelems, const uint *value)
  2181. {
  2182. off_t offset = NC_varoffset(ncp, varp, start);
  2183. size_t remaining = varp->xsz * nelems;
  2184. int status = NC_NOERR;
  2185. void *xp;
  2186. if(nelems == 0)
  2187. return NC_NOERR;
  2188. assert(value != NULL);
  2189. for(;;)
  2190. {
  2191. size_t extent = MIN(remaining, ncp->chunk);
  2192. size_t nput = ncx_howmany(varp->type, extent);
  2193. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2194. RGN_WRITE, &xp);
  2195. if(lstatus != NC_NOERR)
  2196. return lstatus;
  2197. lstatus = ncx_putn_double_uint(&xp, nput, value);
  2198. if(lstatus != NC_NOERR && status == NC_NOERR)
  2199. {
  2200. /* not fatal to the loop */
  2201. status = lstatus;
  2202. }
  2203. (void) ncio_rel(ncp->nciop, offset,
  2204. RGN_MODIFIED);
  2205. remaining -= extent;
  2206. if(remaining == 0)
  2207. break; /* normal loop exit */
  2208. offset += extent;
  2209. value += nput;
  2210. }
  2211. return status;
  2212. }
  2213. static int
  2214. putNCvx_double_ulonglong(NC *ncp, const NC_var *varp,
  2215. const size_t *start, size_t nelems, const ulonglong *value)
  2216. {
  2217. off_t offset = NC_varoffset(ncp, varp, start);
  2218. size_t remaining = varp->xsz * nelems;
  2219. int status = NC_NOERR;
  2220. void *xp;
  2221. if(nelems == 0)
  2222. return NC_NOERR;
  2223. assert(value != NULL);
  2224. for(;;)
  2225. {
  2226. size_t extent = MIN(remaining, ncp->chunk);
  2227. size_t nput = ncx_howmany(varp->type, extent);
  2228. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2229. RGN_WRITE, &xp);
  2230. if(lstatus != NC_NOERR)
  2231. return lstatus;
  2232. lstatus = ncx_putn_double_ulonglong(&xp, nput, value);
  2233. if(lstatus != NC_NOERR && status == NC_NOERR)
  2234. {
  2235. /* not fatal to the loop */
  2236. status = lstatus;
  2237. }
  2238. (void) ncio_rel(ncp->nciop, offset,
  2239. RGN_MODIFIED);
  2240. remaining -= extent;
  2241. if(remaining == 0)
  2242. break; /* normal loop exit */
  2243. offset += extent;
  2244. value += nput;
  2245. }
  2246. return status;
  2247. }
  2248. #endif /*NOTUSED*/
  2249. static int
  2250. getNCvx_char_char(const NC *ncp, const NC_var *varp,
  2251. const size_t *start, size_t nelems, char *value)
  2252. {
  2253. off_t offset = NC_varoffset(ncp, varp, start);
  2254. size_t remaining = varp->xsz * nelems;
  2255. int status = NC_NOERR;
  2256. const void *xp;
  2257. if(nelems == 0)
  2258. return NC_NOERR;
  2259. assert(value != NULL);
  2260. for(;;)
  2261. {
  2262. size_t extent = MIN(remaining, ncp->chunk);
  2263. size_t nget = ncx_howmany(varp->type, extent);
  2264. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2265. 0, (void **)&xp); /* cast away const */
  2266. if(lstatus != NC_NOERR)
  2267. return lstatus;
  2268. lstatus = ncx_getn_char_char(&xp, nget, value);
  2269. if(lstatus != NC_NOERR && status == NC_NOERR)
  2270. status = lstatus;
  2271. (void) ncio_rel(ncp->nciop, offset, 0);
  2272. remaining -= extent;
  2273. if(remaining == 0)
  2274. break; /* normal loop exit */
  2275. offset += extent;
  2276. value += nget;
  2277. }
  2278. return status;
  2279. }
  2280. static int
  2281. getNCvx_schar_schar(const NC *ncp, const NC_var *varp,
  2282. const size_t *start, size_t nelems, schar *value)
  2283. {
  2284. off_t offset = NC_varoffset(ncp, varp, start);
  2285. size_t remaining = varp->xsz * nelems;
  2286. int status = NC_NOERR;
  2287. const void *xp;
  2288. if(nelems == 0)
  2289. return NC_NOERR;
  2290. assert(value != NULL);
  2291. for(;;)
  2292. {
  2293. size_t extent = MIN(remaining, ncp->chunk);
  2294. size_t nget = ncx_howmany(varp->type, extent);
  2295. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2296. 0, (void **)&xp); /* cast away const */
  2297. if(lstatus != NC_NOERR)
  2298. return lstatus;
  2299. lstatus = ncx_getn_schar_schar(&xp, nget, value);
  2300. if(lstatus != NC_NOERR && status == NC_NOERR)
  2301. status = lstatus;
  2302. (void) ncio_rel(ncp->nciop, offset, 0);
  2303. remaining -= extent;
  2304. if(remaining == 0)
  2305. break; /* normal loop exit */
  2306. offset += extent;
  2307. value += nget;
  2308. }
  2309. return status;
  2310. }
  2311. static int
  2312. getNCvx_schar_short(const NC *ncp, const NC_var *varp,
  2313. const size_t *start, size_t nelems, short *value)
  2314. {
  2315. off_t offset = NC_varoffset(ncp, varp, start);
  2316. size_t remaining = varp->xsz * nelems;
  2317. int status = NC_NOERR;
  2318. const void *xp;
  2319. if(nelems == 0)
  2320. return NC_NOERR;
  2321. assert(value != NULL);
  2322. for(;;)
  2323. {
  2324. size_t extent = MIN(remaining, ncp->chunk);
  2325. size_t nget = ncx_howmany(varp->type, extent);
  2326. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2327. 0, (void **)&xp); /* cast away const */
  2328. if(lstatus != NC_NOERR)
  2329. return lstatus;
  2330. lstatus = ncx_getn_schar_short(&xp, nget, value);
  2331. if(lstatus != NC_NOERR && status == NC_NOERR)
  2332. status = lstatus;
  2333. (void) ncio_rel(ncp->nciop, offset, 0);
  2334. remaining -= extent;
  2335. if(remaining == 0)
  2336. break; /* normal loop exit */
  2337. offset += extent;
  2338. value += nget;
  2339. }
  2340. return status;
  2341. }
  2342. static int
  2343. getNCvx_schar_int(const NC *ncp, const NC_var *varp,
  2344. const size_t *start, size_t nelems, int *value)
  2345. {
  2346. off_t offset = NC_varoffset(ncp, varp, start);
  2347. size_t remaining = varp->xsz * nelems;
  2348. int status = NC_NOERR;
  2349. const void *xp;
  2350. if(nelems == 0)
  2351. return NC_NOERR;
  2352. assert(value != NULL);
  2353. for(;;)
  2354. {
  2355. size_t extent = MIN(remaining, ncp->chunk);
  2356. size_t nget = ncx_howmany(varp->type, extent);
  2357. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2358. 0, (void **)&xp); /* cast away const */
  2359. if(lstatus != NC_NOERR)
  2360. return lstatus;
  2361. lstatus = ncx_getn_schar_int(&xp, nget, value);
  2362. if(lstatus != NC_NOERR && status == NC_NOERR)
  2363. status = lstatus;
  2364. (void) ncio_rel(ncp->nciop, offset, 0);
  2365. remaining -= extent;
  2366. if(remaining == 0)
  2367. break; /* normal loop exit */
  2368. offset += extent;
  2369. value += nget;
  2370. }
  2371. return status;
  2372. }
  2373. static int
  2374. getNCvx_schar_float(const NC *ncp, const NC_var *varp,
  2375. const size_t *start, size_t nelems, float *value)
  2376. {
  2377. off_t offset = NC_varoffset(ncp, varp, start);
  2378. size_t remaining = varp->xsz * nelems;
  2379. int status = NC_NOERR;
  2380. const void *xp;
  2381. if(nelems == 0)
  2382. return NC_NOERR;
  2383. assert(value != NULL);
  2384. for(;;)
  2385. {
  2386. size_t extent = MIN(remaining, ncp->chunk);
  2387. size_t nget = ncx_howmany(varp->type, extent);
  2388. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2389. 0, (void **)&xp); /* cast away const */
  2390. if(lstatus != NC_NOERR)
  2391. return lstatus;
  2392. lstatus = ncx_getn_schar_float(&xp, nget, value);
  2393. if(lstatus != NC_NOERR && status == NC_NOERR)
  2394. status = lstatus;
  2395. (void) ncio_rel(ncp->nciop, offset, 0);
  2396. remaining -= extent;
  2397. if(remaining == 0)
  2398. break; /* normal loop exit */
  2399. offset += extent;
  2400. value += nget;
  2401. }
  2402. return status;
  2403. }
  2404. static int
  2405. getNCvx_schar_double(const NC *ncp, const NC_var *varp,
  2406. const size_t *start, size_t nelems, double *value)
  2407. {
  2408. off_t offset = NC_varoffset(ncp, varp, start);
  2409. size_t remaining = varp->xsz * nelems;
  2410. int status = NC_NOERR;
  2411. const void *xp;
  2412. if(nelems == 0)
  2413. return NC_NOERR;
  2414. assert(value != NULL);
  2415. for(;;)
  2416. {
  2417. size_t extent = MIN(remaining, ncp->chunk);
  2418. size_t nget = ncx_howmany(varp->type, extent);
  2419. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2420. 0, (void **)&xp); /* cast away const */
  2421. if(lstatus != NC_NOERR)
  2422. return lstatus;
  2423. lstatus = ncx_getn_schar_double(&xp, nget, value);
  2424. if(lstatus != NC_NOERR && status == NC_NOERR)
  2425. status = lstatus;
  2426. (void) ncio_rel(ncp->nciop, offset, 0);
  2427. remaining -= extent;
  2428. if(remaining == 0)
  2429. break; /* normal loop exit */
  2430. offset += extent;
  2431. value += nget;
  2432. }
  2433. return status;
  2434. }
  2435. static int
  2436. getNCvx_schar_longlong(const NC *ncp, const NC_var *varp,
  2437. const size_t *start, size_t nelems, longlong *value)
  2438. {
  2439. off_t offset = NC_varoffset(ncp, varp, start);
  2440. size_t remaining = varp->xsz * nelems;
  2441. int status = NC_NOERR;
  2442. const void *xp;
  2443. if(nelems == 0)
  2444. return NC_NOERR;
  2445. assert(value != NULL);
  2446. for(;;)
  2447. {
  2448. size_t extent = MIN(remaining, ncp->chunk);
  2449. size_t nget = ncx_howmany(varp->type, extent);
  2450. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2451. 0, (void **)&xp); /* cast away const */
  2452. if(lstatus != NC_NOERR)
  2453. return lstatus;
  2454. lstatus = ncx_getn_schar_longlong(&xp, nget, value);
  2455. if(lstatus != NC_NOERR && status == NC_NOERR)
  2456. status = lstatus;
  2457. (void) ncio_rel(ncp->nciop, offset, 0);
  2458. remaining -= extent;
  2459. if(remaining == 0)
  2460. break; /* normal loop exit */
  2461. offset += extent;
  2462. value += nget;
  2463. }
  2464. return status;
  2465. }
  2466. static int
  2467. getNCvx_schar_uint(const NC *ncp, const NC_var *varp,
  2468. const size_t *start, size_t nelems, uint *value)
  2469. {
  2470. off_t offset = NC_varoffset(ncp, varp, start);
  2471. size_t remaining = varp->xsz * nelems;
  2472. int status = NC_NOERR;
  2473. const void *xp;
  2474. if(nelems == 0)
  2475. return NC_NOERR;
  2476. assert(value != NULL);
  2477. for(;;)
  2478. {
  2479. size_t extent = MIN(remaining, ncp->chunk);
  2480. size_t nget = ncx_howmany(varp->type, extent);
  2481. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2482. 0, (void **)&xp); /* cast away const */
  2483. if(lstatus != NC_NOERR)
  2484. return lstatus;
  2485. lstatus = ncx_getn_schar_uint(&xp, nget, value);
  2486. if(lstatus != NC_NOERR && status == NC_NOERR)
  2487. status = lstatus;
  2488. (void) ncio_rel(ncp->nciop, offset, 0);
  2489. remaining -= extent;
  2490. if(remaining == 0)
  2491. break; /* normal loop exit */
  2492. offset += extent;
  2493. value += nget;
  2494. }
  2495. return status;
  2496. }
  2497. static int
  2498. getNCvx_schar_ulonglong(const NC *ncp, const NC_var *varp,
  2499. const size_t *start, size_t nelems, ulonglong *value)
  2500. {
  2501. off_t offset = NC_varoffset(ncp, varp, start);
  2502. size_t remaining = varp->xsz * nelems;
  2503. int status = NC_NOERR;
  2504. const void *xp;
  2505. if(nelems == 0)
  2506. return NC_NOERR;
  2507. assert(value != NULL);
  2508. for(;;)
  2509. {
  2510. size_t extent = MIN(remaining, ncp->chunk);
  2511. size_t nget = ncx_howmany(varp->type, extent);
  2512. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2513. 0, (void **)&xp); /* cast away const */
  2514. if(lstatus != NC_NOERR)
  2515. return lstatus;
  2516. lstatus = ncx_getn_schar_ulonglong(&xp, nget, value);
  2517. if(lstatus != NC_NOERR && status == NC_NOERR)
  2518. status = lstatus;
  2519. (void) ncio_rel(ncp->nciop, offset, 0);
  2520. remaining -= extent;
  2521. if(remaining == 0)
  2522. break; /* normal loop exit */
  2523. offset += extent;
  2524. value += nget;
  2525. }
  2526. return status;
  2527. }
  2528. static int
  2529. getNCvx_short_schar(const NC *ncp, const NC_var *varp,
  2530. const size_t *start, size_t nelems, schar *value)
  2531. {
  2532. off_t offset = NC_varoffset(ncp, varp, start);
  2533. size_t remaining = varp->xsz * nelems;
  2534. int status = NC_NOERR;
  2535. const void *xp;
  2536. if(nelems == 0)
  2537. return NC_NOERR;
  2538. assert(value != NULL);
  2539. for(;;)
  2540. {
  2541. size_t extent = MIN(remaining, ncp->chunk);
  2542. size_t nget = ncx_howmany(varp->type, extent);
  2543. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2544. 0, (void **)&xp); /* cast away const */
  2545. if(lstatus != NC_NOERR)
  2546. return lstatus;
  2547. lstatus = ncx_getn_short_schar(&xp, nget, value);
  2548. if(lstatus != NC_NOERR && status == NC_NOERR)
  2549. status = lstatus;
  2550. (void) ncio_rel(ncp->nciop, offset, 0);
  2551. remaining -= extent;
  2552. if(remaining == 0)
  2553. break; /* normal loop exit */
  2554. offset += extent;
  2555. value += nget;
  2556. }
  2557. return status;
  2558. }
  2559. static int
  2560. getNCvx_short_uchar(const NC *ncp, const NC_var *varp,
  2561. const size_t *start, size_t nelems, uchar *value)
  2562. {
  2563. off_t offset = NC_varoffset(ncp, varp, start);
  2564. size_t remaining = varp->xsz * nelems;
  2565. int status = NC_NOERR;
  2566. const void *xp;
  2567. if(nelems == 0)
  2568. return NC_NOERR;
  2569. assert(value != NULL);
  2570. for(;;)
  2571. {
  2572. size_t extent = MIN(remaining, ncp->chunk);
  2573. size_t nget = ncx_howmany(varp->type, extent);
  2574. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2575. 0, (void **)&xp); /* cast away const */
  2576. if(lstatus != NC_NOERR)
  2577. return lstatus;
  2578. lstatus = ncx_getn_short_uchar(&xp, nget, value);
  2579. if(lstatus != NC_NOERR && status == NC_NOERR)
  2580. status = lstatus;
  2581. (void) ncio_rel(ncp->nciop, offset, 0);
  2582. remaining -= extent;
  2583. if(remaining == 0)
  2584. break; /* normal loop exit */
  2585. offset += extent;
  2586. value += nget;
  2587. }
  2588. return status;
  2589. }
  2590. static int
  2591. getNCvx_short_short(const NC *ncp, const NC_var *varp,
  2592. const size_t *start, size_t nelems, short *value)
  2593. {
  2594. off_t offset = NC_varoffset(ncp, varp, start);
  2595. size_t remaining = varp->xsz * nelems;
  2596. int status = NC_NOERR;
  2597. const void *xp;
  2598. if(nelems == 0)
  2599. return NC_NOERR;
  2600. assert(value != NULL);
  2601. for(;;)
  2602. {
  2603. size_t extent = MIN(remaining, ncp->chunk);
  2604. size_t nget = ncx_howmany(varp->type, extent);
  2605. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2606. 0, (void **)&xp); /* cast away const */
  2607. if(lstatus != NC_NOERR)
  2608. return lstatus;
  2609. lstatus = ncx_getn_short_short(&xp, nget, value);
  2610. if(lstatus != NC_NOERR && status == NC_NOERR)
  2611. status = lstatus;
  2612. (void) ncio_rel(ncp->nciop, offset, 0);
  2613. remaining -= extent;
  2614. if(remaining == 0)
  2615. break; /* normal loop exit */
  2616. offset += extent;
  2617. value += nget;
  2618. }
  2619. return status;
  2620. }
  2621. static int
  2622. getNCvx_short_int(const NC *ncp, const NC_var *varp,
  2623. const size_t *start, size_t nelems, int *value)
  2624. {
  2625. off_t offset = NC_varoffset(ncp, varp, start);
  2626. size_t remaining = varp->xsz * nelems;
  2627. int status = NC_NOERR;
  2628. const void *xp;
  2629. if(nelems == 0)
  2630. return NC_NOERR;
  2631. assert(value != NULL);
  2632. for(;;)
  2633. {
  2634. size_t extent = MIN(remaining, ncp->chunk);
  2635. size_t nget = ncx_howmany(varp->type, extent);
  2636. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2637. 0, (void **)&xp); /* cast away const */
  2638. if(lstatus != NC_NOERR)
  2639. return lstatus;
  2640. lstatus = ncx_getn_short_int(&xp, nget, value);
  2641. if(lstatus != NC_NOERR && status == NC_NOERR)
  2642. status = lstatus;
  2643. (void) ncio_rel(ncp->nciop, offset, 0);
  2644. remaining -= extent;
  2645. if(remaining == 0)
  2646. break; /* normal loop exit */
  2647. offset += extent;
  2648. value += nget;
  2649. }
  2650. return status;
  2651. }
  2652. static int
  2653. getNCvx_short_float(const NC *ncp, const NC_var *varp,
  2654. const size_t *start, size_t nelems, float *value)
  2655. {
  2656. off_t offset = NC_varoffset(ncp, varp, start);
  2657. size_t remaining = varp->xsz * nelems;
  2658. int status = NC_NOERR;
  2659. const void *xp;
  2660. if(nelems == 0)
  2661. return NC_NOERR;
  2662. assert(value != NULL);
  2663. for(;;)
  2664. {
  2665. size_t extent = MIN(remaining, ncp->chunk);
  2666. size_t nget = ncx_howmany(varp->type, extent);
  2667. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2668. 0, (void **)&xp); /* cast away const */
  2669. if(lstatus != NC_NOERR)
  2670. return lstatus;
  2671. lstatus = ncx_getn_short_float(&xp, nget, value);
  2672. if(lstatus != NC_NOERR && status == NC_NOERR)
  2673. status = lstatus;
  2674. (void) ncio_rel(ncp->nciop, offset, 0);
  2675. remaining -= extent;
  2676. if(remaining == 0)
  2677. break; /* normal loop exit */
  2678. offset += extent;
  2679. value += nget;
  2680. }
  2681. return status;
  2682. }
  2683. static int
  2684. getNCvx_short_double(const NC *ncp, const NC_var *varp,
  2685. const size_t *start, size_t nelems, double *value)
  2686. {
  2687. off_t offset = NC_varoffset(ncp, varp, start);
  2688. size_t remaining = varp->xsz * nelems;
  2689. int status = NC_NOERR;
  2690. const void *xp;
  2691. if(nelems == 0)
  2692. return NC_NOERR;
  2693. assert(value != NULL);
  2694. for(;;)
  2695. {
  2696. size_t extent = MIN(remaining, ncp->chunk);
  2697. size_t nget = ncx_howmany(varp->type, extent);
  2698. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2699. 0, (void **)&xp); /* cast away const */
  2700. if(lstatus != NC_NOERR)
  2701. return lstatus;
  2702. lstatus = ncx_getn_short_double(&xp, nget, value);
  2703. if(lstatus != NC_NOERR && status == NC_NOERR)
  2704. status = lstatus;
  2705. (void) ncio_rel(ncp->nciop, offset, 0);
  2706. remaining -= extent;
  2707. if(remaining == 0)
  2708. break; /* normal loop exit */
  2709. offset += extent;
  2710. value += nget;
  2711. }
  2712. return status;
  2713. }
  2714. static int
  2715. getNCvx_short_longlong(const NC *ncp, const NC_var *varp,
  2716. const size_t *start, size_t nelems, longlong *value)
  2717. {
  2718. off_t offset = NC_varoffset(ncp, varp, start);
  2719. size_t remaining = varp->xsz * nelems;
  2720. int status = NC_NOERR;
  2721. const void *xp;
  2722. if(nelems == 0)
  2723. return NC_NOERR;
  2724. assert(value != NULL);
  2725. for(;;)
  2726. {
  2727. size_t extent = MIN(remaining, ncp->chunk);
  2728. size_t nget = ncx_howmany(varp->type, extent);
  2729. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2730. 0, (void **)&xp); /* cast away const */
  2731. if(lstatus != NC_NOERR)
  2732. return lstatus;
  2733. lstatus = ncx_getn_short_longlong(&xp, nget, value);
  2734. if(lstatus != NC_NOERR && status == NC_NOERR)
  2735. status = lstatus;
  2736. (void) ncio_rel(ncp->nciop, offset, 0);
  2737. remaining -= extent;
  2738. if(remaining == 0)
  2739. break; /* normal loop exit */
  2740. offset += extent;
  2741. value += nget;
  2742. }
  2743. return status;
  2744. }
  2745. static int
  2746. getNCvx_short_uint(const NC *ncp, const NC_var *varp,
  2747. const size_t *start, size_t nelems, uint *value)
  2748. {
  2749. off_t offset = NC_varoffset(ncp, varp, start);
  2750. size_t remaining = varp->xsz * nelems;
  2751. int status = NC_NOERR;
  2752. const void *xp;
  2753. if(nelems == 0)
  2754. return NC_NOERR;
  2755. assert(value != NULL);
  2756. for(;;)
  2757. {
  2758. size_t extent = MIN(remaining, ncp->chunk);
  2759. size_t nget = ncx_howmany(varp->type, extent);
  2760. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2761. 0, (void **)&xp); /* cast away const */
  2762. if(lstatus != NC_NOERR)
  2763. return lstatus;
  2764. lstatus = ncx_getn_short_uint(&xp, nget, value);
  2765. if(lstatus != NC_NOERR && status == NC_NOERR)
  2766. status = lstatus;
  2767. (void) ncio_rel(ncp->nciop, offset, 0);
  2768. remaining -= extent;
  2769. if(remaining == 0)
  2770. break; /* normal loop exit */
  2771. offset += extent;
  2772. value += nget;
  2773. }
  2774. return status;
  2775. }
  2776. static int
  2777. getNCvx_short_ulonglong(const NC *ncp, const NC_var *varp,
  2778. const size_t *start, size_t nelems, ulonglong *value)
  2779. {
  2780. off_t offset = NC_varoffset(ncp, varp, start);
  2781. size_t remaining = varp->xsz * nelems;
  2782. int status = NC_NOERR;
  2783. const void *xp;
  2784. if(nelems == 0)
  2785. return NC_NOERR;
  2786. assert(value != NULL);
  2787. for(;;)
  2788. {
  2789. size_t extent = MIN(remaining, ncp->chunk);
  2790. size_t nget = ncx_howmany(varp->type, extent);
  2791. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2792. 0, (void **)&xp); /* cast away const */
  2793. if(lstatus != NC_NOERR)
  2794. return lstatus;
  2795. lstatus = ncx_getn_short_ulonglong(&xp, nget, value);
  2796. if(lstatus != NC_NOERR && status == NC_NOERR)
  2797. status = lstatus;
  2798. (void) ncio_rel(ncp->nciop, offset, 0);
  2799. remaining -= extent;
  2800. if(remaining == 0)
  2801. break; /* normal loop exit */
  2802. offset += extent;
  2803. value += nget;
  2804. }
  2805. return status;
  2806. }
  2807. static int
  2808. getNCvx_int_schar(const NC *ncp, const NC_var *varp,
  2809. const size_t *start, size_t nelems, schar *value)
  2810. {
  2811. off_t offset = NC_varoffset(ncp, varp, start);
  2812. size_t remaining = varp->xsz * nelems;
  2813. int status = NC_NOERR;
  2814. const void *xp;
  2815. if(nelems == 0)
  2816. return NC_NOERR;
  2817. assert(value != NULL);
  2818. for(;;)
  2819. {
  2820. size_t extent = MIN(remaining, ncp->chunk);
  2821. size_t nget = ncx_howmany(varp->type, extent);
  2822. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2823. 0, (void **)&xp); /* cast away const */
  2824. if(lstatus != NC_NOERR)
  2825. return lstatus;
  2826. lstatus = ncx_getn_int_schar(&xp, nget, value);
  2827. if(lstatus != NC_NOERR && status == NC_NOERR)
  2828. status = lstatus;
  2829. (void) ncio_rel(ncp->nciop, offset, 0);
  2830. remaining -= extent;
  2831. if(remaining == 0)
  2832. break; /* normal loop exit */
  2833. offset += extent;
  2834. value += nget;
  2835. }
  2836. return status;
  2837. }
  2838. static int
  2839. getNCvx_int_uchar(const NC *ncp, const NC_var *varp,
  2840. const size_t *start, size_t nelems, uchar *value)
  2841. {
  2842. off_t offset = NC_varoffset(ncp, varp, start);
  2843. size_t remaining = varp->xsz * nelems;
  2844. int status = NC_NOERR;
  2845. const void *xp;
  2846. if(nelems == 0)
  2847. return NC_NOERR;
  2848. assert(value != NULL);
  2849. for(;;)
  2850. {
  2851. size_t extent = MIN(remaining, ncp->chunk);
  2852. size_t nget = ncx_howmany(varp->type, extent);
  2853. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2854. 0, (void **)&xp); /* cast away const */
  2855. if(lstatus != NC_NOERR)
  2856. return lstatus;
  2857. lstatus = ncx_getn_int_uchar(&xp, nget, value);
  2858. if(lstatus != NC_NOERR && status == NC_NOERR)
  2859. status = lstatus;
  2860. (void) ncio_rel(ncp->nciop, offset, 0);
  2861. remaining -= extent;
  2862. if(remaining == 0)
  2863. break; /* normal loop exit */
  2864. offset += extent;
  2865. value += nget;
  2866. }
  2867. return status;
  2868. }
  2869. static int
  2870. getNCvx_int_short(const NC *ncp, const NC_var *varp,
  2871. const size_t *start, size_t nelems, short *value)
  2872. {
  2873. off_t offset = NC_varoffset(ncp, varp, start);
  2874. size_t remaining = varp->xsz * nelems;
  2875. int status = NC_NOERR;
  2876. const void *xp;
  2877. if(nelems == 0)
  2878. return NC_NOERR;
  2879. assert(value != NULL);
  2880. for(;;)
  2881. {
  2882. size_t extent = MIN(remaining, ncp->chunk);
  2883. size_t nget = ncx_howmany(varp->type, extent);
  2884. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2885. 0, (void **)&xp); /* cast away const */
  2886. if(lstatus != NC_NOERR)
  2887. return lstatus;
  2888. lstatus = ncx_getn_int_short(&xp, nget, value);
  2889. if(lstatus != NC_NOERR && status == NC_NOERR)
  2890. status = lstatus;
  2891. (void) ncio_rel(ncp->nciop, offset, 0);
  2892. remaining -= extent;
  2893. if(remaining == 0)
  2894. break; /* normal loop exit */
  2895. offset += extent;
  2896. value += nget;
  2897. }
  2898. return status;
  2899. }
  2900. static int
  2901. getNCvx_int_int(const NC *ncp, const NC_var *varp,
  2902. const size_t *start, size_t nelems, int *value)
  2903. {
  2904. off_t offset = NC_varoffset(ncp, varp, start);
  2905. size_t remaining = varp->xsz * nelems;
  2906. int status = NC_NOERR;
  2907. const void *xp;
  2908. if(nelems == 0)
  2909. return NC_NOERR;
  2910. assert(value != NULL);
  2911. for(;;)
  2912. {
  2913. size_t extent = MIN(remaining, ncp->chunk);
  2914. size_t nget = ncx_howmany(varp->type, extent);
  2915. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2916. 0, (void **)&xp); /* cast away const */
  2917. if(lstatus != NC_NOERR)
  2918. return lstatus;
  2919. lstatus = ncx_getn_int_int(&xp, nget, value);
  2920. if(lstatus != NC_NOERR && status == NC_NOERR)
  2921. status = lstatus;
  2922. (void) ncio_rel(ncp->nciop, offset, 0);
  2923. remaining -= extent;
  2924. if(remaining == 0)
  2925. break; /* normal loop exit */
  2926. offset += extent;
  2927. value += nget;
  2928. }
  2929. return status;
  2930. }
  2931. static int
  2932. getNCvx_int_float(const NC *ncp, const NC_var *varp,
  2933. const size_t *start, size_t nelems, float *value)
  2934. {
  2935. off_t offset = NC_varoffset(ncp, varp, start);
  2936. size_t remaining = varp->xsz * nelems;
  2937. int status = NC_NOERR;
  2938. const void *xp;
  2939. if(nelems == 0)
  2940. return NC_NOERR;
  2941. assert(value != NULL);
  2942. for(;;)
  2943. {
  2944. size_t extent = MIN(remaining, ncp->chunk);
  2945. size_t nget = ncx_howmany(varp->type, extent);
  2946. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2947. 0, (void **)&xp); /* cast away const */
  2948. if(lstatus != NC_NOERR)
  2949. return lstatus;
  2950. lstatus = ncx_getn_int_float(&xp, nget, value);
  2951. if(lstatus != NC_NOERR && status == NC_NOERR)
  2952. status = lstatus;
  2953. (void) ncio_rel(ncp->nciop, offset, 0);
  2954. remaining -= extent;
  2955. if(remaining == 0)
  2956. break; /* normal loop exit */
  2957. offset += extent;
  2958. value += nget;
  2959. }
  2960. return status;
  2961. }
  2962. static int
  2963. getNCvx_int_double(const NC *ncp, const NC_var *varp,
  2964. const size_t *start, size_t nelems, double *value)
  2965. {
  2966. off_t offset = NC_varoffset(ncp, varp, start);
  2967. size_t remaining = varp->xsz * nelems;
  2968. int status = NC_NOERR;
  2969. const void *xp;
  2970. if(nelems == 0)
  2971. return NC_NOERR;
  2972. assert(value != NULL);
  2973. for(;;)
  2974. {
  2975. size_t extent = MIN(remaining, ncp->chunk);
  2976. size_t nget = ncx_howmany(varp->type, extent);
  2977. int lstatus = ncio_get(ncp->nciop, offset, extent,
  2978. 0, (void **)&xp); /* cast away const */
  2979. if(lstatus != NC_NOERR)
  2980. return lstatus;
  2981. lstatus = ncx_getn_int_double(&xp, nget, value);
  2982. if(lstatus != NC_NOERR && status == NC_NOERR)
  2983. status = lstatus;
  2984. (void) ncio_rel(ncp->nciop, offset, 0);
  2985. remaining -= extent;
  2986. if(remaining == 0)
  2987. break; /* normal loop exit */
  2988. offset += extent;
  2989. value += nget;
  2990. }
  2991. return status;
  2992. }
  2993. static int
  2994. getNCvx_int_longlong(const NC *ncp, const NC_var *varp,
  2995. const size_t *start, size_t nelems, longlong *value)
  2996. {
  2997. off_t offset = NC_varoffset(ncp, varp, start);
  2998. size_t remaining = varp->xsz * nelems;
  2999. int status = NC_NOERR;
  3000. const void *xp;
  3001. if(nelems == 0)
  3002. return NC_NOERR;
  3003. assert(value != NULL);
  3004. for(;;)
  3005. {
  3006. size_t extent = MIN(remaining, ncp->chunk);
  3007. size_t nget = ncx_howmany(varp->type, extent);
  3008. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3009. 0, (void **)&xp); /* cast away const */
  3010. if(lstatus != NC_NOERR)
  3011. return lstatus;
  3012. lstatus = ncx_getn_int_longlong(&xp, nget, value);
  3013. if(lstatus != NC_NOERR && status == NC_NOERR)
  3014. status = lstatus;
  3015. (void) ncio_rel(ncp->nciop, offset, 0);
  3016. remaining -= extent;
  3017. if(remaining == 0)
  3018. break; /* normal loop exit */
  3019. offset += extent;
  3020. value += nget;
  3021. }
  3022. return status;
  3023. }
  3024. static int
  3025. getNCvx_int_uint(const NC *ncp, const NC_var *varp,
  3026. const size_t *start, size_t nelems, uint *value)
  3027. {
  3028. off_t offset = NC_varoffset(ncp, varp, start);
  3029. size_t remaining = varp->xsz * nelems;
  3030. int status = NC_NOERR;
  3031. const void *xp;
  3032. if(nelems == 0)
  3033. return NC_NOERR;
  3034. assert(value != NULL);
  3035. for(;;)
  3036. {
  3037. size_t extent = MIN(remaining, ncp->chunk);
  3038. size_t nget = ncx_howmany(varp->type, extent);
  3039. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3040. 0, (void **)&xp); /* cast away const */
  3041. if(lstatus != NC_NOERR)
  3042. return lstatus;
  3043. lstatus = ncx_getn_int_uint(&xp, nget, value);
  3044. if(lstatus != NC_NOERR && status == NC_NOERR)
  3045. status = lstatus;
  3046. (void) ncio_rel(ncp->nciop, offset, 0);
  3047. remaining -= extent;
  3048. if(remaining == 0)
  3049. break; /* normal loop exit */
  3050. offset += extent;
  3051. value += nget;
  3052. }
  3053. return status;
  3054. }
  3055. static int
  3056. getNCvx_int_ulonglong(const NC *ncp, const NC_var *varp,
  3057. const size_t *start, size_t nelems, ulonglong *value)
  3058. {
  3059. off_t offset = NC_varoffset(ncp, varp, start);
  3060. size_t remaining = varp->xsz * nelems;
  3061. int status = NC_NOERR;
  3062. const void *xp;
  3063. if(nelems == 0)
  3064. return NC_NOERR;
  3065. assert(value != NULL);
  3066. for(;;)
  3067. {
  3068. size_t extent = MIN(remaining, ncp->chunk);
  3069. size_t nget = ncx_howmany(varp->type, extent);
  3070. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3071. 0, (void **)&xp); /* cast away const */
  3072. if(lstatus != NC_NOERR)
  3073. return lstatus;
  3074. lstatus = ncx_getn_int_ulonglong(&xp, nget, value);
  3075. if(lstatus != NC_NOERR && status == NC_NOERR)
  3076. status = lstatus;
  3077. (void) ncio_rel(ncp->nciop, offset, 0);
  3078. remaining -= extent;
  3079. if(remaining == 0)
  3080. break; /* normal loop exit */
  3081. offset += extent;
  3082. value += nget;
  3083. }
  3084. return status;
  3085. }
  3086. static int
  3087. getNCvx_float_schar(const NC *ncp, const NC_var *varp,
  3088. const size_t *start, size_t nelems, schar *value)
  3089. {
  3090. off_t offset = NC_varoffset(ncp, varp, start);
  3091. size_t remaining = varp->xsz * nelems;
  3092. int status = NC_NOERR;
  3093. const void *xp;
  3094. if(nelems == 0)
  3095. return NC_NOERR;
  3096. assert(value != NULL);
  3097. for(;;)
  3098. {
  3099. size_t extent = MIN(remaining, ncp->chunk);
  3100. size_t nget = ncx_howmany(varp->type, extent);
  3101. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3102. 0, (void **)&xp); /* cast away const */
  3103. if(lstatus != NC_NOERR)
  3104. return lstatus;
  3105. lstatus = ncx_getn_float_schar(&xp, nget, value);
  3106. if(lstatus != NC_NOERR && status == NC_NOERR)
  3107. status = lstatus;
  3108. (void) ncio_rel(ncp->nciop, offset, 0);
  3109. remaining -= extent;
  3110. if(remaining == 0)
  3111. break; /* normal loop exit */
  3112. offset += extent;
  3113. value += nget;
  3114. }
  3115. return status;
  3116. }
  3117. static int
  3118. getNCvx_float_uchar(const NC *ncp, const NC_var *varp,
  3119. const size_t *start, size_t nelems, uchar *value)
  3120. {
  3121. off_t offset = NC_varoffset(ncp, varp, start);
  3122. size_t remaining = varp->xsz * nelems;
  3123. int status = NC_NOERR;
  3124. const void *xp;
  3125. if(nelems == 0)
  3126. return NC_NOERR;
  3127. assert(value != NULL);
  3128. for(;;)
  3129. {
  3130. size_t extent = MIN(remaining, ncp->chunk);
  3131. size_t nget = ncx_howmany(varp->type, extent);
  3132. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3133. 0, (void **)&xp); /* cast away const */
  3134. if(lstatus != NC_NOERR)
  3135. return lstatus;
  3136. lstatus = ncx_getn_float_uchar(&xp, nget, value);
  3137. if(lstatus != NC_NOERR && status == NC_NOERR)
  3138. status = lstatus;
  3139. (void) ncio_rel(ncp->nciop, offset, 0);
  3140. remaining -= extent;
  3141. if(remaining == 0)
  3142. break; /* normal loop exit */
  3143. offset += extent;
  3144. value += nget;
  3145. }
  3146. return status;
  3147. }
  3148. static int
  3149. getNCvx_float_short(const NC *ncp, const NC_var *varp,
  3150. const size_t *start, size_t nelems, short *value)
  3151. {
  3152. off_t offset = NC_varoffset(ncp, varp, start);
  3153. size_t remaining = varp->xsz * nelems;
  3154. int status = NC_NOERR;
  3155. const void *xp;
  3156. if(nelems == 0)
  3157. return NC_NOERR;
  3158. assert(value != NULL);
  3159. for(;;)
  3160. {
  3161. size_t extent = MIN(remaining, ncp->chunk);
  3162. size_t nget = ncx_howmany(varp->type, extent);
  3163. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3164. 0, (void **)&xp); /* cast away const */
  3165. if(lstatus != NC_NOERR)
  3166. return lstatus;
  3167. lstatus = ncx_getn_float_short(&xp, nget, value);
  3168. if(lstatus != NC_NOERR && status == NC_NOERR)
  3169. status = lstatus;
  3170. (void) ncio_rel(ncp->nciop, offset, 0);
  3171. remaining -= extent;
  3172. if(remaining == 0)
  3173. break; /* normal loop exit */
  3174. offset += extent;
  3175. value += nget;
  3176. }
  3177. return status;
  3178. }
  3179. static int
  3180. getNCvx_float_int(const NC *ncp, const NC_var *varp,
  3181. const size_t *start, size_t nelems, int *value)
  3182. {
  3183. off_t offset = NC_varoffset(ncp, varp, start);
  3184. size_t remaining = varp->xsz * nelems;
  3185. int status = NC_NOERR;
  3186. const void *xp;
  3187. if(nelems == 0)
  3188. return NC_NOERR;
  3189. assert(value != NULL);
  3190. for(;;)
  3191. {
  3192. size_t extent = MIN(remaining, ncp->chunk);
  3193. size_t nget = ncx_howmany(varp->type, extent);
  3194. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3195. 0, (void **)&xp); /* cast away const */
  3196. if(lstatus != NC_NOERR)
  3197. return lstatus;
  3198. lstatus = ncx_getn_float_int(&xp, nget, value);
  3199. if(lstatus != NC_NOERR && status == NC_NOERR)
  3200. status = lstatus;
  3201. (void) ncio_rel(ncp->nciop, offset, 0);
  3202. remaining -= extent;
  3203. if(remaining == 0)
  3204. break; /* normal loop exit */
  3205. offset += extent;
  3206. value += nget;
  3207. }
  3208. return status;
  3209. }
  3210. static int
  3211. getNCvx_float_float(const NC *ncp, const NC_var *varp,
  3212. const size_t *start, size_t nelems, float *value)
  3213. {
  3214. off_t offset = NC_varoffset(ncp, varp, start);
  3215. size_t remaining = varp->xsz * nelems;
  3216. int status = NC_NOERR;
  3217. const void *xp;
  3218. if(nelems == 0)
  3219. return NC_NOERR;
  3220. assert(value != NULL);
  3221. for(;;)
  3222. {
  3223. size_t extent = MIN(remaining, ncp->chunk);
  3224. size_t nget = ncx_howmany(varp->type, extent);
  3225. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3226. 0, (void **)&xp); /* cast away const */
  3227. if(lstatus != NC_NOERR)
  3228. return lstatus;
  3229. lstatus = ncx_getn_float_float(&xp, nget, value);
  3230. if(lstatus != NC_NOERR && status == NC_NOERR)
  3231. status = lstatus;
  3232. (void) ncio_rel(ncp->nciop, offset, 0);
  3233. remaining -= extent;
  3234. if(remaining == 0)
  3235. break; /* normal loop exit */
  3236. offset += extent;
  3237. value += nget;
  3238. }
  3239. return status;
  3240. }
  3241. static int
  3242. getNCvx_float_double(const NC *ncp, const NC_var *varp,
  3243. const size_t *start, size_t nelems, double *value)
  3244. {
  3245. off_t offset = NC_varoffset(ncp, varp, start);
  3246. size_t remaining = varp->xsz * nelems;
  3247. int status = NC_NOERR;
  3248. const void *xp;
  3249. if(nelems == 0)
  3250. return NC_NOERR;
  3251. assert(value != NULL);
  3252. for(;;)
  3253. {
  3254. size_t extent = MIN(remaining, ncp->chunk);
  3255. size_t nget = ncx_howmany(varp->type, extent);
  3256. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3257. 0, (void **)&xp); /* cast away const */
  3258. if(lstatus != NC_NOERR)
  3259. return lstatus;
  3260. lstatus = ncx_getn_float_double(&xp, nget, value);
  3261. if(lstatus != NC_NOERR && status == NC_NOERR)
  3262. status = lstatus;
  3263. (void) ncio_rel(ncp->nciop, offset, 0);
  3264. remaining -= extent;
  3265. if(remaining == 0)
  3266. break; /* normal loop exit */
  3267. offset += extent;
  3268. value += nget;
  3269. }
  3270. return status;
  3271. }
  3272. static int
  3273. getNCvx_float_longlong(const NC *ncp, const NC_var *varp,
  3274. const size_t *start, size_t nelems, longlong *value)
  3275. {
  3276. off_t offset = NC_varoffset(ncp, varp, start);
  3277. size_t remaining = varp->xsz * nelems;
  3278. int status = NC_NOERR;
  3279. const void *xp;
  3280. if(nelems == 0)
  3281. return NC_NOERR;
  3282. assert(value != NULL);
  3283. for(;;)
  3284. {
  3285. size_t extent = MIN(remaining, ncp->chunk);
  3286. size_t nget = ncx_howmany(varp->type, extent);
  3287. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3288. 0, (void **)&xp); /* cast away const */
  3289. if(lstatus != NC_NOERR)
  3290. return lstatus;
  3291. lstatus = ncx_getn_float_longlong(&xp, nget, value);
  3292. if(lstatus != NC_NOERR && status == NC_NOERR)
  3293. status = lstatus;
  3294. (void) ncio_rel(ncp->nciop, offset, 0);
  3295. remaining -= extent;
  3296. if(remaining == 0)
  3297. break; /* normal loop exit */
  3298. offset += extent;
  3299. value += nget;
  3300. }
  3301. return status;
  3302. }
  3303. static int
  3304. getNCvx_float_uint(const NC *ncp, const NC_var *varp,
  3305. const size_t *start, size_t nelems, uint *value)
  3306. {
  3307. off_t offset = NC_varoffset(ncp, varp, start);
  3308. size_t remaining = varp->xsz * nelems;
  3309. int status = NC_NOERR;
  3310. const void *xp;
  3311. if(nelems == 0)
  3312. return NC_NOERR;
  3313. assert(value != NULL);
  3314. for(;;)
  3315. {
  3316. size_t extent = MIN(remaining, ncp->chunk);
  3317. size_t nget = ncx_howmany(varp->type, extent);
  3318. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3319. 0, (void **)&xp); /* cast away const */
  3320. if(lstatus != NC_NOERR)
  3321. return lstatus;
  3322. lstatus = ncx_getn_float_uint(&xp, nget, value);
  3323. if(lstatus != NC_NOERR && status == NC_NOERR)
  3324. status = lstatus;
  3325. (void) ncio_rel(ncp->nciop, offset, 0);
  3326. remaining -= extent;
  3327. if(remaining == 0)
  3328. break; /* normal loop exit */
  3329. offset += extent;
  3330. value += nget;
  3331. }
  3332. return status;
  3333. }
  3334. static int
  3335. getNCvx_float_ulonglong(const NC *ncp, const NC_var *varp,
  3336. const size_t *start, size_t nelems, ulonglong *value)
  3337. {
  3338. off_t offset = NC_varoffset(ncp, varp, start);
  3339. size_t remaining = varp->xsz * nelems;
  3340. int status = NC_NOERR;
  3341. const void *xp;
  3342. if(nelems == 0)
  3343. return NC_NOERR;
  3344. assert(value != NULL);
  3345. for(;;)
  3346. {
  3347. size_t extent = MIN(remaining, ncp->chunk);
  3348. size_t nget = ncx_howmany(varp->type, extent);
  3349. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3350. 0, (void **)&xp); /* cast away const */
  3351. if(lstatus != NC_NOERR)
  3352. return lstatus;
  3353. lstatus = ncx_getn_float_ulonglong(&xp, nget, value);
  3354. if(lstatus != NC_NOERR && status == NC_NOERR)
  3355. status = lstatus;
  3356. (void) ncio_rel(ncp->nciop, offset, 0);
  3357. remaining -= extent;
  3358. if(remaining == 0)
  3359. break; /* normal loop exit */
  3360. offset += extent;
  3361. value += nget;
  3362. }
  3363. return status;
  3364. }
  3365. static int
  3366. getNCvx_double_schar(const NC *ncp, const NC_var *varp,
  3367. const size_t *start, size_t nelems, schar *value)
  3368. {
  3369. off_t offset = NC_varoffset(ncp, varp, start);
  3370. size_t remaining = varp->xsz * nelems;
  3371. int status = NC_NOERR;
  3372. const void *xp;
  3373. if(nelems == 0)
  3374. return NC_NOERR;
  3375. assert(value != NULL);
  3376. for(;;)
  3377. {
  3378. size_t extent = MIN(remaining, ncp->chunk);
  3379. size_t nget = ncx_howmany(varp->type, extent);
  3380. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3381. 0, (void **)&xp); /* cast away const */
  3382. if(lstatus != NC_NOERR)
  3383. return lstatus;
  3384. lstatus = ncx_getn_double_schar(&xp, nget, value);
  3385. if(lstatus != NC_NOERR && status == NC_NOERR)
  3386. status = lstatus;
  3387. (void) ncio_rel(ncp->nciop, offset, 0);
  3388. remaining -= extent;
  3389. if(remaining == 0)
  3390. break; /* normal loop exit */
  3391. offset += extent;
  3392. value += nget;
  3393. }
  3394. return status;
  3395. }
  3396. static int
  3397. getNCvx_double_uchar(const NC *ncp, const NC_var *varp,
  3398. const size_t *start, size_t nelems, uchar *value)
  3399. {
  3400. off_t offset = NC_varoffset(ncp, varp, start);
  3401. size_t remaining = varp->xsz * nelems;
  3402. int status = NC_NOERR;
  3403. const void *xp;
  3404. if(nelems == 0)
  3405. return NC_NOERR;
  3406. assert(value != NULL);
  3407. for(;;)
  3408. {
  3409. size_t extent = MIN(remaining, ncp->chunk);
  3410. size_t nget = ncx_howmany(varp->type, extent);
  3411. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3412. 0, (void **)&xp); /* cast away const */
  3413. if(lstatus != NC_NOERR)
  3414. return lstatus;
  3415. lstatus = ncx_getn_double_uchar(&xp, nget, value);
  3416. if(lstatus != NC_NOERR && status == NC_NOERR)
  3417. status = lstatus;
  3418. (void) ncio_rel(ncp->nciop, offset, 0);
  3419. remaining -= extent;
  3420. if(remaining == 0)
  3421. break; /* normal loop exit */
  3422. offset += extent;
  3423. value += nget;
  3424. }
  3425. return status;
  3426. }
  3427. static int
  3428. getNCvx_double_short(const NC *ncp, const NC_var *varp,
  3429. const size_t *start, size_t nelems, short *value)
  3430. {
  3431. off_t offset = NC_varoffset(ncp, varp, start);
  3432. size_t remaining = varp->xsz * nelems;
  3433. int status = NC_NOERR;
  3434. const void *xp;
  3435. if(nelems == 0)
  3436. return NC_NOERR;
  3437. assert(value != NULL);
  3438. for(;;)
  3439. {
  3440. size_t extent = MIN(remaining, ncp->chunk);
  3441. size_t nget = ncx_howmany(varp->type, extent);
  3442. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3443. 0, (void **)&xp); /* cast away const */
  3444. if(lstatus != NC_NOERR)
  3445. return lstatus;
  3446. lstatus = ncx_getn_double_short(&xp, nget, value);
  3447. if(lstatus != NC_NOERR && status == NC_NOERR)
  3448. status = lstatus;
  3449. (void) ncio_rel(ncp->nciop, offset, 0);
  3450. remaining -= extent;
  3451. if(remaining == 0)
  3452. break; /* normal loop exit */
  3453. offset += extent;
  3454. value += nget;
  3455. }
  3456. return status;
  3457. }
  3458. static int
  3459. getNCvx_double_int(const NC *ncp, const NC_var *varp,
  3460. const size_t *start, size_t nelems, int *value)
  3461. {
  3462. off_t offset = NC_varoffset(ncp, varp, start);
  3463. size_t remaining = varp->xsz * nelems;
  3464. int status = NC_NOERR;
  3465. const void *xp;
  3466. if(nelems == 0)
  3467. return NC_NOERR;
  3468. assert(value != NULL);
  3469. for(;;)
  3470. {
  3471. size_t extent = MIN(remaining, ncp->chunk);
  3472. size_t nget = ncx_howmany(varp->type, extent);
  3473. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3474. 0, (void **)&xp); /* cast away const */
  3475. if(lstatus != NC_NOERR)
  3476. return lstatus;
  3477. lstatus = ncx_getn_double_int(&xp, nget, value);
  3478. if(lstatus != NC_NOERR && status == NC_NOERR)
  3479. status = lstatus;
  3480. (void) ncio_rel(ncp->nciop, offset, 0);
  3481. remaining -= extent;
  3482. if(remaining == 0)
  3483. break; /* normal loop exit */
  3484. offset += extent;
  3485. value += nget;
  3486. }
  3487. return status;
  3488. }
  3489. static int
  3490. getNCvx_double_float(const NC *ncp, const NC_var *varp,
  3491. const size_t *start, size_t nelems, float *value)
  3492. {
  3493. off_t offset = NC_varoffset(ncp, varp, start);
  3494. size_t remaining = varp->xsz * nelems;
  3495. int status = NC_NOERR;
  3496. const void *xp;
  3497. if(nelems == 0)
  3498. return NC_NOERR;
  3499. assert(value != NULL);
  3500. for(;;)
  3501. {
  3502. size_t extent = MIN(remaining, ncp->chunk);
  3503. size_t nget = ncx_howmany(varp->type, extent);
  3504. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3505. 0, (void **)&xp); /* cast away const */
  3506. if(lstatus != NC_NOERR)
  3507. return lstatus;
  3508. lstatus = ncx_getn_double_float(&xp, nget, value);
  3509. if(lstatus != NC_NOERR && status == NC_NOERR)
  3510. status = lstatus;
  3511. (void) ncio_rel(ncp->nciop, offset, 0);
  3512. remaining -= extent;
  3513. if(remaining == 0)
  3514. break; /* normal loop exit */
  3515. offset += extent;
  3516. value += nget;
  3517. }
  3518. return status;
  3519. }
  3520. static int
  3521. getNCvx_double_double(const NC *ncp, const NC_var *varp,
  3522. const size_t *start, size_t nelems, double *value)
  3523. {
  3524. off_t offset = NC_varoffset(ncp, varp, start);
  3525. size_t remaining = varp->xsz * nelems;
  3526. int status = NC_NOERR;
  3527. const void *xp;
  3528. if(nelems == 0)
  3529. return NC_NOERR;
  3530. assert(value != NULL);
  3531. for(;;)
  3532. {
  3533. size_t extent = MIN(remaining, ncp->chunk);
  3534. size_t nget = ncx_howmany(varp->type, extent);
  3535. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3536. 0, (void **)&xp); /* cast away const */
  3537. if(lstatus != NC_NOERR)
  3538. return lstatus;
  3539. lstatus = ncx_getn_double_double(&xp, nget, value);
  3540. if(lstatus != NC_NOERR && status == NC_NOERR)
  3541. status = lstatus;
  3542. (void) ncio_rel(ncp->nciop, offset, 0);
  3543. remaining -= extent;
  3544. if(remaining == 0)
  3545. break; /* normal loop exit */
  3546. offset += extent;
  3547. value += nget;
  3548. }
  3549. return status;
  3550. }
  3551. static int
  3552. getNCvx_double_longlong(const NC *ncp, const NC_var *varp,
  3553. const size_t *start, size_t nelems, longlong *value)
  3554. {
  3555. off_t offset = NC_varoffset(ncp, varp, start);
  3556. size_t remaining = varp->xsz * nelems;
  3557. int status = NC_NOERR;
  3558. const void *xp;
  3559. if(nelems == 0)
  3560. return NC_NOERR;
  3561. assert(value != NULL);
  3562. for(;;)
  3563. {
  3564. size_t extent = MIN(remaining, ncp->chunk);
  3565. size_t nget = ncx_howmany(varp->type, extent);
  3566. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3567. 0, (void **)&xp); /* cast away const */
  3568. if(lstatus != NC_NOERR)
  3569. return lstatus;
  3570. lstatus = ncx_getn_double_longlong(&xp, nget, value);
  3571. if(lstatus != NC_NOERR && status == NC_NOERR)
  3572. status = lstatus;
  3573. (void) ncio_rel(ncp->nciop, offset, 0);
  3574. remaining -= extent;
  3575. if(remaining == 0)
  3576. break; /* normal loop exit */
  3577. offset += extent;
  3578. value += nget;
  3579. }
  3580. return status;
  3581. }
  3582. static int
  3583. getNCvx_double_uint(const NC *ncp, const NC_var *varp,
  3584. const size_t *start, size_t nelems, uint *value)
  3585. {
  3586. off_t offset = NC_varoffset(ncp, varp, start);
  3587. size_t remaining = varp->xsz * nelems;
  3588. int status = NC_NOERR;
  3589. const void *xp;
  3590. if(nelems == 0)
  3591. return NC_NOERR;
  3592. assert(value != NULL);
  3593. for(;;)
  3594. {
  3595. size_t extent = MIN(remaining, ncp->chunk);
  3596. size_t nget = ncx_howmany(varp->type, extent);
  3597. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3598. 0, (void **)&xp); /* cast away const */
  3599. if(lstatus != NC_NOERR)
  3600. return lstatus;
  3601. lstatus = ncx_getn_double_uint(&xp, nget, value);
  3602. if(lstatus != NC_NOERR && status == NC_NOERR)
  3603. status = lstatus;
  3604. (void) ncio_rel(ncp->nciop, offset, 0);
  3605. remaining -= extent;
  3606. if(remaining == 0)
  3607. break; /* normal loop exit */
  3608. offset += extent;
  3609. value += nget;
  3610. }
  3611. return status;
  3612. }
  3613. static int
  3614. getNCvx_double_ulonglong(const NC *ncp, const NC_var *varp,
  3615. const size_t *start, size_t nelems, ulonglong *value)
  3616. {
  3617. off_t offset = NC_varoffset(ncp, varp, start);
  3618. size_t remaining = varp->xsz * nelems;
  3619. int status = NC_NOERR;
  3620. const void *xp;
  3621. if(nelems == 0)
  3622. return NC_NOERR;
  3623. assert(value != NULL);
  3624. for(;;)
  3625. {
  3626. size_t extent = MIN(remaining, ncp->chunk);
  3627. size_t nget = ncx_howmany(varp->type, extent);
  3628. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3629. 0, (void **)&xp); /* cast away const */
  3630. if(lstatus != NC_NOERR)
  3631. return lstatus;
  3632. lstatus = ncx_getn_double_ulonglong(&xp, nget, value);
  3633. if(lstatus != NC_NOERR && status == NC_NOERR)
  3634. status = lstatus;
  3635. (void) ncio_rel(ncp->nciop, offset, 0);
  3636. remaining -= extent;
  3637. if(remaining == 0)
  3638. break; /* normal loop exit */
  3639. offset += extent;
  3640. value += nget;
  3641. }
  3642. return status;
  3643. }
  3644. #ifdef NOTUSED
  3645. static int
  3646. getNCvx_schar_uchar(const NC *ncp, const NC_var *varp,
  3647. const size_t *start, size_t nelems, uchar *value)
  3648. {
  3649. off_t offset = NC_varoffset(ncp, varp, start);
  3650. size_t remaining = varp->xsz * nelems;
  3651. int status = NC_NOERR;
  3652. const void *xp;
  3653. if(nelems == 0)
  3654. return NC_NOERR;
  3655. assert(value != NULL);
  3656. for(;;)
  3657. {
  3658. size_t extent = MIN(remaining, ncp->chunk);
  3659. size_t nget = ncx_howmany(varp->type, extent);
  3660. int lstatus = ncio_get(ncp->nciop, offset, extent,
  3661. 0, (void **)&xp); /* cast away const */
  3662. if(lstatus != NC_NOERR)
  3663. return lstatus;
  3664. lstatus = ncx_getn_schar_uchar(&xp, nget, value);
  3665. if(lstatus != NC_NOERR && status == NC_NOERR)
  3666. status = lstatus;
  3667. (void) ncio_rel(ncp->nciop, offset, 0);
  3668. remaining -= extent;
  3669. if(remaining == 0)
  3670. break; /* normal loop exit */
  3671. offset += extent;
  3672. value += nget;
  3673. }
  3674. return status;
  3675. }
  3676. #endif /*NOTUSED*/
  3677. /*
  3678. * For ncvar{put,get},
  3679. * find the largest contiguous block from within 'edges'.
  3680. * returns the index to the left of this (which may be -1).
  3681. * Compute the number of contiguous elements and return
  3682. * that in *iocountp.
  3683. * The presence of "record" variables makes this routine
  3684. * overly subtle.
  3685. */
  3686. static int
  3687. NCiocount(const NC *const ncp, const NC_var *const varp,
  3688. const size_t *const edges,
  3689. size_t *const iocountp)
  3690. {
  3691. const size_t *edp0 = edges;
  3692. const size_t *edp = edges + varp->ndims;
  3693. const size_t *shp = varp->shape + varp->ndims;
  3694. if(IS_RECVAR(varp))
  3695. {
  3696. if(varp->ndims == 1 && ncp->recsize <= varp->len)
  3697. {
  3698. /* one dimensional && the only 'record' variable */
  3699. *iocountp = *edges;
  3700. return(0);
  3701. }
  3702. /* else */
  3703. edp0++;
  3704. }
  3705. assert(edges != NULL);
  3706. /* find max contiguous */
  3707. while(edp > edp0)
  3708. {
  3709. shp--; edp--;
  3710. if(*edp < *shp )
  3711. {
  3712. const size_t *zedp = edp;
  3713. while(zedp >= edp0)
  3714. {
  3715. if(*zedp == 0)
  3716. {
  3717. *iocountp = 0;
  3718. goto done;
  3719. }
  3720. /* Tip of the hat to segmented architectures */
  3721. if(zedp == edp0)
  3722. break;
  3723. zedp--;
  3724. }
  3725. break;
  3726. }
  3727. assert(*edp == *shp);
  3728. }
  3729. /*
  3730. * edp, shp reference rightmost index s.t. *(edp +1) == *(shp +1)
  3731. *
  3732. * Or there is only one dimension.
  3733. * If there is only one dimension and it is 'non record' dimension,
  3734. * edp is &edges[0] and we will return -1.
  3735. * If there is only one dimension and and it is a "record dimension",
  3736. * edp is &edges[1] (out of bounds) and we will return 0;
  3737. */
  3738. assert(shp >= varp->shape + varp->ndims -1
  3739. || *(edp +1) == *(shp +1));
  3740. /* now accumulate max count for a single io operation */
  3741. for(*iocountp = 1, edp0 = edp;
  3742. edp0 < edges + varp->ndims;
  3743. edp0++)
  3744. {
  3745. *iocountp *= *edp0;
  3746. }
  3747. done:
  3748. return((int)(edp - edges) - 1);
  3749. }
  3750. /*
  3751. * Set the elements of the array 'upp' to
  3752. * the sum of the corresponding elements of
  3753. * 'stp' and 'edp'. 'end' should be &stp[nelems].
  3754. */
  3755. static void
  3756. set_upper(size_t *upp, /* modified on return */
  3757. const size_t *stp,
  3758. const size_t *edp,
  3759. const size_t *const end)
  3760. {
  3761. while(upp < end) {
  3762. *upp++ = *stp++ + *edp++;
  3763. }
  3764. }
  3765. /*
  3766. * The infamous and oft-discussed odometer code.
  3767. *
  3768. * 'start[]' is the starting coordinate.
  3769. * 'upper[]' is the upper bound s.t. start[ii] < upper[ii].
  3770. * 'coord[]' is the register, the current coordinate value.
  3771. * For some ii,
  3772. * upp == &upper[ii]
  3773. * cdp == &coord[ii]
  3774. *
  3775. * Running this routine increments *cdp.
  3776. *
  3777. * If after the increment, *cdp is equal to *upp
  3778. * (and cdp is not the leftmost dimension),
  3779. * *cdp is "zeroed" to the starting value and
  3780. * we need to "carry", eg, increment one place to
  3781. * the left.
  3782. *
  3783. * TODO: Some architectures hate recursion?
  3784. * Reimplement non-recursively.
  3785. */
  3786. static void
  3787. odo1(const size_t *const start, const size_t *const upper,
  3788. size_t *const coord, /* modified on return */
  3789. const size_t *upp,
  3790. size_t *cdp)
  3791. {
  3792. assert(coord <= cdp && cdp <= coord + NC_MAX_VAR_DIMS);
  3793. assert(upper <= upp && upp <= upper + NC_MAX_VAR_DIMS);
  3794. assert(upp - upper == cdp - coord);
  3795. assert(*cdp <= *upp);
  3796. (*cdp)++;
  3797. if(cdp != coord && *cdp >= *upp)
  3798. {
  3799. *cdp = start[cdp - coord];
  3800. odo1(start, upper, coord, upp -1, cdp -1);
  3801. }
  3802. }
  3803. #ifdef _CRAYC
  3804. #pragma _CRI noinline odo1
  3805. #endif
  3806. /* Define a macro to allow hash on two type values */
  3807. #define CASE(nc1,nc2) (nc1*256+nc2)
  3808. static int
  3809. readNCv(const NC* ncp, const NC_var* varp, const size_t* start,
  3810. const size_t nelems, void* value, const nc_type memtype)
  3811. {
  3812. int status = NC_NOERR;
  3813. switch (CASE(varp->type,memtype)) {
  3814. case CASE(NC_CHAR,NC_CHAR):
  3815. case CASE(NC_CHAR,NC_UBYTE):
  3816. status = getNCvx_char_char(ncp,varp,start,nelems,(char*)value);
  3817. break;
  3818. case CASE(NC_BYTE,NC_BYTE):
  3819. case CASE(NC_BYTE,NC_UBYTE):
  3820. status = getNCvx_schar_schar(ncp,varp,start,nelems,(signed char*)value);
  3821. break;
  3822. case CASE(NC_BYTE,NC_SHORT):
  3823. status = getNCvx_schar_short(ncp,varp,start,nelems,(short*)value);
  3824. break;
  3825. case CASE(NC_BYTE,NC_INT):
  3826. status = getNCvx_schar_int(ncp,varp,start,nelems,(int*)value);
  3827. break;
  3828. case CASE(NC_BYTE,NC_FLOAT):
  3829. status = getNCvx_schar_float(ncp,varp,start,nelems,(float*)value);
  3830. break;
  3831. case CASE(NC_BYTE,NC_DOUBLE):
  3832. status = getNCvx_schar_double(ncp,varp,start,nelems,(double *)value);
  3833. break;
  3834. case CASE(NC_BYTE,NC_INT64):
  3835. status = getNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value);
  3836. break;
  3837. case CASE(NC_BYTE,NC_UINT):
  3838. status = getNCvx_schar_uint(ncp,varp,start,nelems,(unsigned int*)value);
  3839. break;
  3840. case CASE(NC_BYTE,NC_UINT64):
  3841. status = getNCvx_schar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
  3842. break;
  3843. case CASE(NC_SHORT,NC_BYTE):
  3844. status = getNCvx_short_schar(ncp,varp,start,nelems,(signed char*)value);
  3845. break;
  3846. case CASE(NC_SHORT,NC_UBYTE):
  3847. status = getNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3848. break;
  3849. case CASE(NC_SHORT,NC_SHORT):
  3850. status = getNCvx_short_short(ncp,varp,start,nelems,(short*)value);
  3851. break;
  3852. case CASE(NC_SHORT,NC_INT):
  3853. status = getNCvx_short_int(ncp,varp,start,nelems,(int*)value);
  3854. break;
  3855. case CASE(NC_SHORT,NC_FLOAT):
  3856. status = getNCvx_short_float(ncp,varp,start,nelems,(float*)value);
  3857. break;
  3858. case CASE(NC_SHORT,NC_DOUBLE):
  3859. status = getNCvx_short_double(ncp,varp,start,nelems,(double*)value);
  3860. break;
  3861. case CASE(NC_SHORT,NC_INT64):
  3862. status = getNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value);
  3863. break;
  3864. case CASE(NC_SHORT,NC_UINT):
  3865. status = getNCvx_short_uint(ncp,varp,start,nelems,(unsigned int*)value);
  3866. break;
  3867. case CASE(NC_SHORT,NC_UINT64):
  3868. status = getNCvx_short_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
  3869. break;
  3870. case CASE(NC_INT,NC_BYTE):
  3871. status = getNCvx_int_schar(ncp,varp,start,nelems,(signed char*)value);
  3872. break;
  3873. case CASE(NC_INT,NC_UBYTE):
  3874. status = getNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3875. break;
  3876. case CASE(NC_INT,NC_SHORT):
  3877. status = getNCvx_int_short(ncp,varp,start,nelems,(short*)value);
  3878. break;
  3879. case CASE(NC_INT,NC_INT):
  3880. status = getNCvx_int_int(ncp,varp,start,nelems,(int*)value);
  3881. break;
  3882. case CASE(NC_INT,NC_FLOAT):
  3883. status = getNCvx_int_float(ncp,varp,start,nelems,(float*)value);
  3884. break;
  3885. case CASE(NC_INT,NC_DOUBLE):
  3886. status = getNCvx_int_double(ncp,varp,start,nelems,(double*)value);
  3887. break;
  3888. case CASE(NC_INT,NC_INT64):
  3889. status = getNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value);
  3890. break;
  3891. case CASE(NC_INT,NC_UINT):
  3892. status = getNCvx_int_uint(ncp,varp,start,nelems,(unsigned int*)value);
  3893. break;
  3894. case CASE(NC_INT,NC_UINT64):
  3895. status = getNCvx_int_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
  3896. break;
  3897. case CASE(NC_FLOAT,NC_BYTE):
  3898. status = getNCvx_float_schar(ncp,varp,start,nelems,(signed char*)value);
  3899. break;
  3900. case CASE(NC_FLOAT,NC_UBYTE):
  3901. status = getNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3902. break;
  3903. case CASE(NC_FLOAT,NC_SHORT):
  3904. status = getNCvx_float_short(ncp,varp,start,nelems,(short*)value);
  3905. break;
  3906. case CASE(NC_FLOAT,NC_INT):
  3907. status = getNCvx_float_int(ncp,varp,start,nelems,(int*)value);
  3908. break;
  3909. case CASE(NC_FLOAT,NC_FLOAT):
  3910. status = getNCvx_float_float(ncp,varp,start,nelems,(float*)value);
  3911. break;
  3912. case CASE(NC_FLOAT,NC_DOUBLE):
  3913. status = getNCvx_float_double(ncp,varp,start,nelems,(double*)value);
  3914. break;
  3915. case CASE(NC_FLOAT,NC_INT64):
  3916. status = getNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value);
  3917. break;
  3918. case CASE(NC_FLOAT,NC_UINT):
  3919. status = getNCvx_float_uint(ncp,varp,start,nelems,(unsigned int*)value);
  3920. break;
  3921. case CASE(NC_FLOAT,NC_UINT64):
  3922. status = getNCvx_float_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
  3923. break;
  3924. case CASE(NC_DOUBLE,NC_BYTE):
  3925. status = getNCvx_double_schar(ncp,varp,start,nelems,(signed char*)value);
  3926. break;
  3927. case CASE(NC_DOUBLE,NC_UBYTE):
  3928. status = getNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3929. break;
  3930. case CASE(NC_DOUBLE,NC_SHORT):
  3931. status = getNCvx_double_short(ncp,varp,start,nelems,(short*)value);
  3932. break;
  3933. case CASE(NC_DOUBLE,NC_INT):
  3934. status = getNCvx_double_int(ncp,varp,start,nelems,(int*)value);
  3935. break;
  3936. case CASE(NC_DOUBLE,NC_FLOAT):
  3937. status = getNCvx_double_float(ncp,varp,start,nelems,(float*)value);
  3938. break;
  3939. case CASE(NC_DOUBLE,NC_DOUBLE):
  3940. status = getNCvx_double_double(ncp,varp,start,nelems,(double*)value);
  3941. break;
  3942. case CASE(NC_DOUBLE,NC_INT64):
  3943. status = getNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value);
  3944. break;
  3945. case CASE(NC_DOUBLE,NC_UINT):
  3946. status = getNCvx_double_uint(ncp,varp,start,nelems,(unsigned int*)value);
  3947. break;
  3948. case CASE(NC_DOUBLE,NC_UINT64):
  3949. status = getNCvx_double_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
  3950. break;
  3951. default:
  3952. return NC_EBADTYPE;
  3953. }
  3954. return status;
  3955. }
  3956. static int
  3957. writeNCv(NC* ncp, const NC_var* varp, const size_t* start,
  3958. const size_t nelems, const void* value, const nc_type memtype)
  3959. {
  3960. int status = NC_NOERR;
  3961. switch (CASE(varp->type,memtype)) {
  3962. case CASE(NC_CHAR,NC_CHAR):
  3963. case CASE(NC_CHAR,NC_UBYTE):
  3964. status = putNCvx_char_char(ncp,varp,start,nelems,(char*)value);
  3965. break;
  3966. case CASE(NC_BYTE,NC_BYTE):
  3967. status = putNCvx_schar_schar(ncp,varp,start,nelems,(signed char*)value);
  3968. break;
  3969. case CASE(NC_BYTE,NC_UBYTE):
  3970. status = putNCvx_schar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3971. break;
  3972. case CASE(NC_BYTE,NC_SHORT):
  3973. status = putNCvx_schar_short(ncp,varp,start,nelems,(short*)value);
  3974. break;
  3975. case CASE(NC_BYTE,NC_INT):
  3976. status = putNCvx_schar_int(ncp,varp,start,nelems,(int*)value);
  3977. break;
  3978. case CASE(NC_BYTE,NC_FLOAT):
  3979. status = putNCvx_schar_float(ncp,varp,start,nelems,(float*)value);
  3980. break;
  3981. case CASE(NC_BYTE,NC_DOUBLE):
  3982. status = putNCvx_schar_double(ncp,varp,start,nelems,(double *)value);
  3983. break;
  3984. case CASE(NC_BYTE,NC_INT64):
  3985. status = putNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value);
  3986. break;
  3987. case CASE(NC_SHORT,NC_BYTE):
  3988. status = putNCvx_short_schar(ncp,varp,start,nelems,(signed char*)value);
  3989. break;
  3990. case CASE(NC_SHORT,NC_UBYTE):
  3991. status = putNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  3992. break;
  3993. case CASE(NC_SHORT,NC_SHORT):
  3994. status = putNCvx_short_short(ncp,varp,start,nelems,(short*)value);
  3995. break;
  3996. case CASE(NC_SHORT,NC_INT):
  3997. status = putNCvx_short_int(ncp,varp,start,nelems,(int*)value);
  3998. break;
  3999. case CASE(NC_SHORT,NC_FLOAT):
  4000. status = putNCvx_short_float(ncp,varp,start,nelems,(float*)value);
  4001. break;
  4002. case CASE(NC_SHORT,NC_DOUBLE):
  4003. status = putNCvx_short_double(ncp,varp,start,nelems,(double*)value);
  4004. break;
  4005. case CASE(NC_SHORT,NC_INT64):
  4006. status = putNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value);
  4007. break;
  4008. case CASE(NC_INT,NC_BYTE):
  4009. status = putNCvx_int_schar(ncp,varp,start,nelems,(signed char*)value);
  4010. break;
  4011. case CASE(NC_INT,NC_UBYTE):
  4012. status = putNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  4013. break;
  4014. case CASE(NC_INT,NC_SHORT):
  4015. status = putNCvx_int_short(ncp,varp,start,nelems,(short*)value);
  4016. break;
  4017. case CASE(NC_INT,NC_INT):
  4018. status = putNCvx_int_int(ncp,varp,start,nelems,(int*)value);
  4019. break;
  4020. case CASE(NC_INT,NC_FLOAT):
  4021. status = putNCvx_int_float(ncp,varp,start,nelems,(float*)value);
  4022. break;
  4023. case CASE(NC_INT,NC_DOUBLE):
  4024. status = putNCvx_int_double(ncp,varp,start,nelems,(double*)value);
  4025. break;
  4026. case CASE(NC_INT,NC_INT64):
  4027. status = putNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value);
  4028. break;
  4029. case CASE(NC_FLOAT,NC_BYTE):
  4030. status = putNCvx_float_schar(ncp,varp,start,nelems,(signed char*)value);
  4031. break;
  4032. case CASE(NC_FLOAT,NC_UBYTE):
  4033. status = putNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  4034. break;
  4035. case CASE(NC_FLOAT,NC_SHORT):
  4036. status = putNCvx_float_short(ncp,varp,start,nelems,(short*)value);
  4037. break;
  4038. case CASE(NC_FLOAT,NC_INT):
  4039. status = putNCvx_float_int(ncp,varp,start,nelems,(int*)value);
  4040. break;
  4041. case CASE(NC_FLOAT,NC_FLOAT):
  4042. status = putNCvx_float_float(ncp,varp,start,nelems,(float*)value);
  4043. break;
  4044. case CASE(NC_FLOAT,NC_DOUBLE):
  4045. status = putNCvx_float_double(ncp,varp,start,nelems,(double*)value);
  4046. break;
  4047. case CASE(NC_FLOAT,NC_INT64):
  4048. status = putNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value);
  4049. break;
  4050. case CASE(NC_DOUBLE,NC_BYTE):
  4051. status = putNCvx_double_schar(ncp,varp,start,nelems,(signed char*)value);
  4052. break;
  4053. case CASE(NC_DOUBLE,NC_UBYTE):
  4054. status = putNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value);
  4055. break;
  4056. case CASE(NC_DOUBLE,NC_SHORT):
  4057. status = putNCvx_double_short(ncp,varp,start,nelems,(short*)value);
  4058. break;
  4059. case CASE(NC_DOUBLE,NC_INT):
  4060. status = putNCvx_double_int(ncp,varp,start,nelems,(int*)value);
  4061. break;
  4062. case CASE(NC_DOUBLE,NC_FLOAT):
  4063. status = putNCvx_double_float(ncp,varp,start,nelems,(float*)value);
  4064. break;
  4065. case CASE(NC_DOUBLE,NC_DOUBLE):
  4066. status = putNCvx_double_double(ncp,varp,start,nelems,(double*)value);
  4067. break;
  4068. case CASE(NC_DOUBLE,NC_INT64):
  4069. status = putNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value);
  4070. break;
  4071. default:
  4072. return NC_EBADTYPE;
  4073. }
  4074. return status;
  4075. }
  4076. /**************************************************/
  4077. int
  4078. NC3_get_vara(int ncid, int varid,
  4079. const size_t *start, const size_t *edges0,
  4080. void *value0,
  4081. nc_type memtype)
  4082. {
  4083. int status = NC_NOERR;
  4084. NC* ncp;
  4085. NC_var *varp;
  4086. int ii;
  4087. size_t iocount;
  4088. size_t memtypelen;
  4089. char* value = (char*) value0; /* legally allow ptr arithmetic */
  4090. const size_t* edges = edges0; /* so we can modify for special cases */
  4091. size_t modedges[NC_MAX_VAR_DIMS];
  4092. status = NC_check_id(ncid, &ncp);
  4093. if(status != NC_NOERR)
  4094. return status;
  4095. if(NC_indef(ncp))
  4096. return NC_EINDEFINE;
  4097. varp = NC_lookupvar(ncp, varid);
  4098. if(varp == NULL)
  4099. return NC_ENOTVAR;
  4100. if(memtype == NC_NAT) memtype=varp->type;
  4101. if(memtype == NC_CHAR && varp->type != NC_CHAR)
  4102. return NC_ECHAR;
  4103. else if(memtype != NC_CHAR && varp->type == NC_CHAR)
  4104. return NC_ECHAR;
  4105. /* If edges is NULL, then this was called from nc_get_var() */
  4106. if(edges == NULL && varp->ndims > 0) {
  4107. /* If this is a record variable, then we have to
  4108. substitute the number of records into dimension 0. */
  4109. if(varp->shape[0] == 0) {
  4110. (void*)memcpy((void*)modedges,(void*)varp->shape,
  4111. sizeof(size_t)*varp->ndims);
  4112. modedges[0] = NC_get_numrecs(ncp);
  4113. edges = modedges;
  4114. } else
  4115. edges = varp->shape;
  4116. }
  4117. status = NCcoordck(ncp, varp, start);
  4118. if(status != NC_NOERR)
  4119. return status;
  4120. status = NCedgeck(ncp, varp, start, edges);
  4121. if(status != NC_NOERR)
  4122. return status;
  4123. /* Get the size of the memtype */
  4124. memtypelen = nctypelen(memtype);
  4125. if(varp->ndims == 0) /* scalar variable */
  4126. {
  4127. return( readNCv(ncp, varp, start, 1, (void*)value, memtype) );
  4128. }
  4129. if(IS_RECVAR(varp))
  4130. {
  4131. if(*start + *edges > NC_get_numrecs(ncp))
  4132. return NC_EEDGE;
  4133. if(varp->ndims == 1 && ncp->recsize <= varp->len)
  4134. {
  4135. /* one dimensional && the only record variable */
  4136. return( readNCv(ncp, varp, start, *edges, (void*)value, memtype) );
  4137. }
  4138. }
  4139. /*
  4140. * find max contiguous
  4141. * and accumulate max count for a single io operation
  4142. */
  4143. ii = NCiocount(ncp, varp, edges, &iocount);
  4144. if(ii == -1)
  4145. {
  4146. return( readNCv(ncp, varp, start, iocount, (void*)value, memtype) );
  4147. }
  4148. assert(ii >= 0);
  4149. { /* inline */
  4150. ALLOC_ONSTACK(coord, size_t, varp->ndims);
  4151. ALLOC_ONSTACK(upper, size_t, varp->ndims);
  4152. const size_t index = ii;
  4153. /* copy in starting indices */
  4154. (void) memcpy(coord, start, varp->ndims * sizeof(size_t));
  4155. /* set up in maximum indices */
  4156. set_upper(upper, start, edges, &upper[varp->ndims]);
  4157. /* ripple counter */
  4158. while(*coord < *upper)
  4159. {
  4160. const int lstatus = readNCv(ncp, varp, coord, iocount, (void*)value, memtype);
  4161. if(lstatus != NC_NOERR)
  4162. {
  4163. if(lstatus != NC_ERANGE)
  4164. {
  4165. status = lstatus;
  4166. /* fatal for the loop */
  4167. break;
  4168. }
  4169. /* else NC_ERANGE, not fatal for the loop */
  4170. if(status == NC_NOERR)
  4171. status = lstatus;
  4172. }
  4173. value += (iocount * memtypelen);
  4174. odo1(start, upper, coord, &upper[index], &coord[index]);
  4175. }
  4176. FREE_ONSTACK(upper);
  4177. FREE_ONSTACK(coord);
  4178. } /* end inline */
  4179. return status;
  4180. }
  4181. int
  4182. NC3_put_vara(int ncid, int varid,
  4183. const size_t *start, const size_t *edges0,
  4184. const void *value0,
  4185. nc_type memtype)
  4186. {
  4187. int status = NC_NOERR;
  4188. NC *ncp;
  4189. NC_var *varp;
  4190. int ii;
  4191. size_t iocount;
  4192. size_t memtypelen;
  4193. char* value = (char*) value0; /* legally allow ptr arithmetic */
  4194. const size_t* edges = edges0; /* so we can modify for special cases */
  4195. size_t modedges[NC_MAX_VAR_DIMS];
  4196. status = NC_check_id(ncid, &ncp);
  4197. if(status != NC_NOERR)
  4198. return status;
  4199. if(NC_readonly(ncp))
  4200. return NC_EPERM;
  4201. if(NC_indef(ncp))
  4202. return NC_EINDEFINE;
  4203. varp = NC_lookupvar(ncp, varid);
  4204. if(varp == NULL)
  4205. return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */
  4206. if(memtype == NC_NAT) memtype=varp->type;
  4207. if(memtype == NC_CHAR && varp->type != NC_CHAR)
  4208. return NC_ECHAR;
  4209. else if(memtype != NC_CHAR && varp->type == NC_CHAR)
  4210. return NC_ECHAR;
  4211. /* Get the size of the memtype */
  4212. memtypelen = nctypelen(memtype);
  4213. /* If edges is NULL, then this was called from nc_get_var() */
  4214. if(edges == NULL && varp->ndims > 0) {
  4215. /* If this is a record variable, then we have to
  4216. substitute the number of records into dimension 0. */
  4217. if(varp->shape[0] == 0) {
  4218. (void*)memcpy((void*)modedges,(void*)varp->shape,
  4219. sizeof(size_t)*varp->ndims);
  4220. modedges[0] = NC_get_numrecs(ncp);
  4221. edges = modedges;
  4222. } else
  4223. edges = varp->shape;
  4224. }
  4225. status = NCcoordck(ncp, varp, start);
  4226. if(status != NC_NOERR)
  4227. return status;
  4228. status = NCedgeck(ncp, varp, start, edges);
  4229. if(status != NC_NOERR)
  4230. return status;
  4231. if(varp->ndims == 0) /* scalar variable */
  4232. {
  4233. return( writeNCv(ncp, varp, start, 1, (void*)value, memtype) );
  4234. }
  4235. if(IS_RECVAR(varp))
  4236. {
  4237. status = NCvnrecs(ncp, *start + *edges);
  4238. if(status != NC_NOERR)
  4239. return status;
  4240. if(varp->ndims == 1
  4241. && ncp->recsize <= varp->len)
  4242. {
  4243. /* one dimensional && the only record variable */
  4244. return( writeNCv(ncp, varp, start, *edges, (void*)value, memtype) );
  4245. }
  4246. }
  4247. /*
  4248. * find max contiguous
  4249. * and accumulate max count for a single io operation
  4250. */
  4251. ii = NCiocount(ncp, varp, edges, &iocount);
  4252. if(ii == -1)
  4253. {
  4254. return( writeNCv(ncp, varp, start, iocount, (void*)value, memtype) );
  4255. }
  4256. assert(ii >= 0);
  4257. { /* inline */
  4258. ALLOC_ONSTACK(coord, size_t, varp->ndims);
  4259. ALLOC_ONSTACK(upper, size_t, varp->ndims);
  4260. const size_t index = ii;
  4261. /* copy in starting indices */
  4262. (void) memcpy(coord, start, varp->ndims * sizeof(size_t));
  4263. /* set up in maximum indices */
  4264. set_upper(upper, start, edges, &upper[varp->ndims]);
  4265. /* ripple counter */
  4266. while(*coord < *upper)
  4267. {
  4268. const int lstatus = writeNCv(ncp, varp, coord, iocount, (void*)value, memtype);
  4269. if(lstatus != NC_NOERR)
  4270. {
  4271. if(lstatus != NC_ERANGE)
  4272. {
  4273. status = lstatus;
  4274. /* fatal for the loop */
  4275. break;
  4276. }
  4277. /* else NC_ERANGE, not fatal for the loop */
  4278. if(status == NC_NOERR)
  4279. status = lstatus;
  4280. }
  4281. value += (iocount * memtypelen);
  4282. odo1(start, upper, coord, &upper[index], &coord[index]);
  4283. }
  4284. FREE_ONSTACK(upper);
  4285. FREE_ONSTACK(coord);
  4286. } /* end inline */
  4287. return status;
  4288. }